注意:这篇文章上次更新于228天前,文章内容可能已经过时。
This article was last updated228 days ago, the content may be outdated.
本文记录在 Windows 11 上安装 WSL2 以及调试相关问题的过程与经验。
开启 WSL 功能
打开 Windows 控制面板,依次点击程序 => 启用或关闭 Windows 功能


开启 Hyper-V、Virtual Machine Platform 和 适用于 Linux 的 Windows 子系统。

然后重启计算机。
安装 WSL
以管理员身份运行 Windows 终端,然后执行 wsl --update
1 | PS C:\Users\wgxls> wsl --update |
使用 wsl --version 查看 wsl 版本。
1 | PS C:\Users\wgxls> wsl --version |
使用 wsl --install 安装 Linux(Ubuntu) 子系统。
输入两次密码,就完成了 Ubuntu 系统的初始化。
1 | PS C:\Users\wgxls> wsl --install |
我的电脑中默认安装的是 Ubuntu 24.04.3 LTS
1 | wgxls@DESKTOP-DMRH21F:/mnt/c/Users/wgxls$ lsb_release -a |
WSL 配置
WSL 存储位置迁移
WSL 的默认存储位置在 C 盘,随着 WSL 的使用,其磁盘会不断增大,占用大量 C 盘空间。可以通过以下步骤将 WSL 存储位置迁移到其他盘符。
以管理员身份运行 Windows 终端,执行以下命令查看已经安装的 WSL 发行版:
1 | PS C:\Users\wgxls> wsl -l -v |
我这里目前只安装了一个 Ubuntu 发行版,并且正在运行。
首先关闭正在运行的 WSL 发行版:
1 | PS C:\Users\wgxls> wsl --shutdown |
以 vhd 格式导出 WSL 发行版,我这里指定导出到 D 盘的 D:\WSL\Ubuntu.vhdx 文件中:
1 | PS C:\Users\wgxls> wsl --export Ubuntu D:\WSL\Ubuntu.vhdx --vhd |
删除当前的 WSL 发行版:
1 | PS C:\Users\wgxls> wsl --unregister Ubuntu |
导入之前导出的 WSL 发行版到新的位置:
1 | PS C:\Users\wgxls> wsl --import Ubuntu D:\WSL\Ubuntu\ D:\WSL\Ubuntu.vhdx --vhd |
可以看到 WSL 发行版已经成功导入到新的位置,这里使用 ls 命令查看 D:\WSL\Ubuntu\ 目录:
1 | PS C:\Users\wgxls> ls D:\WSL\Ubuntu\ |
刚刚的 Ubuntu.vhdx 文件就可以删除了,释放空间。
可以使用 wsl --set-default Ubuntu 命令将新导入的 Ubuntu 发行版设置为默认发行版:
1 | PS C:\Users\wgxls> wsl --set-default Ubuntu |
WSL Settings
可以通过在 Windows 用户目录下创建 .wslconfig 文件来配置 WSL 的一些参数,例如内存限制、处理器数量等。
也可以通过 WSL Settings GUI 工具进行配置。
- 内存和 CPU 限制
我习惯将 WSL 的内存和处理器数量设置为和宿主机相同,以充分利用系统资源。毕竟 WSL 才是主要的工作环境。
使用如下命令获取以 MB 为单位的总内存大小:
1 | PS C:\Users\wgxls> Get-CimInstance Win32_ComputerSystem | Select-Object @{Name="TotalPhysicalMemoryMB";Expression={"{0:N0}" -f ($_.TotalPhysicalMemory/1MB)}} |
将获取到的内存大小填写到 WSL Settings 中:

- 文件系统
在文件系统选项中,可以设置 WSL 虚拟硬盘的最大大小,默认的设置是 1TB,根据需要可以调整,我这里保持默认。
- 网络
在网络选项中,我习惯使用镜像网络模式,并开启主机地址回环,这样可以更方便地在 Windows 和 WSL 之间进行网络通信。

- 可选功能 和 开发人员选项 我都保持了默认设置。
最终在 .wslconfig 文件中会生成如下内容:
1 | [wsl2] |
WSLg 设置
WSLg 是 WSL 的图形化支持组件,可以让我们在 WSL 中运行 Linux GUI 应用程序。
这里参考官方文档进行配置:
https://learn.microsoft.com/zh-cn/windows/wsl/tutorials/gui-apps
若要运行 Linux GUI 应用,应首先安装与以下系统匹配的驱动程序。 这样,便可以使用虚拟 GPU (vGPU),以便从硬件加速的 OpenGL 渲染中获益。
- 更新 Ubuntu 系统
在 Linux 系统中执行:
1 | sudo apt update && sudo apt upgrade -y |
- 安装 gedit 文本编辑器
1 | sudo apt install gedit -y |
安装完成之后,在 Windows 的开始菜单中可以看到 Linux 系统下的应用程序,并且可以直接点击运行。
也可以在 Linux 系统中使用终端命令开启 GUI 程序。

- 安装 Google Chrome for Linux
将目录更改为临时文件夹:
1 | cd /tmp |
使用 wget 下载它:
1 | wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb |
1 | sudo apt install -f ./google-chrome-stable_current_amd64.deb |
此选项
-f用于修复安装过程中可能出现的损坏依赖项。 该./命令指定.deb文件所在的当前目录。 如果.deb文件位于其他目录中,则需要在命令中指定该文件的路径。
更多应用我就不再继续装了,毕竟 WSLg 并不是主要的使用场景。
Ubuntu 系统配置
Ubuntu 设置中文字体
让 WSL 直接使用 Windows 字体,WSL 会自动挂在 Windows 的字体目录 /mnt/c/Windows/Fonts,我们只需要指定字体即可。
1 | sudo gedit /etc/fonts/local.conf |
在打开的文件中添加如下内容:
1 |
|
保存后,刷新字体缓存。
1 | sudo fc-cache -fv |
使用 fc-list 命令查看字体列表,确认 Windows 字体已经被识别。
1 | $ fc-list :lang=zh | grep "Microsoft YaHei" |
安装 1Panel 面板
1 | sudo bash -c "$(curl -sSL https://resource.fit2cloud.com/1panel/package/v2/quick_start.sh)" |
安裝成功提示如下:
1 | [1Panel 2026-01-05 22:35:44 install Log]: 1Panel 服务已成功启动,正在继续执行后续配置,请稍候... |
这里我设置了端口 9999 进行访问。
安装完成后,使用 Windows 浏览器访问 http://localhost:9999/0000 或者 http://127.0.0.1:9999/0000 能够成功访问,表示我们在 WSL Settings 中配置的镜像网络模式和主机地址回环是正确的。
安装 miniconda
https://www.anaconda.com/docs/getting-started/miniconda/install
1 | sudo mkdir /opt/miniconda3 |
激活 conda 环境。
1 | source /opt/miniconda3/bin/activate |
初始化 conda 环境对于所有 shell 环境。
1 | conda init --all |
执行完以上命令之后,重新计入终端会默认进入到 conda 的 base 环境。
如果想要取消 conda 的自动激活,可以执行以下命令:
1 | conda config --set auto_activate false |
开启 SSH 服务
安装 OpenSSH 服务器:
1 | sudo apt install openssh-server -y |
开启 SSH 服务:
1 | sudo systemctl start ssh |
设置开机自启动:
1 | sudo systemctl enable ssh |
查看 SSH 服务状态:
1 | sudo systemctl status ssh |
输出内容显示 Active: active (running) 表示 SSH 服务已经成功启动。
1 | wgxls@DESKTOP-DMRH21F:~$ sudo systemctl status ssh |
如果你无法从外部设备通过 SSH 连接到 WSL,可能需要配置 Windows 防火墙允许端口 22 的入站连接。
打开 Wondows 安全中心,依次点击防火墙和网络保护 => 高级设置

点击 入站规则 => 新建规则…,选择端口,点击下一步。

选择TCP,并指定本地端口为22,点击下一步。
我这里选择所有本地端口,表示允许所有端口通过防火墙。

选择允许连接,点击下一步。

选择域、专用 和 公用,点击下一步。

为规则命名,例如 IN_TCP_ALL,点击完成。

可以通过重复的步骤为 UDP 协议创建入站规则或者出站规则。
SSH 允许 root 用户登录
我主要在局域网内使用 SSH 登录 WSL,为了方便,我通过 1Panel 面板设置了允许 root 用户通过 SSH 登录。

为 root 用户设置密码:
1 | sudo passwd root |
1 | wgxls@DESKTOP-DMRH21F:~$ sudo passwd root |
允许普通用户免输 sudo 密码
编辑 sudoers 文件:
1 | sudo visudo |
在文件末尾添加如下内容:
1 | wgxls ALL=(ALL) NOPASSWD: ALL |
保存并退出。现在,用户 wgxls 在使用 sudo 命令时将不再需要输入密码。
修改 SSH 会话 PATH 环境变量
在 WSL 中,默认情况下,通过 SSH 登录时,PATH 环境变量可能与直接在 WSL 终端中登录时不同。这可能导致某些命令无法找到。
比如,在 WSL 终端中可以执行 nvidia-smi 命令:
1 | wgxls@DESKTOP-DMRH21F:~$ nvidia-smi |
但是通过 SSH 登录时,执行 nvidia-smi 命令会提示找不到命令:
1 | wgxls@DESKTOP-DMRH21F:~$ echo $PATH |
可以看到,通过 SSH 登录时,PATH 环境变量比 WSL 终端中少了很多路径,并提示找不到 nvidia-smi 命令。
而实际上 nvidia-smi 命令位于 /usr/lib/wsl/lib/ 目录下。
为了解决这个问题,我们可以配置文件 /etc/environment,将缺失的路径添加进去。
这个修改会影响所有通过 SSH 登录的用户。
1 | sudo vim /etc/environment |
这里我们不过多添加其他路径,把所有 /mnt 开头的路径都删除掉,只保留 /usr/lib/wsl/lib 路径。
修改前:
1 | PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" |
修改后:
1 | PATH="/opt/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/snap/bin" |
重新 SSH 登录, nvidia-smi 命令就可以正常使用了。
修改 systemd 环境变量
现在 systemd 启动的服务(例如 1Panel 面板服务)也无法识别 /usr/lib/wsl/lib 路径下的命令。

为了让 systemd 服务也能识别该路径下的命令,我们需要修改 systemd 的环境变量配置文件。
1 | sudo vim /etc/systemd/system.conf |
在文件中找到 #DefaultEnvironment= 行,去掉注释并添加我们需要的路径。
修改前:
1 | #DefaultEnvironment= |
修改后:
1 | DefaultEnvironment=PATH="/opt/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/snap/bin" |
保存并退出。
重新启动 systemd:
1 | sudo systemctl daemon-reexec |
可以使用 systemctl show-environment 命令查看 systemd 的环境变量,确认修改已经生效。
1 | wgxls@DESKTOP-DMRH21F:~$ systemctl show-environment |
重新启动 1Panel 服务:
1 | sudo 1pctl restart |
可以看到 1Panel 服务已经成功启动,并且可以正常使用 nvidia-smi 命令了。

