WIN10安装Linux子系统

win10安装linux子系统

配置环境

系统设置-更新和安全-开发者选项。打开开发人员模式。

搜索‘启用或关闭Windows功能’(控制面板、程序和功能里),勾选“适用于Linux的Windows子系统”选项,确认并重启电脑。

下载软件

在window的微软软件商城,搜索Ubuntu,找到需要的版本,我选择的是Ubuntu20.04.5版本,点击获取,开始下载。

等待下载完成,点击打开,程序会执行一些初始化安装。

设置用户名、密码。就可以开始使用子系统。

移动安装位置

子系统默认安装在系统盘,可以使用LxRunOffline移动系统位置。

下载LxRunOffline:

https://github.com/DDoSolitary/LxRunOffline/releases

解压后,目录下会有exe可执行文件

可以将文件添加到环境变量,也可以直接在cmd窗口执行。

 .\LxRunOffline.exe list
 #查看安装的子系统
 
 wsl --shutdown
 #中止所有运行的子系统
 
 .\LxRunOffline.exe move -n Ubuntu-20.04 -d E:\ubuntu20
 #将名为Ubuntu-20.04的子系统移动到E盘ubuntu20目录下
 #移动过程中会有warning,不必关心,等待几分钟后移动完成

遇到报错

执行 .\LxRunOffline.exe list的时候报错:
[ERROR] Couldn't get the value "DistributionName" of the registry key "Software\Microsoft\Windows\CurrentVersion\Lxss\TryStoreWSL".
win+R运行regedit,找到HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss
删除TryStoreWSL目录

WSL1升级WSL2

wsl --set-version Ubuntu-20.04 2
将Ubuntu20.04的WSL1升级成WSL2,需要等待几分钟

遇到问题:

  • WSL2需要更新其内核组件,去微软官网下载Linux的kernel的升级包

Install WSL | Microsoft Learn

下载完是一个msi文件,双击安装即可

  • 请启用虚拟机平台 Windows 功能并确保在 BIOS 中启用虚拟化

确认电脑的“适用于Linux子系统。。。”等选项是打开的。可能是之前使用过VMware等虚拟机软件导致的,会和WSL2冲突。

找到Hyper-V,确认勾选(我没找到这一选项)

在命令行执行:

bcdedit /set hypervisorlaunchtype auto

重启电脑,再次尝试升级WSL

配置Ubuntu

更换apt源

修改/etc/apt/sources.list

Ubuntu20,ailiyun的源

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

sudo apt update
posted @ 2022-12-30 16:37  WuYunTaXue  阅读(590)  评论(0编辑  收藏  举报