I was pulling my hair out trying to get audio working in my QEMU virtual machines through Virt-Manager. Everything seemed perfect - the VM booted fine, graphics worked, but absolutely no sound. After hours of debugging, I finally found the solution.
The Problem I Faced I had just migrated my Gentoo system from PulseAudio to PipeWire (because, let's be honest, PipeWire is the best :D ). Everything worked beautifully on my host system, but when I tried to run VMs through Virt-Manager, I hit a wall:
- VMs launched perfectly through Virt-Manager GUI
- Graphics, networking, everything worked except audio
- Direct QEMU command-line worked with audio (which was frustrating!)
- Kept seeing GSpice warnings in Virt-Manager output
- No matter what I tried in the Virt-Manager GUI, no audio devices appeared in the VM !!!
My System Setup: When I encountered this issue, I was running:
- Distribution: Gentoo Linux
- Init System: systemd
- Audio Server: PipeWire (migrated from PulseAudio)
- QEMU Version: 8.x+
- Virt-Manager: 4.x+
- Libvirt: Standard setup (emerge with spice tag)
How We Fixed It? After reviewing the documentation and forums we realized the issue and figured out that: Virt-Manager wasn't automatically configuring the audio devices properly for PipeWire. The solution required manually editing the libvirt XML configuration.
Here's exactly what we did:
Step 1: Find Your VM's XML File
First, we located my VM's configuration file. These are stored in /etc/libvirt/qemu/:
/etc/libvirt/qemu/your-vm-name.xml
Step 2: Add the Missing Audio Configuration
I opened the XML file and added these blocks inside the <devices> section:
<sound model="ich9">
<codec type="micro"/>
<address type="pci" domain="0x0000" bus="0x00" slot="0x1b" function="0x0"/>
</sound>
<audio id="1" type="pipewire" runtimeDir="/run/user/1000">
<input name="qemuinput"/>
<output name="qemuoutput"/>
</audio>
Step 3: Edit the File
I used nano to edit the configuration:
(You can also use VS Code if you prefer):
$ sudo -E code --no-sandbox --user-data-dir ~/.vscode-root /etc/libvirt/qemu/your-vm-name.xml
Step 4: Restart and Test
After saving the file, I restarted the VM through Virt-Manager. Finally! Audio worked perfectly.
What These Settings Do Let me break down what I learned about these configurations:
The Sound Device
- Sound Model:
ich9 - Codec:
micro - Audio Type:
pipewire- Tells QEMU to use PipeWire backend - Runtime Directory:
/run/user/1000- Points to the user session runtime directory
Critical Points I Discovered
- The
runtimeDironly works when your user session is active - Your GUI session must be running with PipeWire active
- Virt-Manager doesn't automatically add the
<audio>block for PipeWire - Manual XML editing is the only way to make this work properly
,What I Tried Before (That Worked, But Not Ideal)
For reference, I knew direct QEMU worked perfectly because this command gave me audio:
qemu-system-x86_64 \
-enable-kvm \
-m 4096 \
-cpu host \
-machine q35 \
-device ich9-intel-hda \
-device hda-duplex,audiodev=audio0 \
-audiodev pa,id=audio0,out.buffer-length=10000,in.buffer-length=10000 \
-cdrom /path/to/your/iso/file.iso
This worked fine, but it uses PulseAudio backend (pa), which wasn't ideal for my PipeWire setup. I wanted the proper PipeWire integration through Virt-Manager.
If You're Still Having Issues
Here's what to check if my solution doesn't work for you:
Common Problems I Encountered
- Still no audio: Make sure PipeWire is actually running and your user session is active
- XML errors: Double-check the syntax and make sure it's properly nested in the
<devices>block
We spent way too many hours on this problem, so hopefully this saves you some time! [Sorry for my bad language]