WSL 挂在 ext4 磁盘
Windows 系统是无法直接访问 ext4 文件系统的,如果磁盘格式已经是 ext4,可以通过 WSL 来访问。
因为我的机械硬盘之前用在了 Linux 系统中,格式化为了 ext4 文件系统,现在想在 WSL 中挂载使用。
此时我需要参考的是官方文档中关于挂载已分区磁盘的内容:
https://learn.microsoft.com/zh-cn/windows/wsl/wsl2-mount-disk#mounting-a-partitioned-disk
首先以管理员身份运行 Windows 终端,使用 Get-CimInstance -Query "SELECT * from Win32_DiskDrive" 列出所有磁盘。
我这里有一个 4TB 的机械硬盘,ID 是 \\.\PHYSICALDRIVE0。
1 | PS C:\Users\wgxls> Get-CimInstance -Query "SELECT * from Win32_DiskDrive" |
执行 wsl.exe --mount <Disk> --bare 命令挂载该磁盘:
1 | wsl --mount \\.\PHYSICALDRIVE0 --bare |
然后进入 WSL 系统,使用 lsblk 命令查看挂载的磁盘:
可以看到我这里的 4TB 硬盘已经成功挂载为 sde 磁盘,并且有一个分区 sde1。
1 | wgxls@DESKTOP-DMRH21F:~$ lsblk |
下面通过修改 /etc/fstab 文件实现开机自动挂载这块磁盘。
获取该分区的 UUID:
1 | wgxls@DESKTOP-DMRH21F:~$ sudo blkid /dev/sde1 |
编辑 /etc/fstab 文件:
1 | sudo vim /etc/fstab |
在文件末尾添加如下内容:
1 | UUID=dceaaac0-3867-4b2c-86e2-2ddc4af28807 /mnt/4tb_disk ext4 defaults,nofail 0 2 |
保存并退出。
创建挂载点目录:
1 | sudo mkdir /mnt/4tb_disk |
重新启动 WSL:
1 | wsl --shutdown |
重新进入 WSL 系统,使用 df -h 命令查看挂载情况:
1 | wgxls@DESKTOP-DMRH21F:~$ df -h |
可以看到 4TB 硬盘已经成功挂载到 /mnt/4tb_disk 目录下。
WSL 开机自启并保持运行
默认情况下,WSL 发行版在不使用时会自动关闭,以节省系统资源。但是,有时我们希望 WSL 在系统启动时自动启动,并保持运行状态,尤其是当我们在 WSL 中运行服务器或后台服务时。
可以通过创建一个计划任务来实现这一点。
- 打开任务计划程序
Win + R,输入 taskschd.msc 并按回车,打开任务计划程序。
- 点击 “创建任务…”

- 在 “常规” 选项卡中,填写任务名称,例如 “wsl-mount” ,并选择 “使用最高权限运行”。

- 在 “触发器” 选项卡中,点击 “新建…”,选择 “启动时” 作为触发器,选择 “延迟任务” 选项,设置延迟时间为 30 秒,点击 “确定”。

- 在 “操作” 选项卡中,点击 “新建…”,选择 “启动程序” 作为操作,程序或脚本填写
C:\Windows\System32\wsl.exe,添加参数填写--mount \\.\PHYSICALDRIVE0 --bare,起始于填写C:\Windows\System32或者留空,点击 “确定”。

第一个操作是挂载硬盘到 WSL。
再添加一个 shell 会话来保持 WSL 运行。

-
在 “条件” 选项卡中,保持默认设置即可。如果你是笔记本电脑用户,可以取消 “仅在使用交流电源时启动此任务” 选项。
-
在 “设置” 选项卡中,取消勾选 如果任务超时则停止任务 选项,保持其他默认设置。

最后点击确定保存任务。
重启电脑后,可以看到 WSL 发行版已经自动启动并且会保持运行状态。
⚠️
在我这样设置之后,WSLg 似乎无法正常工作,图形界面应用无法启动。如果你需要使用 WSLg,需要先执行
wsl --shutdown命令关闭 WSL,然后再重新打开 WSL 发行版。一旦执行了
wsl --shutdown命令,计划任务启动的 WSL 会话将会被关闭。WSL 无法保持持续运行状态。
This article documents the process and experience of installing WSL2 on Windows 11 and debugging related issues.
Enabling the WSL Feature
Open the Windows Control Panel, then click Programs => Turn Windows features on or off


Enable Hyper-V, Virtual Machine Platform, and Windows Subsystem for Linux.

