Windows访问Linux的Ext4格式磁盘

前言:

目前Windows下没有特别好的软件可以读取Ext4格式磁盘,DiskGenius复制Ext4格式磁盘文件需要购买专业版才可以,比较好用的就剩WSL了。具体的Windows启用WSL的方式请参考其他文章。

WSL读取Ext4格式磁盘

一:核对WSL版本为2,老版本需要更新

使用命令:wsl --version 查看WSL版本

Windows 11启用WSL的时候默认会带一个Ubuntu22.04版本,无需再手动安装

# WSL版本信息
PS C:\Users\lemon> wsl --version
WSL 版本: 2.2.4.0
内核版本: 5.15.153.1-2
WSLg 版本: 1.0.61
MSRDC 版本: 1.2.5326
Direct3D 版本: 1.611.1-81528511
DXCore 版本: 10.0.26091.1-240325-1447.ge-release
Windows 版本: 10.0.22631.3737
PS C:\Users\lemon>

# WSL中已有的Linux子系统
PS C:\Users\lemon> wsl --list
适用于 Linux 的 Windows 子系统分发:
Ubuntu (默认)
docker-desktop-data
docker-desktop
PS C:\Users\lemon>

二:接入Ext4磁盘到Windows系统中

需要注意的两点:
①Ext4格式磁盘接入Windows系统会识别为未初始化的磁盘,千万别初始化,数据会丢失。
②WSL只支持挂载整块磁盘,不能仅挂载某一个指定分区。对于U盘和移动硬盘无所谓,对于一块磁盘安装Windows和Linux双系统就比较难受了,如果启动了磁盘上的Windows系统你就不能将磁盘整体挂载给WSL了,需要借助另一台电脑使用NVME扩展盒的方式挂载整块磁盘。

接入Ext4磁盘到Windows11 系统容后磁盘管理器中提示我的Ext4格式磁盘为未初始化磁盘,此时不可初始化,也别点击GPT/MBR选项,什么都不做即可。

三:挂载磁盘

打开终端管理员 PowerShell,
输入命令:GET-CimInstance -query "SELECT * from Win32_DiskDrive"
即可查看本机接入的所有磁盘信息,需要关注的是第一列DeviceID

PS C:\Users\lemon> GET-CimInstance -query "SELECT * from Win32_DiskDrive"

DeviceID           Caption                               Partitions Size          Model
--------           -------                               ---------- ----          -----
\\.\PHYSICALDRIVE2 Realtek RTL9210 NVME SCSI Disk Device 0          1024203640320 Realtek RTL9210 NVME SCSI Disk Device
\\.\PHYSICALDRIVE0 SAMSUNG MZVLB1T0HBLR-00007            7          1024203640320 SAMSUNG MZVLB1T0HBLR-00007
\\.\PHYSICALDRIVE1 Realtek RTL9210B-CG SCSI Disk Device  1          1024203640320 Realtek RTL9210B-CG SCSI Disk Device


PS C:\Users\lemon>

输入命令:wsl --mount \\.\PHYSICALDRIVE2
挂载磁盘  \\.\PHYSICALDRIVE2 (\\.\PHYSICALDRIVE2为上续命令输出列表中的DeviceID)

PS C:\Users\lemon> wsl --mount \\.\PHYSICALDRIVE2
已成功将磁盘装载为“/mnt/wsl/PHYSICALDRIVE2”。
注意: 如果已修改 /etc/wsl.conf 中的 automount.root 设置,则位置将不同。
若要卸载和分离磁盘,请运行“wsl.exe --unmount \\.\PHYSICALDRIVE2”。
PS C:\Users\lemon>

四:访问磁盘

有两种方式访问这个挂载的磁盘,一个是通过Windows文件管理器访问,一个是通过命令行访问

①Windows文件管理器访问

进入目录:\\wsl.localhost\Ubuntu\mnt\wsl\PHYSICALDRIVE2

其中\\wsl.localhost\Ubuntu\mnt\wsl目录下还存在你的Windows系统的磁盘,再WSL的Linux系统中也是可以访问你的Windows磁盘资料

②命令行访问
再Windows的搜索中输入Ubuntu就看见看到你Windows系统开启的Linux子系统,点击打开进入Ubuntu命令行

使用命令: cd /mnt 
进入/mnt挂载目录就可以看到你资源管理器中一样的目录接口,也可以访问Windows的磁盘


五:卸载磁盘

使用命令:wsl --unmount \\.\PHYSICALDRIVE2
卸载掉磁盘,此时就可以拔掉U盘/移动硬盘

PS C:\Users\lemon> wsl.exe --unmount \\.\PHYSICALDRIVE2
操作成功完成。
PS C:\Users\lemon>

结尾:

需要注意的一点就是,对于接入的磁盘格式是否支持需要看你的Linux子系统内核是否支持这种格式的磁盘,对于支持的格式就可以挂载使用,不支持的格式就无法使用。

WSL访问Ext4格式磁盘的本质是使用Linux系统内核访问磁盘,然后通过内部网络映射给Windows的资源管理器。

可以读写Ext2,以Ext2方式挂载Ext3文件系统(不支持Ext3日志),不支持中文! It provides Windows NT4.0/2000/XP/2003/Vista/2008 with full access to Linux Ext2 volumes (read access andwrite access). This may be useful if you have installed both Windows and Linux as a dual boot environment on your computer. What features are supported? Complete reading and writing access to files and directories of volumes with theExt2 orExt3 file system. Supports features which are specific to the I/O-system of Windows: Byte Range Locks, Directory Notfication (so the Explorer updates the view of a directory on changes within that directory), Oplocks (so SMB clients are able to cache the content of files). Allows Windows to run with paging files on Ext2 volumes. UTF-8 encoded file names are supported. The driver treats files with file names that start with a dot "." character ashidden. Supports GPT disks if the Windows version used also does. Supports use of the Windows mountvol utility to create or delete drive letters for Ext2 volumes (except on Windows NT 4.0). See also section"Can drive letters also be configured from scripts?". What features are *not* supported? Inodes that are larger than 128 bytes are not supported. Access rights are not maintained. All users can access all the directories and files of an Ext2 volume. If a new file or directory is created, it inherits all the permissions, the GID and the UID from the directory where it has been created. There is one exception to this rule: a file (but not a directory) the driver has created always has cleared "x" permissions, it inherits the "r" and the "w" permissions only. See also section"What limitations arise from not maintaining access rights?". The driver does not allow accessing special files at Ext2 volumes, the access will be always denied. (Special files are sockets, soft links, block devices, character devices and pipes.) Alternate 8.3-DOS names are not supported (just because there is no place to store them in an Ext2 file system). This can prevent legacy DOS applications, executed by the NTVDM of Windows, from accessing some files or directories. Currently the driver does not implement defragging support. So defragmentation applications will neither show fragmentation information nor defragment any Ext2 volume. This software does not achieve booting a Windows operating system from an Ext2 volume. LVM volumes are not supported, so it is not possible to access them.
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值