How to get sound in an LXD linux virtual machine?

What devices should be added to get audio in a LXD based linux virtual machine?

Is it a PCI based sound card/chip? If so then the pci device will likely work:

https://linuxcontainers.org/lxd/docs/master/instances#type-pci

Although that won’t share it with the host.

Doesn’t libvirt provide a intel hda sound card as part of the virtualisation?

I’m not sure, but LXD doesn’t use libvirt, its uses QEMU directly.

I went with the lxc raw.qemu: -device intel-hda -device hda-duplex and the virtual machine seems to have an audio card aplay -l is able to list it, but when i try to play <wav file> there isn’t any audio.

It turns out that qemu/kvm via virt-manager works fine with the same distro. For some reason lxd virtual machine doesn’t seem to do audio correctly

Best open an issue then to see if it can be resolved.

Thanks

With Libvirt, maybe it route the sound from your VM to PulseAudio or whatever sound manager on your host.

As it stands, there are no virtio sound cards that LXD could use and we’re in general against using any fully virtualized hardware (like what libvirt will use) as those have a tendency to come with problematic security issues.

I believe there’s some work on virtio-sound that’s been going on over the past few years, once that matures a bit and it can be relied on at the QEMU level, we’ll be happy to add it to our VMs.

Until then, you can most likely use raw.qemu to directly instruct qemu to add your virtual sound card of choice, this should work fine so long as the qemu build you’re using supports it.

I’ve added the raw.qemu device but there isn’t any sound. I’ve tried this across 2 distros and confirmed that it should work in virt-manager. I could use jack and do a network based solution.

But what are these problematic security issues with the fully virtualized hardware?

The majority of Qemu CVEs (Qemu : Security vulnerabilities) are related to full hardware emulation as it requires QEMU to emulate the entire behavior of an arbitrary piece of hardware rather than being able to rely on the host system’s kernel or hardware to provide what’s needed to the guest.

For this reason, LXD relies almost entirely on virtio devices and doesn’t make use of those other devices. As mentioned, there is a virtio-sound initiative in progress with early kernel code already available though that doesn’t appear to be merged yet (at least not in my current kernel) and QEMU support appears to still be missing too.