Then restart the computer.
Installing WSL
Run Windows Terminal as administrator, then execute wsl --update
1 | PS C:\Users\wgxls> wsl --update |
Use wsl --version to check the WSL version.
1 | PS C:\Users\wgxls> wsl --version |
Use wsl --install to install the Linux (Ubuntu) subsystem.
Enter the password twice, and the Ubuntu system initialization is complete.
1 | PS C:\Users\wgxls> wsl --install |
The default version installed on my computer is Ubuntu 24.04.3 LTS
1 | wgxls@DESKTOP-DMRH21F:/mnt/c/Users/wgxls$ lsb_release -a |
WSL Configuration
Migrating the WSL Storage Location
WSL’s default storage location is on the C: drive. As you use WSL, its virtual disk keeps growing and takes up a lot of C: drive space. You can migrate the WSL storage location to another drive with the following steps.
Run Windows Terminal as administrator and execute the following command to view the installed WSL distributions:
1 | PS C:\Users\wgxls> wsl -l -v |
I currently have only one Ubuntu distribution installed here, and it’s running.
First, shut down the running WSL distribution:
1 | PS C:\Users\wgxls> wsl --shutdown |
Export the WSL distribution in vhd format; here I specify exporting to the D:\WSL\Ubuntu.vhdx file on the D: drive:
1 | PS C:\Users\wgxls> wsl --export Ubuntu D:\WSL\Ubuntu.vhdx --vhd |
Unregister the current WSL distribution:
1 | PS C:\Users\wgxls> wsl --unregister Ubuntu |
Import the previously exported WSL distribution to the new location:
1 | PS C:\Users\wgxls> wsl --import Ubuntu D:\WSL\Ubuntu\ D:\WSL\Ubuntu.vhdx --vhd |
You can see the WSL distribution has been successfully imported to the new location. Here I use the ls command to view the D:\WSL\Ubuntu\ directory:
1 | PS C:\Users\wgxls> ls D:\WSL\Ubuntu\ |
The Ubuntu.vhdx file from earlier can now be deleted to free up space.
You can use the wsl --set-default Ubuntu command to set the newly imported Ubuntu distribution as the default:
1 | PS C:\Users\wgxls> wsl --set-default Ubuntu |
WSL Settings
You can configure some WSL parameters, such as memory limits and processor count, by creating a .wslconfig file in the Windows user directory.
You can also configure them through the WSL Settings GUI tool.
- Memory and CPU limits
I prefer to set WSL’s memory and processor count to the same values as the host machine to make full use of system resources. After all, WSL is my main working environment.
Use the following command to get the total memory size in MB:
1 | PS C:\Users\wgxls> Get-CimInstance Win32_ComputerSystem | Select-Object @{Name="TotalPhysicalMemoryMB";Expression={"{0:N0}" -f ($_.TotalPhysicalMemory/1MB)}} |
Fill the obtained memory size into WSL Settings:

- File system
In the file system options, you can set the maximum size of the WSL virtual hard disk. The default setting is 1TB, and you can adjust it as needed — I keep the default here.
- Network
In the network options, I prefer to use Mirrored networking mode and enable Host address loopback, which makes network communication between Windows and WSL more convenient.

- For Optional features and Developer options, I kept the default settings.
In the end, the following content is generated in the .wslconfig file:
1 | [wsl2] |
WSLg Settings
WSLg is WSL’s graphical support component that lets us run Linux GUI applications in WSL.
Here I follow the official documentation for configuration:
https://learn.microsoft.com/zh-cn/windows/wsl/tutorials/gui-apps
To run Linux GUI applications, you should first install drivers that match the following systems. This way, you can use the virtual GPU (vGPU) to benefit from hardware-accelerated OpenGL rendering.
- Update the Ubuntu system
Run the following in the Linux system:
1 | sudo apt update && sudo apt upgrade -y |
- Install the gedit text editor
1 | sudo apt install gedit -y |
After installation, you can see the Linux applications in the Windows Start menu and run them directly by clicking.
You can also launch GUI programs with terminal commands in the Linux system.

- Install Google Chrome for Linux
Change the directory to the temporary folder:
1 | cd /tmp |
Use wget to download it:
1 | wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb |
1 | sudo apt install -f ./google-chrome-stable_current_amd64.deb |
The
-foption is used to fix broken dependencies that may occur during installation. The./prefix specifies the current directory where the .deb file is located. If the .deb file is in another directory, you need to specify the path to that file in the command.
I won’t install more applications — after all, WSLg isn’t my main use case.
Ubuntu System Configuration
Setting Up Chinese Fonts in Ubuntu
To let WSL directly use Windows fonts: WSL automatically mounts the Windows font directory at /mnt/c/Windows/Fonts; we just need to specify the fonts.
1 | sudo gedit /etc/fonts/local.conf |
Add the following content to the opened file:
1 |
|
After saving, refresh the font cache.
1 | sudo fc-cache -fv |
Use the fc-list command to view the font list and confirm that Windows fonts are recognized.
1 | $ fc-list :lang=zh | grep "Microsoft YaHei" |
Installing the 1Panel Panel
1 | sudo bash -c "$(curl -sSL https://resource.fit2cloud.com/1panel/package/v2/quick_start.sh)" |
The success message is as follows:
1 | [1Panel 2026-01-05 22:35:44 install Log]: 1Panel 服务已成功启动,正在继续执行后续配置,请稍候... |
Here I set port 9999 for access.
After installation, if you can successfully access http://localhost:9999/0000 or http://127.0.0.1:9999/0000 from the Windows browser, it means the Mirrored networking mode and Host address loopback configured in WSL Settings are correct.
Installing Miniconda
https://www.anaconda.com/docs/getting-started/miniconda/install
1 | sudo mkdir /opt/miniconda3 |
Activate the conda environment.
1 | source /opt/miniconda3/bin/activate |
Initialize conda for all shell environments.
1 | conda init --all |
After running the above commands, reopening the terminal will default to conda’s base environment.
If you want to disable conda’s auto-activation, run the following command:
1 | conda config --set auto_activate false |
Enabling the SSH Service
Install the OpenSSH server:
1 | sudo apt install openssh-server -y |
Start the SSH service:
1 | sudo systemctl start ssh |
Enable it to start automatically at boot:
1 | sudo systemctl enable ssh |
Check the SSH service status:
1 | sudo systemctl status ssh |
If the output shows Active: active (running), the SSH service has started successfully.
1 | wgxls@DESKTOP-DMRH21F:~$ sudo systemctl status ssh |
If you can’t connect to WSL via SSH from an external device, you may need to configure the Windows Firewall to allow inbound connections on port 22.
Open Windows Security, then click Firewall & network protection => Advanced settings

Click Inbound Rules => New Rule…, select Port, and click Next.

Select TCP, specify local port 22, and click Next.
Here I chose All local ports, which allows all ports through the firewall.

Select Allow the connection and click Next.

Check Domain, Private, and Public, then click Next.

Name the rule, e.g. IN_TCP_ALL, and click Finish.

You can repeat the steps to create inbound or outbound rules for the UDP protocol.
Allowing Root Login via SSH
I mainly use SSH to log into WSL within my LAN. For convenience, I configured the 1Panel panel to allow root users to log in via SSH.

Set a password for the root user:
1 | sudo passwd root |
1 | wgxls@DESKTOP-DMRH21F:~$ sudo passwd root |
Allowing a Regular User to Run sudo Without a Password
Edit the sudoers file:
1 | sudo visudo |
Add the following content at the end of the file:
1 | wgxls ALL=(ALL) NOPASSWD: ALL |
Save and exit. Now user wgxls will no longer be prompted for a password when using the sudo command.
Modifying the PATH Environment Variable for SSH Sessions
In WSL, by default, the PATH environment variable when logging in via SSH may differ from when logging in directly in the WSL terminal. This can cause some commands to be unfindable.
For example, the nvidia-smi command works in the WSL terminal:
1 | wgxls@DESKTOP-DMRH21F:~$ nvidia-smi |
But when logging in via SSH, running the nvidia-smi command reports that the command can’t be found:
1 | wgxls@DESKTOP-DMRH21F:~$ echo $PATH |
You can see that when logging in via SSH, the PATH environment variable has many fewer paths than in the WSL terminal, and it reports that the nvidia-smi command can’t be found.
In fact, the nvidia-smi command is located in the /usr/lib/wsl/lib/ directory.
To solve this problem, we can configure the /etc/environment file and add the missing paths.
This change affects all users logging in via SSH.
1 | sudo vim /etc/environment |
Here I won’t add too many other paths — I’ll remove all paths starting with /mnt and keep only the /usr/lib/wsl/lib path.
Before:
1 | PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" |
After:
1 | PATH="/opt/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/snap/bin" |
After re-logging in via SSH, the nvidia-smi command works properly.
Modifying systemd Environment Variables
Now services started by systemd (such as the 1Panel panel service) also can’t find commands under the /usr/lib/wsl/lib path.

