0% found this document useful (0 votes)
479 views8 pages

Access Linux Filesystems in Windows and WSL 2 - Windows Command Line

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
479 views8 pages

Access Linux Filesystems in Windows and WSL 2 - Windows Command Line

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

DevBlogs

Windows Command Line


Product Blogs
Login

DevOps

Access Linux
Languagesfilesystems in Windows and WSL 2

.NET

Platform Development
Pierre
September 10th, 2020
Data Development
  

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
g y
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.

Pierre Boulay
Software Engineer II, Linux on Windows

Posted in Command Line

Read next

Windows Package Manager Preview Windows Terminal Preview 1.4 Release


(v0.2.2521) Welcome to another release of Windows Terminal
We have been humbled by all the positive support for Preview and Windows Terminal! Windows Terminal
the Windows Package Manager. You have taken us from Preview is now on version 1.4 and will have the new
zero to over one thousand packages in six months. This is features listed below. ...
an ...
Kayla Cinnamon September 22, 2020
Demitrius Nelon September 22, 2020
14 comments
7 comments
41 comments
Comments are closed. Login to edit/delete your existing comments

Newer Comments →

JinShil September 10, 2020 6:45 pm  

But, can you edit the files?

Emmanuel Adebiyi September 11, 2020 6:40 am  

Of course

Pierre Boulay September 14, 2020 11:56 am  

Yes, that’s the whole point

Amedea Ramsey September 16, 2020 7:22 am  

Please I need someone to teach me programming and coding willingly.

Ascii Wolf September 11, 2020 2:32 am  

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

Pierre Boulay September 14, 2020 11:58 am  

You can mount an SFTP share in WSL, and then access it through the \WSL$ path in the Windows Explorer.

Ryan Avery October 2, 2020 4:43 pm  

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 Boulay October 12, 2020 3:54 pm  


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

Jason Jarvis September 11, 2020 7:54 am  

How’s the performance?

Pierre Boulay September 14, 2020 11:58 am  

Should be close to native from inside WSL 2. From the Windows Explorer there is some penalty

Stefan Maric September 11, 2020 8:14 am  

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 Boulay September 14, 2020 12:01 pm  

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 September 15, 2020 3:24 pm  

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

Stefan Maric September 16, 2020 2:07 am  

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!

Ben Beige September 11, 2020 9:48 am  

Will this work with LVM partitions as well?


Pierre Boulay September 14, 2020 12:16 pm  

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 September 12, 2020 4:42 am  

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 Boulay September 14, 2020 12:12 pm  

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.

Marcel Lunes Palau October 13, 2020 10:49 am  

In PowerShell “Invalid command line option: –mount”

Pierre Boulay October 13, 2020 12:03 pm  

There are two dashes (-) on this argument.


If that doesn’t help, please create an issue

K Kaland September 12, 2020 8:39 am  

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?

Pierre Boulay September 14, 2020 12:13 pm  

Yes, this scenario isn’t supported at this time.

Pavel Minaev September 12, 2020 6:19 pm  

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 Boulay September 14, 2020 12:15 pm  

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.
Ihor Dutchak October 19, 2020 6:26 am  

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…

Pierre Boulay October 19, 2020 12:42 pm  

That’s an interesting idea.

I’d recommend creating a feature request

tsuki Shimo September 15, 2020 12:32 am  

Can WSL2 mount other filesystem like JFS with this function?

Pierre Boulay September 24, 2020 3:31 pm  

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.

Rohat Bozyil September 20, 2020 10:37 pm  

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 Boulay September 24, 2020 3:32 pm  

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

Newer Comments →

Topics

Accessibility AF_UNIX ANSI/VT Sequences automount background tasks Bash BASIC Buffers Build2017 Build2019 Build2020 chmod

Chocolatey cmd Color Command-Line ConPTY Console containers Creators Update daemons DrvFs DvfFs Encoding filesystem

font ifconfig inotify interop Linux LinuxTools metadata MS-DOS networking Open-Source OpenSSH PowerShell PseduoConsole

Pseudo Console PTY release Rendering settings sockets Store Syscalls Tabs & Sets Teletype Terminal Themes Tmux TTY

Ubuntu Unicode UTF-8 VIntage Visual Studio What's New Win10S Windows Windows 10 Windows 10 S Windows Package Manager

winget winget.exe winui WSL wslconf Zoom


Top Bloggers

Kayla Cinnamon
Program Manager

Craig Loewen
Program Manager

Demitrius Nelon
Senior Program Manager

Pierre Boulay
Software Engineer II

Tyler Citrin
Program Manager

Archive

November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020

Stay informed

What's new Microsoft Store Education Enterprise Developer Company


Surface Duo Account profile Microsoft in education Azure Microsoft Visual Studio Careers

Surface Laptop Go Download Center Office for students AppSource Windows Dev Center About Microsoft

Surface Pro X Microsoft Store support Office 365 for schools Automotive Developer Center Company news

Surface Go 2 Returns Deals for students & Government Microsoft developer Privacy at Microsoft
parents program
Surface Book 3 Order tracking Healthcare Investors
Microsoft Azure in Channel 9
Microsoft 365 education Manufacturing Diversity and inclusion
Virtual workshops and Microsoft 365 Dev Center
Windows 10 apps Financial services Accessibility
training
Microsoft 365 Developer
HoloLens 2 Retail Security
Microsoft Store Promise Program

Financing Microsoft Garage

 English (United States) Sitemap Contact Microsoft Privacy Terms of use Trademarks Safety & eco About our ads © Microsoft 2020

You might also like