当前位置: 首页 > Linux

wsl2配置archlinux

时间:2023-04-06 05:47:20 Linux

本文来自我的笔记https://github.com/levinit以下内容说明在powershell或windows终端中执行windows命令(推荐,默认使用powershell)。Enablewsl2EnablehypervEnablesubsystemforlinuxEnable-WindowsOptionalFeature-Online-FeatureNameVirtualMachinePlatformHomeEdition启用hyperv,创建一个bat文件如hyperv.bat,内容如下:pushd"%~dp0"dir/b%SystemRoot%\服务\Packages\*Hyper-V*.mum>hyper-v.txtfor/f%%iin('findstr/i.hyper-v.txt2^>nul')dodism/online/norestart/add-package:"%SystemRoot%\servicing\Packages\%%i"delhyper-v.txtDism/online/enable-feature/featurename:Microsoft-Hyper-V-All/LimitAccess/ALL管理员用户执行上述bat文件。系统可能需要重新启动。安装wsl2archlinux使用wsl作为默认的wsl版本:wsl--set-default-version2使用wsl-l-v查看当前的wsl版本和linux列表。可能会提示其内核组件需要更新,根据提示的网址下载内核安装。下载ArchWSL2并解压目录。这里假设压缩目录ArchWSL2放在C:\\目录下,点击目录下的Arch2.exe进行安装。将C:\ArchWSL2添加到环境变量中,方便使用搜索路径,在系统属性--环境变量中编辑Path行,添加这个环境变量。Arch基本配置在wslarchlinuxshell中执行以下内容,根据需要进行一些基本配置:#Key初始化pacman-key--initpacman-key--populatearchlinux#修改源,使用中文源curl'https://www.archlinux.org/mirrorlist/?country=CN&protocol=https&ip_version=4'|sed"s/^#//">/etc/pacman.d/mirrorlist#update系统pacman-Syyu--noconfirm#rootpasswordpasswdroot#添加archlinuxcn源(可选)echo'[archlinuxcn]Server=https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch'>>/etc/pacman.confpacman-Syypacman-Sarchlinuxcn-keyring--noconfirm#安装一些软件(可选)pacman-S--noconfirmvimhtopgitsudo#添加一个普通用户(可选)useradd-m-gwheellevin#与linux共享一些windows目录(可选)#ln-sf/mnt/c/path/to/Documents~/设置wsl默认登录用户archlinuxwsl默认使用root用户登录。wsl安装创建普通用户后,在windows终端配置wsl默认登录用户:arch2config--default-userlevinitwsl2hardwareresourceallocation在用户目录C:\\Users\\下创建.wslconfig文件:[wsl2]#kernel=C:\\temp\\myCustomKernelmemory=4GB#LimitVMmemoryinWSL2to4GBprocessors=2#WSL2VM使用两个虚拟处理器