Booting Ubuntu-12.04 cloud images without a cloud


I was recently asking myself why the P2V concept has not been more fully embraced by the open-source community – and generalized to V2C, virtual machine to cloud instance. From a scientific computing perspective, it would be ideal to seamlessly be able to prototype a data analysis in a virtual machine on a laptop and then run large-scale data processing on, say 50 copies of that same machine – in a cloud.

I know of Bitnami, TurnKey Linux and the now defunct rPath (where does that leave CernVM BTW?). They all allow the same kind of image to be deployed on virtual machines and “in the cloud”, but what I’d like to see is that the same image is run both places (modulo network configuration etc. of course). Moreover, these are all relatively small fish. Why is that?

Anyway, I’m drifting. My intention with this post was to document how to run an Ubuntu cloud image with KVM on a local machine (with local I just mean one I control).

After some amount of googling I was surprised not to be able to find any direct recipes. So here’s what I could put together from various sources [1-4] (I’m doing this on an Ubuntu 12.04 desktop):

First get the image and loop-back mount it:

modprobe nbd max_part=63
qemu-nbd -c /dev/nbd0 `pwd`/ubuntu-12.04-server-cloudimg-amd64-disk1.img
mkdir image
mount /dev/nbd0p1 image

Next, add the following kernel parameters: “init=/usr/lib/cloud-init/uncloud-init ubuntu-pass=ubuntu ds=nocloud”

e.g. by (you probably want to configure grub in a more official way by editing “/etc/default/grub” and running update-grub):

sed -ri ‘s|(/boot/vmlinuz-3.2.0-38-virtual root=LABEL=cloudimg-rootfs.*)$|\1 init=/usr/lib/cloud-init/uncloud-init ubuntu-pass=ubuntu ds=nocloud|’ image/boot/grub/grub.cfg


umount image
killall -9 qemu-nbd
modprobe -r nbd

and boot:

kvm -redir tcp:4022::22 ubuntu-12.04-server-cloudimg-amd64-disk1.img

You may also want to do away with a small nuisance with sudo. Make sure the top (IPv4) part of you “/etc/hosts” file looks like: localhost ubuntu ubuntu ubuntu.localdomain

assuming your “/etc/hostname” file reads


That’s it. A cloud image running on your desktop. Customize, 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>