Someone asked me to write a small tutorial about building a OpenStack Slackware image. Since I have to write the tutorial I may as well share it on LinuxQuestions.
Building a Slackware image for OpenStack is not different from building any other custom Linux image. A custom image must fulfill a set of requirements:
- The image must support KVM disk paravirtualization ( disks will be named /dev/vdX instead of /dev/sdX)
- After launching the image it is necessary to expand the filesystem in order to match the virtual disk.
- The boot log should be redirect to ttyS0 (serial port), that way is possible to analyze the boot log at runtime.
- The image must be able to retrieve metadata from OpenStack (ssh keys).
To build the custom image you need a machine virtualizer. I use QEMU to build my custom images (it is available in
slackbuilds.org). In the rest of the tutorial the specifics will be explained with QEMU.
After installing QEMU the fist thing you need to do is build a new virtual disk:
Code:
qemu-img create -f qcow2 slackCloud.qcow 10G
This command creates a qcow2 disk named "slackCloud.qcow" with 10 gigabytes.
QCOW2 is native format of QEMU and it is supported by OpenStack.
To begin the installation type:
Code:
qemu-system-x86 -m 1024 -cdrom image.iso -drive file=slackCloud.qcow,if=virtio,index=0 -boot d -net nic -net user
The command starts a virtual machine with 1 gigabyte of memory (-m 1024), 1 CPU (default option) and user mode networking (-net nic -net user).
The Virtual Machine (VM) disk is paravirtualization through
virtio.
To use virtio paravirtualization with qemu just type "-drive file=slackCloud.qcow,if=virtio,index=0", where slackCloud.qcow is the name of the disk.
Finally the system needs to boot from the installation media, in our example a ISO image.
The option "-cdrom image.iso" adds a cdrom drive, and the option "-boot d" makes qemu boot from the cdrom drive.
Do a normal installation, just remember the disk are named /dev/vdX instead of /dev/sdX.
After installing the system you reach the boot loader step. It is not possible to install LILO with the default configuration. You can just skip this step.
Before rebooting the VM it is necessary to tweak the system a little bit.
We are going to 'chroot' into our fresh installation:
Edit the "/etc/lilo.conf" file (or create a fresh one) and the following lines:
Code:
#Boot from virtio devices(/dev/vdX)
boot=/dev/vda
disk=/dev/vda bios=0x80 max-partitions=7
#Redirect boot log to ttyS0
serial=0,115200n8
append="console=tty0 console=ttyS0,115200n8"
To use a generic kernel it is necessary to generate a initrd (more information in
here).
Slackware ships a useful tool that outputs a the command to generate a initrd:
Code:
/usr/share/mkinitrd/mkinitrd_command_generator.sh
Copy the generated command, run it and add the initrd to the lilo configuration file.
After switching to the generic kernel, run "lilo" to install the boot loader.
OpenStack has a special metadata service that enables virtual machines to retrieve specific metadata.
VM access the metadata service through
http://169.254.169.254.
The VMs imports several configurations through metadata, the most important being SSH keys.
CloudInit is the Ubuntu package that handles early initialization of a VM.
I made a smaller script that fetches the root ssh key (rc.cloud).
Copy the script into the VM and add the following lines to
rc.local
Code:
if [ -x /etc/rc.d/rc.cloud ]; then
/etc/rc.d/rc.cloud start
fi
So now you have a shiny custom image ready for OpenStack.
You can compress the image with the following command:
Code:
qemu-img convert -p -c -O qcow2 disk.qcow new_disk.qcow