3

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)

3 Answers 3

6

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/

7
  • Thanks. I have a windows quest. The sound is not passed to pulseaudio. There is something else that I am missing. It is playing it in windows on "High definition audio device". I hear nothing because is is not passed.
    – user63726
    Nov 11, 2019 at 16:18
  • When you start vm, open in ubuntu pavucontrol program, and check if there is qemu in playback programs. If no, then try to check for problem in qemu log: /var/log/libvirt/qemu/your_vm.log
    – randomei
    Nov 11, 2019 at 18:46
  • I got this error in the log file.
    – user63726
    Nov 12, 2019 at 19:27
  • pulseaudio: pa_context_connect() failed pulseaudio: Reason: Connection refused pulseaudio: Failed to initialize PA contextaudio: Could not init `pa' audio driver
    – user63726
    Nov 12, 2019 at 19:34
  • 1
    I had the same problem, I've tried to configure apparmor without success and simpliest solution was to enable tcp protocol for pulse. Copy /etc/pulse/default.pa to ~/.config/pulse/ then find: #load-module module-native-protocol-tcp change this line to: load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 then edit your vm configuration: <qemu:commandline> <qemu:arg value='-audiodev'/> <qemu:arg value='pa,id=pa1,server=127.0.0.1'/> </qemu:commandline>
    – randomei
    Nov 13, 2019 at 14:31
0

Its running fine for me on 19.10 but I'm running Ubuntu natively. I also had to do a repair install so my config files kind of got a fresh start.

I'd try: Get rid of old versions and any old config files

sudo apt-get purge qemu

sudo apt-get purge pulseaudio

sudo bash -c 'for i in update {,dist-}upgrade auto{remove,clean}; do apt-get $i -y; done'

Then reinstall them:

sudo apt install qemu
sudo apt install pulseaudio

That way you have fresh fully updated applications without old configs mucking things up.

I assume you mean your host OS is Windows 10? And that you're running on WSL2?

1
  • My host is ubuntu 19.10 and the guest is windows 10. The KVM was created on ubuntu 19.04. I know that I need to change the config file to match the new version of qemu. Everything that I found did not work for me. It is not well documented how to change the config to the new version of qemu.
    – user63726
    Oct 28, 2019 at 1:23
0

Alternative (simple) solution: (1 command)

sudo systemctl restart libvirtd.service # Might just be a temporary workaround, but this worked for me

Hopefully useful for the future.

You must log in to answer this question.

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