Here’s how I create an OpenStack disk image. Everyone has their
own tweaks here; the most unusual thing
I do is that I don’t use cloud-init, because I don’t want to rely on
DHCP; I use OpenStack’s ‘configuration drive’ instead. I think that
cloud-init has support for config-drive in its very latest versions,
so I may revisit this in future.
A few comments:
I think that Grub is crazily complicated, requiring too many UUIDs to match up with
each other; I use extlinux instread.
# Sadly, most of this needs to be done as root..sudo bash
# Choose your image OSOS=squeeze
KERNEL=linux-image-2.6-amd64
# Create a (sparse) 8 gig imagedd if=/dev/null bs=1M seek=8192of=disk.raw
#Create partitionsparted -s disk.raw mklabel msdos
parted -s disk.raw mkpart primary 0% 100%
parted -s disk.raw set 1 boot on
# Install Master Boot Recordinstall-mbr disk.raw
# Mount the partitionsmodprobe dm_mod
kpartx -av disk.raw
# Hopefully it’s loop0p1..LOOPBACK_PARTITION=/dev/mapper/loop0p1
# Format filesystemyes | mkfs.ext4 ${LOOPBACK_PARTITION}# Don’t force a check based on datestune2fs -i 0 /dev/mapper/loop0p1
# Mount the disk imagemkdir mnt
mount ${LOOPBACK_PARTITION} mnt/
# Create root partition using debootstraphttp_proxy="http://127.0.0.1:3142" debootstrap \ --include=openssh-server,${KERNEL}${OS} mnt/
# Prepare for chrootmount -t proc proc mnt/proc/
# Use chroot to fix up a few things (locales, mostly)chroot mnt/ apt-get update
chroot mnt/ apt-get install locales
chroot mnt/ locale-gen en_US.utf8
chroot mnt/ /bin/bash -c "DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales"# Finishing the imagechroot mnt/ apt-get upgrade
chroot mnt/ apt-get clean
# Remove persistent device names so that eth0 comes up as eth0rm mnt/etc/udev/rules.d/70-persistent-net.rules
I highly recommend using config drive. There’s a little init script
I contributed which can apply the network configuration from the config drive,
located in contrib/openstack-config in the source tree of nova.
# Sync and unmount (with paranoid levels of sync-ing)sync; sleep 2; sync
umount mnt/proc
umount mnt/
sync
kpartx -d disk.raw
sync
# Convert to qcow2 (which means that the raw image size isn’t too important)rm disk.qcow2
qemu-img convert -f raw -O qcow2 disk.raw disk.qcow2
Upload the image into glance
12345678910111213
# We don't need to be root any more...exitRAW_SIZE=`cat disk.qcow2 | wc -c`echo"RAW_SIZE=${RAW_SIZE}"# Change these parameters to the correct valuesexport OS_AUTH_USER=`whoami`export OS_AUTH_KEY="secret"export OS_TENANT_NAME=privatecloud
export OS_AUTH_URL=http://192.168.191.1:5000/v2.0/
glance add name=DebianSqueeze is_public=True disk_format=qcow2 container_format=bare image_size="${RAW_SIZE}" < disk.qcow2