Access Linux filesystems in Windows and WSL 2
从 Windows Insiders 预览版构建 20211 开始,WSL 2 将提供一项新功能:wsl --mount。这一新参数允许在 WSL 2 中连接并挂载物理磁盘,从而使您能够访问 Windows 本身不支持的文件系统(如 ext4)。
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).
因此,如果你使用不同的磁盘进行 Windows 和 Linux 双启动,现在就可以从 Windows 访问 Linux 文件了!
So, if you’re dual booting with Windows & Linux using different disks, you can now access your Linux files from Windows!
Getting started
要挂载磁盘,请打开具有管理员权限的 PowerShell 窗口并运行:
To mount a disk, open a PowerShell window with administrator privileges and run:
wsl --mount <DiskPath>
要在 Windows 中列出可用磁盘,请运行:
To list the available disks in Windows, run:
wmic diskdrive list brief
要从 WSL 2 中卸载和分离磁盘,请运行:
To unmount and detach the disk from WSL 2, run
wsl --unmount <Diskpath>
磁盘路径可在 “DeviceID ”列中找到。通常是 \.\.\PHYSICALDRIVE* 格式。下面是一个将特定硬盘分区挂载到 WSL 并浏览其文件的示例。
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
挂载后,也可以通过 Windows 资源管理器访问这些磁盘,方法是导航到\\wsl$,然后导航到挂载文件夹。
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
默认情况下,wsl --mount 会尝试将磁盘挂载为 ext4。要指定文件系统,或了解更多高级方案,请查看"在 WSL 2 中挂载磁盘"。
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.
另外请注意,此功能有一个限制,即只能将物理磁盘连接到 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.
参考;
Access Linux filesystems in Windows and WSL 2 - Windows Command Line (microsoft.com)