Here’s a quick rundown on how to get Virtualbox running with iSCSI targets.
But first the why: why would you want to configure Virtualbox to use an iscsi target instead of a native disk image?
The answer is teleport. Sure, you can use an NFS or CIFS share just as easily with teleport, but using iSCSI targets is just that little bit more fun.
If you’re just setting up a standalone virtualbox, stick with disk images on local filesystems. The only reason to put your disk images on shared storage is so that teleport works.
For the uninitiated, teleporting is somewhat similar to VMWare’s “vMotion”. It’s the term given to the process of moving the processing and networking of a virtual machine to a different physical host without any (much) interruption to the virtual host.
Unlike VMWare though, Virtualbox lets you teleport your VM to different types of machines. That means you can teleport your VM from your linux machine to your Macbook Pro, over to your Opensolaris server and even to your Windows machine. The only limitation seems to be that they must have the same processor family (Intel to AMD processors doesn’t appear to work… yet.)
In this example I’m using an Opensolaris server to serve iSCSI targets from my ZFS pool. This gives me neat stuff like dedup and compression, as well as thin provisioning if I would like it. It doesn’t matter if you’re using FreeBSD or indeed any other way of presenting iSCSI targets.
On the Opensolaris server:
- Create a zfs volume to be your iSCSI target. Here I have a zpool named “xpool”.# zfs create -V 20G xpool/targetThis will create a 20Gb volume. To use thin provisioning, use the -s flag to the zfs create command)
- Install the following packages if you haven’t already:
SUNWiscsitu
SUNWiscsitr
SUNWiscsidmu
SUNWiscsidmr
SUNWstmf
SUNWstmfu - Share the target:
# zfs set shareiscsi=on xpool/target
(Note: if you have more recent version of Solaris, this command may fail with “invalid property ‘shareiscsi’ “. In that case, see this post for instructions)
- Make note of the device’s ID:
# iscsitadm list target
Target: xpool/target
iSCSI Name: iqn.1986-03.com.sun:02:74cedff0-250c-eacc-b509-bc930dc897d6
Connections: 0
Now you can create your Virtualbox virtual machine. I’m using the command line here. You can repeat these steps quickly on any machine where you’d like to teleport the machine to. Besides, who needs one of them fancy-pants GUIs, anyhow?
First – register the iSCSI target as a virtualbox disk:
# VBoxManage addiscsidisk –server 1.1.1.1 –target iqn.1986-03.com.sun:02:74cedff0-250c-eacc-b509-bc930dc897d6
Check that it worked…
# VBoxManage list hdds
Sun VirtualBox Command Line Management Interface Version 3.1.4
(C) 2005-2010 Sun Microsystems, Inc.
All rights reserved.
UUID: dfab4e6a-4ad6-44fa-96e0-76d5504b92aa
Format: ISCSI
Location: 1.1.1.1|iqn.1986-03.com.sun:02:74cedff0-250c-eacc-b509-bc930dc897d6
Accessible: yes
Type: normal
Now we can go ahead and create our VM. You can see what types of VMs your server will support with the command:
# VBoxManage list ostypes
It’s probably best to make sure that the type of server you’re going to build is supported on all the hosts you plan on teleporting it to. It might save a bit of pain and anguish later..
This is a simple VM with an IDE controller and a single hard disk. We attach an ISO image to the IDE controller as the second device in order to install our OS. Later we can attach the Virtualbox additions ISO here, too.
# VBoxManage createvm –name testvm –ostype WindowsXP –basefolder /vbox –register
Sun VirtualBox Command Line Management Interface Version 3.1.4
(C) 2005-2010 Sun Microsystems, Inc.
All rights reserved.
Virtual machine ‘testvm’ is created and registered.
UUID: c8a5b6a3-6fb3-4b50-beb2-9a08e656392a
Settings file: ‘/vbox/testvm/testvm.xml’
Now we can add memory limits, disk controllers and disk devices:
# VBoxManage modifyvm testvm –memory 1024 –cpus 4
# VBoxManage storagectl testvm –name “IDE Controller” –add ide –controller PIIX4
# VBoxManage storageattach testvm –storagectl “IDE Controller” –port 0 –device 0 –type hdd –medium dfab4e6a-4ad6-44fa-96e0-76d5504b92aa
# VBoxManage modifyvm testvm –nictype1 82545EM –nic1 bridged –bridgeadapter1 nge0
# VBoxManage modifyvm testvm –vrdp on
Once that’s done, boot it and connect via RDP to your host to install your operating system.
# VBoxManage startvm testvm –type vrdp
While the operating system is installing, repeat the steps on another machine, but don’t power it on. Remember to change the “bridgeadapter” to the appropriate interface name. (Note: You don’t need to use a NIC at all in our VM and this will still work, but what use is a VM without network access?)
Teleporting virtualbox vms
Once you’re set up, you can move VMs around like this:
1. On the host machine that you want to move the virtual machine to: (In this example we’ll assume our destination has IP address 1.1.1.20 and our source has IP address 1.1.1.10)
# VBoxManage modifyvm testvm –teleporter on –teleporteraddress 1.1.1.20 –teleporterport 54321
2. On the host machine, you can now power it on, and it should sit idle waiting for a teleport request to arrive from 1.1.1.10.
# VBoxManage startvm testvm –type vrdp
3. On the host machine that has the running virtual machine:
# VBoxManage controlvm testvm teleport –host 1.1.1.10 –port 54321
Once the progress bar hits 100%, you’re done!

Pingback: pligg.com
A quick tutorial on how to get #VirtualBox running with iSCSI targets. http://bit.ly/as8iHa
Pingback: Tweets that mention Rich’s Blog » Virtualbox, iSCSI targets and teleport -- Topsy.com
Very good article! Only change the last line:
# VBoxManage controlvm testvm teleport –host 1.1.1.10 –port 54321
for this one:
# VBoxManage controlvm testvm teleport –host 1.1.1.20 –port 54321
i think that in this command -host is the destination.
Thanks you!
As of VBox 4 (at least in 4.1.8 that I run), the option ‘addiscsidisk’ does no longer exists. Instead, I wrote a script around the following command:
VBoxManage storageattach “Nexenta CP 1.0.1″ –storagectl “SATA Controller” \
–port 5 –type hdd –medium iscsi –server 192.168.69.8:3260 \
–target iqn.2011-12.com.bayour:storage.nexenta.cp1 –lun 0
and the ‘remove’ (detach?) command:
VBoxManage storageattach “Nexenta CP 1.0.1″ –storagectl “SATA Controller” \
–port 5 –medium none