LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices


Reply
  Search this Thread
Old 02-05-2013, 06:02 PM   #1
charlie101
LQ Newbie
 
Registered: Jun 2012
Posts: 10

Rep: Reputation: Disabled
LXC Container: sound Not working


Hi

Does anyone know how to get sound working within an LXC container?

I am new to LXC and don't know much about sound config.
I've spent days searching for documentation on the subject and come up with zero!

I've tried applying techniques related to hardware access and visibility, like granting access and bind mounting /dev/snd etc etc.

Both container and host are ubuntu 12.04.
Within the container pulse-volume-control shows virtual devices registering audio input and output but there are no physical devices registered. Hence no sound?

Any pointers or suggestions would be greatly appreciated.

Charlie101
 
Old 02-17-2013, 09:17 AM   #2
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Sounds seems to be one of those black arts, with lots of strange programming going on. We have these sound mixing apps, but they don't seem to be all that well designed. To a limited extent they have been able to mix sounds from more than one source. But the UI is awkward for setting the mix levels (suggestion to those developers: try working a real studio mixer some day). And the big issue I see in all of them is the inability to send the same sound to more than one sound device. I plug in 2 headphones and only 1 can ever get the sound at a time.

What we need is a smart sound server. It gets connections from local sound sources via unix named sockets so authentication is simply by userid. It gets connections from network with various authentication methods available. These are the main sound sources. It can output to any or all sound devices, including the connecting to an instance of itself on the same machine, virtual host, or elsewhere on the network (and more than one at a time, too).

Is that what we have now? If yes, then they need to debug and fix it. If not, then make it so we can produce sound from inside VMs. So far, sound continues to be a mess that can't be managed well and works only in limited ways.
 
Old 06-11-2015, 12:54 PM   #3
Soderlund
Member
 
Registered: Aug 2012
Posts: 185

Rep: Reputation: 81
It doesn't work for me either (LXC on Debian Jessie 32-bit).

I've added this to the LXC config file:
Code:
lxc.mount.entry = tmpfs tmp tmpfs defaults
lxc.mount.entry = /dev/dri dev/dri none bind,optional,create=dir
lxc.mount.entry = /dev/snd dev/snd none bind,optional,create=dir
'aplay -l':
Code:
aplay: device_list:268: no soundcards found
'lsmod | grep snd' displays the same output as the host.

'/dev/snd' contains the same things as the host.

'amixer -c 0' doesn't work -- prints the usage instructions.

Running 'alsamixer' outputs:
Code:
cannot open mixer: No such file or directory
I tried all the commands as root.

Sound works on the host out of the box, but I can't get it to work in the container.
 
Old 06-11-2015, 01:49 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
You also have to make Pulseaudio from the host available in the guest with bind-mounting ~/.pulse into the container.
 
1 members found this post helpful.
Old 06-12-2015, 06:34 AM   #5
Soderlund
Member
 
Registered: Aug 2012
Posts: 185

Rep: Reputation: 81
Quote:
Originally Posted by TobiSGD View Post
You also have to make Pulseaudio from the host available in the guest with bind-mounting ~/.pulse into the container.
Do you mean '~/.config/pulse' (contains 'cookie' and some files whose names begin with a hash)? I don't have a '~/.pulse' directory in the host.

I inserted this into the config file:
Code:
lxc.mount.entry = /home/<USERNAME>/.pulse home/<USERNAME>/.pulse none bind,optional,create=dir
lxc.mount.entry = /home/<USERNAME>/.config/pulse home/<USERNAME>/.config/pulse none bind,optional,create=dir
'paplay -v <FILE>' says:

Code:
Failed to create secure directory (/home/<USERNAME>/.pulse): Operation not permitted
However, it plays the file successfully (but without sound).

I tried to bind-mount:
  • Both '~/.config/pulse' and '~/.pulse'
  • Only '~/.pulse'
  • Only '~/.config/pulse'

But the same thing happens.

'alsamixer' works now, and the sound is not muted.

I can get rid of the "failed to create secure directory" error by bind-mounting '~/.config/pulse' (on the host) as '~/.pulse' (in LXC), but that makes no sense since both the host and LXC run Debian Jessie (so they should both use the same secure pulse directory, right?). And the sound still doesn't work when I do that.

By the way, pulseaudio would not start in the LXC container at all until I commented out this from '/etc/pulse/defaults.pa':

Code:
#.ifexists module-console-kit.so
#load-module module-console-kit
#.endif
#.ifexists module-systemd-login.so
#load-module module-systemd-login
#.endif
 
Old 06-12-2015, 07:12 AM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by Soderlund View Post
Do you mean '~/.config/pulse' (contains 'cookie' and some files whose names begin with a hash)? I don't have a '~/.pulse' directory in the host.
Might be possible that different distros place this in a different location.
Quote:
I inserted this into the config file:
Code:
lxc.mount.entry = /home/<USERNAME>/.pulse home/<USERNAME>/.pulse none bind,optional,create=dir
lxc.mount.entry = /home/<USERNAME>/.config/pulse home/<USERNAME>/.config/pulse none bind,optional,create=dir
'paplay -v <FILE>' says:

Code:
Failed to create secure directory (/home/<USERNAME>/.pulse): Operation not permitted
Make sure that the user in the container has permissions to access the bind-mounted directories, for example with giving them the same UID.
 
1 members found this post helpful.
Old 06-12-2015, 07:43 AM   #7
Soderlund
Member
 
Registered: Aug 2012
Posts: 185

