Saturday, April 21, 2012

Running FreeNAS on a virtual machine

I prefer to have my physical servers bare, containing only the barest changes required to run virtual machines. Thus, when I need to migrate to a different hardware, its as simple as moving the VMs.

Usually, I only have the base server packages running with the packages needed to act as a virtual machine host. On linux systems, this translates to libvirt and related utilities. In addition, I also usually install hardware monitoring packages to check for overheating, etc.

The only config change I make are usually to make the network interface bridged:


# The loopback network interface
auto lo
iface lo inet loopback


# The primary network interface
auto br0
iface br0 inet dhcp
        bridge_ports eth0
        bridge_fd 9
        bridge_hello 2
        bridge_maxage 12
        bridge_stp off


So when I need to install FreeNAS, I wanted it to directly interact with the underlying disks yet the ability to simply ship my VM (and disks) to another server if desired. So I decided to install FreeNAS on a VM using qemu.

Here is how I finally got it working:

Your root filesystem where FreeNAS is installed should be ide. FreeNAS refuses to install on other types. You can get it to work on scsi by adding a boot option, but using ide is a lot simpler.

Once you install the system, you need to enable virtio for paravirtualized devices.


mount -uw /wget http://people.freebsd.org/~kuriyama/virtio/8.2/virtio-kmod-0.228301.tbzpkg_add virtio-kmod-0.228301.tbz > /tmp/out

/tmp/out contains instructions to enable virtio drivers. Essentially, change /boot/loader.conf to load virtio drivers and /etc/rc.conf and /etc/fstab to point to the virtualized device names.



You can then go to the admin console and setup the volumes. My ZIL partitions were only 2GB and it failed to create a zpool with zil. So I had to create a volume without a ZIL, ssh into the box and add it manually using:


zpool add log zfs_pool_name mirror vtbd1 vtbd2 


(Use actual names of the devices from the FreeNAS volume manager in place of vtbd1,vtbd2)


You can now use the admin GUI to perform the rest of the setup.




1 comment:

Michael said...

Huge help, thanks for the post.