Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

Enable block storage devices in WSL2

  • December 23, 2020
  • 8 min read
StarWind Solutions Architect. Oleg has over 10 years of experience in the industry, supporting large enterprises, as well as designing data center solutions for a wide range of customers.
StarWind Solutions Architect. Oleg has over 10 years of experience in the industry, supporting large enterprises, as well as designing data center solutions for a wide range of customers.

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.

Hey! Found Oleg’s insights useful? Looking for a cost-effective, high-performance, and easy-to-use hyperconverged platform?
Taras Shved
Taras Shved StarWind HCI Appliance Product Manager
Look no further! StarWind HCI Appliance (HCA) is a plug-and-play solution that combines compute, storage, networking, and virtualization software into a single easy-to-use hyperconverged platform. It's designed to significantly trim your IT costs and save valuable time. Interested in learning more? Book your StarWind HCA demo now to see it in action!