Tag Archives: rescue shell

virt-rescue fixes

Although libguestfs gives you a nice structured library and tools for manipulating disk images, sometimes you just want to run a few Linux commands like mke2fs and fdisk against a disk image. For those times there is another tool called virt-rescue. It gives you a “rescue shell” connected to the disk image, and the usual set of command line Linux tools:

$ truncate -s 10G disk.img
$ virt-rescue -a disk.img
The virt-rescue escape key is ‘^]’.  Type ‘^] h’ for help.

------------------------------------------------------------

Welcome to virt-rescue, the libguestfs rescue shell.

Note: The contents of / (root) are the rescue appliance.
You have to mount the guest's partitions under /sysroot
before you can examine them.
><rescue> fdisk /dev/sda
...
><rescue> mke2fs /dev/sda1
><rescue> sync

Virt-rescue was a bit clumsy to use before because it didn’t (for example) pass Ctrl-C through to the rescue shell, so using that or other control keys would kill, stop or do other drastic things to the whole program.

I spent a bit of time last week fixing all of this, to make a really great, usable rescue shell.

The first thing is that ^C now works right:

><rescue> cat > /tmp/foo
^C
><rescue>

The second most requested feature is support for automatically mounting up the guest’s filesystems (rather than having to tediously type mount commands at the shell prompt). As with guestfish, the -i option now does the right thing:

$ virt-builder debian-7
$ virt-rescue -a debian-7.img -i
><rescue> chroot /sysroot
><rescue> cat /etc/debian_version
7.2

Finally virt-rescue now comes with an escape key which lets you suspend the shell and come back to it, and do some other interesting operations:

><rescue> ^]?
 ^] ? - print this message
 ^] h - print this message
 ^] i - print inspection data
 ^] q - quit virt-rescue
 ^] s - sync the filesystems
 ^] u - unmount filesystems
 ^] x - quit virt-rescue
 ^] z - suspend virt-rescue
to pass the escape key through to the rescue shell, type it twice
^]s
attempting to sync filesystems ...
^]z
[1]+  Stopped         virt-rescue -a debian-7.img -i
$

This is all available in libguestfs ≥ 1.37.1.

Leave a comment

Filed under Uncategorized