foxlet / macOS-Simple-KVM

Tools to set up a quick macOS VM in QEMU, accelerated by KVM.
13.58k stars 1.14k forks source link

Keyboard and mouse passthrough #488

Open 512yottabytes opened 3 years ago

512yottabytes commented 3 years ago

After a lot of tries I've successfully passed through my GPU. (Thanks to QaidVoid (https://github.com/QaidVoid)) But I was unlucky with USB keyboard and mouse. Clover see them, but MacOS installer -- no. Linux and Windows guest work fine with USB keyboard and mouse passed through, but macOS -- no. My script:

VMDIR="/vm/macos-simple-kvm/"
OSK="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
OVMF="$VMDIR/firmware"
ROMFILE="/vm/AMD.RX5500XT.8192.191017.rom"
DISK="$VMDIR/Disk.qcow2"
USER="root"

virsh nodedev-detach pci_0000_03_00_0
virsh nodedev-detach pci_0000_03_00_1

qemu-system-x86_64 \
    -enable-kvm \
    -machine q35,accel=kvm \
    -cpu Penryn,vendor=GenuineIntel,kvm=on,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check,+invtsc \
    -m 4G \
    -smp 4,cores=2 \
    -device isa-applesmc,osk="$OSK" \
    -smbios type=2 \
    -drive if=pflash,format=raw,readonly=on,file="/usr/share/ovmf/OVMF.fd" \
    -drive if=pflash,format=raw,file="$OVMF/OVMF_VARS-1024x768.fd" \
    -device usb-ehci,id=ehci \
    -device ich9-ahci,id=sata \
    -drive id=ESP,if=none,format=qcow2,file=$VMDIR/ESP.qcow2 \
    -device ide-hd,bus=sata.2,drive=ESP \
    -drive id=InstallMedia,format=raw,if=none,file=$VMDIR/BaseSystem.img \
    -device ide-hd,bus=sata.3,drive=InstallMedia \
    -drive id=SystemDisk,if=none,format=qcow2,file=$VMDIR/MyDisk.qcow2 \
    -device ide-hd,bus=sata.4,drive=SystemDisk \
    -net nic \
    -net user \
    -vga none \
    -device vfio-pci,host=03:00.0,multifunction=on,romfile=$ROMFILE \
    -device vfio-pci,host=03:00.1 \
    -object input-linux,id=mouse1,evdev=/dev/input/by-id/usb-YSPRINGTECH_USB_OPTICALSE-event-mouse \
    -object input-linux,id=kbd1,evdev=/dev/input/by-id/usb-BTC_USB_Keyboard-event-kbd,grab_all=on,repeat=on \
    -device virtio-keyboard \
    -device virtio-mouse
virsh nodedev-reattach pci_0000_03_00_0
virsh nodedev-reattach pci_0000_03_00_1

Am I wrong anywhere? Is there a solution?