Linux – Sound output not working properly in chroot

audiochrootespeaklinuxpulseaudio

So I have a 64-bit Linux Mint 17 system and I am trying to set up a chroot environment with a 64-bit Ubuntu 12.04-based system (actually something called Vinux, an Ubuntu remix). The problem is that an application using the sound output (both systems use pulseaudio) from within the chroot is not heard until I switch back to the console where my host system is running (namely, my host's X server; haven't tried the text consoles).

Here are the steps that I am using to set up, enter and test the chroot. The chroot filesystem is mounted on /mnt:

sudo mount --rbind /dev /mnt/dev
sudo mount --rbind /proc /mnt/proc
sudo mount --rbind /sys /mnt/sys
sudo mount --rbind /tmp /mnt/tmp
sudo mount --rbind /run /mnt/run
sudo mount --bind /var/lib/dbus /mnt/var/lib/dbus
sudo chroot /mnt

now in chroot as root user:

su <desired username within chroot - happens to be the same as my username on the host system>
export XDG_RUNTIME_DIR=/run/user/1000
startx -- :1

automatic switch to second X server

CtrlAltT to open terminal

now in terminal

cat /dev/urandom | grep -ao "[a-z]" | espeak

sound only plays when I press the CtrlAlt-… sequence to switch back to my host X server.

I have read every page that I can find about setting up pulseaudio for a chroot but none of the instructions cause any change in this behaviour.

EDIT: Got it to work such that the sound output from the chroot plays, but now any sound output from the host system is suspended until the chroot session ends, not matter which console I switch to.

Best Answer

In my case I needed to copy /etc/machine-id into the chroot's /etc for PulseAudio to start working. That was a fun session with strace and diffuse...

Related Question