How to get sound for user root

Hello.
I get sound for all normal users, but not for root.
How to get sound for root user.
Any help is welcome.

Ps : the question is ‘how’ , please don’t ask why.

Maybe this one:
https://rudd-o.com/linux-and-free-software/how-to-make-pulseaudio-run-once-at-boot-for-all-your-users

Thank you.
I’ll give it a shot.

Hello.

The running system for my test is 15.1 and not 15.2 as told in the prefix.

As I want to modify the config for only user root, I put the service in /root/.config/systemd/user/pulseaudio.service
The file has been modified to remove some warning :

[Unit]
Description=PulseAudio system server for user root

[Service]
Type=notify
ExecStart=/usr/bin/pulseaudio --daemonize=no --system --realtime --log-target=journal  --disallow-exit  --disallow-module-loading  --disable-shm  --disallow-exit  --exit-idle-time=0

[Install]
WantedBy=multi-user.target


I put the client config in in /root/.config/pulse/user

# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PulseAudio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.

## Configuration file for PulseAudio clients. See pulse-client.conf(5) for
## more information. Default values are commented out.  Use either ; or # for
## commenting.

**#                                                #
#    /root/.config/pulse/client.conf
#                                                #
default-server = /var/run/pulse/native
autospawn = no
**
; default-sink =
; default-source =
; default-server =
; default-dbus-server =

; autospawn = yes
; daemon-binary = /usr/bin/pulseaudio
; extra-arguments = --log-target=syslog

; cookie-file =

; enable-shm = yes
; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB

; auto-connect-localhost = no
; auto-connect-display = no

The service is started by a launcher in /root/.config/autostart-scripts/start_pulseaudio.sh

# # ensure running as root
if  "$(id -u)" != "0" ]; then
    exit     ${E_BAD_USER:-11}
fi
#
#

# ------------------------------------------------------------

##########
#                  #
#                  #
#      MAIN    #
#                  #
#                  #
##########

pulseaudio --kill
systemctl --user start pulseaudio.service

exit 0


Excerpt from journal :

août 30 14:28:35 ASUS-G731GV-JC ksmserver[2632]: ksmserver: Kcminit phase 1 done
août 30 14:28:35 ASUS-G731GV-JC ksmserver[2632]: ksmserver: Starting autostart service  "/etc/xdg/autostart/kdeconnectd.desktop" ("/usr/lib64/libexec/kdeconnectd")
**août 30 14:28:35 ASUS-G731GV-JC ksmserver[2632]: ksmserver: Starting autostart service  "/etc/xdg/autostart/pulseaudio.desktop" ("/usr/bin/start-pulseaudio-x11")**
août 30 14:28:35 ASUS-G731GV-JC ksmserver[2632]: ksmserver: Starting autostart service  "/etc/xdg/autostart/xdg-user-dirs.desktop" ("/usr/bin/xdg-user-dirs-update")
août 30 14:28:35 ASUS-G731GV-JC ksmserver[2632]: ksmserver: Autostart 1 done

.......

août 30 14:28:35 ASUS-G731GV-JC ksmserver[2632]: ksmserver: Starting autostart script  "/root/.config/autostart-scripts/start_pulseaudio.sh"
août 30 14:28:35 ASUS-G731GV-JC ksmserver[2632]: ksmserver: Starting autostart service  "/etc/xdg/autostart/pasystray.desktop" ("/usr/bin/pasystray")
août 30 14:28:35 ASUS-G731GV-JC ksmserver[2632]: ksmserver: Starting autostart service  "/etc/xdg/autostart/powerdevil.desktop" ("/usr/lib64/libexec/org_kde_powerdevil")
août 30 14:28:35 ASUS-G731GV-JC ksmserver[2632]: ksmserver: Autostart 2 done
août 30 14:28:35 ASUS-G731GV-JC ksmserver[2632]: ksmserver: Kcminit phase 2 done

........

