下载 centos7 的 docker 镜像内核
https://raw.githubusercontent.com/CentOS/sig-cloud-instance-images/a77b36c6c55559b0db5bf9e74e61d32ea709a179/docker/centos-7-docker.tar.xz
开启linux子系统
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
可以重启下
开启虚拟机平台(WSL2需要)
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
安装Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco upgrade chocolatey
Chocolatey是一款专为Windows系统开发的、基于NuGet的包管理器工具,类似于Node.js的npm,MacOS的brew,Ubuntu的apt-get,它简称为choco。
安装LxRunOffline
cinst LxRunOffline -y
LxRunOffline是用于管理WSL子系统迁移、自定义安装的程序,可以指定安装位置。
设置默认为wsl2
wsl --set-default-version 2
LxRunOffline install -n CentOS7 -d "D:\WSL\CentOS7" -f "C:\Users\Administrator\Downloads\centos-7-docker.tar.xz"
LxRunOffline run -n CentOS7
安装成功后CentOS7还是wsl1,如果需要使用wsl2还有转换
查看安装的所有子系统
wsl -l -v
设置某个发行版为wsl2
wsl --set-version CentOS7 2
bash: ip command not found
解决办法: yum -y install initscripts
bash: ifconfig command not found
yum -y install net-tools
访问wsl文件
\\wsl$\CentOS7
WSL2固定IP地址.bat
@echo off :: 获取管理员权限 ::setlocal ::set uac=~uac_permission_tmp_%random% ::md "%SystemRoot%\system32\%uac%" 2>nul :: echo get uac_permission :: if %errorlevel%==0 ( rd "%SystemRoot%\system32\%uac%" >nul 2>nul ) else ( :: echo set uac = CreateObject("Shell.Application")>"%temp%%uac%.vbs" :: echo uac.ShellExecute "%~s0","","","runas",1 >>"%temp%%uac%.vbs" :: echo WScript.Quit >>"%temp%%uac%.vbs" :: "%temp%%uac%.vbs" /f :: del /f /q "%temp%%uac%.vbs" & exit :: ) ::endlocal setlocal enabledelayedexpansion ::wsl -u root service docker start | findstr "Starting Docker" > nul if !errorlevel! equ 0 ( ::echo docker start success :: set wsl2 ip wsl -u root ip addr | findstr "192.168.10.12" > nul if !errorlevel! equ 0 ( echo wsl ip has set ) else ( wsl -u root ip addr add 192.168.10.12/24 broadcast 192.168.10.255 dev eth0 label eth0:1 echo set wsl ip success: 192.168.10.12 ) :: set windows ip ipconfig | findstr "192.168.10.13" > nul if !errorlevel! equ 0 ( echo windows ip has set ) else ( netsh interface ip add address "vEthernet (WSL)" 192.168.10.13 255.255.255.0 echo set windows ip success: 192.168.10.13 ) ) pause
压缩WSL2系统的vhdx文件
首先WSL关机
关闭全部虚拟机
wsl --shutdown
关闭CentOS7虚拟机
wsl -t CentOS7
进入diskpart工具,cmd下输入如下命令:
diskpart
选择vhdx文件,路径需写绝对路径:
select vdisk file = "D:\WSL\CentOS7\ext4.vhdx"
执行压缩命令:
compact vdisk
WSL1和WSL2比较,大神文章:
https://blog.csdn.net/weixin_33929779/article/details/112238216
- 相关文章
- 查看评论:(0)
【已经有0位大神发现了看法】
- [分享]要抓住男人的心,就要先抓住他的胃。-鬼故事 2012-12-02
- [分享]小两口这样多好啊!就不用我再来替你们洗碗了!-鬼故事 2012-12-02
- [分享]本公司有个严格的规定,绝对不准加班!-鬼故事 2012-12-02
- [分享]光线CMS常用函数及常用代码参考 2012-04-16
- UnixBench-Linux VPS性能测试工具 2012-04-13
- Wordpress忘记密码了,最简单的方法恢复方法 2012-04-13
发表评论: