WSL2 on Windows 10 Build 20211
Windows allows now to mount physical disks using the Windows Subsystem for Linux 2 (WSL).
However, there is a limitation with this approach as noted in the Microsoft documentation. For convenience, this limitation is noted here:
- At this time, only entire disks can be attached to WSL 2, meaning that it's not possible to attach only a partition. Concretely, this means that it's not possible to use
wsl --mount
to read a partition on the boot device, because that device can't be detached from Windows.
For people who are not familiar with WSL2:
... Windows Subsystem for Linux is a compatibility layer for running Linux binary executables natively on Windows 10 and Windows Server 2019. In May 2019, WSL 2 was announced, introducing important changes such as a real Linux kernel, through a subset of Hyper-V features. ...
The Windows 10 WSL2 now supports a mount command for linux filesystems called wsl.
First of all you have to install WSL2 on your windows10+ release. I recommend to simply follow the microsoft installation guide (note the minimum version required).
The following steps are taken from the microsoft's homepage docu wls2-mount-disk :
Identify the disk
Open a powershell (or something else) and type
wmic diskdrive list brief
The disks paths are available under the 'DeviceID' columns. Usually under the \.\PHYSICALDRIVE* format.
List and select the partitions to mount in WSL2
Note your disk to mount and enter:
wsl --mount <DiskPath> --bare
Now the disk is available to the layer and you can use the common linux command
lsblk
as you know well from linux systems.
Mount the selected partitions
Identify your partitons and mount it using the following command
wsl --mount <DiskPath> --partition <PartitionNumber> --type <Filesystem>
If you ommit the
--partition
flag an ext4 filesystem will be choosen. Commands likehelp wsl
orcat /proc/filesystems
will give you more information about the options.Access the disk content
Once mounted, the disk can be accessed under the path pointed to by the config value:
automount.root
. The default value is/mnt/wsl
.From Windows, the disk can be accessed from File Explorer by navigating to:
\\wsl$\\<Distro>\\<Mountpoint>
(pick any Linux distribution).Unmount the disk
To unmount and detach the disk run:
wsl --unmount <DiskPath>