Access Linux filesystems in Windows and WSL 2

Pierre

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.

terminal with wsl text

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.

Accessing an EXT4 partition with file explorer

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

Comments are closed. Login to edit/delete your existing comments

  • Ascii Wolf

    Cool! Now, if only SFTP support was added to Explorer as well, I would be happy. 🙂

      • Ryan Avery

        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:

        sshfs -o idmap=user server:/files /mnt/test_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!

        • Pierre BoulayMicrosoft employee

          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:

          sshfs -o idmap=user server:/files /mnt/test_mount uid=[uid here (without the brackets)]
          

          If that doesn’t work, I recommend creating an issue

  • Stefan Maric

    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.

    • Pierre BoulayMicrosoft employee

      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

      • Simon Kostede

        will a future kernel support dm-crypt natively? I imagine quite a few people run Linux from encrypted and LVM-d filesystems.

      • Stefan Maric

        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!

    • Pierre BoulayMicrosoft employee

      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.

  • Marcel Lunes Palau

    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.

    • Pierre BoulayMicrosoft employee

      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.

  • K Kaland

    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?

  • Pavel Minaev

    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.

    • Pierre BoulayMicrosoft employee

      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.

  • tsuki Shimo

    Can WSL2 mount other filesystem like JFS with this function?

  • Rohat Bozyil

    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.

    • Pierre BoulayMicrosoft employee

      This feature is only limited to storage devices. Unfortunately it can’t be used to pass-through a USB device to WSL 2.