跳至正文
Wener Notes

QEMU FAQ

约 2 分钟阅读
标签:FAQ

持嵌套虚拟化

  • 大多云平台都不支持嵌套虚拟化
  • 裸金属服务器 支持虚拟化
  • 参考

RNG

建议默认添加,否则可能导致非常慢意外 Hang 住

text
-device virtio-rng-pci

默认 /dev/random。 可自定义参数

text
-object rng-random,filename=/dev/hwrng,id=rng0 -device virtio-rng-pci,rng=rng0
bash
qemu-system-x86_64 -object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0,bus=pci.0,addr=0x7

环境检测

bash
# KVM 要求 Intel VT, AMD-V
egrep '(vmx|svm)' /proc/cpuinfo

modprobe kvm
modprobe kvm-intel

访问远程镜像

bash
# apk add qemu-block-ssh
qemu -drive file=ssh://host/path/to/file,if=virtio,cache=none

qemu: uncaught target signal 4 (Illegal instruction) - core dumped

ppc64le 异常

qemu-s390x: warning: 'msa5-base' requires 'klmd-sha-512'

s390x 异常

virtfs

wiki.qemu.org/Documentation/9psetup

ProjectZero QEMU: virtfs permits guest to access entire host filesystem

convert 后无法启动

  • 在 macOS 下从 qcow2 转换为 raw 后分区信息丢失
  • Linux 未遇到这样的问题
  • 转换后可使用 fdisk 检查分区信息

Overhead

Containerization vs. Virtualization – More on Overhead

硬件加速

开启硬件加速和不开启性能可能相差 10 倍+。

bash
qemu-system-x86_64 -accel help
  • tcg - JIT 模式
  • macOS - hvf, hax
    • hvf 实现不是很完整,可能会出现无法运行的情况
    • 如果加速有问题,尝试修改 smp 为 1
  • Windows - hyper, hax
  • Linux - kvm

USB

bash
qemu-system-x86_64 \
  -enable-kvm \
  -M q35 \
  -m 2G \
  -usb -usbdevice host:16b2:1001 \
  -usb -usbdevice host:0529:0001 \
  -usbdevice tablet \
  -net nic \
  -net bridge,br=br0 \
  -vga qxl \
  -spice port=5930,disable-ticketing \
  -device virtio-serial-pci \
  -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
  -chardev spicevmc,id=spicechannel0,name=vdagent \
  -drive file=/mnt/data/win-patch.img,if=virtio

-accel kvm: failed to initialize kvm: Permission denied

bash
addgroup $USER kvm

鼠标偏移

bash
-device usb-ehci,id=usb,bus=pci.0,addr=0x4 -device usb-mouse -device usb-tablet -device usb-kbd

usb

usb2.0

  • 兼容性更好
text
-device usb-ehci,id=usb,bus=pci.0,addr=0x4

usb3.0

text
-device nec-usb-xhci,id=usb,bus=pci.0,addr=0x4

Cannot enable HVF when guest CPU has EL3 enabled

  • Exception Level 3 (EL3)
    • 最高的特权级别

TBD

text
no scancode found for keysym 1185
no scancode found for keysym 65306

关联信息

反向链接、本文链接的其他页面和外部资料。

参考资料

GitHub1 条
Hacker News1 条
其他外链7 条
最近更新commit c6bc0d8编辑