WSL 出现Read-only file system 问题修复

使用WSL时突然出现Read-only file system,仔细一看进入时有提示:

An error occurred mounting the distribution disk, it was mounted read-only as a fallback.
See recovery instructions on: https://aka.ms/wsldiskmountrecovery
/etc/update-motd.d/90-updates-available: line 7: /usr/share/update-notifier/notify-updates-outdated: No such file or directory
run-parts: /etc/update-motd.d/90-updates-available exited with return code 127
ERROR: could not generate new MOTD

This message is shown once a day. To disable it please create the
/root/.hushlogin file.
touch: cannot touch '/root/.motd_shown': Read-only file system
-bash: export: `Files/Docker/Docker/resources/bin:/mnt/c/Program': not a valid identifier
-bash: export: `Files/usbipd-win/:/mnt/c/Users/whshi/AppData/Local/Microsoft/WindowsApps:/mnt/d/Microsoft': not a valid identifier
-bash: export: `Code/bin:/mnt/c/Users/whshi/AppData/Local/OpenHarmony/Sdk/9/toolchains:/snap/bin': not a valid identifier

这时整个linux系统文件都是只读挂载的,在home下创建文件或修改文件会出现Read-only file system错误提示。

root@LAPTOP-U9BLNV2M:/home# touch a
touch: cannot touch 'a': Read-only file system

在windows文件浏览器下创建新文件会提示:错误0X8000FFF:灾难性故障

网上大部分修复方法是:e2fsck -f /dev/sdc,但是使用时出现报错:

/dev/sdc is mounted.
e2fsck: Cannot continue, aborting.

如果出现报错可以退出wsl; wsl –shutdown

然后在powershell里执行

PS C:\Users\whshi> wsl --mount e:\WSL\ext4.vhdx --vhd --bare
操作成功完成。
PS C:\Users\whshi> wsl --list
适用于 Linux 的 Windows 子系统分发:
UBUNTU-20.04-NEW (默认)
Ubuntu-20.04
ubuntu-office
PS C:\Users\whshi> wsl -d UBUNTU-20.04-NEW -u root e2fsck -f /dev/sdc
无法将磁盘“E:\WSL\ext4.vhdx”附加到 WSL2: 另一个程序正在使用此文件,进程无法访问。
错误代码: Wsl/Service/CreateInstance/MountVhd/HCS/ERROR_SHARING_VIOLATION
PS C:\Users\whshi> wsl --system -u root e2fsck -f /dev/sdc
无法将磁盘“E:\WSL\ext4.vhdx”附加到 WSL2: 另一个程序正在使用此文件,进程无法访问。
错误代码: Wsl/Service/CreateInstance/MountVhd/HCS/ERROR_SHARING_VIOLATION
PS C:\Users\whshi> wsl --shutdown
PS C:\Users\whshi> wsl -d UBUNTU-20.04-NEW -u root e2fsck -f /dev/sdc
e2fsck 1.45.5 (07-Jan-2020)
/dev/sdc is mounted.
e2fsck: Cannot continue, aborting.


PS C:\Users\whshi> wsl -d UBUNTU-20.04-NEW -u root e2fsck -f /dev/sdc -y
e2fsck 1.45.5 (07-Jan-2020)
/dev/sdc is mounted.
e2fsck: Cannot continue, aborting.


PS C:\Users\whshi> wsl -d UBUNTU-20.04-NEW -u root e2fsck -f /dev/sdc -p
/dev/sdc is mounted.
e2fsck: Cannot continue, aborting.


PS C:\Users\whshi> wsl --system -u root e2fsck -f /dev/sdc
e2fsck 1.46.5 (30-Dec-2021)
Warning!  /dev/sdc is mounted.
/dev/sdc: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Block bitmap differences:  +(145588012--145588014) -(145682212--145682214)
Fix<y>? yes
Free blocks count wrong for group #4442 (214, counted=211).
Fix<y>? yes
Free blocks count wrong for group #4445 (208, counted=211).
Fix<y>? yes
Free blocks count wrong (4826, counted=4814).
Fix<y>? yes
Free inodes count wrong (56170081, counted=56170077).
Fix<y>? yes

/dev/sdc: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdc: 10938787/67108864 files (2.3% non-contiguous), 268430642/268435456 blocks 
PS C:\Users\whshi> wsl -d UBUNTU-20.04-NEW
/etc/update-motd.d/90-updates-available: line 7: /usr/share/update-notifier/notify-updates-outdated: No such file or directory
run-parts: /etc/update-motd.d/90-updates-available exited with return code 127
ERROR: could not generate new MOTD

This message is shown once a day. To disable it please create the
/root/.hushlogin file.
-bash: export: `Files/Docker/Docker/resources/bin:/mnt/c/Program': not a valid identifier
-bash: export: `Files/usbipd-win/:/mnt/c/Users/whshi/AppData/Local/Microsoft/WindowsApps:/mnt/d/Microsoft': not a valid identifier
-bash: export: `Code/bin:/mnt/c/Users/whshi/AppData/Local/OpenHarmony/Sdk/9/toolchains:/snap/bin': not a valid identifier
root@LAPTOP-U9BLNV2M:/mnt/c/Users/whshi# cd /home/
root@LAPTOP-U9BLNV2M:/home# touch a
root@LAPTOP-U9BLNV2M:/home# 

参考地址:how-to-repair-a-vhd-mounting-error? the tutorial not work at all! · Issue #10169 · microsoft/WSL

发表回复 0

Your email address will not be published. Required fields are marked *