Autostart script (nvidia-smi)

I tried to make my powerlimit script doing a autostart.

The script looks like:

nvidia-smi -pm ENABLED
nvidia-smi -pl 250

The scipt itself works, when started in root-terminal, but not if I add it to /etc/lightdm/Xsession (I use lightdm).

I also tried ~/.xinitrc or /etc/X11/xinit/xinitrc.

To be honest, I have no idea how I can make it work now, because perhaps it works but gets overwritten when the GUI is up and running?

So this leads me to the question whether it is possible to make the script autostart (as root), when the GUI is up?



This should help NVIDIA/Tips and tricks - ArchWiki


I did this:


Description=Set NVIDIA power limit on boot




Description=Set NVIDIA power limit

ExecStart=/usr/bin/nvidia-smi -pl 250

but as this seems like to be a service, I bet I have to do some additional “things” and not only create the files in the folders?

One thing I did is to do a chmod 777 nvidia-tdp.service as I saw other services e.g. the display-manager.service has the same attributes / privileges for user/group/others.

Thanks again!

You have to enable the service and the timer.
systemctl enable --now nvidia-tdp.timer
systemctl enable --now nvidia-tdp.service
something like that …

You could run with sudo

sudo nvidia-smi -pm ENABLED
sudo nvidia-smi -pl 250

And you could add these specific command to the sudoers file to be able to run them without sudo password. It is probably not best secure way to do it but should be simple and work.

sudo visudo

then add at bottom either the line for the whole tool nvidia-smi (so you can sudo the nvidia-smi tool for whatever command without password):

omano    ALL=(ALL)    NOPASSWD: /usr/bin/nvidia-smi

or add the specific exact commands lines (so you can only sudo without password these commands exactly):

omano   ALL=         NOPASSWD: /usr/bin/nvidia-smi -pm ENABLED
omano   ALL=         NOPASSWD: /usr/bin/nvidia-smi -pl 250

Either way will work, change the user name of course. Save it will warn if you made a mistake, then after that you can reload a new terminal and see you can sudo without password these commands.

I did it like @omano said. But I also say THANKS to @bogdancovaciu for his solution.

Just know that it is bad habit to do so, it is neither proper nor secure. It is convenient though.

Hm, ok. The solution of @bogdancovaciu would be better I think?

You do as you want.

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