本文来自我的笔记 https://github.com/levinit
以下内容中windows命令在powershell或windows terminal(倡议,其默认应用powershell)中执行。
启用wsl2
- 启用hyperv
- 启用用于linux的子系统
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
家庭版启用hyperv,创立一个bat文件如hyperv.bat,内容如下:
pushd "%~dp0"dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txtfor /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"del hyper-v.txtDism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL
管理员用户执行下面的bat文件。
可能要重启零碎。
装置wsl2 archlinux
将wsl作为默认wsl版本:
wsl --set-default-version 2
应用
wsl -l -v
查看以后wsl 版本及linux列表。可能提醒须要更新其内核组件,依据提醒的网址下载内核装置。
- 下载ArchWSL2,解压目录,这里假如将加压的目录ArchWSL2放到
C:\\
目录下,点击目录内的Arch2.exe
装置。 - 将
C:\\ArchWSL2
退出环境变量方便使用搜寻path,在 零碎属性--环境变量 中编辑
Path
行,增加该环境变量。
arch 根本配置
以下内容在wsl archlinux的shell中执行,依据须要进行一些根本配置:
#密钥初始化pacman-key --initpacman-key --populate archlinux#批改源,应用China源curl 'https://www.archlinux.org/mirrorlist/?country=CN&protocol=https&ip_version=4'|sed "s/^#//" >/etc/pacman.d/mirrorlist#更新零碎pacman -Syyu --noconfirm#root明码passwd root#增加archlinuxcn源(可选)echo '[archlinuxcn]Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch' >> /etc/pacman.confpacman -Syypacman -S archlinuxcn-keyring --noconfirm#装置一些软件(可选)pacman -S --noconfirm vim htop git sudo#增加一个普通用户(可选)useradd -m -g wheel levin#将windows的一些目录与linux共用(可选)#ln -sf /mnt/c/path/to/Documents ~/
设置wsl默认登录用户
archlinux的wsl默认应用root用户登录。在wsl装创立了普通用户后,在windows terminal中配置wsl默认登录用户:
arch2 config --default-user levinit
wsl2硬件资源调配
在用户目录C:\\Users\\<username>
下创立.wslconfig
文件:
[wsl2]#kernel=C:\\temp\\myCustomKernelmemory=4GB # 将WSL 2中的VM内存限度为4 GBprocessors=2 #使WSL 2 VM应用两个虚构处理器