[Libguestfs] Suggestions on building VM disks from scratch

Richard W.M. Jones rjones at redhat.com
Wed Apr 4 08:45:18 UTC 2012


> Then I created my blank 'disk' file and tried to
> run virt-rescue on it. It crashed out with an 
> error from febootstrap.

First of all, debug this properly:

(1) What is the full error message?

(2) What is the complete, unedited output of 'libguestfs-test-tool'?

(3) What version of libguestfs & febootstrap are using and where did
you get them from?

You can post the details on our mailing list libguestfs at redhat.com
(no need to subscribe if you don't want to).

> After finding nothing terribly
> useful or current on this in searching, I tried
> guestfish instead. After some fiddling I got it
> to attach my blank disk. However I cannot find a
> reasonable way to partition it with the part-add which
> seems to want me to count sectors. All I want is
> a 9G linux and a 2G swap.

Assuming the filesystem was in /tmp/root.tar.gz, the following code
will do this:

  guestfish <<EOF

  sparse /tmp/test.img 11G
  run

  part-init /dev/sda mbr
  # 9GB sda1
  part-add /dev/sda p 64 $(( 9*1024*1024*2 ))
  # remainder in sda2
  part-add /dev/sda p $(( 9*1024*1024*2 + 1 )) -64

  mkfs ext4 /dev/sda1
  mkswap /dev/sda2

  mount /dev/sda1 /
  tgz-in /tmp/root.tar.gz /

  EOF

Example:

  $ sh test.sh 
  $ virt-df -a test.img -h
  Filesystem                                Size       Used  Available  Use%
  test.img:/dev/sda1                        9.0G       276M       8.3G    4%
  $ ll -h test.img 
  -rw-rw-r--. 1 rjones rjones 11G Apr  4 09:39 test.img

Whether this would actually boot is another question: you may also
need to add some grub commands to set up the bootloader, *or* (better
and easier IMHO) set up libvirt so that it boots from an external
kernel + initrd.

> It also lacks access to rsync.

It's not the first time that someone has asked for rsync, and it
wouldn't be too hard to add.  However note that rsync really gives you
no benefit when you're creating a filesystem from scratch, because
there's no original to rsync against.  If you are updating a
filesystem image then rsync makes sense.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org




More information about the Libguestfs mailing list