Booting Ubuntu-14.04 cloud images without a cloud


So, Ubuntu-14.04, Trusty Tahr, is out; and booting the cloud images requires a bit more hacking than booting the 12.04 cloud images. Here goes:

Get the image, resize and loop-back mount it:

qemu-img convert -c -O qcow2 trusty-server-cloudimg-amd64-disk1.img trusty-server-cloudimg-amd64-disk1_30GB.qcow2
qemu-img resize trusty-server-cloudimg-amd64-disk1_30GB.qcow2 30G
sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd0 `pwd`/trusty-server-cloudimg-amd64-disk1_30GB.qcow2
ls image || mkdir image
sudo mount /dev/nbd0p1 image

Tell the system it’s not booting in a cloud:

sudo sed -ri 's|(/boot/vmlinuz-3.13.0-24-generic\s*root=LABEL=cloudimg-rootfs.*)$|\1 ds=nocloud|' image/boot/grub/grub.cfg

sudo sed -ri 's|^(GRUB_CMDLINE_LINUX_DEFAULT=).*$|\1" ds=nocloud"|' image/etc/default/grub

sudo sed -ri 's|^#(GRUB_TERMINAL=console)$|\1|' image/etc/default/grub

sudo mkdir -p image/var/lib/cloud/seed/nocloud

sudo tee image/var/lib/cloud/seed/nocloud/meta-data <<EOF
instance-id: ubuntu
local-hostname: ubuntu

sudo tee image/var/lib/cloud/seed/nocloud/user-data <<EOF
password: ubuntu
chpasswd: { expire: False }
ssh_pwauth: True

sudo sed -ri "s|^(\s*localhost)$|\1\n127.0.0.1 `cat image/etc/hostname`|" image/etc/hosts


sudo sync
sudo umount image
sudo qemu-nbd -d /dev/nbd0
sudo modprobe -r nbd

Boot and customize (log in with username/password ubuntu/ubuntu):

kvm -redir tcp:4022::22 trusty-server-cloudimg-amd64-disk1_30GB.qcow2

Upload and run in a cloud.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>