Support for virtio-sound

Hello everyone!

Since QEMU now seems to officially support virtio-sound as an audio driver is there any way to use it (officially via incus or by editing a conf file) within an Incus VM?

Thanks in advance!

Welcome!

When you create a VM with incus, you can specify directly any QEMU configuration. For example,

incus config set myvm raw.qemu -- "-device intel-hda -device hda-duplex -audio spice"

What should appear here so that virtio-sound is enabled for a VM?

Hi Simos,

Thank you for your reply, however I am not 100% sure, I hoped for some “blessed” config, as it appears that QEMU itself has quite some options itself…

It looks like this should work: -device ‘{“driver”:“virtio-sound-pci”,“id”:“sound0”,“audiodev”:“audio1”,“streams”:2,“bus”:“pci.0”,“addr”:“0x2”}’

Src: libvirt/tests/qemuxmlconfdata/sound-device-virtio.x86_64-latest.args at master · libvirt/libvirt · GitHub

The beauty of all this is to be able to participate in figuring out how to do it yourself.

You may have QEMU installed on your system. Incus however has its own installation of QEMU. We need to figure out the devices and audio systems of QEMU by Incus.

$ incus create images:ubuntu/24.04/cloud --vm sound
Creating sound
$ incus config set sound raw.qemu -- "-device INVALID"
user@user-desktop:~$ incus start sound
Error: Failed to run: forklimits limit=memlock:unlimited:unlimited fd=3 fd=4 -- /opt/incus/bin/qemu-system-x86_64 -S -name sound -uuid 8fb0ac18-2b61-4423-89e8-38af6c7aec13 -daemonize -cpu host,hv_passthrough -nographic -serial chardev:console -nodefaults -no-user-config -sandbox on,obsolete=deny,elevateprivileges=allow,spawn=allow,resourcecontrol=deny -readconfig /run/incus/sound/qemu.conf -spice unix=on,disable-ticketing=on,addr=/run/incus/sound/qemu.spice -pidfile /run/incus/sound/qemu.pid -D /var/log/incus/sound/qemu.log -smbios type=2,manufacturer=LinuxContainers,product=Incus -runas incus -device INVALID: : exit status 1
Try `incus info --show-log sound` for more info
$ 

Up to now we have created a Linux VM for our tests, and we put some invalid parameter in order to obtain the command line for the QEMU package by Incus. We can now run -device help to get a list of all emulated sound devices.

$ sudo /opt/incus/bin/qemu-system-x86_64 -S -name sound -uuid 8fb0ac18-2b61-4423-89e8-38af6c7aec13 -daemonize -cpu host,hv_passthrough -nographic -serial chardev:console -nodefaults -no-user-config -sandbox on,obsolete=deny,elevateprivileges=allow,spawn=allow,resourcecontrol=deny -readconfig /run/incus/sound/qemu.conf -spice unix=on,disable-ticketing=on,addr=/run/incus/sound/qemu.spice -pidfile /run/incus/sound/qemu.pid -D /var/log/incus/sound/qemu.log -smbios type=2,manufacturer=LinuxContainers,product=Incus -runas incus -device help

...
Sound devices:
name "AC97", bus PCI, alias "ac97", desc "Intel 82801AA AC97 Audio"
name "adlib", bus ISA, desc "Yamaha YM3812 (OPL2)"
name "cs4231a", bus ISA, desc "Crystal Semiconductor CS4231A"
name "ES1370", bus PCI, alias "es1370", desc "ENSONIQ AudioPCI ES1370"
name "gus", bus ISA, desc "Gravis Ultrasound GF1"
name "hda-duplex", bus HDA, desc "HDA Audio Codec, duplex (line-out, line-in)"
name "hda-micro", bus HDA, desc "HDA Audio Codec, duplex (speaker, microphone)"
name "hda-output", bus HDA, desc "HDA Audio Codec, output-only (line-out)"
name "ich9-intel-hda", bus PCI, desc "Intel HD Audio Controller (ich9)"
name "intel-hda", bus PCI, desc "Intel HD Audio Controller (ich6)"
name "sb16", bus ISA, desc "Creative Sound Blaster 16"
name "usb-audio", bus usb-bus
name "vhost-user-snd", bus virtio-bus
name "vhost-user-snd-pci", bus PCI
name "virtio-sound-device", bus virtio-bus
name "virtio-sound-pci", bus PCI, alias "virtio-sound", desc "Virtio Sound"
...

$

Now let’s do the audio drivers.

$ sudo /opt/incus/bin/qemu-system-x86_64 -S -name sound -uuid 8fb0ac18-2b61-4423-89e8-38af6c7aec13 -daemonize -cpu host,hv_passthrough -nographic -serial chardev:console -nodefaults -no-user-config -sandbox on,obsolete=deny,elevateprivileges=allow,spawn=allow,resourcecontrol=deny -readconfig /run/incus/sound/qemu.conf -spice unix=on,disable-ticketing=on,addr=/run/incus/sound/qemu.spice -pidfile /run/incus/sound/qemu.pid -D /var/log/incus/sound/qemu.log -smbios type=2,manufacturer=LinuxContainers,product=Incus -runas incus -audio help
Available audio drivers:
none
dbus
oss
spice
wav
$

At this stage we can edit the raw.qemu parameter, try out options and then start the VM. What’s missing is to install some utilities in the VM that will help us try out the audio.
I think this is a first step in testing things out.