win10/winserver2022安装wsl2
win10/winserver2022安装wsl2
启用windows子系统支持
启用windows支持
# 启用WSL和虚拟机平台功能(/norestart表示暂不重启)
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# 或使用PowerShell命令
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux, VirtualMachinePlatform -All -NoRestart{insert\_element\_3\_}
重启服务器
Restart-Computer -Force
安装wsl2内核更新包
# 下载WSL2内核更新包
curl.exe -L -o wsl_update_x64.msi https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
# 安装更新包
msiexec /i wsl_update_x64.msi /quiet /norestart
```
设置 WSL2 为默认版本
```bash
wsl --set-default-version 2
安装 Linux 分发版
# 查看可用分发版列表
wsl --list --online
# 安装Ubuntu(推荐)
wsl --install -d Ubuntu
# 或安装其他分发版,如:
wsl --install -d Debian
wsl --install -d CentOS7
如何在线不行,可以离线安装
# 启用WSL和虚拟机平台功能(/norestart表示暂不重启)
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# 或使用PowerShell命令
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux, VirtualMachinePlatform -All -NoRestart{insert\_element\_3\_}Restart-Computer -Force# 下载WSL2内核更新包
curl.exe -L -o wsl_update_x64.msi https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
# 安装更新包
msiexec /i wsl_update_x64.msi /quiet /norestart
```
设置 WSL2 为默认版本
```bash
wsl --set-default-version 2# 查看可用分发版列表
wsl --list --online
# 安装Ubuntu(推荐)
wsl --install -d Ubuntu
# 或安装其他分发版,如:
wsl --install -d Debian
wsl --install -d CentOS7访问https://store.rg-adguard.net/,选择`ProductId`为9pn20msr04dw,类型为`retail`,下载`appxbundle`结尾的文件。
PS C:\Users\Administrator> cd ../
PS C:\Users> cd ../
PS C:\> cd .\4_ubuntu\
PS C:\4_ubuntu>
PS C:\4_ubuntu> Add-AppxPackage -Path .\Ubuntu22.04LTS.AppxBundle或者
Invoke-WebRequest -Uri "https://cloud-images.ubuntu.com/wsl/jammy/current/ubuntu-jammy-wsl-amd64-ubuntu22.04lts.rootfs.tar.gz" -OutFile "ubuntu2204.tar.gz" -UseBasicParsing
PS C:\4_ubuntu> mkdir C:\wsl\Ubuntu2204
目录: C:\wsl
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2026/6/7 16:53 Ubuntu2204
PS C:\4_ubuntu> wsl --import Ubuntu-22.04 C:\wsl\Ubuntu2204 C:\4_ubuntu\ubuntu2204.tar.gz --version 2
PS C:\4_ubuntu> wsl -d Ubuntu-22.04更新源文件
sudo nano /etc/apt/sources.list清空内容,添加以下内容
# 阿里源(Ubuntu 22.04 LTS专用)
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse更新系统
# 更新软件包列表
sudo apt update
# 升级系统软件
sudo apt upgrade -y管理工具
访问https://gitee.com/bye/wsl-dashboard/releases
wsl2访问windows文件
# 挂载Windows文件系统
wsl --mount /mnt/c /mnt/c --options uid=$(id -u),gid=$(id -g)访问windows文件
# 访问Windows文件
cd /mnt/c安装wsl2桌面环境
# 安装XFCE4桌面环境
sudo apt install -y xfce4 xfce4-goodies
# 安装xrdp远程服务(用于Windows远程连接)
sudo apt install -y xrdp
# 修改xrdp端口(避免与Windows自带远程桌面冲突,默认3389端口,改为3390)
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
# 指定桌面会话(确保远程连接时能正常加载XFCE4桌面)
echo "xfce4-session" | sudo tee -a /etc/xrdp/startwm.sh
# 启动并设置xrdp开机自启:
sudo systemctl enable --now xrdp
#可输入
sudo systemctl status xrdp查看服务状态,显示“active”即为启动成功。
# 连接图形桌面: ① Windows端按 Win+R,输入“mstsc”,打开远程桌面连接; ② 计算机地址填写:localhost:3390,点击“连接”; ③ 弹出登录窗口,输入Ubuntu的用户名和密码,忽略证书警告,即可进入XFCE4桌面(第一次进入可能需要设置桌面布局,按提示操作即可)本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 WenYan Blog!
评论


