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:

$ sudo apt update

2. Install components for building custom kernel:

$ sudo apt install build-essential flex bison libssl-dev libelf-dev libncurses5-dev git

Ubuntu package

3. Clone the Microsoft WSL2 kernel

$ sudo git clone https://github.com/microsoft/WSL2-Linux-Kernel.git

Clone the Microsoft WSL2 kernel

4. Export the current WSL configuration:

$ cd WSL2-Linux-Kernel

$ export KCONFIG_CONFIG=Microsoft/config-wsl

Export the current WSL configuration

5. Start menu config to select kernel modules:

$ sudo make menuconfig

Start menu config to select kernel modules

6. Add the following components:

Device Drivers ---> SCSI device support --->

<*> SCSI CDROM support

Device Drivers ---> SCSI device support --->

<*> SCSI disk support

Device Drivers ---> SCSI device support ---> SCSI Transports --->

<M> iSCSI Transport Attributes

Device Drivers ---> SCSI device support ---> 

<*> SCSI low-level drivers

Device Drivers ---> SCSI device support ---> SCSI low-level drivers

<M> iSCSI Initiator over TCP/IP 

Device Drivers ---> File systems--->

<*> FUSE (Filesystem in Userspace) support

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):

sudo make && sudo make modules_install

Build a kernel

9. Copy a kernel image to User folder:

$ cp ./arch/x86_64/boot/bzImage /mnt/c/Users/YOUR-USER-NAME/

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:

[wsl2]

kernel=C:\\Users\\YOUR-USER-NAME\\bzImage

swap=0

localhostForwarding=true

Create a file on your Windows host

11. Restart WSL2 instance in PowerShell:

wsl --shutdown

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:

$ sudo modprobe libiscsi

$ sudo modprobe scsi_transport_iscsi

$ sudo modprobe libiscsi_tcp

$ sudo modprobe iscsi_tcp

Connect iSCSI Targets inside Ubuntu

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

$ sudo apt install open-iscsi

Install open-iscsi

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

$ sudo nano /etc/iscsi/initiatorname.iscsi

Change the iscsi Initiator name

20. Restart iscsid and start open-iscsi:

$ sudo service iscsid restart

$ sudo /etc/init.d/open-iscsi start

Restart iscsid and start open-iscsi

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

$ sudo iscsiadm -m discovery -t st -p $Your_IP

Discovery iscsi targets

22. Connect targets:

$ sudo iscsiadm -m node --targetname "$Target_name" --portal "$Your_IP:3260" --login

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.

Found Oleg’s article helpful? Looking for a reliable, high-performance, and cost-effective shared storage solution for your production cluster?
Dmytro Malynka
Dmytro Malynka StarWind Virtual SAN Product Manager
We’ve got you covered! StarWind Virtual SAN (VSAN) is specifically designed to provide highly-available shared storage for Hyper-V, vSphere, and KVM clusters. With StarWind VSAN, simplicity is key: utilize the local disks of your hypervisor hosts and create shared HA storage for your VMs. Interested in learning more? Book a short StarWind VSAN demo now and see it in action!