Some time ago, we got a question regarding StarWind VSAN, if it can provide storage for WSL. As the main usage purpose of VSAN is high availability and hyperconvergence, nobody has ever tested such functionality. It was an excellent opportunity to dive deeper into Microsoft Linux and figure out whether it is possible or not.

StarWind VSAN virtualizes local storage (part of local volume/ whole block device/ DVD-ROM) and provides it over iSCSI protocol. The main challenge is to enable iSCSI in WSL because it doesn’t work out of the box right now. The good news is that it is possible but only with WSL2 (as it allows a custom kernel), and that’s the bad news.

This blog article is a detailed guide on how to provide WSL2 with block devices. I used Windows 10 20H2 (OS Build 19042.630) and Ubuntu 20.04 LTS inside WSL2.

Disclaimer: The process described in the following article may change with new releases of WSL2 kernels. Master branch of GitHub repo may contain an older kernel than the one installed on WSL2 machine.

The configuration may be divided into 3 stages:

Stage 1: build a custom kernel with iSCSI modules support

Stage 2: create StarWind iSCSI Targets

Stage 3: connect iSCSI Targets inside Ubuntu

Prerequisites: WSL2 should be installed according to Microsoft guide. Ubuntu 20.04 should run as version 2.

Ubuntu 20.04 should run as version 2

Stage 1: build a custom kernel with iSCSI modules support

1. Update Ubuntu packages:

2. Install components for building custom kernel:

Ubuntu package

3. Clone the Microsoft WSL2 kernel

Clone the Microsoft WSL2 kernel

4. Export the current WSL configuration:

Export the current WSL configuration

5. Start menu config to select kernel modules:

Start menu config to select kernel modules

6. Add the following components:

Add the components

SRP Transport attributes

SCSI low level drivers

FUSE

7. Save the configuration.

Save the configuration

8. Build a kernel (this step can take a couple of hours):

Build a kernel

9. Copy a kernel image to User folder:

10. Create a file on your Windows host’s in “Users\your-user-name” folder called “.wslconfig” (note the dot in-front) with the following text:

Create a file on your Windows host

11. Restart WSL2 instance in PowerShell:

Stage 2: create StarWind iSCSI Targets

To make an example, I’ve created 3 iSCSI targets. The first is for virtual disk stored on C: drive, the second bridges another physical disk, and the third for local DVD-ROM. You can create only one or many targets according to your needs.

12. Install StarWind VSAN (free* or commercial) with the following components:

Install StarWind VSAN

* Free version allows creating devices only via PowerShell. The scripts are located in folder: C:\Program Files\StarWind Software\StarWind\StarWindX\Samples\powershell

13. Start the StarWind Management Console.

14. Create a virtual disk following the steps.

15. Create a disk bridge for the physical disk following the steps.

16. Create a DVD-ROM bridge following the steps.

You are supposed to get almost the same in Management Console:

Management Console

Stage 3: connect iSCSI Targets inside Ubuntu

17. Load iscsi modules:

Connect iSCSI Targets inside Ubuntu

18. Install open-iscsi (it might be already installed):

Install open-iscsi

19. Change the iscsi Initiator name, you need to give own name under “InitiatorName=” and remove string “GenerateName=yes” :

Change the iscsi Initiator name

20. Restart iscsid and start open-iscsi:

Restart iscsid and start open-iscsi

21. Discovery iscsi targets on your host (in my case, I used IP 192.168.12.10):

Discovery iscsi targets

22. Connect targets:

Connect targets

23. Run lsblk to check disks (DVD will be not available here)

Run lsblk to check disks

24. DVD device may be checked with lsscsi command (installation required)

DVD device may be checked

Now you can use block storage devices inside WSL2.

Back to blog
The following two tabs change content below.
Oleg Pankevych
Oleg Pankevych
With 3+ years of experience in supporting enterprise and banks' IT infrastructures, Oleg works as Pre-Sales engineer at StarWind.