Rep: Reputation: 81
Quote:
Originally Posted by TobiSGD View Post
Make sure that the user in the container has permissions to access the bind-mounted directories, for example with giving them the same UID.
Both the host-user and LXC-user have UID 1000.

In the host:
Code:
chmod 0777 $HOME/.pulse
chmod 0777 $HOME/.config/pulse
That removes the error message but there is still no sound.
 
Old 06-12-2015, 08:09 AM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
I should have kept my config file to look up how I did it, but I haven't, so I will just post this link with an extensive description how to do it: https://www.flockport.com/run-gui-ap...xc-containers/
Hope that helps.
 
1 members found this post helpful.
Old 06-12-2015, 10:12 AM   #9
Soderlund
Member
 
Registered: Aug 2012
Posts: 185

Rep: Reputation: 81
Thank you.

Just knowing that it is possible helps. I tried some of the steps in that link but I must have done it wrong (the .pulse_socket disappeared after 10-30 seconds). I'll go through it again from the beginning and do it properly.

Much appreciated.
 
Old 06-12-2015, 11:51 AM   #10
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
I was initially a bit confused by the steps taken in that tutorial, I couldn't find the one I used when I tried this which went down to just bind-mounting as I have stated above. This seems to be more complex, but I haven't tried that approach yet.
 
1 members found this post helpful.
Old 06-14-2015, 11:16 AM   #11
Soderlund
Member
 
Registered: Aug 2012
Posts: 185

Rep: Reputation: 81
I can't get bind-mounting to work.

But there is another solution:

1. On the host, pulseaudio needs to load the modules esound-protocol-tcp and (or?) native-protocol-tcp and specify the IP address or auth-anonymous=1. I added this to default.pa.

2. On the client, set PULSE_SERVER=xxx.xxx.xxx.xxx:4713, where xxx.xxx.xxx.xxx is the IP address of the host. You can add this to the configuration file too, by the way. I think the directive is 'default-server = ...'.

3. On the host, make sure hosts.allow contains 'ALL: yyy.yyy.yyy.yyy', where yyy.yyy.yyy.yyy is the IP address of the LXC container. (Otherwise it will say "connection refused by tcpwrap".)

4. The firewall on the host needs to allow the incoming connection. Shorewall does not do this by default if you used the templates, so you have to add an exception in the rules file: 'ACCEPT net:<ip of client> $FW'; or however your firewall is configured.

Then the client (LXC) will send audio via the network to the host's pulseaudio server.

However, because the pulseaudio server keeps crashing all the time (and the host will not restart it when the client sends a request), I wrote a script that restarts it whenever it dies:
Code:
#!/bin/sh
while true
do
    pulseaudio > /dev/null 2> /dev/null
done
Yeah, I know... but it works.

(I added a counter to that script, by the way, and it crashes / terminates about 30 times per hour for some reason that I haven't figured out yet. It just says 'terminated' when I run pulseaudio with '-vv'.)

[edit]

Oh, I nearly forgot: when you start the pulseaudio server on the host, a cookie file is created somewhere (~/.config/pulse/cookie, ~/.pulse/cookie or ~/.pulse_cookie). You must copy this cookie file to the user's home directory in the LXC container so that the client and the host have the same cookie. The client's home directory is /var/lib/lxc/<container>/rootfs/home/<user>/ -- copy as root and chown it.

Also, I added the users to the following groups, but some of them may not be needed: audio, pulse, pulse-access.

Last edited by Soderlund; 06-14-2015 at 11:34 AM.
 
Old 04-14-2020, 01:15 AM   #12
iftikhar khan
LQ Newbie
 
Registered: Apr 2020
Posts: 1

Rep: Reputation: Disabled
LXC Sound

What finally worked for me was the following config:

lxc.mount.entry = /dev/dri dev/dri none bind,optional,create=dir
lxc.mount.entry = /tmp/.X11-unix tmp/.X11-unix none bind,optional,create=dir
lxc.mount.entry = /dev/video0 dev/video0 none bind,optional,create=file
lxc.mount.entry = /tmp/.lxc tmp/.lxc none bind,optional,create=dir
lxc.mount.entry = /dev/snd dev/snd none bind,optional,create=dir
lxc.cgroup.devices.allow = c 116:* rwm
lxc.hook.pre-start = /var/lib/lxc/guest/setup-pulse.sh

Where setup-pulse.sh is as follows:

#!/bin/sh
PULSE_PATH=/tmp/.lxc/.pulse_socket

if [ ! -e "$PULSE_PATH" ] || [ -z "$(lsof -n $PULSE_PATH 2>&1)" ]; then
sudo -u 'YOUR NORMAL USER' -i pactl load-module module-native-protocol-unix auth-anonymous=1 socket=$PULSE_PATH
fi

and finally a pulseaudio -k on the host machine

Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Outputting X display from inside an LXC Container charlie101 Linux - Virtualization and Cloud 1 02-04-2013 09:41 PM
script to get a lxc-container like iso of current. cod_liver_0il Slackware 1 09-10-2012 11:12 AM
How to end a Linux Container (LXC) from within? Skaperen Linux - Virtualization and Cloud 0 06-14-2011 09:37 AM
Linux-Vserver or lxc or anything else vishesh Linux - Server 2 11-19-2010 03:25 PM
Example Servlets not working with Mod_JK, Apache2 Webserver& Tomcat6's Web Container rtoney5 Linux - Software 13 01-14-2009 06:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 05:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration