Playing audio in a LXC container

LouisM

New Member
Dec 17, 2023
2
0
1
Hello everybody,
I'm using Proxmox since a year, and I can't figure out what I am missing in my configuration.
I want to play audio files into a unprivileged container.
What I done :

1) Allowing access to the onboard soundcard in the container file :
Code:
lxc.cgroup2.devices.allow: c 116:* rwm
lxc.mount.entry: /dev/snd dev/snd none bind,optional,create=dir

After that I can see the card on my LXC container :

Code:
total 0
drwxr-xr-x 3 nobody nogroup     300 Dec 17 20:46 .
drwxr-xr-x 7 root   root        500 Dec 17 21:29 ..
drwxr-xr-x 2 nobody nogroup      60 Dec 17 20:46 by-path
crw-rw---- 1 nobody nogroup 116, 11 Dec 17 20:46 controlC0
crw-rw---- 1 nobody nogroup 116,  9 Dec 17 20:46 hwC0D0
crw-rw---- 1 nobody nogroup 116, 10 Dec 17 20:46 hwC0D2
crw-rw---- 1 nobody nogroup 116,  3 Dec 17 20:46 pcmC0D0c
crw-rw---- 1 nobody nogroup 116,  2 Dec 17 21:00 pcmC0D0p
crw-rw---- 1 nobody nogroup 116,  4 Dec 17 20:46 pcmC0D2c
crw-rw---- 1 nobody nogroup 116,  5 Dec 17 20:46 pcmC0D3p
crw-rw---- 1 nobody nogroup 116,  6 Dec 17 20:46 pcmC0D7p
crw-rw---- 1 nobody nogroup 116,  7 Dec 17 20:46 pcmC0D8p
crw-rw---- 1 nobody nogroup 116,  8 Dec 17 20:46 pcmC0D9p
crw-rw---- 1 nobody nogroup 116,  1 Dec 17 20:46 seq
crw-rw---- 1 nobody nogroup 116, 33 Dec 17 20:46 timer
Now I'm stuck.
I understand that I should map UID and GID... But i'm completely lost with it.
Both users are root, so the UID and GID are 0.

Thanks in advance for the help :)
 
Last edited:
In unprivileged containers uids and gids in the container are mapped to different ids on the host. If you aim to access files on the host from within a container, the uid or gid of the file in the container needs to be mapped to the same id on the host. A detailed explanation is provided in the wiki: https://pve.proxmox.com/wiki/Unprivileged_LXC_containers

Since PVE 8.1 there is a much simpler way to pass devices through to a container. No need to manually bind mount the device nodes.
Code:
pct set <container id> -dev<n> /dev/snd/pcmC0D0c
n is just an arbitrary number from 0 to 255 to identify the device
 
Last edited:
  • Like
Reactions: leesteken and h00bi
Thanks a lot for your help!
So it works :)
My final config file is :
Code:
arch: amd64
cores: 1
dev1: /dev/snd/controlC0
dev2: /dev/snd/hwC0D0
dev3: /dev/snd/hwC0D2
dev4: /dev/snd/pcmC0D0c
dev5: /dev/snd/pcmC0D0p
dev6: /dev/snd/pcmC0D2c
dev7: /dev/snd/pcmC0D3p
dev8: /dev/snd/pcmC0D8p
dev9: /dev/snd/pcmC0D9p
dev10: /dev/snd/seq
dev11: /dev/snd/timer
features: nesting=1
hostname: intercom
memory: 512
net0: name=eth0,bridge=vmbr0,firewall=1,hwaddr=BC:24:11:62:08:E8,ip=dhcp,type=veth
onboot: 1
ostype: debian
rootfs: local-lvm:vm-102-disk-0,size=8G
swap: 512
unprivileged: 1
With this configuration, I can't play a sound when another sound is playing on the machine. That's not a problem now but maybe in the future...
Thanks a lot!
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!