Discussion:
[Lxc-users] LXC and sound in container -
brian mullan
2013-11-09 15:12:13 UTC
Permalink
I've searched the web for 2 weeks now and can find no documentation
describing steps to configure "sound" in an LXC container.

I've read all the lxc-user mail back to April 2011
http://osdir.com/ml/lxc-chroot-linux-containers/2013-11/
and can't find any previous mail on the subject describing the steps
involved:

I will admit that I may not be doing things right or may have left
something out.
I am using Ubuntu 13.10 and LXC.

On the host I do the following:
*$ sudo mount ?-o rw,bind? ?/dev/snd? ?/var/lib/lxc/CN_name/rootfs/dev/snd?*

I then edited the /var/lib/lxc/CN_name/config and added:
*lxc.cgroup.devices.allow = c 116:* rwm*

I then start the container CN_name ( $ sudo lxc-start -n CN_name)

after this I still cannot get any sound out of the container.

I did a check:

$ lspci -v | more

and it comes back with Capabilities Denied for all PCI devices (re my hosts
sound card) but again I am not LXC "smart" enough to know if that's the
problem and if it is how to resolve it.

Although I have seen multiple posts be people around the web saying it can
be done or that they have done it there is never anything added as to
describing the commands or /var/lib/lxc/cn_name/config entries required.

I had really assumed that something like this would have been documented by
now ... somewhere by someone.

The problem is NOT getting a gnome/unity/lxde/xfce etc desktop running in
the container its that there's no sound present

Even Docker Desktop:

http://blog.docker.io/2013/07/docker-desktop-your-desktop-over-ssh-running-inside-of-a-docker-container/#more-368

Although presenting a Desktop via ssh to a container doesn't have sound (if
you were to start firefox and go to youtube... no sound)

I've check ubuntu, arch, debian, mint etc distro LXC documentation and
there just is no documentation concerning the steps to do this ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20131109/32d1a5a3/attachment.html>
brian mullan
2013-11-10 10:35:23 UTC
Permalink
I'd just sent in an email to the lxc-users list concerning Sound in an LXC
container and what seemed
to me a lack of any good available information about how to configure it.

Well, last night I finally figured out what I had to do to make it work
after seeing a 1 line entry in
a Debian oriented blogger's post about LXC and some other device he was
enabling in a container.

I did finally get Sound to work from a desktop running in an LXC container
in my Ubuntu 13.10 x64 system !

One thing remains though is that PulseAudio "by default" in Ubuntu appears
to be locked/owned by whichever
Desktop grabs it first.

This would prevent multiple LXC container Desktops from all using Sound
simultaneously/concurrently for multiple users.

However, *there is a solution,* requiring a per-user pulseaudio config
change that appears minimal that I've found but have
not yet had time to implement and try.

As soon as I do, I will in a few days try to document what I've done so
others interested in the same don't have to go through
the same research.

In the end my particular problem really boiled down to existing
documentation being very minimal regarding this.

Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20131110/a4629055/attachment.html>
Serge Hallyn
2013-11-11 21:46:11 UTC
Permalink
Post by brian mullan
As soon as I do, I will in a few days try to document what I've done so
others interested in the same don't have to go through
the same research.
Thanks, I look forward to seeing it. The current
pulseaudio/consolekit/logind/udev/whatever-is-messing-with-me
setup isn't clear to me either.
brian mullan
2013-11-12 01:40:52 UTC
Permalink
I'm not sure the lxc-user alias will take an file attachment or not. If
not I'll try something else.

I tried to document everything I did to finally get sound working in an LXC
container on my Ubuntu 13.10 system.

I've attached that as a .ODT (librewriter) file to this email because I
tried to be verbose in describing all the steps I did.

My approach could be way off base for all I know ... wouldn't be the first
time <g>.

But after 3 weeks of searching the web to no avail for a How-To Guide or
writeup by anyone including distros (Arch, Debian, Ubuntu etc) on LXC &
Sound.

I at least wanted to write-up everything I've found out or tried so far and
would appreciate any ideas, corrections, solutions.

As I said at the bottom of the doc I think LXC could have a great future
for User Desktops as everything works including Sound but with the caveats
regarding sound that I describe in the .ODT file.

brian mullan
Post by Serge Hallyn
Post by brian mullan
As soon as I do, I will in a few days try to document what I've done so
others interested in the same don't have to go through
the same research.
Thanks, I look forward to seeing it. The current
pulseaudio/consolekit/logind/udev/whatever-is-messing-with-me
setup isn't clear to me either.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20131111/a10866fc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LXC and Sound.odt
Type: application/vnd.oasis.opendocument.text
Size: 29518 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20131111/a10866fc/attachment.odt>
Serge Hallyn
2013-11-14 17:57:04 UTC
Permalink
Post by brian mullan
I'm not sure the lxc-user alias will take an file attachment or not. If
not I'll try something else.
I tried to document everything I did to finally get sound working in an LXC
container on my Ubuntu 13.10 system.
Thanks Brian. If you're interested, I would suggest splitting this into
two howtos, and posting them in a wiki or at linuxcontainers.org. One
would be on just setting up x. That actually could be a main page with
a list of options, one being the one you documented, another (soon)
spice, etc. The other would be on pulseaudio.

St?phane, could you briefly comment on what arkose did to allow
simulatenous host and container pulseaudio access? Brian mentioned
something about glueing in a pulseaudio socket?
Stéphane Graber
2013-11-14 19:12:39 UTC
Permalink
Post by Serge Hallyn
Post by brian mullan
I'm not sure the lxc-user alias will take an file attachment or not. If
not I'll try something else.
I tried to document everything I did to finally get sound working in an LXC
container on my Ubuntu 13.10 system.
Thanks Brian. If you're interested, I would suggest splitting this into
two howtos, and posting them in a wiki or at linuxcontainers.org. One
would be on just setting up x. That actually could be a main page with
a list of options, one being the one you documented, another (soon)
spice, etc. The other would be on pulseaudio.
St?phane, could you briefly comment on what arkose did to allow
simulatenous host and container pulseaudio access? Brian mentioned
something about glueing in a pulseaudio socket?
arkose basically runs:
pactl load-module module-native-protocol-unix socket=/some/path auth-cookie-enabled=0

The bind-mounts that socket inside the container and exports
PULSE_SERVER=/some/path in the container's environment.
--
St?phane Graber
Ubuntu developer
http://www.canonical.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20131114/3aaf44f6/attachment.pgp>
Serge Hallyn
2013-11-14 22:08:43 UTC
Permalink
Post by Stéphane Graber
Post by Serge Hallyn
Post by brian mullan
I'm not sure the lxc-user alias will take an file attachment or not. If
not I'll try something else.
I tried to document everything I did to finally get sound working in an LXC
container on my Ubuntu 13.10 system.
Thanks Brian. If you're interested, I would suggest splitting this into
two howtos, and posting them in a wiki or at linuxcontainers.org. One
would be on just setting up x. That actually could be a main page with
a list of options, one being the one you documented, another (soon)
spice, etc. The other would be on pulseaudio.
St?phane, could you briefly comment on what arkose did to allow
simulatenous host and container pulseaudio access? Brian mentioned
something about glueing in a pulseaudio socket?
pactl load-module module-native-protocol-unix socket=/some/path auth-cookie-enabled=0
The bind-mounts that socket inside the container and exports
PULSE_SERVER=/some/path in the container's environment.
Thanks, St?phane. Interesting.

(I need to find time to work on Xspice in a container, but unfortunately
it was segfaulting for me last week.)
brian mullan
2013-11-17 16:44:08 UTC
Permalink
Attached is a v2.0 writeup of how I configured Sound in my LXC containers.


