With Windows 11 and WSL2, you can do much more than before. For example, you can run application from the WSL2 with graphical interface as well.
I used to have a virtual machine with Linux used mainly to perform tasks like partitioning, Linux filesystem checks etc, mainly with SD cards used on Raspberry Pis or even for external big disks where I keep backups – and the filesystem is EXT4, for example.
Well, with some little “tuning”, you can now have your WSL2 vms (yes, they are virtual machines too) able to access the physical disks/usb devices as you would do in a VMWare vm or if your pc was actually a Linux box.
To do so, at today, May 2025, you can natively access physical disks but not USB pen/SD cards using USB dongle. In fact, if you run zcat /proc/config.gz | grep ^CONFIG_USB_STORAGE
within your WSL VM, you will probably see some output like “not set” or something that’s telling you… nothing here, sorry.
But here… how we can achieve it.
How to access a Physical disk
Source: https://learn.microsoft.com/en-us/windows/wsl/wsl2-mount-disk
You need to open Powershell, and run the following command to identify what is the disk that you want to mount/access from the WSL2 vm.
GET-CimInstance -query "SELECT * from Win32_DiskDrive"
Let’s say that you see that you want to access the secondary disk \\.\PHYSICALDRIVE2
REMEMBER: this procedure is for a physical disk, not USB one.
To safely mount the disk to WSL, it’s recommended to put the disk offline. To do so, use diskpart command.
diskpart /s /select disk 2
diskpart /s /offline disk
Then, still in Powershell (Admin), you can run the following command to expose the full disk to the WSL2. I have multiple WSL2 vms, so I wanted to connect to a specific one called “Workspace” and not to the default Ubuntu one.
wsl -d Workspace --mount \\.\PHYSICALDRIVE2 --bare
At this point, in your Linux WSL2 machine, you should be able to see the new disk. You can use fdisk -l
or any other commands as you would do on a disk physically attached to a Linux box.
Once done, you can unmount (and have the device back in Windows) with:
wsl --unmount \\.\PHYSICALDRIVE2
diskpart /s /select disk 2
diskpart /s /online disk
How to access an USB Mass Storage device
Sources: https://learn.microsoft.com/en-us/windows/wsl/connect-usb and https://www.tomshardware.com/how-to/access-linux-ext4-partitions-in-windows
Here things gets a bit more complicated.
We need to:
- recompile the WSL2 kernel
- configure WSL2 to use the new kernel
- install USBIPD-WIN and use it to connect the USB device to the vm
Recompile the kernel
Source: https://www.tomshardware.com/how-to/access-linux-ext4-partitions-in-windows
I used a second WSL2 vm for this, just to avoid to install loads of packages. But you can safely do in your own.
NOTE: all the WSL vms that you’re running are using the same kernel, unless you specify differently. You can find how to setup Advanced settings configuration in WSL in this link.
Now, you need to be sure to find the right version of the kernel that you’re running. At this stage I’m running version 5.15.167.4
uname -r | awk -F- '{print $1}'
I used this command. Or a simple uname -a
will show all the information and you can pick it manually.
You can elevate yourself as root
user, and run the following:
# Update and install required packages
apt update && apt upgrade
apt install -y build-essential flex bison libgtk2.0-dev libelf-dev libncurses-dev autoconf libudev-dev libtool zip unzip v4l-utils libssl-dev python3-pip cmake git iputils-ping net-tools dwarves usbutils bc git
# Set the version of your kernel and download the right version
VER=$(uname -r | awk -F- '{print $1}')
git clone -b linux-msft-wsl-${VER} https://github.com/microsoft/WSL2-Linux-Kernel.git ${VER}-microsoft-standard && cd ${VER}-microsoft-standard
# Set the config and start menuconfig
cp /proc/config.gz config.gz && sudo gunzip config.gz && sudo mv config .config
At this stage you should see a GUI menu:
- Navigate to Device Drivers > USB support
- Select USB Mass Storage Support and hit Y to put an * next to it, to include this module within the main kernel, instead of adding it as a module.
- Select Exit on the bottom of the screen (using the Tab key) multiple times until you get asked to save
- Make sure to select YES when it asks to save your configuration.
Now, it’s time to compile! (it reminds me the old times…). Well, back to now π
Use the following and fingers crossed:
make -j$(nproc) && make modules_install -j$(nproc) && make install -j$(nproc) && echo "ALL DONE"
Once you see ALL DONE, it means that you can proceed with the following steps. If you see errors… well… time to troubleshooting yourself π
Configure WSL2 to use the new kernel
Hoping all went fine, here the following steps. I assume your Windows username is pippo.
USER="pippo"
cp -rf vmlinux /mnt/c/Users/$USER/
cd /mnt/c/Users/$USER/
echo -e "[wsl2]\nkernel=C:\\\\\\Users\\\\\\$USER\\\\\\\vmlinux" > .wslconfig
You should have now copied the new kernel into pippo’s home directory on the Windows machine, and have a hidden file called .wslconfig
(file that applies to ALL your WSL2 vms – see above the advanced settings) with a content like this:[wsl2]
kernel=C:\Users\pippo\vmlinux
Now, back to Powershell (Admin), and restart WSL to pick up the new changes.
wsl --shutdown
Restart your WSL2 virtual machine. If all went well, you should have your new kernel with the new USB module built in. You can verify it using the same grep that we used before, and you should see a line with a nice “Y”:
$ zcat /proc/config.gz | grep ^CONFIG_USB_STORAGE
CONFIG_USB_STORAGE=y
Install and use USBIPD-WIN
Now that the harder bit has been done, we need the last step to make actually the magic happen. We need to install USBIPD-WIN and actually connect the USB device to the WSL2 virtual machine.
Quicker way – command line, just open again Powershell (Admin) and run:
winget install --interactive --exact dorssel.usbipd-win
Using usbipd list
you can see which are the devices attached and pick the one you want to expose to the WSL2 vm. You need to look for the BUSID.
In this example, I can see that the USB drive is actually ID 1-16
> usbipd list
Connected:
BUSID VID:PID DEVICE STATE
1-10 8087:0026 Intel(R) Wireless Bluetooth(R) Not shared
1-16 05e3:0749 USB Mass Storage Device Not shared
4-1 046d:0893 Logitech StreamCam, Logitech StreamCam WinUSB, USB Input ... Not shared
6-3 046d:c31c USB Input Device Not shared
6-4 045e:0039 Microsoft USB IntelliMouse Optical Not shared
Cool, so we can finally attach (expose) the drive to our WSL2 vm.
As mentioned before, I have multiple WSL2 vms, so I wanted to connect to “Workspace” and not to the default Ubuntu one.
usbipd bind --busid 1-16
usbipd attach --busid 1-16 --wsl Workspace
With this command I have connected the USB Mass Storage Device with BUSID 1-16 to the WSL2 VM called Workspace. Without the name Workspace in the command, it will connect to the default WSL2 vm (you can check with wsl --list
command).
At this stage, if you go again into your WSL2 vm, you should see the device available simply using lsblk
command. And if you have installed gparted
, for example, with a sudo gparted
(needs to run with the main user but with privileged grants) you should access your SD card or USB drive, and perform all the checks etc you’d like to do.
Same, you can mount etc, exactly as you would do with your Linux machine.
Last but not least, once you’ve finished, you need to detach and unbind the device. Simply run in Powershell (Admin) the following:
usbipd detach -a
usbipd unbind -a
And that’s it! π
I might work on a comprehensive script to do so – I have already my repository here – but for the time being, feel free to use these instructions.
Happy WSL2’ing π