Bundling FreeBSD Image for OpenStack
This article explains how to create a FreeBSD 8.2 image on KVM for uploading it to the image store on OpenStack Diablo. The procedure also covers installation of Virtio drivers, as it is essential for an instance running on OpenStack. I have used KVM running on Ubuntu 11.10 64-bit server for creation of the image.
The first step would be to create a qcow2 image. This will represent the main HDD of the virtual machine, so make sure to give it as much space as you will need
kvm-img create -f qcow2 freebsd.img 5G
Start the Virtual Machine and boot from the CD.
kvm -m 256 -cdrom FreeBSD-8.2-RELEASE-i386-disc1.iso -drive file=freebsd.img,if=scsi,index=0 -boot d -net nic -net user -nographic -vnc :1
Connect to the Virtual Machine through VNC (use display number :1) where 10.10.10.1 is the IP address of the host machine.
vncviewer 10.10.10.1 :1
During the post-installation configuration, enable SSH server. Also enable dhcp for the interface re0.
Shutdown the Virtual Machine and power it on to boot from the Hard Drive using the following command.
kvm -m 256 -drive file=freebsd.img,if=scsi,index=0,boot=on -boot c -net nic -net user -nographic -vnc :1
We need to install the Virtio driver for the image to work with OpenStack. For installing the Virtio driver perform the following steps.
Download the compressed snapshot of the ports collection.
Extract the snapshot into /usr/ports.
Download the kernel source using the following steps.
Select Configure -> Distributions which will give you many components that it can install. Select “src”. It will in turn show you some sub components. Select “sys”. Install the components. This will download the kernel source which is needed for the compiling the drivers.
In order to install the Virtio driver, we need to install Subversion and download the source for the driver.
cd /usr/ports/devel/subversion make install make clean cd /usr/src/sys/dev svn co http://svn.freebsd.org/base/projects/virtio/sys/dev/virtio cd /usr/src/sys/modules svn co http://svn.freebsd.org/base/projects/virtio/sys/modules/virtio cd /usr/src/sys/modules/virtio make make install
Add the following lines to /boot/loader.conf to load Virtio drivers on boot.
virtio_load="YES" virtio_pci_load="YES" virtio_blk_load="YES" if_vtnet_load="YES" virtio_balloon_load="YES"
Now the installation and configuration of the virtio driver is over. Make any other changes needed for the image.
Edit the file /etc/fstab to boot from the original drive with Virtio interface.
cp /etc/fstab /etc/fstab.bak cat /etc/fstab.bak | perl -pe "s/da/vtbd/g;" > /etc/fstab
SSH access for root and password authentication is disabled by default. Edit /etc/ssh/sshd_config to enable these.
PermitRootLogin yes PasswordAuthentication yes
TODO: key injection
Shutdown the Virtual Machine and upload the image to OpenStack using the following command.
cloud-publish-image amd64 freebsd.img freebsdbucket
The following output shows that the image has been successfully uploaded.
Verify whether the instance boots from the uploaded image.
euca-run-instances ami-00000001 -t m1.tiny