unable to start kvm (qemu 4.0) because of pulseaudio after upgrade to ubuntu 19.10

When starting the KVM (that was working fine in ubuntu 19.04) I am getting the following error:

Error starting domain: internal error: qemu unexpectedly closed the monitor: pulseaudio: pa_context_connect() failed pulseaudio: Reason: Connection refused pulseaudio: Failed to initialize PA contextaudio: warning: Using timer based audio emulation

Traceback (most recent call last):   File "/usr/share/virt-manager/virtManager/asyncjob.py", line 75, in cb_wrapper
    callback(asyncjob, *args, **kwargs)   File "/usr/share/virt-manager/virtManager/asyncjob.py", line 111, in tmpcb
    callback(*args, **kwargs)   File "/usr/share/virt-manager/virtManager/object/libvirtobject.py", line 66, in newfn
    ret = fn(self, *args, **kwargs)   File "/usr/share/virt-manager/virtManager/object/domain.py", line 1279, in startup
    self._backend.create()   File "/usr/lib/python3/dist-packages/libvirt.py", line 1080, in create
    if ret == -1: raise libvirtError ('virDomainCreate() failed', dom=self) libvirt.libvirtError: internal error: qemu unexpectedly closed the monitor: pulseaudio: pa_context_connect() failed pulseaudio: Reason: Connection refused pulseaudio: Failed to initialize PA contextaudio: warning: Using timer based audio emulation

I have made the changes to the config file. I have added the following lines to reflect the change from qemu 3.1 to 4.0

  <qemu:commandline>
    <qemu:env name="QEMU_AUDIO_DRV" value="pa"/>
    <qemu:env name="QEMU_PA_SERVER" value="/run/user/1000/pulse/native"/>
  </qemu:commandline>

If I remove these lines I cannot passthrough sound to pulseaudio.

yes the kvm audio user is me.

Any help will be appreciated. Is this a bug or a setup issue. my guest is windows 10 (1903)


Solution 1:

This is because change in audio configuration since qemu 4.0. You need to edit your vm configuration:

sudo virsh edit <your_vm>

Then replace your lines:

   <qemu:commandline>
    <qemu:env name="QEMU_AUDIO_DRV" value="pa"/>
    <qemu:env name="QEMU_PA_SERVER" value="/run/user/1000/pulse/native"/>
  </qemu:commandline>

with:

<qemu:commandline>
  <qemu:arg value='-audiodev'/>
  <qemu:arg value='pa,id=pa1,server=/run/user/1000/pulse/native'/>
</qemu:commandline>

I found this here: https://www.reddit.com/r/VFIO/comments/b1crpi/qemu_40_due_soon_might_bring_superb_audio_test_now/