Please note that this document is based on further research into how
PulseAudio can be configured and because of what I learned is both much
shorter & less complex to setup sound in LXC.

See the attached libreoffice .ODT file for the updated information.

Brian Mullan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20131117/0fb546d2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Enabling Sound in LXC containers v2.odt
Type: application/vnd.oasis.opendocument.text
Size: 30387 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20131117/0fb546d2/attachment.odt>
Michael H. Warfield
2013-11-17 18:05:02 UTC
Permalink
Hey...
Post by brian mullan
Attached is a v2.0 writeup of how I configured Sound in my LXC
containers.
Please note that this document is based on further research into how
PulseAudio can be configured and because of what I learned is both
much shorter & less complex to setup sound in LXC.
See the attached libreoffice .ODT file for the updated information.
That's really interesting. Good job.

I also have a personal use case for this that, ironically, has nothing
to do with LXC Containers. I've got a little backburner project at home
of setting up a little audioserver using a Raspberry Pi I can park
around (outdoors during the summer) and drive a remote setup connected
over WiFi. For some reason, it never dawned on me to just remote the
audio over the network using PulseAudio. Nice.
Post by brian mullan
Brian Mullan
Regards,
Mike
Post by brian mullan
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
Lxc-users mailing list
Lxc-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-users
--
Michael H. Warfield (AI4NB) | (770) 978-7061 | mhw at WittsEnd.com
/\/\|=mhw=|\/\/ | (678) 463-0932 | http://www.wittsend.com/mhw/
NIC whois: MHW9 | An optimist believes we live in the best of all
PGP Key: 0x674627FF | possible worlds. A pessimist is sure of it!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 482 bytes
Desc: This is a digitally signed message part
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20131117/de8e0758/attachment.pgp>
brian mullan
2013-11-17 21:09:54 UTC
Permalink
Michael

For your RaspPi use-case you might want to read more here:

http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Network/
Post by Michael H. Warfield
Hey...
Post by brian mullan
Attached is a v2.0 writeup of how I configured Sound in my LXC containers.
Please note that this document is based on further research into how
PulseAudio can be configured and because of what I learned is both
much shorter & less complex to setup sound in LXC.
See the attached libreoffice .ODT file for the updated information.
That's really interesting. Good job.
I also have a personal use case for this that, ironically, has nothing
to do with LXC Containers. I've got a little backburner project at home
of setting up a little audioserver using a Raspberry Pi I can park
around (outdoors during the summer) and drive a remote setup connected
over WiFi. For some reason, it never dawned on me to just remote the
audio over the network using PulseAudio. Nice.
Post by brian mullan
Brian Mullan
Regards,
Mike
Post by brian mullan
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
------------------------------------------------------------------------------
Post by brian mullan
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
Post by brian mullan
_______________________________________________
Lxc-users mailing list
Lxc-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-users
--
Michael H. Warfield (AI4NB) | (770) 978-7061 | mhw at WittsEnd.com
/\/\|=mhw=|\/\/ | (678) 463-0932 |
http://www.wittsend.com/mhw/
NIC whois: MHW9 | An optimist believes we live in the best of all
PGP Key: 0x674627FF | possible worlds. A pessimist is sure of it!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20131117/17d2c7a4/attachment.html>
John
2013-11-15 09:50:58 UTC
Permalink
Post by brian mullan
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
John
2013-11-15 10:13:19 UTC
Permalink
sorry forgot to add - this is on Arch Linux :)
TuxRaiderPen
2013-12-25 15:33:35 UTC
Permalink
Post by John
Post by brian mullan
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.
Very interesting! !! THANK YOU!

I am interested in sound device use inside LXC containers, under ALSA *only*,
so I have a few questions...

Is this sound *output* only ???

Have you tried using :

1) Line in
2) Mic In
3) ALSA plugins:

I use something like this:

