You’ve got a partitioned disk image, how do you pull out of that just the filesystem(s)? It’s easy with libguestfs tools:
$ virt-list-filesystems -al disk.img
$ virt-cat disk.img /dev/sda1 > boot.fs
$ file boot.fs
boot.fs: Linux rev 1.0 ext4 filesystem data (extents) (huge files)
$ virt-cat disk.img /dev/vg_f12x32/lv_root > root.fs
You can also use guestfish to examine the filesystem image:
$ guestfish -a boot.fs -m /dev/sda
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.
Type: 'help' for help with commands
'quit' to quit the shell
><fs> ll /
dr-xr-xr-x. 5 root root 1024 Mar 8 19:37 .
dr-xr-xr-x 19 root root 0 Mar 8 13:40 ..
-rw-r--r--. 1 root root 1486532 Nov 7 21:38 System.map-220.127.116.11-127.fc12.i686.PAE
-rw-r--r--. 1 root root 103788 Nov 7 21:38 config-18.104.22.168-127.fc12.i686.PAE
drwxr-xr-x. 3 root root 1024 Mar 8 19:12 efi
drwxr-xr-x. 2 root root 1024 Mar 8 19:49 grub
-rw-r--r--. 1 root root 11253019 Mar 8 19:39 initramfs-22.214.171.124-127.fc12.i686.PAE.img
drwx------. 2 root root 12288 Mar 8 18:45 lost+found
-rwxr-xr-x. 1 root root 3454368 Nov 7 21:38 vmlinuz-126.96.36.199-127.fc12.i686.PAE
><fs> cat /grub/grub.conf
# grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/vg_f12x32-lv_root
# initrd /initrd-[generic-]version.img
title Fedora (188.8.131.52-127.fc12.i686.PAE)
kernel /vmlinuz-184.108.40.206-127.fc12.i686.PAE ro root=/dev/mapper/vg_f12x32-lv_root LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=uk rhgb quiet
By popular demand, I’ve built Ubuntu packages for the latest libguestfs, guestfish, virt-inspector, virt-cat and virt-df:
These are experimental. If they break, you get to keep both pieces.
One point in particular is there is no Perl Sys::Virt package in Ubuntu, which means you have to supply this yourself, else virt-inspector etc. won’t work.
It’s easy with virt-cat:
$ virt-cat YourWinGuest /WINDOWS/system32/prodspec.ini
;Note to user: DO NOT ALTER OR DELETE THIS FILE.
[SMS Inventory Identification]
Product=Windows Server 2003, Enterprise Edition
There’s not much documentation about the “prodspec” file, except that we know it gets written after an install and after a service pack update.
From what I can tell,
BitVersion seems to be the level of encryption enabled (ie. 40 bit for export or 128 bit for US copies).
No news on whether this is a 32 or 64 bit version of Windows itself — the above is from a 32 bit version.
Want to list out the files in your virtual machine? Step forward virt-ls:
# virt-ls CentOS5x32 /
# virt-ls -R CentOS5x32 /etc/httpd
See also: virt-cat, guestfish.
Do you want to suggest an addition to the virt-* tools family? Please comment here or let me know.
For more half-baked ideas, see my “ideas” tag.
This is an easy idea to simplify Fedora installations.
When anaconda detects it is running inside a VM, instead of asking the user for a root password, it just creates a completely random root password. This password gets written to a local file during the install.
Now you can’t log into a VM easily if you don’t know the root password. But, you can read files out of the VM using virt-cat. So on the host there is a “ssh as root” script which grabs the random root password out of the guest and lets you log in without knowing or needing to know the root password.
This neat trick (with libguestfs 1.0.61) lets you see who is logged in to a Linux virtual machine:
# virt-cat CentOS5x32 /var/run/utmp > /tmp/utmp
# who /tmp/utmp
rjones :0 2009-07-09 11:00
rjones pts/1 2009-07-09 11:00 (:0.0)
or to find out who was logged in:
# virt-cat CentOS5x32 /var/log/wtmp > /tmp/wtmp
# last -f /tmp/wtmp
rjones pts/2 192.168.122.1 Tue Jul 14 14:22 - 15:28 (01:05)
rjones pts/2 192.168.122.1 Tue Jul 14 14:18 - 14:22 (00:03)
rjones pts/2 192.168.122.1 Fri Jul 10 12:28 - 12:44 (00:16)
rjones pts/2 192.168.122.1 Thu Jul 9 11:00 - 11:16 (00:15)
rjones pts/1 :0.0 Thu Jul 9 11:00 gone - no logout
rjones :0 Thu Jul 9 11:00 gone - no logout
virt-cat is a new tool we wrote, which doesn’t particularly do anything more than the existing guestfish ‘cat’ command, but is wrapped up in a way that makes it a bit easier to use.