替换WSL2内核

WSL2内核目录

WSL2的内核可以通过.wslconfig配置文件指定,默认情况下,该文件不存在,需要到%USERPROFILE%目录下创建。

参考:https://docs.microsoft.com/en-us/windows/wsl/wsl-config#configure-global-options-with-wslconfig

编译内核

cp Microsoft/config-wsl .config
# 如果编译报告错误,修改相关的配置即可,例如:
# CONFIG_FRAME_WARN=4096
# 禁用 CONFIG_DEBUG_INFO_BTF
# 如果要使用vscode + clangd,在make前增加bear命令
LOCALVERSION= make -j8
sudo make modules_install -j 8

#假设内核复制到C:\\Dev\\Kernel\\WSL2目录下
cp arch/x86/boot/bzImage /mnt/c/Dev/kernel/WSL2

配置.wslconfig

# Settings apply across all Linux distros running on WSL 2
[wsl2]

# Specify a custom Linux kernel to use with your installed distros. The default kernel used can be found at https://github.com/microsoft/WSL2-Linux-Kernel
kernel=C:\\Dev\\Kernel\\WSL2\\bzImage

# Disable page reporting so WSL retains all allocated memory claimed from Windows and releases none back when free
pageReporting=false

# Turn off default connection to bind WSL 2 localhost to Windows localhost
localhostforwarding=true

# Disables nested virtualization
nestedVirtualization=false

# Turns on output console showing contents of dmesg when opening a WSL 2 distro for debugging
debugConsole=false

重启WSL

关闭再开启即可。

wsl --shutdown

确认新内核生效

posted @ 2022-01-07 10:45  Hartmon  阅读(2681)  评论(2编辑  收藏  举报