Note: This requires libguestfs ≥ 1.4
If files/ is a directory containing some files, you can create a new disk image populated with those files using the command below (virt-make-fs can also be used for this):
$ guestfish -N fs:ext2:400M -m /dev/sda1 tar-in <(tar -C files/ -cf - .) /
Explanation:
-
guestfish -N fs:ext2:400Mcreates a prepared disk image which is 400MB in size with a single partition formatted as ext2. The new disk image is calledtest1.img. -
-m /dev/sda1mounts the new filesystem when guestfish starts up. -
tar-in [...] /uploads and unpacks the tar file into the root directory of the mounted disk image. -
<(tar -C files/ -cf - .)is a bash process substitution which runs the tar command and supplies the output (ie. the tar file) as the input on the command line.
This is a quick way to create “appliances” using febootstrap and libguestfs, although you should note that I don’t think these appliances would really work, I just use them for testing our virtualization management tools, like the ability to detect and manage disk images:
$ febootstrap -i fedora-release -i bash -i setup -i coreutils fedora-13 f13
$ echo '/dev/sda1 / ext2 defaults 1 1' > fstab
$ febootstrap-install f13 fstab /etc 0644 root.root
$ febootstrap-minimize f13
$ guestfish -N fs:ext2:40M -m /dev/sda1 tar-in <(tar -C f13 -cf - .) /
$ guestfish --ro -i -a test1.img
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.
Type: 'help' for a list of commands
'man' to read the manual
'quit' to quit the shell
Operating system: Fedora release 13 (Goddard)
/dev/vda1 mounted on /
><fs> cat /etc/fstab
/dev/sda1 / ext2 defaults 1 1
