You are not logged in.

#1 2016-07-19 13:56:17

wikavalier
Member
Registered: 2013-01-22
Posts: 27

[Solved] Pulseaudio (server) inside LXC not detecting cards

Dear all,

I have been unsuccessfully trying to get pulseaudio working (as sound server) within a LXC. So I want to grant access the LXCguest to the sound card hw and let pulse take over. I will afterwards expose the socket for other containers.

Notice that I am able to run pulseaudio in the host and share the socket with the pulseaudio within LXCguest. Basically I have a kodi running inside a LXC with its own tty->X and pulse client, taking over all input devices to work with synergy.

I will try to enumerate all relevant information that I have tested so far, but I did a lot of trial an error and i may miss something.

I have an up to date system. With no unpriviledged patches in the kernel

uname -a
Linux nexus 4.4.15-1-lts #1 SMP Mon Jul 11 20:46:47 CEST 2016 x86_64 GNU/Linux

- I have the same user in the host and in the guest
In the host

id
uid=1002(demiurgo) gid=1003(demiurgo) groups=1003(demiurgo),10(wheel),92(audio)

in the guest

id
uid=1002(demiurgo) gid=1003(demiurgo) groups=1003(demiurgo),10(wheel),92(audio),996(pulse)

Notice that i added them to a hand made pulse group and to the discouraged audio group. Without the last one, not even alsa will work on the guest

- I am able to see the audio cards and produce noise with ALSA in the host and in the guest with the user. The shared card is the MoBo soundcard. I needed the user to be in the audio group to do this
in the host:

aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: HDMI [HDA Intel HDMI], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: ALC892 Analog [ALC892 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 1: ALC892 Digital [ALC892 Digital]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

in the guest (only the shared audio card)

aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: PCH [HDA Intel PCH], device 0: ALC892 Analog [ALC892 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 1: ALC892 Digital [ALC892 Digital]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

to produce alsa noise i use (in the host and guest)

cat /dev/urandom |aplay -D hw:1,0 -f S16_LE -c 2 -r 44100

- I can see the audio cards and produce noise with the user in the host but not in the guest using pulse.
In the host

pactl list cards short
0	alsa_card.pci-0000_00_03.0	module-alsa-card.c

In the guest

$pulseaudio --start -vvvvvvv
D: [pulseaudio] conf-parser.c: Parsing configuration file '/etc/pulse/client.conf'
D: [pulseaudio] conf-parser.c: /etc/pulse/client.conf.d does not exist, ignoring.
I: [pulseaudio] main.c: Daemon startup successful.

$pactl list cards
---No output-----

Notice that when I start pulseaudio in the guest, fuser in the host wont output anything.

To produce noise with pulseaudio (sadly in the host only) I use:

$cat /dev/urandom |pacat -d 1

- I always check fuser in the host when doing the test on the guest. Notice that I never installed the fluidsynth as stated in the wiki.

fuser -v /dev/snd/*
----NO OUTPUT---

- To share the hardware mounting /dev/snd never worked for me. I have to specify the cgroup and mknod of the different char files belonging to the pci. This is part of my config and autodev of the LXC
the config of the lxc

lxc.cgroup.devices.allow = c 116:2 rwm # controlC1
lxc.cgroup.devices.allow = c 116:3 rwm # pcmC1D0p
lxc.cgroup.devices.allow = c 116:4 rwm # pcmC1D0c
lxc.cgroup.devices.allow = c 116:5 rwm # pcmC1D1p
lxc.cgroup.devices.allow = c 116:6 rwm # pcmC1D2c
lxc.cgroup.devices.allow = c 116:7 rwm # hwC1D0
lxc.cgroup.devices.allow = c 13:68 rwm # event4
lxc.cgroup.devices.allow = c 13:69 rwm # event5
lxc.cgroup.devices.allow = c 13:70 rwm # event6
lxc.cgroup.devices.allow = c 13:71 rwm # event7
lxc.cgroup.devices.allow = c 13:72 rwm # event8
lxc.cgroup.devices.allow = c 13:73 rwm # event9
lxc.cgroup.devices.allow = c 13:74 rwm # event10
lxc.cgroup.devices.allow = c 13:75 rwm # event11
lxc.cgroup.devices.allow = c 116:19 rwm # controlC3
lxc.cgroup.devices.allow = c 116:20 rwm # pcmC3D0p
lxc.cgroup.devices.allow = c 116:21 rwm # pcmC3D0c
lxc.cgroup.devices.allow = c 13:88 rwm # event24
lxc.cgroup.devices.allow = c 189:258 rwm # 3-4
lxc.cgroup.devices.allow = c 246:0 rwm # hidraw0

the autodev to create the devs

#!/bin/bash
cd ${LXC_ROOTFS_MOUNT}/dev

mkdir -p snd
mknod -m 0666 snd/controlC1 c 116 2
mkdir -p snd
mknod -m 0666 snd/pcmC1D0p c 116 3
mkdir -p snd
mknod -m 0666 snd/pcmC1D0c c 116 4
mkdir -p snd
mknod -m 0666 snd/pcmC1D1p c 116 5
mkdir -p snd
mknod -m 0666 snd/pcmC1D2c c 116 6
mkdir -p snd
mknod -m 0666 snd/hwC1D0 c 116 7
mkdir -p input
mknod -m 0666 input/event4 c 13 68
mkdir -p input
mknod -m 0666 input/event5 c 13 69
mkdir -p input
mknod -m 0666 input/event6 c 13 70
mkdir -p input
mknod -m 0666 input/event7 c 13 71
mkdir -p input
mknod -m 0666 input/event8 c 13 72
mkdir -p input
mknod -m 0666 input/event9 c 13 73
mkdir -p input
mknod -m 0666 input/event10 c 13 74
mkdir -p input
mknod -m 0666 input/event11 c 13 75
mkdir -p snd
mknod -m 0666 snd/controlC3 c 116 19
mkdir -p snd
mknod -m 0666 snd/pcmC3D0p c 116 20
mkdir -p snd
mknod -m 0666 snd/pcmC3D0c c 116 21
mkdir -p input
mknod -m 0666 input/event24 c 13 88
mkdir -p input
mknod -m 0666 input/3-4 c 189 258
mkdir -p input
mknod -m 0666 input/hidraw0 c 246 0

And i can see them within the container (otherwise alsa wont work)

$ ls /dev/snd/ -la
total 0
drwxr-xr-x 2 root root      220 Jul 19 09:34 .
drwxr-xr-x 9 root root      600 Jul 19 09:34 ..
crw-rw-rw- 1 root audio 116,  2 Jul 19 09:34 controlC1
crw-rw-rw- 1 root audio 116, 19 Jul 19 09:34 controlC3
crw-rw-rw- 1 root audio 116,  7 Jul 19 09:34 hwC1D0
crw-rw-rw- 1 root audio 116,  4 Jul 19 09:34 pcmC1D0c
crw-rw-rw- 1 root audio 116,  3 Jul 19 09:34 pcmC1D0p
crw-rw-rw- 1 root audio 116,  5 Jul 19 09:34 pcmC1D1p
crw-rw-rw- 1 root audio 116,  6 Jul 19 09:34 pcmC1D2c
crw-rw-rw- 1 root audio 116, 21 Jul 19 09:34 pcmC3D0c
crw-rw-rw- 1 root audio 116, 20 Jul 19 09:34 pcmC3D0p

- I have alsa alsa-utils alsa-plugins pulseaudio pulseaudio-alsa in both the host and the guest


I think there is something wrong with my pulseaudio in the guest. Independently of the LXC or not. I face too many times of obvious packages not installed in the LXC archlinux template that drove me crazy in the past.

Any suggestions??

Best regards and thanks in advance


EDIT---------------------------------------------

I kept researching and took a look at journalctl (doh), and it seems that somehow alsa.so wont load:

E: [pulseaudio] ltdl-bind-now.c: Failed to open module alsa.so: alsa.so: cannot open shared object file: No such file or directory

So i manually added the sinks by:

pactl load-module module-alsa-sink device=hw:1,1

and i can see the sinks

pactl list sinks short
1       alsa_output.hw_1_1     module-alsa-sink.c      s16le 2ch 44100Hz       SUSPENDED

but i cant still see the cards, and modile-alsa-card isnt working either

pactl load-module module-alsa-card
Failure: Module initialization failed

I am checking remotely so I cant tell if i can produce noise :S.

Last edited by wikavalier (2016-07-20 16:20:36)

Offline

#2 2016-07-20 16:19:45

wikavalier
Member
Registered: 2013-01-22
Posts: 27

Re: [Solved] Pulseaudio (server) inside LXC not detecting cards

Solved:

I dont know why pulse is not able to auto-detect the shared audio card. If you invoke the card directly it will work O.o

$pactl load-module module-alsa-card device_id=1

$pactl list sinks short
1	alsa_output.1.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	SUSPENDED

$ pactl list sources short
1	alsa_output.1.analog-stereo.monitor	module-alsa-card.c	s16le 2ch 44100Hz	SUSPENDED
2	alsa_input.1.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	SUSPENDED

$ pactl list cards short
0	alsa_card.1	module-alsa-card.c

One question still remains: how to do an autodetect...

Last edited by wikavalier (2016-07-20 16:24:04)

Offline

#3 2016-07-22 02:09:50

smudge
Member
Registered: 2011-03-20
Posts: 158

Re: [Solved] Pulseaudio (server) inside LXC not detecting cards

I think pulse needs access to /dev/shm by default which it doesn't look like it gets from your autodev output. Have a read of: https://www.freedesktop.org/wiki/Softwa … Notes/9.0/ particularly the "memfd-backed shared memory transport" bit. You could try enable-memfd.

I've not tinkered with LXC so this is just a thought, one that may be useless to you. Good luck smile

Offline

#4 2016-07-26 11:56:29

wikavalier
Member
Registered: 2013-01-22
Posts: 27

Re: [Solved] Pulseaudio (server) inside LXC not detecting cards

Thanks for the tip smudge,

Sadly, sharing the /dev/shm, didnt improve anything. I still have to load the card manually.

I will check how to enable the memfd, but right now is far more easier to load the card manually than researching this new feature.

Offline

#5 2016-08-31 22:00:46

bmullan
Member
Registered: 2016-08-31
Posts: 1

Re: [Solved] Pulseaudio (server) inside LXC not detecting cards

Just to clarify are you using the legacy lxc or the new lxd with the new lxc 2.x syntax & api ?

if legacy lxc an example from here may help:  https://www.flockport.com/run-gui-apps- … ontainers/

If the new lxd/lxc then this will help with its example for mapping for audio devices:  https://www.reddit.com/r/LXD/comments/5 … h=5555b679

In the reddit link be sure the click on the URL at top as that takes you to a web blog that explains how to map both video & audio devices into an LXD container.

Offline

#6 2016-09-01 12:13:45

wikavalier
Member
Registered: 2013-01-22
Posts: 27

Re: [Solved] Pulseaudio (server) inside LXC not detecting cards

Hi bmullan!

I am using lxc-1:2.0.4-1, running in root mode. So, no LXD. I used the standard package.

The flockport example was my starting point also, i have been forced to come back to it. Notice that I managed to effectively run the pulse daemon into a LXC, you just need to load the cards manually as pulse modules, since udev module doesnt work within a container.

My idea was to put all user environment inside an LXC to isolate the different parts that i use to break everytime i play with linux. So I wanted to have as much simple and standard as possible the host. But i never achieved it. There are a lot of things to take into account when leveraging Xorg, pulseaudio, bluetooth, DM, (...) into a LXC container that i gave up for now.

Thanks for the tips!

Offline

Board footer

Powered by FluxBB