Permission denied in systemd startup script for GPU undervolt

Hello all,

I am having permission issues when trying to run a systemd service to undervolt my GPU. The service runs fine (and applies the undervolt) when run manually, however has permission denied errors when running on startup.

EDIT: for people finding this on google: solved by setting After=multi-user.target under [Unit] and WantedBy=graphical.target under [Install]

EDIT2: Although this seemed to help I still got errors over the span of a few days. I am now using a systemd timer to start my script a minute after boot and this seems stable (janky fix I know).

My current service file (I added User=root when troubleshooting this issue - did not help):

[Unit]
Description=Run script to undervolt GPU by 50mV.  ONLY FOR SAPPHIRE Nitro+ RX580!!

[Service]
Type=oneshot
RemainAfterExit=yes
#User=root
ExecStart=/usr/bin/gpu-undervolt

[Install]
WantedBy=multi-user.target

My current gpu-undervolt file (have tried both the sudo sh -c and direct echo variants, same results):

#!/bin/bash
#COPY TO /usr/bin/
# Set clocks and voltages
#sudo sh -c "echo 's 0 300 750' > /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage"  #750 is lowest accepted voltage
echo 's 1 600 750' > /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage
echo 's 2 900 843' > /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage
echo 's 3 1145 1056' > /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage
echo 's 4 1215 1137' > /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage
echo 's 5 1257 1100' > /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage
echo 's 6 1300 1100' > /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage
echo 's 7 1411 1100' > /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage

# Apply
echo 'c' > /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage

Output of journalctl -xe | grep undervolt after startup (i think theres a better way to use journalctl but idk and this works):

Sep 15 19:44:10 eric-wooden systemd[1]: Starting Run script to undervolt GPU by 50mV.  ONLY FOR SAPPHIRE Nitro+ RX580!!...
░░ Subject: A start job for unit gpu-undervolt.service has begun execution
░░ A start job for unit gpu-undervolt.service has begun execution.
Sep 15 19:44:10 eric-wooden gpu-undervolt[464]: /usr/bin/gpu-undervolt: line 5: /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage: Permission denied
Sep 15 19:44:10 eric-wooden audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=gpu-undervolt comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=failed'
Sep 15 19:44:10 eric-wooden gpu-undervolt[464]: /usr/bin/gpu-undervolt: line 6: /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage: Permission denied
Sep 15 19:44:10 eric-wooden gpu-undervolt[464]: /usr/bin/gpu-undervolt: line 7: /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage: Permission denied
Sep 15 19:44:10 eric-wooden gpu-undervolt[464]: /usr/bin/gpu-undervolt: line 8: /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage: Permission denied
Sep 15 19:44:10 eric-wooden gpu-undervolt[464]: /usr/bin/gpu-undervolt: line 9: /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage: Permission denied
Sep 15 19:44:10 eric-wooden gpu-undervolt[464]: /usr/bin/gpu-undervolt: line 10: /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage: Permission denied
Sep 15 19:44:10 eric-wooden gpu-undervolt[464]: /usr/bin/gpu-undervolt: line 11: /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage: Permission denied
Sep 15 19:44:10 eric-wooden gpu-undervolt[464]: /usr/bin/gpu-undervolt: line 14: /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage: Permission denied
Sep 15 19:44:10 eric-wooden systemd[1]: gpu-undervolt.service: Main process exited, code=exited, status=1/FAILURE
░░ An ExecStart= process belonging to unit gpu-undervolt.service has exited.
Sep 15 19:44:10 eric-wooden systemd[1]: gpu-undervolt.service: Failed with result 'exit-code'.
░░ The unit gpu-undervolt.service has entered the 'failed' state with result 'exit-code'.
Sep 15 19:44:10 eric-wooden systemd[1]: Failed to start Run script to undervolt GPU by 50mV.  ONLY FOR SAPPHIRE Nitro+ RX580!!.
░░ Subject: A start job for unit gpu-undervolt.service has failed
░░ A start job for unit gpu-undervolt.service has finished with a failure.

GPU voltages ramain the same

Output after user start (systemctl start gpu-undervolt.service, then entering passcode. Also works with sudo systemctl start gpu-undervolt.service):

Sep 15 19:46:12 eric-wooden polkitd[465]: Operator of unix-session:1 successfully authenticated as unix-user:eric to gain TEMPORARY authorization for action org.freedesktop.systemd1.manage-units for system-bus-name::1.57 [systemctl start gpu-undervolt.service] (owned by unix-user:eric)
Sep 15 19:46:12 eric-wooden systemd[1]: Starting Run script to undervolt GPU by 50mV.  ONLY FOR SAPPHIRE Nitro+ RX580!!...
░░ Subject: A start job for unit gpu-undervolt.service has begun execution
░░ A start job for unit gpu-undervolt.service has begun execution.
Sep 15 19:46:12 eric-wooden systemd[1]: Finished Run script to undervolt GPU by 50mV.  ONLY FOR SAPPHIRE Nitro+ RX580!!.
░░ Subject: A start job for unit gpu-undervolt.service has finished successfully
░░ A start job for unit gpu-undervolt.service has finished successfully.
Sep 15 19:46:12 eric-wooden audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=gpu-undervolt comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Sep 15 19:46:12 eric-wooden kernel: audit: type=1130 audit(1663267572.545:83): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=gpu-undervolt comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'

GPU undervolt applies.

I have tried many different fixes, with varying error outputs, but I cannot find one that works. Any suggestions are greatly appreciated.

have you checked that the script is executable ?

Yes, I did just double check but the script is deffinitely executable, the permission denied errors are for the file /sys/devices/pci0000:00/0000:00:03.1/0000:26:00.0/pp_od_clk_voltage, and it does work when I manually run the service anyway.

may you check with

groups

which groups are assigned to your user-profile. it’s possible that you have to add a group to your profile
https://wiki.archlinux.org/title/User_group

btw, wouldn’t it fit better to create a udev-rule instead ?
https://wiki.archlinux.org/title/CPU_frequency_scaling

Maybe you should change

WantedBy=multi-user.target

into

WantedBy=graphical.target

Thank you!

Google didn’t show me that page when I was searching - even though I think it should have - but as soon as I followed that it worked (I also added After:multi-user.target to the [Unit] section as suggested by the post you linked, idk if this was neccesary but I guess the multi-user target actually initialises the files relating to pci devices)

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.