在 Windows 和 WSL 2 中访问 Linux 文件系统
WSL
![](/data/attachment/album/202009/12/194308wlkz488xi6elixvk.jpg)


从 [Windows Insiders 预览版 20211](https://blogs.windows.com/windows-insider/2020/09/10/announcing-windows-10-insider-preview-build-20211/) 开始，WSL 2 将提供一个新功能：`wsl --mount`。这个新的参数允许在 WSL 2 中连接和挂载一个物理磁盘，这样你就可以访问 Windows 不支持的文件系统（比如 ext4）。


因此，如果你使用不同的磁盘对 Windows 和 Linux 进行双启动，你现在可以从 Windows 访问你的 Linux 文件了。


### 开始使用


要挂载磁盘，请打开具有管理员权限的 PowerShell 窗口并运行。



```
wsl --mount <DiskPath>
```

要在 Windows 中列出可用的磁盘，请运行。



```
wmic diskdrive list brief
```

要从 WSL 2 上卸载和分离磁盘，请运行以下命令



```
wsl --unmount <Diskpath>
```

磁盘路径可在 `DeviceID` 栏中找到。通常是以 `\\.\\.\PHYSICALDRIVE*` 的格式。下面是一个将指定硬盘的特定分区挂载到 WSL 中并浏览其文件的例子：


![](/data/attachment/album/202009/12/194410cqnggacsgq3v6cd2.png)


### 使用文件资源管理器访问这些文件


一旦挂载，也可以通过 Windows 资源管理器访问这些磁盘，通过导航到 `\wsl$`，然后到挂载文件夹。


![](/data/attachment/album/202009/12/194411ysaq2ee33o779jac.png)


### 局限性


默认情况下，`wsl --mount` 会尝试将磁盘挂载为 ext4。要指定一个文件系统，或者更高级的方案，请查看[在 WSL 2 中挂载磁盘](https://docs.microsoft.com/windows/wsl/wsl2-mount-disk)。


另外请注意，这个功能有一个限制，那就是只有物理磁盘可以连接到 WSL 2。目前，还不能附加单个分区。更多关于限制的细节请看[这里](https://docs.microsoft.com/windows/wsl/wsl2-mount-disk#limitations)。


### 反馈


如果你遇到任何问题或反馈，请在 [GitHub](https://github.com/microsoft/wsl/issues) 上提交议题。


OK
Starting with [Windows Insiders preview build 20211](https://blogs.windows.com/windows-insider/2020/09/10/announcing-windows-10-insider-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](https://docs.microsoft.com/windows/wsl/wsl2-mount-disk).

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](https://docs.microsoft.com/windows/wsl/wsl2-mount-disk#limitations).

## Give us your feedback!

If you run into any issues, or have feedback for our team please file an issue on our [Github](https://github.com/microsoft/wsl/issues) , and if you have general questions about WSL you can find all of our team members that are on Twitter on [this twitter list](https://twitter.com/i/lists/1131397802204864512/members).

“At this time, it’s not possible to attach a single partition.” is confusing me.

But the sample you demonstrates does mount a single partition to wsl.

So may I know what’s real limitation of that?

What is meant by that statement is that it’s not possible to have one partition attached to WSL 2 while the disk is in use in Windows.

Concretely, this means that the entire disk must be attached to WSL 2, regardless of which partitions are mounted in there.

When is this coming to stable release of Windows 10? I need this, but don’t want to go to Dev Preview on my main dev machine.

How disappointing, this Insider build was pulled from service, as they found a bug (see note in the announcement.) Any other way to get this feature without having access to the build, by chance? I was really looking forward to accessing my Linux drives.

The latest insider build has the

`wsl --mount`

feature so you should be able to access it.Thanks for that.

Okay, I've switched to the dev branch and am downloading 20231 as I write this.

This is the only features I need and although I chose not to wait, as I have many ext4 drives, I'd really like to be back on stable again. That said, can I leave Insiders at some point and be back to stable, say, if stable catches up and reaches 20231 will I be moved back again? ...

Jumping in to help with this question:

Yes you can leave Insiders at any point and be back to stable! The only stipulation here is that you can't go backwards to an older Windows release. So for your use case it'd probably make sense to start in the Dev Channel (which gives new builds each week) to get access to wsl --mount, and then in the future you can change your settings to the beta channel...

That's great, thanks Craig!

I'm testing the feature out as we speak...

Okay, I ran into an issues and will detail why and how I fixed it:

The code above is missing any reference to the --partition flag, although I now see it's in the image. I'm leaving this here for others, should they run into the same issue and or until the code above has been clarified.

I get an error and am told:

<code>Which I narrow down...

When will this be available for windows 10 stable? Thanks.

Is it supported WSL1 ?

No. wsl –mount is only supported by WSL 2.

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.

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.

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

alsodouble 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

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.

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