I want to pass a audiodev to a vm, but libvirt exit with this error

error: internal error: process exited while connecting to monitor: 2024-03-17T23:29:37.725695Z qemu-system-x86_64: XDG_RUNTIME_DIR not set

those are the line for vm

<qemu:arg value="-device"/>
<qemu:arg value="usb-audio,audiodev=my_audiodev"/>
<qemu:arg value="-audiodev"/>
<qemu:arg value="pa,id=my_audiodev"/>

I know is possible to insert directly a soundcard in xml, but I want to know why give this error, also to try "virtio-sound" then

<qemu:arg value="-device"/>
<qemu:arg value="virtio-sound,audiodev=my_audiodev"/>
<qemu:arg value="-audiodev"/>
<qemu:arg value="pa,id=my_audiodev"/>

Of course without those lines the vm run

qemu-version is 8.2.2 libvirt version is 10.0.0 system is Slackware 15

The error is from qemu using pulseaudio

qemu-system-x86_64 -audiodev pa,id=hda,out.mixing-engine=off -audiodev pa,id=usb,out.mixing-engine=off 
qemu-system-x86_64: XDG_RUNTIME_DIR not set

tryng to setup the xdg-runtime-dir..

qemu-system-x86_64 -device usb-audio -audiodev alsa,id=hda,out.mixing-engine=off -audiodev pa,id=usb,out.mixing-engine=off 
qemu-system-x86_64: could not stat pidfile /pulse/pid: No such file or directory

1 Answer 1


Solution found, for qemu


mkdir /tmp/pulse
XDG_RUNTIME_DIR=/tmp/pulse pulseaudio -D
qemu-system-x86_64 -device usb-audio -audiodev pa,id=hda,out.mixing-engine=off -audiodev pa,id=usb,out.mixing-engine=off 


qemu-system-x86_64 -device usb-audio -audiodev pa,id=hda,out.mixing-engine=off -audiodev pa,id=usb,server=unix:/tmp/pulse-socket

for libvirt another problem (with xdg_runtime_dir), it run as different user (qemu) so I have to find a way to share sound with qemu user

error: internal error: process exited while connecting to monitor: 2024-03-17T23:56:30.886989Z qemu-system-x86_64: could not stat pidfile /tmp/pulse/pulse/pid: Permission denied

Solution found also for libvirt (the xdg_runtime is useless in this case)

<qemu:arg value="-device"/>
    <qemu:arg value="usb-audio,audiodev=my_audiodev"/>
    <qemu:arg value="-audiodev"/>
    <qemu:arg value="pa,id=my_audiodev,server=unix:/tmp/pulse-socket"/>

in default_pa

vim $HOME/.config/pulse/default_pa

load-module module-native-protocol-unix auth-anonymous=1 socket=/tmp/pulse-socket
load-module module-native-protocol-tcp auth-ip-acl=;;

with this configuration you allow other users to use (and hear) your sound without authentication, using acl based on ip (is not 100% safe but for home is ok)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .