Feature #403
Updated by Daniel Curtis over 10 years ago
Now that I have most of my web-based servers switched over to FreeBSD using the popular open source FreeNAS variant of FreeBSD. FreeNAS supports Jails, which are lightweight para-virtualized environments, that allows for numerous separate servers to live on a single machine, utilizing the same kernel. I need a full virtualization solution however, this is where VirtualBox comes in. Until recently FreeNAS would fail to load VirtualBox inside of a Jail, due to the lack of a kernel module. This problem was "reported to be resolved":https://bugs.freenas.org/issues/1974 by adding a few System Tunables to the FreeNAS installation to enable the required kernel modules. h2. Add the required kernel modules to FreeNAS * *Copy the kernel modules to FreeNAS* I used scp to copy the kernel modules to FreeNAS. According to the discussions going on, the kernel modules can be built in a jail by downloading the kernel sources and compiling the VirtualBox kernel modules and then copying the kernel modules to the core of FreeNAS. Luckily, one developer compiled the VirtualBox 4.3.6 kernel modules for FreeNAS 9.2.1; which I have included. Once the kernel modules have been transferred to a place that FreeNAS can access them, log into the admin panel and open a shell. * *Add the kernel modules to FreeNAS <pre> cd /path/to/modules mount -uw / cp *.ko /boot/kernel/ mount -r / </pre> * *Enable the kernel modules* To enable these module immediately: <pre> kldload vboxdrv kldload vboxnetflt kldload vboxnetadp </pre> NOTE: This can be verified by running kldstat, and checking if the kernel modules loaded correctly. To enable these modules at boot time, log in to the FreeNAS admin panel and go to +System -> Tunables -> Add Tunable+ and add the following three Tunables: * Variable: *ng_ether_load* Value: *YES* * Variable: *ng_gif_load* Value: *YES* * Variable: *vboxdrv_load* Value: *YES* * Variable: *vboxnetflt_load* Value: *YES* * Variable: *vboxnetadp_load* Value: *YES* That's it! h2. Create a new Jail for the VirtualBox Host Now create a Jail by going to +Jails -> Add Jail+, and configure the Jail accordingly. I chose to use a *Standard* Jail Type in order to stick to the barest possible FreeBSD installation. Once the Jail is finished installing, open the VirtualBox Jail shell and enable and start SSH, create new root SSH key, set root password, add a new privileged user and then close the web shell. I won't go into detail on how to do this, since it is cover in Issue #329 * When the initial configuration is done, log into the jail using ssh: <pre> ssh user@examplejail.com </pre> * Update the Jails packages and ports tree: <pre> pkg upgrade && portsnap fetch extract </pre> Add a standard user for VirtualBox to be ran as <pre> adduser bob Bob [Enter] [Enter] [Enter] [Enter] [Enter] [Enter] [Enter] [Enter] [Enter] [Enter] SuperSecretPassword SuperSecretPassword [Enter] yes no </pre> * Now install VirtualBox <pre> pkg install virtualbox-ose </pre> * Add the standard user to the VirtualBox Users group <pre> pw groupmod vboxusers -m bob </pre> * Enable Network Bridging Support <pre> echo 'vboxnet_enable="YES"' >> /etc/rc.conf </pre> Now at this point, log back into FreeNAS and reboot it. h2. Create the VirtualBox VM Since this is a headless (No GUI) installation, the VirtualBox machine must be created from the command line. * *Create a Windows 7 64-bit machine* <pre> VBoxManage createvm --name "Windows 7" --register VBoxManage modifyvm "Windows 7" --ostype Windows7_64 --memory 2048 --ioapic on --pae on --hwvirtex on VBoxManage modifyvm "Windows 7" --nic1 bridged --bridgeadapter1 epair0b </pre> NOTE: I needed to use the interface provided to the jail, which can be found using @ifconfig@. * *Create the Virtual hard drive* <pre> VBoxManage createhd --filename /home/user/VirtualBox\ VMs/Billing\ VM/virtualmachine-disk1.vmdk --size 10000 </pre> * *(Optional) Use a virtual hard drive from a .ova file* I had a snag trying to import an OVA directly, luckily .ova files are just simple tar archives and can be extracted like so: <pre> tar xvf /path/to/virtualmachine.ova </pre> Once the OVA has been extracted, there will be a few files: # virtualmachine.ovf - The virtualmachine manifest file # virtualmachine-disk1.vmdk - The virtualmachine hard drive # virtualmachine.mf - A file containing the SHA1 checksums of the above two files The virtual hard drive can be moved to the VirtualBox machine folder <pre> mv /path/to/virtualmachine-disk1.vmdk /home/user/VirtualBox\ VMs/Billing\ VM/ </pre> * *Attach the Virtual hard drive to the Windows 7 host* <pre> VBoxManage storagectl "Windows 7" --name "IDE Controller" --add ide VBoxManage storageattach "Windows 7" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /home/user/VirtualBox\ VMs/Billing\ VM/virtualmachine-disk1.vmdk </pre> h2. Resources * https://bugs.freenas.org/issues/1974