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

1
kvm-img create -f qcow2 freebsd.img 5G

Start the Virtual Machine and boot from the CD.

1
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.

1
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.

1
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.

1
portsnap fetch

Extract the snapshot into /usr/ports.

1
portsnap extract

Download the kernel source using the following steps.

1
sysinstall

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.

1
2
3
4
5
6
7
8
9
10
cd /usr/ports/devel/subversion
make install
make clean
cd /usr/src/sys/dev
cd /usr/src/sys/modules
cd /usr/src/sys/modules/virtio
make
make install

Add the following lines to /boot/loader.conf to load Virtio drivers on boot.

1
2
3
4
5
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.

1
2
cp /etc/fstab /etc/fstab.service-labs.com
cat /etc/fstab.service-labs.com | 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.

1
2
PermitRootLogin yes
PasswordAuthentication yes

TODO: key injection

Shutdown the Virtual Machine and upload the image to OpenStack using the following command.

1
cloud-publish-image amd64 freebsd.img freebsdbucket

The following output shows that the image has been successfully uploaded.

1
ami-00000001 freebsdbucket/freebsd.img.manifest.xml

Verify whether the instance boots from the uploaded image.

1
euca-run-instances ami-00000001 -t m1.tiny

References:
http://viktorpetersson.com/2011/10/20/how-to-use-virtio-on-freebsd-8-2/
http://www.cyberciti.biz/faq/freebsd-install-kernel-source-code/

原文链接:,转发请注明来源!

发表评论