Skip to content

QEMU起動スクリプト

This content is a draft and will not be included in production builds.

#!/bin/sh
set -eu
#loader=/usr/share/ovmf/x64/OVMF_CODE.secboot.fd
loader=/usr/share/ovmf/x64/OVMF_CODE.fd
nvram=OVMF_VARS.fd
exec qemu-system-x86_64 -m 8G -smp 2 \
-machine q35,smm=on,type=pc,accel=kvm \
-device nvme,drive=nvme0,serial=0 \
-drive file=win.img,cache=writethrough,id=nvme0,if=none \
-drive if=pflash,unit=0,format=raw,read-only=on,file=$loader \
-drive if=pflash,unit=1,format=raw,file=$nvram \
-global driver=cfi.pflash01,property=secure,value=on \
-global ICH9-LPC.disable_s3=0 \
-global ICH9-LPC.disable_s4=0 \
-device virtio-net-pci,netdev=ether0 \
-netdev user,id=ether0,net=10.0.2.0/24 \
-audiodev pa,id=snd0,server=/run/user/$(id -u)/pulse/native \
-device intel-hda \
-device hda-duplex,audiodev=snd0 \
-vga virtio -display gtk,grab-on-hover=on,gl=on \
-usb -device usb-tablet

特定のUSBデバイスをパススルー

Section titled “特定のUSBデバイスをパススルー”
Terminal window
$ lsusb
Bus 003 Device 036: ID 3507:000b ZENAIM ARCADE CONTROLLER

これでオプションを構成する。

Terminal window
-device qemu-xhci -device usb-host,vendorid=0x3507,productid=0x000b

USBコントローラ全体をパススルー

Section titled “USBコントローラ全体をパススルー”
Terminal window
$ lsusb
Bus 003 Device 036: ID 3507:000b ZENAIM ARCADE CONTROLLER

これでオプションを構成する。

Terminal window
-device qemu-xhci -device usb-host,hostbus=3,hostaddr=36

USBデバイスはPCIeでもあるらしいので、003 なので usb3 を読むとPCIのID?が分かる。

Terminal window
$ ls -dl /sys/bus/usb/devices/usb3
lrwxrwxrwx 1 root root 0 6月 15 13:04 /sys/bus/usb/devices/usb3 -> ../../../devices/pci0000:00/0000:00:14.0/usb3

この相対パスをルートから再構成すると /sys/devices/pci0000:00/0000:00:14.0/usb3 となるが、この分部を使ってIOMMUグループを特定する。以下の例では 11 に属するらしい。

Terminal window
$ ls -d /sys/kernel/iommu_groups/*/devices/0000:00:14.0
/sys/kernel/iommu_groups/11/devices/0000:00:14.0