[Lxc-users] LXC and sound in container -

John lxc at jelmail.com
Fri Nov 15 09:50:58 UTC 2013


On 09/11/13 15:12, brian mullan wrote:
> I've searched the web for 2 weeks now and can find no documentation 
> describing steps to configure "sound" in an LXC container.
>
Here is what I do. It's just ALSA (not Pulseaudio) but I do run a 
desktop in a container and it works for me.

1. install alsa-lib alsa-utils in the container
2. enable autodev in the container's LXC config

     # Use autodev to be compatible with systemd
     lxc.autodev = 1
     lxc.hook.autodev = /etc/lxc/myhost/autodev

(set the autodev path to an apprpriate location on your host)

3. write an autodev script on the host at the path in "lxc.hook.autodev" 
from step 1. Make it executable.

#!/bin/bash
     # LXC Autodev hook. Created by Amylum
     cd ${LXC_ROOTFS_MOUNT}

     mkdir ./dev/snd
     ifs_char=$IFS
     IFS=$'\n'
     ifs_line=$IFS
     for i in $(ls -l /dev/snd | grep '^c' | tr -s ' ' | awk -F "[ ,]" 
{'print "mknod -m 660 ./dev/snd/"$11" c "$5" "$7" && chown root:audio 
./dev/snd/"$11'})
     do
         IFS=$ifs_char
         eval $i
         IFS=$ifs_line
     done

4. add devices to lxc config file

     # For ALSA Sound
     lxc.cgroup.devices.allow = c 116:* rwm # dev/snd/

5. add any users needing to use audio to the "audio" group

     for user in ${audio_users}
     do
         usermod -a -G audio $user
     done

Some explanation:

Container cannot use udev to create device nodes and the way systemd 
initialises the container's /dev prevents you creating them from the 
host. So, you have to use an autodev hook to create the device nodes at 
start-up (steps 2 and 3). You also need allow access to the devices in 
the container's config and that is what step 4 does.

I ought to get PA working but I haven't had the time or the inclination.

I hope this is of some help.

John






More information about the lxc-users mailing list