guestmount and virt-inspector

I was asked on IRC what the purpose of the $(virt-inspector ...) clause is from the previous example:

$ guestmount $(virt-inspector --ro-fish /dev/vg_trick/Debian5x64) /tmp/rich

Firstly $(...) is the cool modern way to write shell `backquotes`. As well as being cool and modern, it’s also better than using backquotes because you can nest it.

What does the virt-inspector subcommand do? The output of the virt-inspector command is this, split into multiple lines just to make it easier to see:

--ro
-a /dev/vg_trick/Debian5x64
-m /dev/debian5x64/root:/
-m /dev/sda1:/boot
-m /dev/debian5x64/home:/home
-m /dev/debian5x64/tmp:/tmp
-m /dev/debian5x64/usr:/usr
-m /dev/debian5x64/var:/var

Just for comparison I want to run the guestfish commands list-partitions and lvs on the same virtual machine:

$ guestfish -a /dev/vg_trick/Debian5x64 \
    run : echo Partitions : list-partitions : echo Logical volumes : lvs
Partitions
/dev/sda1
/dev/sda2
Logical volumes
/dev/debian5x64/home
/dev/debian5x64/root
/dev/debian5x64/swap_1
/dev/debian5x64/tmp
/dev/debian5x64/usr
/dev/debian5x64/var

virt-inspector has used libguestfs to examine each mountable partition in the guest, has looked at /etc/fstab and other clues, and has decided on how the Debian guest, if running, would mount those partitions.

It then prints the guestfish-compatible -a and -m options to add the disk and mount the partitions up. guestmount uses a broadly compatible set of options, so it works too.

And finally I’d like to note that this also works well with libvirt domain names, so we could equally have written:

$ guestmount $(virt-inspector --ro-fish Debian5x64) /tmp/rich
About these ads

Leave a comment

Filed under Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s