How to start pulseaudio in vagrant VM

Hello,

Is there any documentation please on using sound/audio in a Vagrant VM please ?

I am using Debian Linux 11.1 Bullseye as a host. I installed the official .deb package for vagrant from vagrantup’s repo.

$ apt info vagrant
Package: vagrant
Version: 2.2.18

I am using Vagrant here with VirtualBox 6.1.28.

I created a VM with a Vagrantfile, the guest VM runs OpenIndiana.

I enabled in VirtualBox enable Audio with host audio driver ‘pulseaudio’.

Problem is that when I “vagrant ssh” into the vagrant VM I am not able to start pulseaudio on the guest VM:

I tried: pulseaudio --start

but it gives the following error:

vagrant@openindiana:~$ pulseaudio --start
W: [(null)] caps.c: Normally all extra capabilities would be dropped now, but that’s impossible because PulseAudio was built without capabilities support.
N: [(null)] main.c: User-configured server at {bcef0cfcb8264d8caf562e5413c22efa}unix:/run/user/1000/pulse/native, refusing to start/autospawn.

Note that on the Linux Debian host, I can play sounds fine. Also I tried manually installing OpenIndiana on a VirtualBox VM and then I can play sounds in the VM so the guest VM can play sounds fine as well.

In the latter case, when I do a manual OS install of the guest OS, including a full desktop install (so with a MATE/GNOME desktop in the guest VM) pulseaudio starts fine and it is “autospawn” so automatically started.

That does not happen in my Vagrant VM, where pulseaudio is not autospawn. I suppose a major difference is that my vagrant VM has no full desktop installed.

Perhaps the issue is more OS related (how to start pulseaudio on OpenIndiana when the full desktop is not installed) but I thought to ask here at first, since this situation arises when using a Vagrant VM.

Thanks,
David Stes

Perhaps instead of trying to start pulseaudio in the VM, I could try to set PULSE_SERVER to forward the audio/sound from the vagrant guest vm to the pulseaudio server already running on the host.

This is like X11 forwarding over ssh (which works with vagrant ssh)

With the pulseaudio command “paprefs” it is possible to make pulseaudio accept tcp connections on the host.

My hope is to be able to set PULSE_SERVER in the vagrant vm so to connect to the pulse server on the host.

I have tried adding to the Vagrantfile:

config.vm.network "forwarded_port", guest: 24713, host: 4713

however this does not seem to be quite right, I cannot connect to the host port 4713 with the above.

It would be nice to have something equivalent to

config.ssh.forward_x11 = true

to forward the PULSE_SERVER from the guest vm to the host.

I have meanwhile audio/music working in the Vagrant guest … Sound works now.

The following article describes how sound/music can be forwarded to a remote pulseaudio server by streaming sound to the host:

forwarding-audio-like-x-in-ssh

So on the host (running VirtualBox and vagrant) I verify with the commands “paprefs” and “pax11publish” that the pulseaudio server is listening on port 4713.

Then I start the guest with the – -R 24713:localhost:4713 ssh arguments by using


vagrant ssh -- -R 24713:localhost:4713

The port_forwarding in the Vagrantfile is using the equivalent of ssh -L port:host:hostport and I had to use -R port:host:hostport because I want to forward all traffic from the guest VM port 24713 to the host port 4713 (where the pulseaudio of the host is listening).

So this allows the vagrant VM guest to play music on the host. Works fine.

On the guest VM I can verify the connection with


vagrant@openindiana:~$ pactl info
Server String: tcp:localhost:24713
Library Protocol Version: 33
Server Protocol Version: 34
Is Local: no
Client Index: 16
Tile Size: 65472
Server Name: pulseaudio
Server Version: 14.2
Default Sample Specification: s16le 2ch 44100Hz
Default Channel Map: front-left,front-right
Default Sink: alsa_output.pci-0000_00_1f.3.analog-stereo
Default Source: alsa_output.pci-0000_00_1f.3.analog-stereo.monitor

Regards,
David Stes