virt-builder: Installing cloud-init in a Debian 7 guest

The virt-builder templates that we ship just have core packages from each Linux distro. You can install more packages yourself using the --install option or by writing scripts.

Debian 7 doesn’t have cloud-init in the base distro, but it is in wheezy-backports so we have to write a short script that enables wheezy-backports and installs cloud-init from there:

set -e

# Install wheezy backports.
echo 'deb wheezy-backports main' \
  >> /etc/apt/sources.list
apt-get -y update

# Install cloud-init.
apt-get -y install cloud-init

Then we can run virt-builder, telling it to run the script during the build so that cloud-init will be available in the final image:

virt-builder debian-7 \
  --edit '/etc/inittab: s,^#([1-9].*respawn.*/sbin/getty.*),$1,' \

If you boot this guest, you will see cloud-init messages as it downloads the metadata and continues the customization.

(The complicated --edit option there is necessary to enable virtual consoles, so you can actually see messages being printed during boot. It will work without that option, but you won’t be able to see any messages.)


Leave a comment

Filed under Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.