[vfio-users] Example configuration with CLI Qemu (working VM => host audio)

Melvin Vermeeren mail at melvinvermeeren.com
Fri Aug 14 20:35:33 UTC 2015


Hello everyone,

With the help of the sources below I have successfully made a script that 
starts a few applications and then runs the VM CLI-style. For me, this also 
fixed the problem of VM => host audio passthrough not working when using virt-
manager to create a VM. Note that with this setup, libvirtd does NOT need to 
running when launching the script.

Sources:
https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF
http://pastebin.com/rcnUZCv7 (https://www.youtube.com/watch?v=37D2bRsthfI)
http://vfio.blogspot.nl/

Note that I use a bridge for internet in the VM, it connects to my LAN as a 
separate device. I also use the VIRTIO drivers for increased performance.

For users of NetworkManager: I noticed that networkmanager-qt (mainly KDE) had 
a bug that prevented me from creating a bridge, nm-connection-editor (mainly 
GNOME) worked perfectly though. The name of my bridge is "br0", not the 
default "bridge0" that is used by NetworkManager.

Sources:
https://wiki.archlinux.org/index.php/Network_bridge (in general)
https://www.happyassassin.net/2014/07/23/bridged-networking-for-libvirt-with-networkmanager-2014-fedora-21/ (specific to NM)

The script itself:
=== BEGIN ===

#!/bin/bash

echo "Starting Samba"
sudo systemctl start smbd.service
sudo systemctl start nmbd.service

echo "Starting Synergy"
/usr/bin/synergys --daemon --config /etc/synergy.conf

# This is probably not neccesary, except when updating the OVMF bios
# echo "Removing old OVMF variables"
# rm -v ./Windows_ovmf_vars_x64.bin
# echo "Copying new OVMF variables"
# cp -v /usr/share/ovmf/x64/ovmf_vars_x64.bin ./Windows_ovmf_vars_x64.bin

echo "Exporting PulseAudio driver"
export QEMU_AUDIO_DRV="pa"

echo "Starting VM"
sudo \
    qemu-system-x86_64 \
        -serial none \
        -parallel none \
        -nodefaults \
        -nodefconfig \
        -enable-kvm \
        -name Windows \
        -cpu host,kvm=off,check \
        -smp sockets=1,cores=4,threads=2 \
        -m 12288 \
        -soundhw hda \
        -device ich9-usb-uhci3,id=uhci \
        -device usb-ehci,id=ehci \
        -device nec-usb-xhci,id=xhci \
        -drive 
if=pflash,format=raw,readonly,file=/usr/share/ovmf/x64/ovmf_code_x64.bin \
        -drive if=pflash,format=raw,file=./Windows_ovmf_vars_x64.bin \
        -rtc base=localtime \
        -boot order=c \                                                                                                                                     
        -net nic,vlan=0,macaddr=52:54:00:00:00:01,model=virtio,name=net0 \                                                                                  
        -net bridge,vlan=0,name=bridge0,br=br0 \                                                                                                            
        -drive 
if=virtio,id=drive0,file=./Windows.img,format=raw,cache=none,aio=native \                                                                    
        -nographic \                                                                                                                                        
        -device vfio-pci,host=04:00.0,addr=09.0,multifunction=on \                                                                                          
        -device vfio-pci,host=04:00.1,addr=09.1                                                                                                             
                                                                                                                                                            
# For GPU sound                                                                                                                                             
# add ",multifunction=on" to GPU                                                                                                                            
# -device vfio-pci,host=04:00.1,addr=09.1                                                                                                                   
                                                                                                                                                            
# Standard VGA                                                                                                                                              
# Remove "-nographic \" and "-device vfio-pci" lines                                                                                                        
# -vga std                                                                                                                                                  
                                                                                                                                                            
# Install                                                                                                                                                   
# In addination to the steps "Standard VGA", add or change these options                                                                                    
# -boot order=d \                                                                                                                                           
# -device ide-cd,drive=drive-cd-disk1,id=cd-disk1,unit=0,bus=ide.0 \                                                                                        
# -drive 
file=/run/media/melvin/primarydata/Data/OS/Windows_10.img,if=none,id=drive-cd-
disk1,media=cdrom \   
# -device ide-cd,drive=drive-cd-disk2,id=cd-disk2,unit=0,bus=ide.1 \                                                                                        
# -drive file=/run/media/melvin/primarydata/Data/OS/virtio-
win-0.1.109.iso,if=none,id=drive-cd-disk2,media=cdrom \                                          
                                                                                                                                                            
echo "VM closed"                                                                                                                                            
                                                                                                                                                            
echo "Stopping Synergy"                                                                                                                                     
pkill -u melvin synergys                                                                                                                                    
                                                                                                                                                            
echo "Stopping Samba"                                                                                                                                       
sudo systemctl stop smbd.service                                                                                                                            
sudo systemctl stop nmbd.service

=== END ===

I also intend to create a script, probably based upon the pastebin source 
above, to switch active GPU for X between my NVIDIA and AMD card. This 
requires a restart of X as far as I know. I'll keep the list up-to-date with 
any progress I make.

Also, feel free to post any of this on wikis, blogs, etc. The more people that 
can be helped the better. :)

If there are any questions feel free to ask them.

Regards,

Melvin Vermeeren.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/vfio-users/attachments/20150814/4d66d9b3/attachment.sig>


More information about the vfio-users mailing list