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

3 comments:

  1. Incredibly useful! Thanks, Dustin.

    ReplyDelete
  2. Hi Dustin,

    Apologies in advanced for posting this question here. You can definitely delete it after a few days have passed by.
    I have decided to contact you because you seem to be a guru of Ubuntu, and -having read a previous post of you on the matter- I figured you could probably provide me with sensible answers.
    Im not totally sure what happened last night on my Lucid, but somehow my gnome-power-manager broke-down, which meant I couldn't access the X-server.
    I read a few pages of documentation through my Windows partition, but unfortunately nothing that was being said there solved my problem.
    After a few hours of fiddling-around, I decided to reinstall an image, under a different username, with the idea to later copy the contents of home to my new home (as I dont want to have to re-do the whole look of the gnome environment).
    But to my surprise (I didnt know this was happening until now), I realised that ubuntu has encrypted my content automatically, so that when I logged in under my new username I cannot access my previous home folder.
    I read a bit about it and it says its been done through ecrypts, so I got in the process of manually mounting it to /home/myprevioususername/Private but it doesnt let me do it. Heres why:
    if I use ecryptfs-add-passphrase --fnek and then
    sudo ecryptfs-mount-private /home/myprevioususername/.Private /home/myprevioususername/Private

    I enter the login passphrase (when I first installed Lucid I remember getting a demand for a passphrase -I thought it was supposed to be the same as the login password so I duplicated it) and then it says
    "insterted auto tok with sig [digits&letters] into the user session keyring", and then
    "fopen: no such file or directory"

    ugh!

    I also tried the option
    sudo mount -t ecryptfs /home/previoususername/.Private /home/prev.../Private
    I go through the options and then it says
    "error mounting eCryptfs: [-2] No such file or directory"
    same error?

    Am I doing somethign wrong? Can I recover the data from my old username home folder?

    Thanks a mil!
    Regards,
    Alberto

    ReplyDelete
  3. Oh, I just read your notice on Launchpad. Will move my enquiry there.

    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