headshot of Chris Tonkinson
Chris Tonkinson

tech {enthusiast, practitioner, leader, podcaster, mentor, entrepreneur}

HomeAboutTags



Refactored Podcast

I co-host Refactored, a casual, ongoing conversation between two technology leaders trying to suck a little less every day.

Career Schema Project

I founded the Career Schema Project with the mission of developing open standards and technology to reduce the hassle of online jobseeking.


RSS Subscribe

© 2021 Chris Tonkinson

Configuring VirtualBox for iSCSI with FreeNAS


I recently brought a shiny new FreeNAS server online. One of the objectives for the new network storage device was to offload my VirtualBox virtual machine storage from my workstation. Managing as many VMs as I do can take a lot of space, and running them simultaneously while trying to get real work done will eat through whatever headroom a top-end PC has in short order, particularly if any of those guests are Windows.

To that end, I configured my FreeNAS to export a zvol over iSCSI. Not only was it a simple process, but the results are much better than I anticipated. Here’s the tutorial, assuming FreeNAS 9.3 and VirtualBox 4.3.

WARNING: I address neither performance nor security in this rundown. Maybe I’ll circle back to that in a follow up post, but for now in the name of brevity, I’ll leave that homework up to you.


Step 1: FreeNAS: Create a zvol and export it via iSCSI

1. Create a zvol

ZFS allows the creation of virtual block devices in storage pools, called zvols. The zvol resides in your storage pool so it can be snapshotted, scrubbed, sent — anything that can be done with a normal ZFS filesystem volume. To create a zvol in FreeNAS, navigate to the Storage tab.

Click ‘Create zvol’

Configure the zvol

zvol details

2. Create a portal

This configures the IP address and port through which FreeNAS will expose the block devices.

Click ‘Add Portal’

Make your selection

3. Create an initiator

The initiator configures the client for access to the block device.

Click ‘Add Initiator’

Restrict access

4. Create a target

The target relates a Portal with an Initiator, so that your chosen clients can communicate with the correct server IP/port.

Click ‘Add Target’

Associate the portal and initiator

5. Create an extent

An extent is a concept in FreeNAS that exposes a zvol for use in the iSCSI environment. Be sure to read the tip on LUN RPM - in my case I was creating an iSCSI target for a Windows VM, so I chose SSD.

Click ‘Add Extent’

Associate the target with the zvol

6. Associate the target with the extent

This step correlates An extent will associate the zvol we created earlier with the target we just configured, allowing that target access to that block device.

Click ‘Add Extent’

Associate the target with the zvol

7. Enable iSCSI sharing

The last step toward having an operational iSCSI server using FreeNAS is quite possibly the most difficult technical hurdle you may ever encounter. Navigate to the Sharing tab, and toggle “iSCSI” on.

Enable iSCSI sharing


Step 2: VirtualBox: Create the VM, attach the iSCSI storage

1. Create a new virtual machine

When you create your VM as usual, but don’t add a hard drive. You’ll get a warning

You are about to create a new virtual machine without a hard drive. You will not be able to install an operating system on the machine until you add one. In the mean time you will only be able to start the machine using a virtual optical disk or from the network.

which you should ignore.

2. Attach the iSCSI device to your virtual machine

Next, we’ve got to drop down to the command line, as the VirtualBox GUI doesn’t expose the necessary controls for adding iSCSI devices. The command is thus:

VBoxManage
  storageattach       # subcommand to add storage to a VM
  windows             # the name of your virtual machine
  --storagectl "SATA" # storage interface type
  --type hdd          # device drive type
  --device 0          # local emulated hardware device index
  --port 0            # local emulated hardware device port
  --medium iscsi      # use iSCSI
  --server 10.0.0.2   # FreeNAS server address (from the portal we configured in 1.2)
  --tport 3260        # FreeNAS server TCP port (from the portal we configured in 1.2)
  --target "iqn.2005-10.org.freenas.ctl:windows-target"

Regarding the --target specification, this is pretty easy to figure out. In our (simple) case, it’s comprised of two separate elements of the format B:T, where B is the Base Name from the “Target Global Configuration” tab under Sharing > Block (iSCSI) > Target Global Configuration, and T is the Target Name from step 1.4 above.


Step 3: Profit

And that’s it. You should now be able to boot your VM (VirtualBox should prompt you for install media as per usual). In my case the performance was surprisingly good, even without any tuning, but watching my network monitor, it was obvious that a sub-Gigabit LAN would have kneecapped the speed.

If something goes wrong, you can look in the VirtualBox GUI under File > Virtual Media Manager and after running the storageattach command above, you should see an entry for the iSCSI drive. If there is an error, you’ll see a warning sign and an error message on hover.


UPDATE: See also [Extending Windows C: Drive using VirtualBox and iSCSI with FreeNAS]({% post_url 2015-08-28-extending-windows-c-drive-using-virtualbox-and-iscsi-with-freenas %})