VMware Workstation Windows 10 host Ubuntu 18.04 Guest 中加载 Linux 内核 kvm 模块

Last updated on December 1, 2023 am

这里在 VMware Workstation Guset OS 里使用 qemu 的用法,有点像俄罗斯套娃。

qemu.sh

1
2
3
4
5
6
7
8
9
10
11
12
qemu-system-x86_64 \
-m 2G \
-smp 2 \
-kernel $KERNEL/arch/x86——64/boot/bzImage \
-append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" \
-drive file=$IMAGE/bullseye.img,format=raw \
-net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
-net nic,model=e1000 \
-enable-kvm \
-nographic \
-pidfile vm.pid \
2>&1 | tee vm.log

执行命令后 bash ./qemu.sh 后报错

1
2
Could not access KVM kernel module: No such file or directory. 
qemu-system-x86_64: failed to initialize KVM: No such file or directory

解决 failed to initialize KVM 错误

lsmod | grep -i kvm 发现没有加载 kvm 内核模块

使用 kvm-ok 检查具体情况。

1
2
3
4
sudo /usr/sbin/kvm-ok

INFO: Your CPU does not support KVM extension
KVM acceleration can NOT be used

首先检查 VMware Workstation 的设置,发现处理器没有勾选虚拟化相关的设置。

  • 关机,调整 VMware 设置,设置 -> 硬件 -> 处理器 -> 虚拟化引擎 -> 选择 虚拟化 Intel VT-x / EPT 或 AMD-V / RVI

重新打开 Ubuntu Guest 虚拟机报错 此平台不支持虚拟化的Intel VT-x/EPT

解决此平台不支持虚拟化的Intel VT-x/EPT

首先检查 BIOS 的设置是否正确,任务右键打开任务管理器 -> 性能 -> CPU 右下角,虚拟化:已启用,说明 BIOS 设置没有问题。

网络上的资料说需要禁用 Hyper-V,使用命令行的方法比较方便。

  • 以管理员权限打开 CMD 执行命令 bcdedit /set hypervisorlaunchtype off 关闭 hypervisorlaunchtype,重启系统

重新执行 /usr/sbin/kvm-ok 显示一切正常

1
2
INFO: /dev/kvm exists
KVM acceleration can be used

egrep "vmx|svm" /proc/cpuinfo 匹配 vmx,lsmod | grep -i kvm 显示加载了 kvm_intelkvm 内核模块。

重新验证 Ubuntu Guest 里 qemu 是否正常工作,执行执行 qemu.sh,报错 Could not access KVM kernel module: Permission denied

解决 failed to initialize KVM: Permission denied

看上去是权限问题,将当前用户添加在 kvm 组,sudo usermod -a -G kvm "test",重启系统,执行 bash ./qemu.sh 成功启动

1
2
3
early console in setup code
early console in extract_kerne
...

此文档可能有不完备之处,后续会继续更新此文档。

参考

https://www.xda-developers.com/disable-hyper-v-windows-11/


VMware Workstation Windows 10 host Ubuntu 18.04 Guest 中加载 Linux 内核 kvm 模块
http://usmacd.com/cn/qemu_kvm/
Author
henices
Posted on
November 28, 2023
Licensed under