Build a basic KVM guest on:
o 192.168.122.100/24
o 192.168.122.1 - default-gw
o 4GB RAM
o 100GB disk partition
o ubuntu Lucid

root@kvm:~# vmbuilder kvm ubuntu --suite=lucid --flavour=virtual --arch=amd64 --mirror=http://us.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --dest /data/vm/test-vm1/image --ip=192.168.122.101 --gw=192.168.122.1 --part=/data/vm/test-vm1/vmbuilder.partition --templates /home/morrowc/kvm/templates/mytemplates --user=USERNAME --name=’COMMENT’ --pass=PASSWD --addpkg=vim-nox --addpkg=unattended-upgrades --mem=4096 --hostname=test-vm1 --bridge=virbr0
2011-07-10 21:32:39,630 INFO : Calling hook: preflight_check
2011-07-10 21:32:39,633 INFO : Calling hook: set_defaults
2011-07-10 21:32:39,633 INFO : Calling hook: bootstrap
2011-07-10 21:42:36,456 INFO : Calling hook: configure_os
2011-07-10 21:44:54,116 INFO : update-rc.d: warning: unattended-upgrades start runlevel arguments (none) do not match LSB Default-Start values (0 6)
2011-07-10 21:44:54,117 INFO : update-rc.d: warning: unattended-upgrades stop runlevel arguments (0 6) do not match LSB Default-Stop values (none)
2011-07-10 21:45:04,989 INFO :
2011-07-10 21:45:04,990 INFO : Current default time zone: ‘Etc/UTC’
2011-07-10 21:45:04,992 INFO : Local time is now:  Mon Jul 11 01:45:04 UTC 2011.
2011-07-10 21:45:04,992 INFO : Universal Time is now:  Mon Jul 11 01:45:04 UTC 2011. vmbuilder kvm ubuntu --suite=lucid --flavour=virtual --arch=amd64 --mirror=http://us.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --dest /data/vm/test-vm1/image --ip=192.168.122.101 --gw=192.168.122.1 --part=/data/vm/test-vm1/vmbuilder.partition --templates /home/morrowc/kvm/templates/mytemplates --user=morrowc --name=’Chris Morrow’ --pass=S3cr3t! --addpkg=vim-nox --addpkg=unattended-upgrades --mem=4096 --hostname=test-vm1 --bridge=virbr0
2011-07-10 21:45:04,992 INFO :
Extracting templates from packages: 100%
2011-07-10 21:46:46,416 INFO :
2011-07-10 21:46:46,416 INFO : Current default time zone: ‘Etc/UTC’
2011-07-10 21:46:46,418 INFO : Local time is now:  Mon Jul 11 01:46:46 UTC 2011.
2011-07-10 21:46:46,419 INFO : Universal Time is now:  Mon Jul 11 01:46:46 UTC 2011.
2011-07-10 21:46:46,419 INFO : Run ‘dpkg-reconfigure tzdata’ if you wish to change it.
2011-07-10 21:46:46,419 INFO :
2011-07-10 21:54:56,513 INFO : start: Unknown parameter: JOB
2011-07-10 21:55:04,580 INFO : Calling hook: post_install
2011-07-10 21:55:04,582 ERROR : Partitions are overlapping
Traceback (most recent call last):
File “/usr/bin/vmbuilder”, line 24, in
cli.main()
File “/usr/lib/python2.6/dist-packages/VMBuilder/contrib/cli.py”, line 116, in main
self.set_disk_layout(hypervisor)
File “/usr/lib/python2.6/dist-packages/VMBuilder/contrib/cli.py”, line 255, in set_disk_layout
self.do_disk(hypervisor, curdisk, size)
File “/usr/lib/python2.6/dist-packages/VMBuilder/contrib/cli.py”, line 270, in do_disk
disk.add_part(offset, int(pair[1]), pair[0], pair[0])
File “/usr/lib/python2.6/dist-packages/VMBuilder/disk.py”, line 214, in add_part
raise VMBuilderUserError(’Partitions are overlapping’) --addpkg=vim-nox --addpkg=unattended-upgrades --mem=4096 --hostname=test-vm1 --bridge=virbr0
2011-07-10 21:32:39,630 INFO : Calling
VMBuilder.exception.VMBuilderUserError: Partitions are overlapping
root@kvm:~#

It looks like correcting the cmdline to something like:


vmbuilder kvm ubuntu --suite=lucid --flavour=virtual --arch=amd64 \
--mirror=http://us.archive.ubuntu.com/ubuntu -o \
--libvirt=qemu:///system --dest /data/vm/test-vm1 \
--ip=192.168.122.101 --gw=192.168.122.1 \
--rootsize=100000 \
--user=USERNAME --name=’COMMENT’ --pass=PASSWD \
--addpkg=vim-nox --addpkg=unattended-upgrades \
--addpkg=openssh-server --firstboot=/home/morrowc/first-boot.sh \
--mem=4096 --hostname=test-vm1 --bridge=virbr0 \
--domain=ops-netman.net --cpus=2

Note:
The dest directory has to exist
zero swapfile fails (and is a known bug)

If you need to edit files on the VM before it can boot, you can follow these quick steps:
o load nbd module

sudo modprobe nbd max_part=8

o attach the qcow2 image to the nbd device

sudo qemu-nbd --connect=/dev/nbd0 file.qcow2

o mount the partition

mount /dev/nbd0p1 /mnt/kvm

o unmount when done


umount /mnt/kvm
nbd-client -d /dev/nbd0