[PATCH 0/2] Add a 'virt-rescue' command
Inspired by something Glauber asked me about today, I made a very simple pair of patches which add a 'virt-rescue' command to libguestfs. This uses the appliance as a "rescue appliance", so people can boot into a disk image and repair it in an unstructured, interactive way. (Specifically, Glauber's question was how to run fsck interactively - with this patch you could do that). Example session: $ virt-rescue --ro /dev/vg_trick/F11x64 Welcome to virt-rescue, the libguestfs rescue shell. Note: The contents of / are the rescue appliance. You have to mount the guest's partitions under /sysroot before you will be able to examine them. bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell
<rescue> mount /dev/vg_f11x64/lv_root /sysroot EXT4-fs (dm-0): barriers enabled kjournald2 starting: pid 269, dev dm-0:8, commit interval 5 seconds EXT4-fs (dm-0): internal journal on dm-0:8 EXT4-fs (dm-0): delayed allocation enabled EXT4-fs: file extents enabled EXT4-fs: mballoc enabled EXT4-fs (dm-0): mounted filesystem with ordered data mode <rescue> ls /sysroot/ bin dev home lib64 media opt root selinux sys usr boot etc lib lost+found mnt proc sbin srv tmp var <rescue> exit
I'd really like to know how to get rid of that bash error message. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 75 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
There are actually going to be 3 patches in this series. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
-- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 75 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
Richard W.M. Jones wrote:
Subject: [PATCH 1/3] Tidy up appliance rescue code.
The appliance shouldn't run the daemon after we leave the rescue shell. It should just exit instead. --- appliance/init | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/appliance/init b/appliance/init index fe135b4..8b97590 100755 --- a/appliance/init +++ b/appliance/init @@ -61,7 +61,11 @@ lsmod # Improve virtio-blk performance (RHBZ#509383). for f in /sys/block/vd*/queue/rotational; do echo 1 > $f; done
-if grep -sq guestfs_rescue=1 /proc/cmdline; then - bash -i +if ! grep -sq guestfs_rescue=1 /proc/cmdline; then + exec guestfsd -f fi -exec guestfsd -f + +TERM=linux ;# XXX library should pass this from library's environment +PS1='><rescue> ' +export TERM PS1 +exec bash -i
Looks right. ACK
-- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
Richard W.M. Jones wrote:
Subject: [PATCH 2/3] Add direct appliance mode flag and implementation.
When the g->direct flag is set, the appliance stdin/stdout are not connected to the library. Instead they inherit the stdin/stdout of the caller.
THis looks fine. ACK ...
diff --git a/src/guestfs.c b/src/guestfs.c index 6eafcf5..03089ea 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -119,6 +119,7 @@ struct guestfs_h int verbose; int trace; int autosync; + int direct;
char *path; /* Path to kernel, initrd. */ char *qemu; /* Qemu binary. */ @@ -651,6 +652,19 @@ guestfs__get_trace (guestfs_h *g) return g->trace; }
+int +guestfs__set_direct (guestfs_h *g, int d) +{ + g->direct = !!d; + return 0; +} + +int +guestfs__get_direct (guestfs_h *g) +{ + return g->direct; +}
Probably of only marginal benefit (who has const guestfs_h* pointers?), but at least from its definition, you can see that this parameter can be "const".
-- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
Slightly updated patch, which just changes the documentation. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
Richard W.M. Jones wrote: ...
Subject: [PATCH 3/3] Add 'virt-rescue' command.
This command runs a "rescue appliance" against a virtual machine or disk image. This is useful for making ad-hoc interactive ... diff --git a/rescue/Makefile.am b/rescue/Makefile.am ... +if HAVE_RESCUE + +man_MANS = virt-rescue.1
I have a vague memory that recent automake generates better rules if you spell the above like this: dist_man1_MANS = virt-rescue.1
+noinst_DATA = @top_builddir@/html/virt-rescue.1.html
IMHO, it's better to avoid automake's obsolescent @VAR@ notation. Instead, use $(VAR). There's even a syntax-check rule for this, but it's currently disabled.
+virt-rescue.1: virt-rescue.pl + $(POD2MAN) \ + --section 1 \ + -c "Virtualization Support" \ + --release "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" \ + $< > $@
Don't redirect directly to $@, in case the command fails without removing the incomplete result. This idiom ensures that it is updated atomically: $< > $@-t && mv $@-t $@
+@top_builddir@/html/virt-rescue.1.html: virt-rescue.pl + mkdir -p @top_builddir@/html + cd @top_builddir@ && pod2html \ + --css 'pod.css' \ + --title 'virt-rescue, run a rescue shell on a virtual machine' \ + --htmldir html \ + --outfile html/virt-rescue.1.html \ + rescue/$< + +install-data-hook: + mkdir -p $(DESTDIR)$(bindir) + install -m 0755 virt-rescue.pl $(DESTDIR)$(bindir)/virt-rescue + +endif
diff --git a/rescue/run-rescue-locally b/rescue/run-rescue-locally ... +my $path = $0; + +# Follow symlinks until we get to the real file +while(-l $path) { + my $link = readlink($path);
You'll want to handle the case in which readlink fails and returns "undef".
+ if(File::Spec->file_name_is_absolute($link)) { + $path = $link; + } else { + $path = File::Spec->catfile(dirname($path), $link); + }
On Wed, Sep 23, 2009 at 12:36:34PM +0200, Jim Meyering wrote:
Richard W.M. Jones wrote:
+man_MANS = virt-rescue.1
I have a vague memory that recent automake generates better rules if you spell the above like this:
dist_man1_MANS = virt-rescue.1
I'm not sure if that would work with the older automakes. The other three things, I will submit as separate patches in a moment, since the same problems affect four other directories too. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
participants (2)
-
Jim Meyering -
Richard W.M. Jones