开启Windows的WSL特性(需要家庭版以上的版本)
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
执行完这一步需要重启机子。
接下来要下载一个Linux镜像,这里选用的是Ubuntu20.04LTS
可以在PowerShell里面使用命令下载:
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-2004 -OutFile Ubuntu2004.appx -UseBasicParsing
或者浏览器直接访问https://aka.ms/wslubuntu2004
。
Downloading distributions其他Linux镜像。
将下载下来的镜像的appx后缀改为zip后缀,然后解压出来:
Expand-Archive UbuntuXxx.zip
假设解压出来的目录是UbuntuXxx,里面有一个ubuntu2004.exe文件,只要这个文件即可开始安装。
参考:
- https://kontext.tech/column/tools/308/how-to-install-windows-subsystem-for-linux-on-a-non-c-drive
- https://superuser.com/questions/1572834/is-there-any-ways-to-install-wsl-on-non-c-drive
- https://docs.microsoft.com/en-us/windows/wsl/install-manual
其他
libQt5Core.so.5: cannot open shared object file
在WSL1中安装完KeePassXC之后,运行keepassxc-cli
出现错误:
keepassxc-cli: error while loading shared libraries: libQt5Core.so.5: cannot open shared object file: No such file or directory
根据Can’t load shared library libQt5Core.so.5,需要执行以下命令:
sudo strip --remove-section=.note.ABI-tag /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
如果没有strip,则需要安装binutils。
18.4看这边:Ubuntu 18.4 libQt5Core.so.5: cannot open shared object file: No such file or directory。
(本篇完)
2022-06-07更新
一些WSL命令
wsl -l -v
列出当前安装的WSLwsl --set-version Dist 2
,将某个Dist设为WSL2wsl -d Dist hostname -I
,打出某个Dist,https://superuser.com/questions/1586386/how-to-find-wsl2-machines-ip-address-from-windows
autossh
https://git.io/autossh教程说如何在wsl2里面开启openssh服务,其Github页面https://github.com/rescenic/autossh。
可以看到很多配置文件在/usr目录下,而不是直接在/etc下面,Configuration files in /etc and /usr/etc为此做了一些解释
rcsshd start在wsl2下不能用,因为wsl2没有使用systemd作为系统控制框架。
执行sudo /usr/bin/ssh-keygen -A
生成一个系统密钥
/usr/sbin/sshd
开启sshd服务
Windows宿主上安装OpenSSH Server
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
其他参考:
- https://www.cyberithub.com/how-to-start-and-enable-sshd-service-in-opensuse-linux/
- https://unix.stackexchange.com/questions/162092/how-can-i-list-all-files-which-have-been-installed-by-an-zypp-zypper-package
- https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse
- https://en.opensuse.org/SDB:Configure_openSSH
(更新完)
2022-10-22更新
可以通过wsl --update
来更新wsl的基础内容,还有wsl --status
可以查看wsl的状态。
(更新完)