Systemd service unit not starting at boot time

I am new to linux (couple of weeks) and am trying to handle power of my graphic card through a script and automate at boot with a systemd service unit.
The script is fairly simple: its a 2 liner.

sudo sh -c "echo manual > /sys/class/drm/card0/device/power_dpm_force_performance_level"
sudo sh -c "echo 2 > /sys/class/drm/card0/device/pp_power_profile_mode"

The service unit is also very straight forward

[Unit]
Description=Change GPU profile to powersave 
   
[Service]
Type=oneshot
ExecStart=/bin/bash /usr/bin/gpu
   
[Install]
WantedBy=multi-user.target

Both the script or the service unit work after boot with no issue if start manually using a terminal.

The issue is that the service unit is not being picked up at boot and never runs. I have no error being recorded in the logs. Since the service unit, when started manually after boot runs fine, I have got nothing to go on.

Any ideas is much appreciated

Instead of using the same script, make a new one for root. Sudo asks for prompt, which you obviously cannot insert in the boot up process.

#!/bin/sh
echo manual > /sys/class/drm/card0/device/power_dpm_force_performance_level
echo 2 > /sys/class/drm/card0/device/pp_power_profile_mode

Use this script instead. Also make sure the script is executable: chmod 700 new_script.sh. Make sure the owner is root (chown root:root new_script.sh) and have it inside the root user’s directory (mv new_script.sh /root). If any of the commands in this paragraph don’t work, use sudo on them.

You can use this script as root if you run /root/new_script.sh. As a user, you can’t, because it will be owned by root and invisible to you. But if it was in your home directory, you would instead do sudo /home/user/script.sh or sudo ./script.sh (if you are already in the same directory).

Early boot doesn’t know what command is which, it’s always a good idea to add shebangs to your scripts. If you find yourself using bashism a lot, use #!/bin/bash instead of sh, which in many distros defaults to dash (Debian family usually), while in others sh already points to bash (RedHat Enterprise Linux and Fedora family).

Also, early boot always runs as root. You can point systemd to run as a user, but in this case, running as root is mandatory anyway (since you need root privileges to echo in the /sys dir). For early boot scripts, avoid sudo or using scripts that require user input.

I noticed the script was called /usr/bin/gpu. You can modify that instead and remove the sudo sh -c. Instead, you would just call sudo gpu. Also, in that scenario, you would want it chmod 755 /usr/bin/gpu, so that users can’t edit it, just root. Just security good practice.

Thanks learnt a lot. The issue was indeed the root aspect and the fact that at boot time the system does not know how to bring up a tty to run the script.
Also, will leave the gpu profile at default on boot for the moment. It seems there is not much difference from a power level from Default to Powersave.