WSL
安装 WSL
wsl --help wsl --install -d Debian --location D:\Debian wsl --install --from-file D:\Debian_WSL_AMD64_v1.20.0.0.wsl --name Debian --location D:\Debian wsl --export Debian D:\debian.tar wsl --export --vhd Debian D:\Debian\ext4.vhdx wsl --unregister Debian wsl --import Debian D:\Debian\ D:\debian.tar --version 2 wsl --import-in-place Debian D:\Debian\ext4.vhdx wsl --shutdown wsl --manage Debian --move D:\Debian wsl --manage Debian --set-sparse false optimize-vhd -Path .\Debian\ext4.vhdx -Mode full wsl --manage Debian --set-sparse true wsl --manage Debian --set-default-user my # Debian config --default-user my del %USERPROFILE%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt # regedit,HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss
https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json
注:出现 MobaXterm 无法连接,可能是 name 导致。配置 appendWindowsPath 可确定 WSL 是否会将 Windows 路径元素添加到 $PATH 环境变量
WSL 安装 Docker
参考 https://www.cnblogs.com/jhxxb/p/11410816.html,这里记录一些问题
# 自启动,wsl systemd 支持:https://learn.microsoft.com/zh-cn/windows/wsl/wsl-config#systemd-support sudo vim /etc/wsl.conf [boot] systemd=true # WSL Debian Docker 启动失败 # https://superuser.com/questions/1468316/which-kernel-moduules-are-really-needed-for-docker-installation sudo update-alternatives --set iptables /usr/sbin/iptables-legacy sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy # grep: /etc/fstab: No such file or directory sudo touch /etc/fstab # 重启 docker sudo service docker restart sudo service docker status # 有些容器启动失败可能是文件权限问题 # https://blog.csdn.net/x356982611/article/details/108732844 # https://docs.microsoft.com/zh-cn/windows/wsl/wsl-config#per-distribution-configuration-options-with-wslconf sudo vim /etc/wsl.conf [automount] enabled = true options = "metadata" mountFsTab = false # 重启 wsl(windows 命令) # https://docs.microsoft.com/zh-cn/windows/wsl/basic-commands#shutdown wsl --shutdown
WSL Alpine Docker 安装
# 换源 https://mirrors.ustc.edu.cn/help/alpine.html sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories # 安装 apk add --no-cache openrc docker docker-compose # 启动 openrc touch /run/openrc/softlevel service docker start # /etc/init.d/docker start # rc-update add docker default # 用户 apk add shadow sudo # 用户添加到 wheel 组,只有在 wheel 组的用户才能使用 sudo addgroup [username] wheel # 去掉执行 sudo 命令时每次输入密码,找到行"# %wheel ALL=(ALL) NOPASSWD: ALL"去掉注释 visudo
其它子系统:https://wsldl-pg.github.io/docs/Using-wsldl
WSL 更新 Kernel
一、编译,两种选择
wget https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags/linux-msft-wsl-5.15.133.1.tar.gz tar -zxf linux-msft-wsl-5.15.133.1.tar.gz cd WSL2-Linux-Kernel-linux-msft-wsl-5.15.133.1 # 依赖 sudo apt install build-essential flex bison dwarves libssl-dev libelf-dev # 配置,如果需要。输入 / 可进入搜索模式 make menuconfig KCONFIG_CONFIG=Microsoft/config-wsl # 编译 make -j64 KCONFIG_CONFIG=Microsoft/config-wsl # 复制内核到 D 盘根目录 cp arch/x86/boot/bzImage /mnt/d/
下载官方 kernel 源码,使用 microsoft 的配置
wget https://mirrors.tuna.tsinghua.edu.cn/kernel/v5.x/linux-5.15.136.tar.xz sudo apt install -y tar xz-utils && tar -xf linux-5.15.136.tar.xz cd linux-5.15.136 # 复制配置 cp ../WSL2-Linux-Kernel-linux-msft-wsl-5.15.133.1/Microsoft/config-wsl .config # 编译,不用 KCONFIG_CONFIG=Microsoft/config-wsl 指定配置 make -j64 # 复制内核到 D 盘根目录 cp arch/x86/boot/bzImage /mnt/d/
二、替换内核
在用户目录新建 .wslconfig 文件,例如 C:\Users\Administrator\.wslconfig。然后配置内核路径
[wsl2] kernel=D:\\bzImage
重启 wsl:wsl --shutdown,使用 uname -a 查看内核版本
https://github.com/microsoft/WSL2-Linux-Kernel
https://learn.microsoft.com/zh-cn/windows/wsl/wsl-config#main-wsl-settings
https://github.com/microsoft/wslg/wiki/WSLg-Configuration-Options-for-Debugging

浙公网安备 33010602011771号