août 30 14:28:35 ASUS-G731GV-JC systemd[2492]: Starting PulseAudio system server...
août 30 14:28:35 ASUS-G731GV-JC pulseaudio[2750]: Running in system mode, forcibly disabling exit idle time.
**août 30 14:28:35 ASUS-G731GV-JC pulseaudio[2750]: Home directory of user 'pulse' is not '/var/run/pulse', ignoring.**
août 30 14:28:35 ASUS-G731GV-JC pulseaudio[2750]: OK, so you are running PA in system mode. Please make sure that you actually do want to do that.
août 30 14:28:35 ASUS-G731GV-JC pulseaudio[2750]: Please read http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/ for an explanation why system mode is usually a bad idea.

.......

août 30 14:30:05 ASUS-G731GV-JC systemd[2492]: pulseaudio.service: Start operation timed out. Terminating.
août 30 14:30:05 ASUS-G731GV-JC plasmashell[2654]: org.kde.plasma.pulseaudio: context kaput
août 30 14:30:05 ASUS-G731GV-JC plasmashell[2654]: org.kde.plasma.pulseaudio: No object for name "alsa_output.pci-0000_00_1f.3.analog-stereo"
août 30 14:30:05 ASUS-G731GV-JC plasmashell[2654]: org.kde.plasma.pulseaudio: No object for name "alsa_output.pci-0000_00_1f.3.analog-stereo"
août 30 14:30:05 ASUS-G731GV-JC plasmashell[2654]: org.kde.plasma.pulseaudio: No object for name "alsa_input.pci-0000_00_1f.3.analog-stereo"
août 30 14:30:05 ASUS-G731GV-JC systemd[2492]: Failed to start PulseAudio system server.
août 30 14:30:05 ASUS-G731GV-JC systemd[2492]: pulseaudio.service: Unit entered failed state.
août 30 14:30:05 ASUS-G731GV-JC systemd[2492]: pulseaudio.service: Failed with result 'timeout'.

Audio Volume show no device.
PAM show connection refused.

Any help is welcome.

Doing a test with the pulseaudio.service given in the Sauerland’s link

ExecStart=/usr/bin/pulseaudio --daemonize=no --system --realtime --log-target=journal

Does not make difference.

there is a “Got signal SIGTERM”

Root session initialization :
https://paste.opensuse.org/255743

Test with speaker-test :
https://paste.opensuse.org/51670988

result :
https://paste.opensuse.org/93157402

Any help is welcome

I suspected that PolKit is blocking the user “root” – it seems that isn’t the case.

  • Therefore, it’s possibly hard-coded into Pulse as a means to work around a security issue …

Hi
If you switch to root user and run;

pulseaudio -D

Does it run?

jdcole -

Have you had any success with pulseaudio in a root session?

If not, did you try the approach outlined on the freedesktop site? https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/SystemWide/

Yes with the option --system. I can view tutorials on youtube with sound.

**ASUS-G731GV-JC:~ #** pulseaudio -D 
W: [pulseaudio] main.c: **This program is not intended to be run as root (unless --system is specified).

** 
**ASUS-G731GV-JC:~ #** pulseaudio --system -D 
W: [pulseaudio] main.c: **Running in system mode, but --disallow-exit not set.** 
W: [pulseaudio] main.c: **Running in system mode, but --disallow-module-loading not set.** 
N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode. 
N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time. 
**ASUS-G731GV-JC:~ #** 


Then I can add the code in user root .profile ( or .bashrc ) ?

Hi
I would assume so, or maybe just a script to run on demand…

Thank you very much for helping

I tried the -D option and it’s working here as well.

I am unable to locate a profile or startup file to modify. Where would I put the code for startup in root?

Also, is the code the following or do I need more?

pulseaudio --system -D

In a new file named “.profile” in /etc/profile.d/? See Table 15.1 in https://doc.opensuse.org/documentation/leap/startup/html/book-startup/cha-adm-shell.html

Upon further research, perhaps I may need to copy .profile from /etc/skel and place that file in /root/.

I am still uncertain about the syntax for the command. Or, more specifically, what I need to add to the file for the pulseaudio command.