How i can run a command line during boot process

hello guys,
i'm a total noop in linux overall and
i need assistance in running this command line in boot process to make my gpu work by default

echo 1 | sudo tee /sys/bus/platform/devices/MSHW0041:00/dgpu_power

or at least in auto start once i log-in

I never had to do anything similar, but I'd say you could go to:
System Settings -> Startup and Shutdown -> Autostart -> Add... -> Add Login Script and select a previously prepared script containing only that command
Remember to add #!/bin/sh as first line and make it executable

2 Likes

ok i managed to auto start a program with (the command line) in .sh file
but now its asking a password everytime i login to run it

i prefer its in boot process
or at least without a sudo asking a password

I think this could be avoided entering the command in /etc/rc.local which is run as root by the system.
E.g. check:
https://www.cyberciti.biz/faq/how-to-enable-rc-local-shell-script-on-systemd-while-booting-linux-system/
I think this would need to install rc-local from AUR first.

2 Likes

i mananged to do it thanks for the help
here is how i did that if anyone wondring

1- downloading this package
https://aur.archlinux.org/packages/rc-local/

2- then running makepkg

3- then check the status if you type the following command in terminal:
sudo systemctl status rc-local

4- then adding my command lines
sudo nano /etc/rc.local
at the end of this file

5- then i ran chmod
sudo chmod +x /etc/rc.local

6- lastly enable it
sudo systemctl enable rc-local

2 Likes

Using rclocal is totally unnecessary and is a deprecated method since the advent of systemd on Arch based systems.

Systemd allows you to execute a script or a command as root (or a user) at startup.

You simply need to write a systemd service.

3 Likes

This looks like when you want to fly from Greece to Italy and go East to China, pass the Pacific, then the Atlantic and then straight to Italy. :rofl:

4 Likes

I'm afraid I must have been the root cause of this messy tour :pensive:

3 Likes

Live and learn.

Learning systemd usage is far more useful in the long run. It has many uses and benefits.

4 Likes

this been a will aware issue in Surface devices that the dgpu will not connect with linux because of microsoft integrated some auto setting into the gpu system itself , unless you are running a surface-linux kernel and you run the command and it will not stay on all the time it will disconnect,
so many of the surface community tried but it didnt workout
this is looks like a solution for them
btw we tried the systemd service before
the gpu would not stay on after restarting

Problems with dGPU on SB1: "The NVIDIA GPU installed in this system has fallen off the bus" · Issue #376 · linux-surface/linux-surface · GitHub

and i'm not a professional by all means, but a whole kernel wouldn't fix it
and i tried this and it worked out somehow.

As long as your issue is fixed, all is fine.
In your posted link (bug report), they are suggesting a service and a script. That's what you need.
The rest of our/my comments are about using a depreciated method to do what is properly done as suggested in the bug report discussion.
Using sudo in a service which is non-interactive is not working.
System services are executed as root, which means you don't need sudo.

If you need more help on this gpu issue,ask again.

2 Likes

thanks buddy

2 Likes

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