Tag Archives: virt-cat

Tip: extract a filesystem from a disk image

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
/dev/sda1 ext4
/dev/vg_f12x32/lv_root ext4
/dev/vg_f12x32/lv_swap swap
$ 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 /
total 15941
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-2.6.31.5-127.fc12.i686.PAE
-rw-r--r--.  1 root root   103788 Nov  7 21:38 config-2.6.31.5-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-2.6.31.5-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-2.6.31.5-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
#boot=/dev/sda
default=0
timeout=0
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.31.5-127.fc12.i686.PAE)
	root (hd0,0)
	kernel /vmlinuz-2.6.31.5-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
	initrd /initramfs-2.6.31.5-127.fc12.i686.PAE.img

><fs>

1 Comment

Filed under Uncategorized

Ubuntu 9.10 packages for libguestfs

By popular demand, I’ve built Ubuntu packages for the latest libguestfs, guestfish, virt-inspector, virt-cat and virt-df:

http://www.annexia.org/tmp/debian/

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.

2 Comments

Filed under Uncategorized

Tip: Get Windows version / service pack number

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]
Version=1.0

[Product Specification]
Product=Windows Server 2003, Enterprise Edition

Version=5.0
Localization=English
ServicePackNumber=0
BitVersion=40
[Version]
DriverVer=10/01/2002,5.2.3790.0

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.

3 Comments

Filed under Uncategorized

New tool: virt-ls

Want to list out the files in your virtual machine? Step forward virt-ls:

# virt-ls CentOS5x32 /
.autofsck
bin
boot
dev
etc
[...]
# virt-ls -R CentOS5x32 /etc/httpd
modules
conf
conf/httpd.conf
conf/magic
run
logs
conf.d
conf.d/welcome.conf
conf.d/README
conf.d/proxy_ajp.conf

See also: virt-cat, guestfish.

Do you want to suggest an addition to the virt-* tools family? Please comment here or let me know.

7 Comments

Filed under Uncategorized

Half-baked ideas: random root passwords for VMs

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.

4 Comments

Filed under Uncategorized

libguestfs: How to find out who is logged in to a virtual machine

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.

Leave a comment

Filed under Uncategorized