关于linux:wsl2-配置arch-linux

本文来自我的笔记 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.txt

for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"

del hyper-v.txt

Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL

管理员用户执行下面的bat文件。

可能要重启零碎。

装置wsl2 archlinux

  1. 将wsl作为默认wsl版本:

    wsl --set-default-version 2

    应用wsl -l -v查看以后wsl 版本及linux列表。

    可能提醒须要更新其内核组件,依据提醒的网址下载内核装置。

  2. 下载ArchWSL2,解压目录,这里假如将加压的目录ArchWSL2放到C:\\目录下,点击目录内的Arch2.exe装置。
  3. C:\\ArchWSL2退出环境变量方便使用

    搜寻path,在 零碎属性–环境变量 中编辑 Path 行,增加该环境变量。

arch 根本配置

以下内容在wsl archlinux的shell中执行,依据须要进行一些根本配置:

#密钥初始化
pacman-key --init
pacman-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.conf
pacman -Syy
pacman -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\\myCustomKernel
memory=4GB # 将WSL 2中的VM内存限度为4 GB
processors=2 #使WSL 2 VM应用两个虚构处理器

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理