Sponsored Links

VirtualBox and iSCSI / NAS How-To – Linux and Windows

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.

Here’s how…

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…

iSCSI portal page



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.




iSCSI Target Management


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.





The wonderful wizard of, er, iSCSI… ahem..


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.






Naming the target and alias



Next screen is setting up the names for the target and an alias – I’m using “example” for both.






Authentication settings



Next comes the authentication settings for the new iSCSI target… I’m not going to bother with this for simplicity’s sake.





LUN creation



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.




Confirm settings




Everything’s looking good, so I go forward…








And finished!






iSCSI page showing newly-added target and mapped 20GB LUN



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

Creating the new VM




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.






Memories are made of this..




2048MB should be enough I think ;)






Un-tick / de-select “Start-up Disk” box




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”…





Everybody Panic!




The VBox wizard graciously reminds us that which we already know, so, click “Continue”…






Summary screen – not much to look at but what can you do?




Finally at the Summary screen click Create and VBox will do the rest.







Storage settings for the new VM



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.

The Windows CLI window showing the parameters for VBoxManage.


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>
–storagectl <name>
[–port <number>]
[–device <number>]
[–type dvddrive|hdd|fdd]
[–medium none|emptydrive|
[–mtype normal|writethrough|immutable|shareable|
[–comment <text>]
[–setuuid <uuid>]
[–setparentuuid <uuid>]
[–passthrough on|off]
[–tempeject on|off]
[–nonrotational on|off]
[–bandwidthgroup <name>]
[–server <name>|<ip>]
[–target <target>]
[–tport <port>]
[–lun <lun>]
[–encodedlun <lun>]
[–username <username>]
[–password <password>]


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;

--port 0

The device number of the virtual storage controller;

--device 0

The type of the attached storage – this is usually “hdd” for Hard Disk Drive;

--type hdd

The type of medium from which you’re attaching the storage device – in this case it’s iSCSI so;

--medium iscsi

The address of the NAS server (in my case it’s;


The iSCSI target name (in my case as discussed earlier it’s “iqn.2004-04.com.qnap:ts-419pplus:iscsi.example.c78d5b”);

--target "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);

--tport 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 --target "iqn.2004-04.com.qnap:ts-419pplus:iscsi.example.c78d5b" --tport 3260

All appears to have gone well…


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…

The VM with it’s shiny new 20GB iSCSI target attached :)




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…

Same newly created VM as the Windows example above…



I’ve booted into Linux Mint and have just created the same VM configuration as the example above I did via Windows…






The exact same command line as used in the Windows CLI…




I used exactly the same command line as I used in the example above I used for Windows…







Linux VM with iSCSI target attached



And as promised it works exactly the same under Linux.





The iSCSI target showing up as a Hard DIsk in the VM





I attached an Ubuntu Server ISO, powered up the VM and here’s the 20GB iSCSI target showing up as a VirtualBox hard disk.








Before writing the partition table…





Just before writing the partition table…








Formatting the disk






Partition layout and formatting is working, so the VM is both seeing and accessing the iSCSI target properly.







The VM boots from the iSCSI target






And here’s the GRUB boot menu after installing Ubuntu server…








The running server VM





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.

VN:F [1.9.22_1171]
Rate This Article
Rating: 9.7/10 (53 votes cast)
VirtualBox and iSCSI / NAS How-To - Linux and Windows, 9.7 out of 10 based on 53 ratings
Share the knowledge :
Facebook Twitter Pinterest Linkedin Digg Delicious Reddit Stumbleupon Posterous Email Snailmail

9 comments to VirtualBox and iSCSI / NAS How-To – Linux and Windows

  • Great Article! I was looking for a way to set this up and you provided great instructions. I just installed Windows 7 Home Premium this way to my Synology DS110j. I’m using a Mac with Lion 10.7.2 and the terminal worked fine to run the commands. I didn’t have to use cd at all it worked fine without. I did notice in my case that I had to put quotes ” ” around the name of the VM i.e. “ScaryExample” and it threw up an error about line 7 which is the type of medium. I just chose –mtype normal and it worked just fine. Other than those little details it was spot on. Thanks!

    VA:F [1.9.22_1171]
    Rating: +1 (from 1 vote)
  • Stephan Vermette

    Excellent article.  Thank you!
    I use a Synology Disk Station as my iSCSI target, and I found that I need to add the –lun 1 argument, or else Virtual Box 4.1.20 doesn't read the LUN size correctly (it shows up as 32KB, and VirtualBox refuses to start, complaining with VERR_VD_IMAGE_READ_ONLY)
    This could be due to my previous experimenting with multiple LUNs on the same target, then removing the first LUN.

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • storeman

    Thanks for this clear article, saved me a lot of reading through the docs and worked without any trouble, even over an internet-connection. Although it was to slow for an Ubuntu install.
    Used it with Virtualbox and a Synology DS412+

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • charlie

    I also have a QNAP – do you know if this iSCSI technique can be used to connect a volume of my NAS box as a backup device for the new Windows Server Backup?
    As you may know, Windows Server 2008 R2 Backup will not use standard network share locations (Mapped drives nor UNC paths) to do incrememntal backups. It only works if the drive is actually connected to the box. This is annoying for me as i don't want to use fast, expensive SAN storage for backups. For that i'd really rather use my cheap (relatively!) NAS box.
    Thanks for the great article!

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • friedbanana

    Thanks a lot for this How-To! Just got my QNAP TS-219P II and set up the iSCSI drive. It's one of the main reasons i got that specific NAS.

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • sparky

    I tried this on my synology 413 and get the following error (even after reboot) "Runtime error opening /home/…..vbox for reading: -38 (Access Denied)" I followed the steps and didn't setup a Chap password on the NAS.  One issue I did notice was even before I rebooted and got this message I saw that in the section "if all goes well you will see “iSCSI disk created. UUID: 1f8f3183-0f1a-4079-866f-79d6db1e9230″.  I got to that point and it showed the same thing.  However, the next step of going in the Virtualbox settings and checking didn't show that it took (even after closing down and/or rebooting).


    Does anybody have any suggestions as to what may be going on and a solution?




    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  • DDavis

    Well written Article. Though in my implementation I had to change SATA Controller to just SATA but thanks all the same.

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
    • Thanks – and yeah, at the time the article was written, the SATA controllers were named “SATA Controller” by default, which was a pain, and since then shortened to the more sensible “SATA”.


      VN:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
  • Guillaume FRANCAIS

    Thank you very much for this tutorial. It works good for me. VirtualBox 5.2, running on Ubuntu 18.04, hosting a VM Centos 7-4, connecting to a NAS QNAP TS-251.

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>




This site uses Akismet to reduce spam. Learn how your comment data is processed.