某些軟件需要有梯子
1. 打開 WSL
使用管理員權限打開 powershell,執行
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
或者在程序和功能選中 Windows-Subsystem-Linux。
2. 下載 Centos 7 的docker 鏡像
可以參考 https://github.com/RoliSoft/WSL-Distribution-Switcher 來下載。
或者直接下載 下面的鏈接給出的鏡像。
https://raw.githubusercontent.com/CentOS/sig-cloud-instance-images/CentOS-7-x86_64/docker/centos-7-x86_64-docker.tar.xz
3. 安裝 chocolatey
3.1 使用choco安裝
- 安裝choco
參考 :https://chocolatey.org/install
使用管理員權限打開 powershell,執行
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) - 安裝LxRunOffline
choco install lxrunoffline - 常用LxRunOffline命令
LxRunOffline.exe list
已經安裝的wslLxRunOffline.exe install
安裝wslLxRunOffline.exe export
備份wslLxRunOffline.exe run
啓動一個wsl
3.2 下載LxRunOffline可執行文件安裝
https://github.com/DDoSolitary/LxRunOffline
4. 使用 LxRunOffline 部署 CentOS 到WSL
LxRunOffline.exe install -n CentOS -d D:\Data\WSL\CentOS -f d:\Data\WSL\images\centos-7-x86_64-docker.tar.xz
其中 -d 後面是要安裝到的目錄,-f 是前面下載的鏡像, -n 用來指定名稱。
查看幫助:.\LxRunOffline.exe -?
卸載centos: LxRunOffline.exe ur -n CentOS
若已經有linux,需要卸載
5. 啓動Linux
5.1 使用LxRunOffline
然後使用 LxRunOffine 來開啓 CentosLxRunOffline run -n centos
或者:直接在wsl執行命令:bash
5.2 使用WSL
使用 wsl -d CentOS
啓動CentOS
wsl -l
查看已安裝發行版本wsl -d <DistributionName>
啓動執行的發行版本wsl -s <DistributionName>
將發行版本設置爲默認值wsl -t <DistributionName>
終止分發wsl --unregister <DistributionName>
註銷分發wsl --help
顯示幫助