Getting A Windows VM With Physical Disks Under FreeBSD

I recently decided to migrate away from Windows and onto FreeBSD, to make the transition smoother I created a dual boot environment (via the BIOS boot menu) with 2 drives which think they are the primary in the different boot scenarios. I still wanted access to the existing Windows 7 installation while using FreeBSD as the primary OS on the machine. This is the FreeBSD side of how to do that yourself.

This assumes you have already installed VirtualBox and it is able to execute along with some helpers like sudo.  You might want to read through the handbook entry on how to do this (I didn’t and ended up with the error at the bottom of this as a result.)
Within VirtualBox Manager create a new virtual machine in Expert Mode. Give it a name and some memory but do not add a virtual hard disk, for reference I’m calling mine Win7 for the purpose of this tutorial.

Navigate to the location of the VM, for me this was:

cd "/usr/home/cory/VirtualBox VMs/Win7"

Create virtual machine disks (VMDKs)

In my case I had 3 drives from my former Windows 7 system so I added them all.

sudo VBoxManage internalcommands createrawvmdk -filename c.vmdk -rawdisk /dev/ada1
sudo VBoxManage internalcommands createrawvmdk -filename d.vmdk -rawdisk /dev/ada2
sudo VBoxManage internalcommands createrawvmdk -filename e.vmdk -rawdisk /dev/ada3

Set Permissions

sudo chmod 0600 ./*.vmdk
sudo chown cory:cory ./*.vmdk

Check Permissions

ls -l ./*.vmdk
-rw------- 1 cory cory 538 Mar 12 15:53 ./c.vmdk
-rw------- 1 cory cory 539 Mar 12 15:53 ./d.vmdk
-rw------- 1 cory cory 539 Mar 12 15:53 ./e.vmdk

Addings Disks To The VM

Open the settings for the newly created VM and navigate to the Storage section.
Create a new controller, in my case I used SATA, yours may differ.
Add each of the drives starting with the primary to the controller, if any are SSDs check off the Solid-state Drive box for each SSD drive after it has been added.
If any of the drives are already mounted you will need to umount them.

Setting More Permissions

Give yourself access to the vboxusers, wheel, and operator groups with:

sudo pw group mod vboxusers -m cory
sudo pw group mod wheel -m cory
sudo pw group mod operator -m cory

This should create entries in /etc/group for your username under each group, if they aren’t there add them after root by prefixing your username with a comma.
Add the operator to the respective drives via the following entries to /etc/devfs.conf:

own /dev/ada1 root:operator
perm /dev/ada1 0666
own /dev/ada2 root:operator
perm /dev/ada2 0666
own /dev/ada3 root:operator
perm /dev/ada3 0666

Add an entry to /etc/sysctl.conf to allow user mounting as:

sudo sysctl -w vfs.usermount=1

At this point I rebooted and attempted to start the VM after, only to receive the following because I didn’t bother with the FreeBSD handbook entry.  I’m posting it here in case anyone else is searching for the solution to this:

Failed to open a session for the virtual machine Win7.
The virtual machine 'Win7' has terminated unexpectedly during startup with exit code 1 (0x1).
Result Code: 
NS_ERROR_FAILURE (0x80004005)

Followed a moment later by:

VirtualBox - Error In suplibOsInit
Kernel driver not installed (rc=-1908)
Make sure the kernel module has been loaded successfully.
where: suplibOsInit what: 3 VERR_VM_DRIVER_NOT_INSTALLED (-1908) - The support driver is not installed. On linux, open returned ENOENT.

This is a really simple one to fix, if not a pain to search around for. When you run:

sudo kldstat

You should notice vboxdrv.ko is not in the list, so just run:

sudo kldload vboxdrv

It turned out while configuring VirtualBox I had missed adding the following line to /boot/loader.conf:


And the result:

Leave a Reply

Your email address will not be published. Required fields are marked *