libguestfs – fun with tar

I’ve added tar support to libguestfs. Two examples:

Extract a directory subtree

This pulls out /usr/share/doc from the guest and saves it as a local file called /tmp/doc.tar.gz:

$ guestfish -a guest.img -m /dev/VolGroup00/LogVol00 

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> tgz-out /usr/share/doc /tmp/doc.tar.gz

Convert a tarball to an ext3 filesystem

$ cat /tmp/tar2ext3.sh
#!/bin/sh -
if [ $# -ne 2 ]; then
    echo "tar2ext3 input.tgz output.img"; exit 1
fi
guestfish <<EOF
alloc $2 100M
run
sfdisk /dev/sda 0 0 0 ,
mkfs ext3 /dev/sda1
mount /dev/sda1 /
tgz-in $1 /
sync
EOF
$ /tmp/tar2ext3.sh libguestfs-1.0.2.tar.gz test.img
$ ll test.img
-rw-rw-r--. 1 rjones rjones 104857600 2009-04-20 15:49 test.img

Now test.img contains all those files, inside an ext3 filesystem.

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