# 安装工具链
apt install build-essential flex bison bc dwarves libssl-dev libelf-dev libncurses-dev
# 根据uname -a下载对应版本的wsl内核
https://github.com/microsoft/WSL2-Linux-Kernel
https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags/linux-msft-wsl-5.15.90.1.zip
# 配置内核
make menuconfig KCONFIG_CONFIG=Microsoft/config-wsl
# 配置内核
make menuconfig KCONFIG_CONFIG=Microsoft/config-wsl
Device Drivers ---> Android
# 编译kvm相关模块
Virtualization-> KVM for Intel/ KVM for AMD 两个全部点击M键将其编译成模块
Processor type and features -> Linux guest support -> KVM Guest support 点击Y选中
Device Drivers > VHOST drivers >vhost virtio-vsock driver 点击M将其编译成模块
# 编译内核
make KCONFIG_CONFIG=Microsoft/config-wsl
# 编译模块
make modules KCONFIG_CONFIG=Microsoft/config-wsl
# 加载模块
make modules_install && make install
将arch/x86/boot/bzImage拷贝到主机本地目录XXX
编辑%UserProfile%/.wslconfig文件,增加
[wsl2]
kernel=XXX\\bzImage
# 重启wsl
wsl --shutdown
# 加载kvm相关模块
sudo modprobe kvm vhost_vsock vhost_net kvm_intel
apt-get install cpu-checker
kvm-ok
grep -c -w "vmx\|svm" /proc/cpuinfo