Forward ALSA audio to LXC container

Thyraz

New Member
Jul 11, 2018
1
0
1
43
Hello everybody,

I need access to an USB microphone (insde an USB camera) in one of my LXC containers.
I installed ALSA on both, the host system and the container.

When I enter arecord -l on the host it detects the USB mic fine.
But on the guest it's not showing up.

Host:
Code:
root@pve:~# arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC283 Analog [ALC283 Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: CameraB409241 [USB Camera-B4.09.24.1], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
root@pve:~#

I can see the mic here:
Code:
root@pve:~# ls -la /dev/snd/by-id/
total 0
drwxr-xr-x 2 root root  60 Jul 10 23:26 .
drwxr-xr-x 4 root root 360 Jul 10 23:26 ..
lrwxrwxrwx 1 root root  12 Jul 11 08:50 usb-OmniVision_Technologies__Inc._USB_Camera-B4.09.24.1-01 -> ../controlC1

the linked controlC1 is listed fine here with group 116:
Code:
root@pve:~# ls -la /dev/snd
total 0
drwxr-xr-x  4 root root      360 Jul 10 23:26 .
drwxr-xr-x 24 root root     4300 Jul 10 23:26 ..
drwxr-xr-x  2 root root       60 Jul 10 23:26 by-id
drwxr-xr-x  2 root root       80 Jul 10 23:26 by-path
crw-rw----  1 root audio 116,  2 Jul 11 08:50 controlC0
crw-rw----  1 root audio 116, 12 Jul 11 08:50 controlC1
...

I also tested recording audio on the host and I can hear my voice in the WAV file afterwards:
Code:
arecord --device=hw:1,0 -f S16_LE -c 4 -r 16000 -d5 test.wav

I added to /etc/pve/nodes/pve/lxc/107.conf:
Code:
lxc.mount.entry: /dev/snd dev/snd none bind,create=dir,optional 0 0
lxc.cgroup.devices.allow: c 116:* rwm

But a arecord - l on the container only prints a
Code:
arecord -l
arecord: device_list:268: no soundcards found...

Any idea what I'm missing here?
 
Working with a similar config as yours:

Code:
root@proxmox /etc/pve/lxc > cat 1233.conf
...
unprivileged: 0

lxc.cgroup.devices.allow = c 116:* rwm
lxc.mount.entry = /dev/snd dev/snd none bind,create=dir 0 0


root@proxmox /etc/pve/lxc > pct enter 1233
alexa:/# arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: Intel [HDA Intel], device 0: AD1984 Analog [AD1984 Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
 
same here. no soundcard found.
EDIT: solved! always the same mistake. its lxc.cgroup2.devices.allow not lxc.cgroup.devices.allow!
 
Last edited:
same here. no soundcard found.
EDIT: solved! always the same mistake. its lxc.cgroup2.devices.allow not lxc.cgroup.devices.allow!
How do you know when to use lxc.cgroup2.devices.allow vs lxc.cgroup.devices.allow ? I am struggling with the same thing.
 
"cgroup-v2 first appeared in Linux kernel 4.5 released on 14 March 2016."

check your kernel version with uname -a command. or just check which one works :-)