Widnows10中WSL使用Ubuntu

Windows10 使用WSL2运行Ubuntu

系统配置

安装流程

  1. 安装WSL,打开系统设置-应用与功能-Windows 功能,勾选其中的Virtual Machine PlatformWindows Subsystem for Linux,重启电脑

  2. install-manual 下载WSL2 Linux kernel update package for x64 machines,并安装

  3. PowerShell中执行wsl --set-default-version 2设置使用WSL2

  4. ubuntu官网 下载24.04 LTS的WSL的镜像文件64-bit PC (AMD64) WSL image,得到文件ubuntu-24.04.3-wsl-amd64.wsl

  5. 把这个文件解压后得到1.3GB的ubuntu-24.04.3-wsl-amd64文件

  6. 使用wsl导入系统镜像到指定目录wsl --import <系统名称> <安装位置> <镜像文件路径>

    1
    2
    3
    4
    5
    6
    wsl --import Ubuntu-24.04 "E:\wsl\Ubuntu-24.04" "E:\wsl\ubuntu-24.04.3-wsl-amd64"

    wsl.exe --import <Distro> <InstallLocation> <FileName> [Options]
    Options:
    --version <Version>
    --vhd

    安装完成后会在E:\wsl\Ubuntu-24.04目录中生成一个ext4.vhdx文件,大小为1.5G多

  7. 使用wsl --list --all查看当前已经安装的系统

1
2
3
PS C:\Users\Edison> wsl --list --all
Windows Subsystem for Linux Distributions:
Ubuntu-24.04 (Default)
  1. 运行系统wsl因为只有一个子系统可以不用带其他参数,也可以指定系统wsl -d Ubuntu-24.04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 PS C:\Users\Edison> wsl
Windows Subsystem for Linux is now available in the Microsoft Store!
You can upgrade by running 'wsl.exe --update' or by visiting https://aka.ms/wslstorepage
Installing WSL from the Microsoft Store will give you the latest WSL updates, faster.
For more information please visit https://aka.ms/wslstoreinfo

Welcome to Ubuntu 24.04.3 LTS (GNU/Linux 5.10.16.3-microsoft-standard-WSL2 x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro

System information as of Thu Aug 7 23:27:19 CST 2025

System load: 0.08 Processes: 9
Usage of /: 0.5% of 250.98GB Users logged in: 0
Memory usage: 1% IPv4 address for eth0: 172.25.129.208
Swap usage: 0%

This message is shown once a day. To disable it please create the
/root/.hushlogin file.

常用命令

  • 查看当前系统状态, 在powershell中执行wsl -l -v
  • 使用root用户登录,在powershell中执行wsl -u -root或者wsl --distribution <Distribution Name> --user <User Name>
  • 帮助信息wsl --help
  • 关闭系统wsl --shutdown 或者wsl -t <系统名称>

文件访问

windows访问ubuntu系统文件

在windows资源管理器的地址栏输入\\wsl$,可以看到一个发行版名称的挂在目录

ubuntu访问windows目录

直接在终端下访问/mnt/<windows盘符>,例如cd /mnt/e就可以切换到windows的e盘下

系统使用

修改系统源

把ubuntu.sources备份一个后,使用Vim修改里面的内容

1
2
3
cd /etc/apt/sources.list.d/
cp ubuntu.sources ubuntu.sources_bak
vim ubuntu.sources

文件中一共有两段内容,把其中官网地址都改为Aliyun的地址http://mirrors.aliyun.com/ubuntu/,其他不用变

1
2
3
4
5
Types: deb
URIs: http://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

更新软件信息sudo apt-get update

新增一个用户

  • 新增用户adduser walker,过程中按提示设置密码

  • 新增用户默认是user用户组,如果以后要执行管理员权限命令,需要增加到sudo组中 usermod -aG sudo walker

  • 查看用户的用户组groups walker

  • 修改wsl的默认登录用户为waker,root账户下在/etc/wsl.conf文件中添加以下内容

    1
    2
    [user]
    default=walker

AMD 显卡驱动

安装显卡驱动

amd官方指南文档 https://rocm.docs.amd.com/projects/radeon/en/latest/docs/install/wsl/install-radeon.html

  1. 下载地址https://www.amd.com/zh-cn/support/download/linux-drivers.html,下文件`amdgpu-install_6.4.60402-1_all.deb`

  2. sudo dpkg -i amdgpu-install_6.4.60402-1_all.deb 安装amdgpu-install脚本

  3. 更新widnows驱动到AMD Software: Adrenalin Edition™ 25.8.1 for WSL2.

  4. 在这之前一定配置好国外的安装源,要下载很多文件,执行amdgpu-install -y --usecase=wsl,rocm --no-dkms 安装WSL usecase

  5. 执行rocminfo查看版本信息

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    *******
    Agent 1
    *******
    Name: AMD Ryzen 5 5600 6-Core Processor
    Uuid: CPU-XX
    Marketing Name: AMD Ryzen 5 5600 6-Core Processor
    Vendor Name: CPU
    Feature: None specified
    Profile: FULL_PROFILE
    Float Round Mode: NEAR

####

0%