The operating systems used by virtual machine instances in Nimbula Director are packaged into a form known as a “machineimage”. Nimbula Director users and administrators may upload many machineimages to make the operating systems available in the Nimbula environment. This blog post details the necessary steps to build a FreeBSD machineimage using a Linux host with KVM to create the image.
- A Linux host with KVM installed and working. (This host will be used to construct the FreeBSD machineimage. No data on this host will be destroyed.)
- Download the FreeBSD 9.0 install disk from http://www.freebsd.org/where.html
- Download the virtio drivers for FreeBSD 9.0 from http://people.freebsd.org/~kuriyama/virtio/
In these instructions, commands to be run under Linux are shown in blue and commands to be run under the FreeBSD guest OS are shown in red.
Create an empty disk image (10GB)
The basis of a machineimage is a sparse file that is sized to the desired maximum size of the virtual hard drive. In these instructions we will use a 10GB maximum size. With a blocksize of 1024 bytes, a 10GB file consists of 10485760 blocks.
On your Linux host, run the following command to create the sparse file:
dd if=/dev/null of=freebsd-9_0.raw bs=1024 seek=10485760
Boot the FreeBSD installer and perform installation
Launch kvm to boot from the FreeBSD iso file with the sparse virtual hard drive file as the attached virtual hard drive.
On your Linux host, run the following command:
sudo kvm -vnc 0.0.0.0:55 -drive file=freebsd-9_0.raw,if=ide -net nic -net user -cdrom FreeBSD-9.0-RELEASE-amd64-disc1.iso
This will start up KVM exposing the virtual console via VNC port 5955 (vnc base of 5900 + 55 from kvm command).
Connect to the guest OS using a VNC client pointed to port 5955 on your Linux host. (The VNC client may also run on your Linux host.)
Step through the FreeBSD installer:
- Allocate the whole virtual drive to FreeBSD.
- Configure networking to use IPv4 and DHCP.
When the installer finishes, reboot the FreeBSD guest.
Install VirtIO drivers
KVM and Nimbula Director support virtualization-optimized device emulation for hard drives and network adapters known as “virtio”. This virtio device emulation provides significant performance gains over full device emulation. To use virtio, specific device drivers need to be installed in the guest OS.
Download the binary package of virtio drivers for FreeBSD 9.0 from http://people.freebsd.org/~kuriyama/virtio/. Copy the driver file to the guest OS.
Install the package by running the following command in the guest OS:
Configure the VirtIO drivers
/boot/loader.conf file to add the following lines:
/etc/fstab in the guest OS to change the device identifiers to
/dev/vtbd*. (The following example shows the original device entries commented out. The new entries in bold are the virtio entries.)
# Device Mountpoint FStype Options Dump Pass#
#/dev/ada0p2 / ufs rw 1 1
#/dev/ada0p3 none swap sw 0 0
/dev/vtbd0p2 / ufs rw 1 1
/dev/vtbd0p3 none swap sw 0 0
/etc/rc.conf in the guest OS to add the line shown in bold. (This line configures FreeBSD to use DHCP when bringing up the
vtnet0 network interface.):
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
Power off the guest.
Relaunch using virtio for the virtual hard drive and virtual network adapter using the following KVM command on your Linux host:
sudo kvm -vnc 0.0.0.0:54 -drive file=freebsd-9_0.raw,if=virtio -net nic,model=virtio -net user
Verify correct hard drive and network operation in the guest OS.
If the hard drive and network appear to be working correctly then power off the FreeBSD guest.
At this stage you have created a virtual hard drive image with a functioning FreeBSD installation that includes virtio support. The remaining step is to package up the hard drive image as a Nimbula Director machineimage.
Package the machineimage
Tar up the
freebsd-9_0.raw file to produce the Nimbula Director machine image using the following command on your Linux host:
tar zcvf freebsd-9_0.tar.gz freebsd-9_0.raw
FreeBSD virtio setup resources
The following resources were used to prepare these instructions: