Skip to content

Instantly share code, notes, and snippets.

@rikka0w0
Created May 17, 2022 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikka0w0/273f82cfe980613eb1c3b952c77362fc to your computer and use it in GitHub Desktop.
Save rikka0w0/273f82cfe980613eb1c3b952c77362fc to your computer and use it in GitHub Desktop.
QEMU KVM + Pulseaudio

By default, pulseaudio will only be available to the current login user. If running the QEMU as the root user, the audio will not be available. The common error thrown by QEMU looks like this: Could not init 'pa' audio driver. The following step sets up a globally accessible Unix socket for the other users to access the audio interface. Note that any user on this PC will be able to use it, hence if you really worry about the security issue, please consider assigning an user group to the socket and restrict its access(load-module module-native-protocol-unix auth-group=sharepulse socket=/tmp/pulseaudio.sock).

  1. Edit /etc/pulse/default.pa. Look for a line starts with load-module module-native-protocol-unix and change it to load-module module-native-protocol-unix auth-anonymous=1 socket=/tmp/pulseaudio.sock.
  2. Edit /etc/pulse/client.conf. Change/add: default-server = unix:/tmp/pulseaudio.sock and autospawn = no.
  3. Copy /home/CURRENT_USER/.config/pulse/cookie to /root/.config/pulse/cookie, create any folder if they are not there.
  4. In you QEMU command line, add/modify:
-device hda-micro,audiodev=hda \
-audiodev pa,id=hda,server=unix\:/tmp/pulseaudio.sock \
-device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment