Create a FreeBSD 9.0 machine image under Linux

This is a guide to building a virtual machine image for KVM that runs FreeBSD with virtio drivers installed.

Requirements:

Notes:

Commands and to be performed under Linux are shown in green.
Commands and file edits to be performed under the FreeBSD guest OS are shown in purple.

Create empty disk image (10GB):

  •  On your Linux host, run the command:
dd if=/dev/null of=freebsd-9_0.raw bs=1024 seek=10485760

Boot FreeBSD installer and install:

  • On your Linux host, run the command:
sudo kvm -vnc 0.0.0.0:54 -drive file=freebsd-9_0.raw,if=ide -net nic -net user -cdrom FreeBSD-9.0-RELEASE-amd64-disc1.iso
  • Connect to the guest OS using a VNC client pointed to port 5954. (5900 + 54 from command above.)
  • Step through the FreeBSD installer:
    • allocate the whole virtual drive to FreeBSD.
    • Configure networking to use IPv4 and DHCP.
  • Reboot the FreeBSD guest.

Install Virt IO drivers:

  • Download the binary package from http://people.freebsd.org/~kuriyama/virtio/
  • Install the package by running the command “pkg_add virtio-kmod-9-0.239473.tbz” in the guest OS.
  • Edit /boot/loader.conf to add the following lines:
virtio_load="YES"
virtio_pci_load="YES"
virtio_blk_load="YES"
if_vtnet_load="YES"
  • Edit /etc/fstab in the guest OS to change the device identifiers to “/dev/vtbd*“. (The following example shows the original device entries commented out followed by 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
  • Edit /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.):
hostname="freebsd-90"
ifconfig_re0="DHCP"
 ifconfig_vtnet0="DHCP"
sshd_enable="YES"
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="NO"
  • Power off the guest.
  • Relaunch using virtio for the virtual hard drive and virtual network adapter using the following KVM command:
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.

VirtIO in FreeBSD setup resources:

This entry was posted in operating systems, virtualization. Bookmark the permalink.

Leave a Reply