From the Canyon Edge -- :-Dustin

Friday, July 2, 2010

Creating Ubuntu Server Disk Images using live-helper

I recently showed you how to create Ubuntu Server images using vmbuilder, but promised to also show how to use live-helper. Without further ado...


Start by installing live-helper.

sudo apt-get install live-helper

If you want a splash image for the boot loader, grab one. Here's an example

wget https://launchpadlibrarian.net/39290722/byobu_192.png

Next, we use lh_config with a lengthy set of options, to build:
  • disable apt recommends (keep the image small)
  • build 64 bit (for large memory instances)
  • enable main and universe
  • build a usb disk style image
  • append a few kernel options (like "toram" and "noprompt")
  • use the syslinux bootloader
  • build from ubuntu lucid
  • use the linux-image-server kernel
  • add a few packages (like "byobu" and "vim")
  • add your boot splash image
  • set the boot timeout to 2 seconds
  • use aufs
  • set the root disk size to 2GB

/usr/share/live-helper/helpers/lh_config \
--apt-recommends false \
--architecture amd64 \
--archive-areas "main universe" \
--binary-image usb-hdd \
--bootappend-live "toram persistent noprompt" \
--bootloader syslinux \
--distribution lucid \
--exposed-root true \
--initramfs casper \
--linux-flavours server \
--linux-packages linux-image \
--mode ubuntu \
--packages "byobu vim" \
--syslinux-timeout 2 \
--syslinux-splash ./byobu_192.png \
--union-filesystem aufs \
--virtual-root-size 2000

Configure any "local hooks". These are scripts of your design that can modify your image inside of the chroot.

cat >config/chroot_local-hooks/01-byobu.sh <<EOF
#!/bin/sh
ln -sf /usr/bin/byobu-launch /etc/profile.d/Z98-byobu.sh
EOF
chmod +x config/chroot_local-hooks/01-byobu.sh

Now, you can perform the build. This takes about 8 minutes for me on my laptop, with an SSD and local mirror.

sudo /usr/share/live-helper/helpers/lh_build
Finally, test your image. You can run it in KVM.

kvm -m 512 -hda binary.img
Alternatively, you could write this directly to a hard drive, as an install. Note that this will overwrite ALL data on that drive. Use with great care!!!

dd if=binary.img of=/dev/sda

Enjoy!
:-Dustin