Sunday, June 27, 2010

Creating Ubuntu Server Disk Images using vmbuilder

From time to time, I need to precisely replicate an Ubuntu Server installation over and over again. If my testing requires turning the installation crank, preseeding can certainly help automate that. But Ubuntu Server installations on ext4 have slowed down dramatically due to an ext4/dpkg/fsync bug.

In any case, there are at least 2 different ways of creating bootable Ubuntu Server disk images, which can be written directly to a hard drive using dd.
  1. vmbuilder
  2. live-helper
This post shows how to do so using vmbuilder. I'll explore live-helper in a subsequent post (as I'm just now learning that utility).

Create a minimal image (without recommended packages), ~20min:
sudo vmbuilder kvm ubuntu --arch 'amd64'  --rootsize '4096' \
--kernel-flavour 'server' --components 'main,universe' \
--addpkg eucalyptus-nc --user 'ubuntu' --pass 'ubuntu' \
-v --debug
N.B. The most important option above, for the sake of this tutorial, is --kernel-flavour 'server'. By default, vmbuilder includes the linux-image-virtual kernel, which lacks some drivers necessary for booting and running from real hardware. vmbuilder supports many options which are not documented in the manpage:
vmbuilder kvm ubuntu --help
Convert the qcow2 to raw, ~4sec:
qemu-img convert -O raw *.qcow2 disk.raw

Optionally, compress the image for transfer over the network, ~90sec:
lzma disk.raw

Finally, decompress it and write it directly to disk. For this step, I often use an Ubuntu Desktop liveCD, and change to the root user.
sudo -s
lzma -dc disk.raw.lzma > /dev/sda
And now, you should be able to boot and run from /dev/sda.

:-Dustin

photo © MIROSLAV VAJDIƄ†
from
openphoto.net CC:Attribution-ShareAlike

1 comment:

  1. nice tutorial. Thansk! But can i set the keyboard layout? I start the vm with ./run.sh but then i have the english keyboard layout but i have a german keyboard.
    i tried to edit the run.sh scipt and added "-k de" to the kvm command, but that does not help. any ideas?

    ReplyDelete

Please do not use blog comments for support requests! Blog comments do not scale well to this effect.

Instead, please use Launchpad for Bugs and StackExchange for Questions.
* bugs.launchpad.net
* stackexchange.com

Thanks,
:-Dustin