Install FreeBSD 8.1 as a Virtual Machine in KVM on Ubuntu 10.10

Install KVM and libvirt:

sudo apt-get install kvm virtinst libvirt-bin

If you also want the graphical helpers (viewer via vnc and a manager of the installed virtual machines) install:

sudo apt-get install virt-viewer virt-manager

Now set up the connection to the local KVM hypervisor:

sudo virsh connect qemu:///system

Get the installation DVD (for amd64):

sudo mkdir -p /var/kvm/cd-images
sudo mkdir -p /var/kvm/installation-disks
cd /kvm/cd-images
gunzip FreeBSD-8.1-RELEASE-amd64-dvd1.iso.gz

You can use the graphical user interface virt-manager to set up the system or do it on the command line:

sudo virt-install \
--name freebsd \
--ram 512 \
--vcpus=1 \
--os-type unix \
--hvm \
--cdrom=/var/kvm/cd-images/FreeBSD-8.1-RELEASE-amd64-dvd1.iso \
--network=bridge:br0,model=ne2k_pci,mac=00:00:00:00:00:07 \
--vnc \
--disk path=/var/kvm/installation-disks/freebsd8.1.img,size=12

Explanation of the parameters:

  • --name sets the name for the virtual machine
  • --ram specifies how much ram you want to assign to the new virtual machine
  • --vcpus sets the number of available virtual cpu cores
  • --os-type specifies the type of guest os for the new vm (freebsd is a unix)
  • --hvm tells libvirt (virsh) to create the vm with software virtualization
  • --cdrom specifies the ISO image to install from
  • --network
    The network is set up using the bridge br0. The virtual network interface is set to the model ne2k_pci which is OK for FreeBSD (for a list of all supported models runqemu -net nic,model=? /dev/null)
  • --vnc will make the virtual machine start a vnc server to access its display using virt-viewer -n vmname
  • --disk is the specifiaction of the hard disk image file to install to (size=12 lets the command create a 12 GiB image)

Now continue the installation on the VNC viewer using virt-viewer -n freebsd.

Start the virtual machine using:

sudo virsh start freebsd

If it does not shut down properly itself (and it doesn't at this time due to a bug in seabios, see this ), you might have to force a shutdown ("cut power"):

sudo virsh destroy freebsd

If you are annoyed by virt-viewer capturing (and not releasing) your mouse pointer, then you might want to connect using a virtual terminal. To set it up, execute the following commands on the FreeBSD host as described in the manual:

echo 'console="comconsole"' >> /boot/loader.conf

And then change in /etc/ttys the line ttyu0 "/usr/libexec/getty std.9600" dialup off secure to ttyu0 "/usr/libexec/getty std.9600" vt100 on secure.

To list all virtual machines:

virsh list --all
## or
sudo virsh --connect qemu:///system list --all