asound.conf
pcm.onboard{
type hw
card 0
}
ctl.onboard {
type hw
card 0
}
### Dsnoop both channels
pcm.dsnoop_onboard {
type dsnoop
ipc_key 32
slave {
pcm "onboard"
channels 2
period_size 320
rate 48000
buffer_size 8192
format S32_LE
}
bindings {
0 0
1 1
}
}
### Dsnoop splited channels
pcm.onboard_left {
type dsnoop
ipc_key 32
slave {
pcm "onboard"
channels 2
}
bindings.0 0
}

pcm.onboard_right {
type dsnoop
ipc_key 32
slave {
pcm "onboard"
channels 2
}
bindings.0 1
}

### PLUGS ##
### used with darkice
### device = plug:plug_onboard_left
pcm.plug_onboard_left{
type route
slave.pcm "onboard_left"
slave.channels 1
ttable.0.0 1
}
pcm.plug_onboard_right{
type route
slave.pcm "onboard_right"
slave.channels 1
ttable.0.0 1
}


I then feed these pcm.plug_onboard_right to some software to process each
plugin...

I am not so much interested in SOUND OUTPUT, but CAPTURE of audio via a
software package and then feeding it onward...

I am very interested in your solution as it uses ALSA only, as I may be using
KUbuntu, highly customized, but first step I do is

sudo apt-get purge pulseaudio

So I am very interested in your solution and getting access to the ALSA
plugins....

Hmmm.. maybe it would be best to get a few of those USB fob sound cards and
just assign each to a specific LXC container, and then put the asound.conf into
each container and thus each container could do two encodings... hmmmm...

Thanks again for your input on ALSA based sound in LXC!
John
2014-01-17 09:40:23 UTC
Permalink
Post by TuxRaiderPen
Post by John
Post by brian mullan
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.
Apoligies for late response to this post - it fell off my radar. I was
busy eating turkey on the 25th December!!!
Post by TuxRaiderPen
Very interesting! !! THANK YOU!
I am interested in sound device use inside LXC containers, under ALSA *only*,
so I have a few questions...
Is this sound *output* only ???
1) Line in
2) Mic In
I have thus far only tried sound output, as that is all that I needed.
If I get a chance I may try out a few tests of sound input - I can't see
why it wouldn't work...
Post by TuxRaiderPen
asound.conf
pcm.onboard{
type hw
card 0
}
ctl.onboard {
type hw
card 0
}
### Dsnoop both channels
pcm.dsnoop_onboard {
type dsnoop
ipc_key 32
slave {
pcm "onboard"
channels 2
period_size 320
rate 48000
buffer_size 8192
format S32_LE
}
bindings {
0 0
1 1
}
}
### Dsnoop splited channels
pcm.onboard_left {
type dsnoop
ipc_key 32
slave {
pcm "onboard"
channels 2
}
bindings.0 0
}
pcm.onboard_right {
type dsnoop
ipc_key 32
slave {
pcm "onboard"
channels 2
}
bindings.0 1
}
### PLUGS ##
### used with darkice
### device = plug:plug_onboard_left
pcm.plug_onboard_left{
type route
slave.pcm "onboard_left"
slave.channels 1
ttable.0.0 1
}
pcm.plug_onboard_right{
type route
slave.pcm "onboard_right"
slave.channels 1
ttable.0.0 1
}
I then feed these pcm.plug_onboard_right to some software to process each
plugin...
I am not so much interested in SOUND OUTPUT, but CAPTURE of audio via a
software package and then feeding it onward...
I am very interested in your solution as it uses ALSA only, as I may be using
KUbuntu, highly customized, but first step I do is
sudo apt-get purge pulseaudio
So I am very interested in your solution and getting access to the ALSA
plugins....
Hmmm.. maybe it would be best to get a few of those USB fob sound cards and
just assign each to a specific LXC container, and then put the asound.conf into
each container and thus each container could do two encodings... hmmmm...
Thanks again for your input on ALSA based sound in LXC!
_______________________________________________
lxc-users mailing list
lxc-users at lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-users
Loading...