To let systemd services also find commands under that path, we need to modify systemd’s environment variable configuration file.
1 | sudo vim /etc/systemd/system.conf |
Find the #DefaultEnvironment= line in the file, uncomment it, and add the paths we need.
Before:
1 | #DefaultEnvironment= |
After:
1 | DefaultEnvironment=PATH="/opt/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/snap/bin" |
Save and exit.
Restart systemd:
1 | sudo systemctl daemon-reexec |
You can use the systemctl show-environment command to view systemd’s environment variables and confirm the change has taken effect.
1 | wgxls@DESKTOP-DMRH21F:~$ systemctl show-environment |
Restart the 1Panel service:
1 | sudo 1pctl restart |
You can see that the 1Panel service has started successfully and the nvidia-smi command works properly.

Mounting an ext4 Disk in WSL
Windows can’t directly access the ext4 file system. If a disk is already formatted as ext4, you can access it through WSL.
Because my mechanical hard drive was previously used in a Linux system and formatted as ext4, I now want to mount and use it in WSL.
At this point, I need to refer to the official documentation on mounting partitioned disks:
https://learn.microsoft.com/zh-cn/windows/wsl/wsl2-mount-disk#mounting-a-partitioned-disk
First, run Windows Terminal as administrator and use Get-CimInstance -Query "SELECT * from Win32_DiskDrive" to list all disks.
I have a 4TB mechanical hard drive here, with ID \\.\PHYSICALDRIVE0.
1 | PS C:\Users\wgxls> Get-CimInstance -Query "SELECT * from Win32_DiskDrive" |
Run the wsl.exe --mount <Disk> --bare command to mount the disk:
1 | wsl --mount \\.\PHYSICALDRIVE0 --bare |
Then enter the WSL system and use the lsblk command to view the mounted disks:
You can see that my 4TB drive has been successfully mounted as disk sde, with one partition sde1.
1 | wgxls@DESKTOP-DMRH21F:~$ lsblk |
Next, we’ll set up automatic mounting of this disk at boot by modifying the /etc/fstab file.
Get the partition’s UUID:
1 | wgxls@DESKTOP-DMRH21F:~$ sudo blkid /dev/sde1 |
Edit the /etc/fstab file:
1 | sudo vim /etc/fstab |
Add the following content at the end of the file:
1 | UUID=dceaaac0-3867-4b2c-86e2-2ddc4af28807 /mnt/4tb_disk ext4 defaults,nofail 0 2 |
Save and exit.
Create the mount point directory:
1 | sudo mkdir /mnt/4tb_disk |
Restart WSL:
1 | wsl --shutdown |
Re-enter the WSL system and use the df -h command to check the mount status:
1 | wgxls@DESKTOP-DMRH21F:~$ df -h |
You can see the 4TB drive has been successfully mounted to the /mnt/4tb_disk directory.
Auto-Starting WSL at Boot and Keeping It Running
By default, WSL distributions shut down automatically when unused to save system resources. However, sometimes we want WSL to start automatically at system boot and stay running, especially when we run servers or background services in WSL.
This can be achieved by creating a scheduled task.
- Open Task Scheduler
Press Win + R, type taskschd.msc and press Enter to open Task Scheduler.
- Click “Create Task…”

- In the “General” tab, enter a task name, e.g. “wsl-mount”, and select “Run with the highest privileges”.

- In the “Triggers” tab, click “New…”, choose “At startup” as the trigger, check the “Delay task for” option, set the delay to 30 seconds, and click “OK”.

- In the “Actions” tab, click “New…”, choose “Start a program” as the action, enter
C:\Windows\System32\wsl.exein Program/script, enter--mount \\.\PHYSICALDRIVE0 --barein Add arguments, enterC:\Windows\System32in Start in (or leave it blank), and click “OK”.

The first action mounts the hard drive into WSL.
Then add a shell session to keep WSL running.

-
In the “Conditions” tab, keep the default settings. If you’re a laptop user, you can uncheck “Start the task only if the computer is on AC power”.
-
In the “Settings” tab, uncheck the “Stop the task if it runs longer than” option and keep the other default settings.

Finally, click OK to save the task.
After restarting the computer, you can see that the WSL distribution has started automatically and stays running.
⚠️
After configuring it this way, WSLg seems to stop working properly — GUI applications can’t start. If you need to use WSLg, you’ll have to run
wsl --shutdownfirst to shut down WSL, then reopen the WSL distribution.Once you run
wsl --shutdown, the WSL session started by the scheduled task will be terminated. WSL can no longer stay running continuously.


