Wednesday, April 25, 2012

Installing FreeNAS using virt-install

A simple way to install FreeNAS on a VM is to use virt-install. I had to add a sata controller since I have more than 4 drives:


virt-install -nFreeNAS -r 6144 --vcpus=2 --autostart --os-variant=freebsd7 --accelerate --network bridge=br0,model=rtl8139 --disk path=/mnt/img/FreeNAS.img --disk path=/dev/sda2,bus=sata --disk path=/dev/sdb2,bus=sata --disk path=/dev/sdb1,bus=sata -c /mnt/img/FreeNAS8.2.0B3.iso --vnc --controller sata

Note: I ended up not using the FreeNAS on a VM because attaching the host partitions to the VM ended up giving terrible performance on disk IO. This was true for both UFS and ZFS on fully or paravirtualized drivers.

Abandoning this approach and having the host manage its own disks greatly improved performance and am very happy with it. For every compartmentalized task such as media servers I'm still using a VM with the filesystem from the host mounted over NFS.

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.