Finalmente, encontrei uma maneira de fazer isso usando as informações deste tópico: link
O script de trabalho é:
#!/bin/bash
# Which device and which related HDMI audio device. They're usually in pairs.
export VGA_DEVICE=0000:01:00.0
export AUDIO_DEVICE=0000:01:00.1
export VGA_DRIVER=radeon
export AUDIO_DRIVER=snd_hda_intel
# Passing through USB devices. Querying bus address and feeding that to QEMU
# instead of the device ID, so you can yank and replug the keyboard to regain
# control.
export KEYBOARD="1b1c:1b08"
export MOUSE="046d:c24a"
# Unbinds a device and loads the driver specified.
flipdriver() {
dev="$1"
driver="$2"
if [ -z $driver ] | [ -z $dev ];
then
return 1
fi
vendor=$(cat /sys/bus/pci/devices/${dev}/vendor)
device=$(cat /sys/bus/pci/devices/${dev}/device)
echo -n Unbinding $vendor:$device ...
if [ -e /sys/bus/pci/devices/${dev}/driver ]; then
echo ${dev} > /sys/bus/pci/devices/${dev}/driver/unbind
while [ -e /sys/bus/pci/devices/${dev}/driver ]; do
sleep 0.5
echo -n .
done
fi
echo " OK!"
echo -n Binding \'$driver\' to $vendor:$device ...
echo ${vendor} ${device} > /sys/bus/pci/drivers/${driver}/new_id
echo " OK!"
return 0
}
# Common error message
fliperror()
{
echo Couldn\'t perform required driver switch\'n\'bait!
exit 1
}
# Xorg shouldn't run.
if [ -n "$( ps -C xinit | grep xinit )" ];
then
echo Don\'t run this inside Xorg!
exit 1
fi
# Unbind specified graphics card and audio device.
echo Pulling the plug on the specified passthrough devices...
flipdriver $VGA_DEVICE vfio-pci
flipdriver $AUDIO_DEVICE vfio-pci
export QEMU_PA_SAMPLES=128
export QEMU_AUDIO_DRV=alsa
# Get the bus addresses for keyboard and mouse.
export QEMU_KEYB=$( lsusb | sed -n 's/Bus \([0-9]*\) Device \([0-9]*\): ID '$KEYBOARD'.*/-device usb-host,bus=xhci.0,hostbus=,hostaddr=/p' )
export QEMU_MOUS=$( lsusb | sed -n 's/Bus \([0-9]*\) Device \([0-9]*\): ID '$MOUSE'.*/-device usb-host,bus=xhci.0,hostbus=,hostaddr= -show-cursor/p' )
# Check if VM drive is mounted
if ! grep -qs '/media/user/VM' /proc/mounts; then
echo "Attempting to mount VM drive."
sudo mount /dev/sdc1
fi
#network stuff
tunctl -t vmtap10
ip link set dev tap10 address 42:42:42:42:42:10
ifconfig vmtap10 192.168.42.1 up
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eno1 -j MASQUERADE
iptables -A FORWARD -i vmtap10 -j ACCEPT
iptables -A FORWARD -o vmtap10 -m state --state RELATED,ESTABLISHED -j ACCEPT
#pactl set-sink-volume 2 50%
echo Starting virtual machine...
sleep 0.2
# QEMU stuff
sudo kvm -monitor stdio -vnc :1 -vga none \
-drive if=pflash,format=raw,file=./OVMF.fd -rtc base=localtime \
-m 4G -mem-path /dev/hugepages \
-cpu host -smp sockets=1,cores=6,threads=1 \
-soundhw ac97 \
-device vfio-pci,host=01:00.0 \
-usb -usbdevice host:046d:c215 \
-usb -device nec-usb-xhci,id=xhci \
$QEMU_KEYB \
$QEMU_MOUS \
-net nic,macaddr=42:42:42:42:42:42 -net tap,ifname=vmtap10,script=no,downscript=no,vhost=on \
-drive file=/media/user/VM/vm10.img,format=qcow2,cache=writeback \
-smb /media/ljosalfur \
-cdrom /home/user/Downloads/virtio-win-0.1.105.iso
# Rebind the devices for the host.
echo Adios vfio, reloading the host drivers for the passedthrough devices...
flipdriver $AUDIO_DEVICE $AUDIO_DRIVER
flipdriver $VGA_DEVICE $VGA_DRIVER
iptables -F
iptables -t nat -F POSTROUTING
ip link delete vmtap10