Access Linux filesystems in Windows and WSL 2
Starting with Windows Insiders preview build 20211, WSL 2 will be offering a new feature: wsl --mount
. This new parameter allows a physical disk to be attached and mounted inside WSL 2, which enables you to access filesystems that aren’t natively supported by Windows (such as ext4).
So, if you’re dual booting with Windows & Linux using different disks, you can now access your Linux files from Windows!
Getting started
To mount a disk, open a PowerShell window with administrator privileges and run:
wsl --mount <DiskPath>
To list the available disks in Windows, run:
wmic diskdrive list brief
To unmount and detach the disk from WSL 2, run
wsl --unmount <Diskpath>
The disks paths are available under the ‘DeviceID’ columns. Usually under the \\.\\\.\PHYSICALDRIVE*
format. Below is an example of mounting a specific partition of a given hard disk into WSL and browsing its files.
Accessing these files with File Explorer
Once mounted, it’s also possible to access these disks through the Windows explorer by navigating to \wsl$ and then to the mount folder.
Limitations
By default, wsl --mount
attempts to mount the disk as ext4. To specify a filesystem, or for more advanced scenarios, check out Mount a disk in WSL 2.
Also please note that this feature comes with the limitation that only physical disks can be attached to WSL 2. At this time, it’s not possible to attach a single partition. More details on the limitations here.
Give us your feedback!
If you run into any issues, or have feedback for our team please file an issue on our Github , and if you have general questions about WSL you can find all of our team members that are on Twitter on this twitter list.
42 comments
But, can you edit the files?
Of course
Yes, that’s the whole point 🙂
Please I need someone to teach me programming and coding willingly.
Hi Amedea,
What kind of programs would you like make? Web sites, games, mobile applications?
Here are some websites that can teach the skills you need to get started, all of them are great:
Free Resources:
– https://www.freecodecamp.org
– https://www.khanacademy.org
– https://www.codecademy.com
Paid Resources (around 25$/Month)
– https://www.pluralsight.com
– https://www.lynda.com
Hope you’ll find what you’re looking for.
Best of luck ✨
Cool! Now, if only SFTP support was added to Explorer as well, I would be happy. 🙂
You can mount an SFTP share in WSL, and then access it through the \WSL$ path in the Windows Explorer.
Pierre, does this actually work? I just tried mounting an SSHFS system in WSL2. It mounts fine and files are available in Ubuntu, but when I use Explorer and browse to the mounted folder, I get the error message:
“\wsl$\Ubuntu\mnt\test_mount is not accessible. You might not have permission to use this network resource. Contact the administrator of this server to find out if you have access permissions.
Attempt to access invalid address.”
If it helps, I am using the following to mount:
And server is aliased in my .ssh/config to the hostname, port, and username for that server
Note that when unmounted, windows explorer can open the folder, but of course the contents are empty.
Thanks!
This is probably caused by a uid mismatch.
To make the mountpoint accessible in the explorer, the uid needs to match the default wsl user for your distro.
To figure out your uid, run
id -u
inside WSL.Once you have that, change your mount command line to something like:
If that doesn’t work, I recommend creating an issue
How’s the performance?
Should be close to native from inside WSL 2. From the Windows Explorer there is some penalty
If the whole device is exposed to the Linux kernel, does that mean I could mount an encrypted LUKS volume inside WSL and navigate the fs using explorer.exe?
That would be awesome. It would mean one doesn’t need VeraCrypt for disk encryption interop between windows and linux.
You can as long as the Linux kernel supports dm-crypt.
Unfortunately the kernel that we currently ship doesn’t, but you can build you own (just make sure that
CONFIG_DM_CRYPT
is ‘y’), and then install in%windir%\system32\lxss\tools\kernel
will a future kernel support dm-crypt natively? I imagine quite a few people run Linux from encrypted and LVM-d filesystems.
Interesting. Any plans on have it enabled in the default distribution in the future?
I guess that before WSL having support for disks mounts it made no sense to enable it, but now I would include any disk mapper supported by the linux kernel.
But exiting news nonetheless!
Will this work with LVM partitions as well?
Unfortunately not, because lvm relies on a daemon that isn’t running in WSL 2.
It might be possible to get it to work if you manually start lvmetad, but this scenario isn’t supported at this time.
Exactly what linux file systems will be accessed?
I use xfs and I would like it to be able to access that file system from windows.
All filesystems supported by the kernel you’re running can be mounted from WSL (in your case, xfs is supported by the kernel we ship).
For more complex use cases, you can run
wsl --mount <Device> --bare
, and then manually mount the device from inside WSL.In PowerShell “Invalid command line option: –mount”
There are two dashes (-) on this argument.
If that doesn’t help, please create an issue
Does the limitation of only working with disks mean it’s not possible to mount Linux partitions if they are on the same physical disk (boot disk) as Windows, e.g. on a laptop?
Yes, this scenario isn’t supported at this time.
Does this make it possible to use a physical disk for a WSL root filesystem? It would be truly amazing if one could have a full-fledged dual-boot setup that could also double as WSL.
That’s an interesting idea.
It’s not possible to boot directly on a mounted disk, but you can chroot into it after mounting it.
Would be cool to have a way to chroot to a specific device quickly, like wsl –chroot \.\PHYSICALDRIVE… without need to mount a drive -> mount all the /dev/… /proc/… etc. -> chroot…
That’s an interesting idea.
I’d recommend creating a feature request
Can WSL2 mount other filesystem like JFS with this function?
The kernel that we officially ship doesn’t support JFS at this time, but if you build your own, you should be able to mount a JFS volume.
Hello Pierre
Is this functionality only limited to storage devices, or would it enable me to make use of peripheral devices which connect through the same USB receptacles?
An example would be if I could use a wired joystick-controller that makes use of the USB type-A interface, the same way I use USB type-A for my flash drive.
This feature is only limited to storage devices. Unfortunately it can’t be used to pass-through a USB device to WSL 2.