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.