今天打开wsl, 报如下错误, 无法进入:
C:\d>wsl
灾难性故障
错误代码: Wsl/Service/CreateInstance/E_UNEXPECTED
按照网上的提示更新wsl。
C:\d>wsl --update
正在检查更新。
正在更新适用于 Linux 的 Windows 子系统: 3.0.1。
[= 2.2% ]
更新很慢,大约3小时,而 https://github.com/microsoft/WSL/releases/download/3.0.1/wsl.3.0.1.0.x64.msi 的大小只有340MB
更新完成后,打开wsl, 报如下错误, 但是能进入Linux提示符状态。
Microsoft Windows [版本 10.0.26200.9457]
(c) Microsoft Corporation。保留所有权利。
C:\Users\lt>wsl
wsl: An error occurred mounting the distribution disk, it was mounted read-only as a fallback.
wsl: See recovery instructions on: https://aka.ms/wsldiskmountrecovery
在浏览器打开错误提示给出的链接 https://aka.ms/wsldiskmountrecovery ,按照文档的提示, 输入如下命令测试
root@DESKTOP-59T6U68:/mnt/c/Users/lt# touch file
root@DESKTOP-59T6U68:/mnt/c/Users/lt# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 722.9M 1 disk
sdb 8:16 0 96.5M 1 disk
sdc 8:32 0 3G 0 disk [SWAP]
sdd 8:48 0 256G 0 disk /mnt/wslg/distro
root@DESKTOP-59T6U68:/mnt/c/Users/lt#
root@DESKTOP-59T6U68:/mnt/c/Users/lt# ls file
file
我的错误和文档中的不同,touch file没有报错。但是RO为1的设备有2个,文档中只有1个。
虽然打开一些文件可以执行,总是有类似read-only错误,docker容器无法打开。
root@DESKTOP-59T6U68:/mnt/c/d# docker start gcc
Error: error opening database /var/lib/containers/storage/libpod/bolt_state.db: open /var/lib/containers/storage/libpod/bolt_state.db: read-only file system
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\Users\lt> wsl --version
WSL 版本: 3.0.1.0
内核版本: 6.18.40.1-1
WSLg 版本: 1.0.79
MSRDC 版本: 1.2.7214
Direct3D 版本: 1.611.1-81528511
DXCore 版本: 10.0.26100.1-240331-1435.ge-release
Windows 版本: 10.0.26200.9457
PS C:\Users\lt> (Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq '<distribution-name>' }).GetValue("BasePath") + "\ext4.vhdx"
不能对 Null 值表达式调用方法。
所在位置 行:1 字符: 1
+ (Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [],RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
PS C:\Users\lt> (Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq 'Debian' }).GetValue("BasePath") + "\ext4.vhdx"
C:\Users\lt\AppData\Local\wsl\{4668a706-3712-4276-9040-4c3f9669f677}\ext4.vhdx
第一次命令没有输入实际的distribution-name,导致报错。
在windows搜索框输入regedit命令进入注册表编辑器,查看HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss条目,看出distribution-name是Debian,把它填入,就返回了虚拟机文件名。
文档中说,如果只安装了一个Linux发布版本, 修复需要先装另一个发布版本,查看可用版本,结果如下:
Microsoft Windows [版本 10.0.26200.9457]
(c) Microsoft Corporation。保留所有权利。
C:\Users\lt>cd\d
C:\d>wsl --list --online
以下是可安装的有效分发的列表。
使用"wsl.exe --install <Distro>"安装。
NAME FRIENDLY NAME
Ubuntu Ubuntu
Ubuntu-26.04 Ubuntu 26.04 LTS
Ubuntu-24.04 Ubuntu 24.04 LTS
Ubuntu-22.04 Ubuntu 22.04 LTS
openSUSE-Tumbleweed openSUSE Tumbleweed
openSUSE-Leap-16.0 openSUSE Leap 16.0
RLCPlus-9 Rocky Linux Plus 9 (CIQ)
RLCPlus-10 Rocky Linux Plus 10 (CIQ)
SUSE-Linux-Enterprise-15-SP7 SUSE Linux Enterprise 15 SP7
SUSE-Linux-Enterprise-16.0 SUSE Linux Enterprise 16.0
kali-linux Kali Linux Rolling
Debian Debian GNU/Linux
AlmaLinux-8 AlmaLinux OS 8
AlmaLinux-9 AlmaLinux OS 9
AlmaLinux-Kitten-10 AlmaLinux OS Kitten 10
AlmaLinux-10 AlmaLinux OS 10
archlinux Arch Linux
FedoraLinux-44 Fedora Linux 44
FedoraLinux-43 Fedora Linux 43
eLxr eLxr 12.12.0.0 GNU/Linux
OracleLinux_7_9 Oracle Linux 7.9
OracleLinux_8_10 Oracle Linux 8.10
OracleLinux_9_5 Oracle Linux 9.5
SUSE-Linux-Enterprise-15-SP6 SUSE Linux Enterprise 15 SP6
以下是修复步骤,设备名是/mnt/wslg/distro对应的sde, 中间两个优化选了否,修复都选了是。
C:\d>wsl.exe --shutdown
C:\d>wsl.exe --mount C:\Users\lt\AppData\Local\wsl\{4668a706-3712-4276-9040-4c3f9669f677}\ext4.vhdx --vhd --bare
操作成功完成。
C:\d>wsl.exe lsblk
wsl: An error occurred mounting the distribution disk, it was mounted read-only as a fallback.
wsl: See recovery instructions on: https://aka.ms/wsldiskmountrecovery
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 722.9M 1 disk
sdb 8:16 0 96.5M 1 disk
sdc 8:32 0 3G 0 disk [SWAP]
sdd 8:48 0 1T 0 disk
sde 8:64 0 256G 0 disk /mnt/wslg/distro
C:\d>wsl.exe sudo e2fsck -f /dev/sde
wsl: An error occurred mounting the distribution disk, it was mounted read-only as a fallback.
wsl: See recovery instructions on: https://aka.ms/wsldiskmountrecovery
e2fsck 1.46.5 (30-Dec-2021)
Warning! /dev/sde is mounted.
/dev/sde: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Inode 701779 extent tree (at level 2) could be narrower. Optimize<y>? no
Inode 1048411 extent tree (at level 2) could be narrower. Optimize<y>? no
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Block bitmap differences: -(38666240--38764543)
Fix<y>? yes
Free inodes count wrong for group #170 (7852, counted=7853).
Fix<y>? yes
Directories count wrong for group #170 (2, counted=1).
Fix<y>? yes
Free inodes count wrong (15384268, counted=15384269).
Fix<y>? yes
Inode bitmap differences: Group 170 inode bitmap does not match checksum.
FIXED.
/dev/sde: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sde: 1392947/16777216 files (0.6% non-contiguous), 37059616/67108864 blocks
C:\d>wsl.exe --unmount
操作成功完成。
现在wsl不报错了,也能打开docker容器了。
C:\d>wsl
root@DESKTOP-59T6U68:/mnt/c/d# docker start gcc
gcc
root@DESKTOP-59T6U68:/mnt/c/d# docker exec -it gcc bash
root@6ae32a5ffcde:/#