Monday, 23 May 2022

Mapping additional and network drives inside an unRaid Windows VM

On the unRaid forums recently, I was responding to a user who was asking why his VM gcow2 image did not shrink when files are removed (thread here). I advised that auto-shrink is not standard behaviour, and in the discussion, it became clear that the use case was security camera footage. The user figured out that perhaps saving video files to a network share would be better than to the VM boot / system drive, and I mentioned that I do this with my BlueIris setup. I promised a quick guide, so here it is....

I run my BlueIris application in a Windows 10 VM on unRaid. While what follows is specific to my set-up, the general principles would apply to any VM OS and application software.

In my BlueIris 'Clips & Archiving' settings, I have new footage set to save to the local V: drive;






After 2 days, clips are moved to the 'Stored' location, an unRaid share, where they are maintained for 2 weeks;




These locations exist in the VM's Windows Explorer as a locally mounted drive and a network volume respectively;


That V: Drive is a 4TB HD in unRaid unassigned devices;



And the W: drive is an unRaid share;



I use the network path to the share in BlueIris rather than the W: drive letter as I found it to be more reliable. However, you can see from the above that it's possible to map an unRaid share to a network volume inside a VM. 

To do this, simply go to File Explorer, click on the 'Network' left menu item, open your unRaid server, right-click on the desired share and select 'Map Network Drive' from the contextual menu. This will open the mapping dialog. Assign a drive letter and be sure to tick the 'Reconnect at sign-in' if you want the share to persist between VM restarts.  Click finish. You'll need to enter your unRaid user password and you're done.



So that's how everything is configured in a Windows VM, and the principles are the same if your VM is Linux or MacOS, but what about on the unRaid side? What do you need to do to set it up so that the VM can access these disks and shares?

Well, there's nothing more to do on the network share side. Provided that the share is set up and exported to SMB, it will be available to any systems on your network, including VMs. Here's the key setup pages in unRaid for the share I've referenced above;




To get an unRaid disk image or physical drive passed through to the VM and to appear as an 'internal' drive as in the V: example above, it's just a matter of adding it to the VM configuration in unRaid;



That's the disk configuration portion of my Windows VM. In addition to the standard Primary vDisk that's set to a qcow image, I've added a 2nd vDisk location. (You add additional disks by clicking the green (+) icon on the left margin)

When setting this up, you just configure a disk image to taste. Here's what I see if I select to add a 3rd disk to this VM;


And that's it. Once you do this, the disk image will appear as an unformatted disk when you boot the VM. Format it, add a drive letter (for windows) and the disk works just like a physical disk inside a real PC.

If you're just after a basic 2nd, (or 3rd), disk inside your VM, this is as far as you need to go. 

In my case, I've set it up a little different. Rather than pass through a disk image, I'm passing through a full physical disk located in the server. I like this approach as I feel it eeks out a little more performance.

You do this by choosing the 'Manual' vDisk location option and entering the disk's id path.

The what?

You get the disk ID path by opening a terminal to unRaid and navigating to the /dev/disk/by-id/ location and listing;

root@UNRAID:~# cd /dev/disk/by-id/
root@UNRAID:/dev/disk/by-id# ls

This will give you a list of all the disks and partitions in your system;


I've highlighted the 4TB Hitachi disk we saw in unassigned devices earlier. This is the disk I want to pass into my VM.

In my case, this is the disk ID I need. It's important to chose the disk ID, not any partition (ends in '-part'). Simply concatenate this with the path to the folder and use that path in the VM disk location field.

/dev/disk/by-id/ata-Hitachi_HDS5C4040ALE630_PL1331LAG51UBH

And that's all there is to it. Using these techniques, any disk image or physical disk can be passed into a VM where it appears and functions as if a native disk. Any properly configured unRaid share can be mapped as a network drive inside the VM.

Happy virtualising!

No comments: