一、准备工作
1、开启子系统
控制面板 > 程序与功能 > 启动或关闭Windows功能 勾选 “适用于LInux的Windows子系统“ 和 “虚拟机平台”,重启即可 2、安装内核更新包 https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
3、设置wsl默认版本2 win+x以管理员身份打开powershell/window终端
wsl --set-default-version 2
二、安装子系统(以ubuntu22.04为例)
1、microsoft store下载安装ubuntu22.04 2、启动,会自动安装子系统ubuntu22.04 之后一路Done~,最后Rebot now
三、配置windows terminal
1、microsoft store下载windows terminal(win11需要先卸载再安装,原因是自带的版本太低,设置界面直接没了) 2、打开windows terminal进行配置 修改启动为ubtuntu-22.04 保存
四、配置ubuntu
1、ubuntu22.04(也就是windows terminal终端)下修改系统软件源
sudo mv /etc/apt/sources.list /etc/apt/source.list.bak
sudo vim /etc/apt/sources.list
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
sudo apt update
2、安装zsh
sudo apt install zsh
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
推荐插件:https://blog.csdn.net/iamzhoujunjia/article/details/107730585?spm=1001.2014.3001.5502
五、支持systemd
sudo su
wget -O /etc/apt/trusted.gpg.d/wsl-transdebian.gpg https://arkane-systems.github.io/wsl-transdebian/apt/wsl-transdebian.gpg
chmod a+r /etc/apt/trusted.gpg.d/wsl-transdebian.gpg
cat << EOF > /etc/apt/sources.list.d/wsl-transdebian.list
deb https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main
deb-src https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main
EOF
apt update
apt install -y systemd-genie
先用powershell查看子系统的名称
wsl -l -v
windows terminal设置修改ubuntu启动命令,追加 genie -s,保存 ubuntu(也就是windows terminal终端)执行下面命令
sudo ssh-keygen -A
sudo e2label /dev/sdb cloudimg-rootfs
sudo systemctl mask multipathd.service
修改文件/usr/lib/systemd/system/systemd-sysusers.service,注释掉LoadCredential,并加多一空值行 关闭windows terminal,在powershell下重启wsl 重新打开windows terminal,查看是否wsl守护进程程序修改为systemd
ps u -q 1
六、安装docker
1、如果是ubuntu22.04需要先进行iptables降级,切换回iptables-legacy
sudo update-alternatives --config iptables
2、安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
普通用户操作docker权限问题解决
sudo groupadd docker
sudo gpasswd -a $USER docker
newgrp docker
3、更换docker镜像源
sudo vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://2l5j7ihl.mirror.aliyuncs.com"]
}
sudo systemctl daemon-reload
sudo systemctl restart docker
后话
至此就可以在windows下利用window terminal终端,进行愉快的子系统玩耍了
|