How to fix the conflict between my WSL2 and WSL Settings?

linqi he 20 Reputation points
2026-07-21T09:49:30.56+00:00

我的WSL2和WSL Settings的存在冲突,当WSL Settings的内存与处理器-交换文件位置指向WSL的vhdx文件时,会导致启动失败。我该如何修正它,或者把交换文件位置初始化为空白。

具体情况如下:

1.执行”wsl --import Ubuntu-20.04 E:\WSL\Ubuntu-20.04 E:\WSL\ubuntu-20.04.6-wsl-amd64.wsl --version 2“创建了一个Ubuntu-20.04系统,一切正常

2.我在WSL Settings中设置了交换文件位置为Ubuntu-20.04\ext4.vhdx。wsl --shutdown后wsl重新启动失败,报错“PS C:\WINDOWS\system32> wsl 无法启动分发。错误代码: 16,失败步骤: 2 错误代码: Wsl/Service/CreateInstance/E_FAIL”

3.注销系统,执行”wsl --import Ubuntu-20.04 E:\WSL\Ubuntu-Data E:\WSL\ubuntu-20.04.6-wsl-amd64.wsl --version 2“创建了一个新Ubuntu-20.04系统,弹出警告“wsl: 未能在“E:\WSL\Ubuntu-20.04\ext4.vhdx”中创建交换磁盘: 系统找不到指定的路径。”,但是可以正常的wsl --shutdown 后启动。

4.我将交换文件位置改为Ubuntu-Data\ext4.vhdx,wsl启动失败,报错“PS C:\WINDOWS\system32> wsl 无法启动分发。错误代码: 16,失败步骤: 2 错误代码: Wsl/Service/CreateInstance/E_FAIL”

5.注销系统,执行”wsl --import Ubuntu-20.04 E:\WSL\Ubuntu-20.04 E:\WSL\ubuntu-20.04.6-wsl-amd64.wsl --version 2“,弹出“wsl: 未能在“E:\WSL\Ubuntu-Data\ext4.vhdx”中创建交换磁盘: 系统找不到指定的路径。”,新系统可以正常的wsl --shutdown 后启动。

Windows for home | Windows 11 | Apps
0 comments No comments

Answer accepted by question author
Abhishek U 170 Reputation points
2026-07-21T11:52:17.81+00:00

你的 WSL2 启动失败是因为你把交换文件的位置直接指向了发行版的 ext4.vhdx 文件。交换文件必须是一个单独的文件,而不是虚拟磁盘本身。

要解决这个问题,请在 .wslconfig 中重置或删除交换文件路径,使其为空或指向一个有效的独立文件。

打开你的 .wslconfig 文件,路径为:

%UserProfile%.wslconfig

将交换文件条目重置为空或禁用交换:

[wsl2]

swap=0

swapFile=

保存文件并运行:

wsl --shutdown

重启 WSL,现在应该可以正常启动了。

可选项

如果你想启用交换文件,请将其指向一个专用文件,而不是发行版的 .vhdx:

[wsl2]

memory=8GB

processors=4

swap=1

swapFile=E:WSLswap.vhdx

如果不存在,WSL 会自动创建 swap.vhdx。

不要把交换文件位置设置到你的发行版 ext4.vhdx。要么留空(禁用交换),要么使用独立文件路径。这样可以避免冲突,确保 WSL2 可靠启动。

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Newest
  1. Abhishek U 170 Reputation points
    2026-07-21T11:51:49.6333333+00:00

    Your WSL2 startup failures are happening because you pointed the swap file location directly to the distro’s ext4.vhdx file. The swap file must be a separate file, not the virtual disk itself.

    To fix this, reset or remove the swap file path in .wslconfig so it’s blank or points to a valid standalone file.

    Open your .wslconfig file located at:

    %UserProfile%.wslconfig

    Reset the swap file entry to blank or disable swap:

    [wsl2]

    swap=0

    swapFile=

    Save the file and run:

    wsl --shutdown

    Restart WSL. It should now start normally.

    Optional

    If you want swap enabled, point it to a dedicated file instead of the distro’s .vhdx:

    [wsl2]

    memory=8GB

    processors=4

    swap=1

    swapFile=E:\WSL\swap.vhdx

    WSL will create swap.vhdx automatically if it doesn’t exist.

    Do not set the swap file location to your distribution’s ext4.vhdx. Use either a blank entry (to disable swap) or a separate file path. This prevents conflicts and ensures WSL2 starts reliably.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.