解决WSL子系统打开ubuntu时闪退问题:Sleeping for 1 second to let systemd settlen
1.问题
开机后直接打开ubuntu会报错:sleeping for 1 second to let systemd settle,然后闪退,再次打开后一片黑,只有一个光标:
适用于 Linux 的 Windows 子系统现已在 Microsoft Store!
你可以通过运行 “wsl.exe --update” 进行升级 或通过访问 https://aka.ms/wslstorepage
从Microsoft Store安装 WSL 将提供最新的 WSL 更新, faster.
有关详细信息,请访问 https://aka.ms/wslstoreinfo
Sleeping for 1 second to let systemd settle
在PowerShell中输入wsl启动子系统时,也报错:
Sleeping for 1 second to let systemd settlen
nsenter: 打不开 /proc/31/ns/time: 没有那个文件或目录
2.解决
以管理员身份打开PowerShell,执行:
> wsl --user root
登录后将下面脚本复制并回车执行:
#!/bin/bash
self_dir=$(pwd)
echo "Uninstalling ubuntu-wsl2-systemd-script"
sudo rm -rf /usr/sbin/start-systemd-namespace
sudo rm -rf /usr/sbin/enter-systemd-namespace
sudo rm -rf /etc/sudoers.d/systemd-namespace
cd /var/tmp
if [ -f "/etc/bash.bashrc" ]; then
sudo grep -v "# Start or enter a PID namespace in WSL2
export USE_WSLG_SOCKET=false
export USE_WSLG_SOCKET=true
source /usr/sbin/start-systemd-namespace" /etc/bash.bashrc > tmpfile
sudo mv tmpfile /etc/bash.bashrc
fi
cd $self_dir
再次尝试打开WSL2:
> wsl
可以打开wsl,但是报错:
PS C:\WINDOWS\system32> wsl -bash: /usr/sbin/start-systemd-namespace: No such file or directory
打开文件:
> sudo vim /etc/bash.bashrc
注释掉相应语句—source /usr/sbin/start-systemd-namespace:
重新打开wsl就正常啦!
参考:博客Sleeping for 1 second to let systemd settle nsenter: 打不开 /proc/31/ns/time: 没有那个文件或目录