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.
Stage 1: build a custom kernel with iSCSI modules support
1. Update Ubuntu packages:
1 |
$ sudo apt update |
2. Install components for building custom kernel:
1 |
$ sudo apt install build-essential flex bison libssl-dev libelf-dev libncurses5-dev git |
3. Clone the Microsoft WSL2 kernel
1 |
$ sudo git clone https://github.com/microsoft/WSL2-Linux-Kernel.git |
4. Export the current WSL configuration:
1 2 3 |
$ cd WSL2-Linux-Kernel $ export KCONFIG_CONFIG=Microsoft/config-wsl |
5. Start menu config to select kernel modules:
1 |
$ sudo make menuconfig |
6. Add the following components:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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 |
7. Save the configuration.
8. Build a kernel (this step can take a couple of hours):
1 |
sudo make && sudo make modules_install |
9. Copy a kernel image to User folder:
1 |
$ 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:
1 2 3 4 5 6 7 |
[wsl2] kernel=C:\\Users\\YOUR-USER-NAME\\bzImage swap=0 localhostForwarding=true |
11. Restart WSL2 instance in PowerShell:
1 |
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:
* 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:
Stage 3: connect iSCSI Targets inside Ubuntu
17. Load iscsi modules:
1 2 3 4 5 6 7 |
$ sudo modprobe libiscsi $ sudo modprobe scsi_transport_iscsi $ sudo modprobe libiscsi_tcp $ sudo modprobe iscsi_tcp |
18. Install open-iscsi (it might be already installed):
1 |
$ sudo apt install open-iscsi |
19. Change the iscsi Initiator name, you need to give own name under “InitiatorName=” and remove string “GenerateName=yes” :
1 |
$ sudo nano /etc/iscsi/initiatorname.iscsi |
20. Restart iscsid and start open-iscsi:
1 2 3 |
$ sudo service iscsid restart $ sudo /etc/init.d/open-iscsi start |
21. Discovery iscsi targets on your host (in my case, I used IP 192.168.12.10):
1 |
$ sudo iscsiadm -m discovery -t st -p $Your_IP |
22. Connect targets:
1 |
$ sudo iscsiadm -m node --targetname "$Target_name" --portal "$Your_IP:3260" --login |
23. Run lsblk to check disks (DVD will be not available here)
24. DVD device may be checked with lsscsi command (installation required)
Now you can use block storage devices inside WSL2.