I have a NAS. It’s a nice NAS. It’s a QNAP TurboNAS TS-419P, and it’s just what I need for my SOHO setup.
Amongst many other things it can do, it can allow me to use its RAID array as iSCSI targets.
VirtualBox is also great. It can use iSCSI targets as storage devices, and it can do this directly, without ever touching either Windows’ or Linux’s iSCSI utilities.
This HOWTO works for both Windows and Linux – the command to access the iSCSI target for both is exactly the same and I show this in the tutorial.
For this example, I am going to set up a very basic Virtual Machine, and allocate 20GB to the iSCSI target/LUN… so here goes..
1) Set up an iSCSI target for use with your VBox virtual machine
This procedure will differ, depending on what make and model of NAS you have, so you’ll have to modify your steps to suit your setup. I’ll just go through setting up an iSCSI target using my own NAS…
First log into your NAS’s administration site – this is done via web pages on my make and model of NAS.
Notice the iSCSI port number is 3260 on my NAS – again your port # may differ.
Here’s the iSCSI target management page. Ignore the ones already there – I use those for existing VM’s and testing.
What I’m going to do is use the iSCSI setup wizard to create a new target, for this example.
What I want is not only a new iSCSI target, but to create a mapped LUN for it as well – the mapped LUN is basically the disk space I’ll be allocating for this new VM later.
Next screen is setting up the names for the target and an alias – I’m using “example” for both.
Next comes the authentication settings for the new iSCSI target… I’m not going to bother with this for simplicity’s sake.
Next up is LUN creation, which as I mentioned earlier is basically how much of your RAID storage you’re going to allocate for this iSCSI target – this in turn determines what size your storage device that your Virtual machine will see, once configured.
I’m going to nab a nice round 20GB for this example.
Everything’s looking good, so I go forward…
And back to the iSCSI Target Management page, showing the new target “Example” , and the 20GB mapped LUN called “example” on my NAS.
Note the “(iqn.2004-04.com.qnap:ts-419pplus:iscsi.example.c78d5b)” next to the alias “Example” – that’s how we’re going to reference the iSCSI target, when we get around to configuring the new VirtualBox VM, which strangely enough, is what we’re going to be doing next ;)
2) Set up a new Virtual Machine in VirtualBox
First of all fire up the VirtualBox Manager, and click on Create New Virtual Machine.
I’m going to call mine “ScaryExample”, I’m also going to select OS Type: Linux and Version: Linux 2.6, just as an example.
2048MB should be enough I think ;)
Okay, at the Virtual Hard Disk screen, un-tick the box next to “Start-up Disk”
I’m going to be using the iSCSI disk as my eventual system/boot disk, so at this moment in time the newly created vm will have no Start-up disk configured, and it’ll whine about that after you click on “Next”…
The VBox wizard graciously reminds us that which we already know, so, click “Continue”…
Finally at the Summary screen click Create and VBox will do the rest.
After that, have a quick look at the Storage settings for the new VM. As configured by the choices made at the creation wizard, there’s not an awful lot to see. I have 1 IDE Controller with a virtual CD/DVD drive attached, and one SATA Controller. You can of course decide at this point what changes you wish to make to this new VM – whether to remove the SATA controller and add in a different type or not. FOr this example, I’m going to stick with the IDE and SATA controller….
This is where we now have to tell VirtualBox to attach the iSCSI target to the SATA controller…
3) Attaching an iSCSI target to a virtual disk controller for your VBox Virtual Machine
This works for VirtualBox 4.x.x in both Linux and Windows (whatever other OS can run VirtualBox, presumably)…
We can’t do this by using the VirtualBox Manager. Instead, we have to use the command line, so run either “cmd” on Windows to bring up a DOS box, or in Linux bring up a terminal window.
Since I’m typing this via Windows, I’ll just show the Windows CLI window.
Note that beforehand I had to cd to the location where VirtualBox installed on my system. For some reason VBox didn’t set up a PATH to the commands it uses, so I have to do this (and I haven’t been bothered to set up a PATH for this yet – later…)
The command we need to use is VBoxManage storageattach
As you can see from the screenshot, this command has a number of at first confusing looking parameters, necessary to tell VIrtualBox how to attach a storage device to the virtual machine of your choice…
VBoxManage storageattach <uuid|vmname>
I have highlighted the arguments required for our usage case – which is to attach the iSCSI target to the new virtual machine’s virtual SATA controller.
In my particular case the parameters will be;
The name of your Virtual Machine you wish to configure;
“vmname” = “ScaryExample“
The name of the virtual storage controller you’re going to attach the iSCSI target to;
--storagectl <name> = --storagectl "SATA Controller"
The port number of the virtual storage controller;
The device number of the virtual storage controller;
The type of the attached storage – this is usually “hdd” for Hard Disk Drive;
The type of medium from which you’re attaching the storage device – in this case it’s iSCSI so;
The address of the NAS server (in my case it’s 10.0.0.1);
The iSCSI target name (in my case as discussed earlier it’s “iqn.2004-04.com.qnap:ts-419pplus:iscsi.example.c78d5b”);
And finally the port number your NAS uses to issue iSCSI targets (in my case as discussed earlier it’s 3260);
Now, put that all together, and the resultant command is;
VBoxManage storageattach ScaryExample --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium iscsi --server 10.0.0.1 --target "iqn.2004-04.com.qnap:ts-419pplus:iscsi.example.c78d5b" --tport 3260
If all went well, you should see a message saying something like “iSCSI disk created. UUID: 1f8f3183-0f1a-4079-866f-79d6db1e9230″.
If you had the VirtualBox Manager utility loaded whilst you did this, it probably doesn’t show the updated configuration (it didn’t when I had it running whilst entering the “storageattach” command in Windows whilst writing this HOWTO) , so, just exit out of the Manager and restart it…
And if you go to the Storage settings of your VM, you’ll see the iSCSI target has successfully been attached to your VM!
At this point I can now configure the Virtual Machine with a Linux distro ISO of my choice, and install Linux to that 20GB target, and it will be used as the main storage and boot disk for the new VM.
Later, if I wished, I could configure another iSCSI target and attach that to the virtual machine as well, perhaps if say I needed a 500GB data “disk” as well, if I used that VM as a server for something.
Finally, here’s the last stage of the process, using Linux Mint as the host system…
I’ve booted into Linux Mint and have just created the same VM configuration as the example above I did via Windows…
I used exactly the same command line as I used in the example above I used for Windows…
And as promised it works exactly the same under Linux.
I attached an Ubuntu Server ISO, powered up the VM and here’s the 20GB iSCSI target showing up as a VirtualBox hard disk.
Just before writing the partition table…
Partition layout and formatting is working, so the VM is both seeing and accessing the iSCSI target properly.
And here’s the GRUB boot menu after installing Ubuntu server…
Aaaaaand finally, the running virtual machine showing the disk space from the virtual hard drive running from the iSCSI target.
And that’s it! Hopefully - again – this helps those who didn’t understand how to use iSCSI with VirtualBox. If it did, you might consider the DONATE button (yeah yeah here we go with the begging bowl yet again) on the right side of this blog near the top :P
What’s more, now that you can configure Virtual Machines using iSCSI, you can now move onto Teleporting VM’s from one physical VirtualBox server to another, which will be written soon.