How to add sound to an Ubuntu LXD VM

I have a Windows 11 LXD VM and adding sound to it was easy:
lxc config set win11-vm raw.qemu -- "-device intel-hda -device hda-duplex"

When I created an Ubuntu LXD VM Desktop:

lxc launch images:ubuntu/22.04/desktop test-vm --vm --profile default --profile bridgeprofile -c limits.memory=4096MB -c limits.cpu=2

and then added the same command for sound:

lxc config set test-vm raw.qemu -- "-device intel-hda -device hda-duplex"

The result was only a “dummy output” device. Any ideas?

I suspect it may be because the linux-virtual kernel we’re using doesn’t include it.
You may need to install the matching linux-modules-extra package for the kernel and reboot for it to show up.

At the LXD level, we’re waiting for virtio-sound to be more widely available and supported before introducing a sound card device to our VMs.

The 5.13 kernel apparently got the kernel module added but we still need the QEMU side of things for that to be usable too.

@stgraber My LXD host is running Linux Kernel 5.15. From what you have said, I should have sound support at the Linux kernel and we know that the QEMU version supports it because my Win 11 LXD VM has sound.


So, what do you suppose we might be missing? Is the ball in my park or must I wait for a QEMU upgrade?

By the way, my LXD VM is also at the same kernel.


It is notable to me that while the LXD VM is running, sound on the host is absent.

No, QEMU doesn’t have support for virtio-sound, it only has support for the intel audio or realtek type virtual sound cards which LXD won’t use.

In general, LXD doesn’t use virtualized hardware like those, only paravirtualized hardware from virtio. So until QEMU grows support for virtio-sound, your only option is to use raw.qemu as you described above.

Ok, that explains a lot. So, is it possible for me to get sound on using raw.qemu, because my efforts were unsuccessful. I tried:
lxc config set test-vm raw.qemu -- "-device intel-hda -device hda-duplex"
with no luck. Can you make a suggestion?

Did you try installing the missing linux-modules-extra package and rebooting?

Perfect! Thanks so much. I forgot the reboot.

Glad you got it working!

I really appreciate your very clear and concise advice. Thanks again.

FYI, I found that the zabbly incus packages ship qemu 8.2 and when I was using lxc config set vm-name raw.qemu -- "-device intel-hda -device hda-duplex" with LXD 5.0.x (which has qemu 8.0), with incus 0.5.1 I need to use incus config set vm-name raw.qemu -- "-device intel-hda -device hda-duplex -audio spice".

Without -audio spice the VM doesn’t start and incus info --show-log vm-name shows:

qemu-system-x86_64: -device hda-duplex: no default audio driver available

Can see /opt/incus/bin/qemu-system-x86_64 -audio help for available drivers in addition to spice. CC @stgraber

Good work. Not sure if this may be an intentional omission by @stgraber.

An issue with -audio spice is that the audio of the host stops working while the VM is running.
I do not remember, was that also the case previously?

An issue with -audio spice is that the audio of the host stops working while the VM is running. I do not remember, was that also the case previously?

This is probably system dependent? On my Ubuntu 22.04 system (pulseaudio) using virt-viewer, multiplexing works (that said, perhaps my sound card supports hardware multiplexing).