[Solved] Need sudo command(s) to run on boot

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Post Reply
SpookyWatcher
Level 3
Level 3
Posts: 182
Joined: Fri May 10, 2013 4:06 pm

[Solved] Need sudo command(s) to run on boot

Post by SpookyWatcher »

I need a series of sudo commands to run at boot. These commands undervolt everything (cpu and cpu cache etc) by -125mV.

Code: Select all

sudo bash -c 'wrmsr 0x150 0x80000011f0000000 && wrmsr 0x150 0x80000111f0000000 && wrmsr 0x150 0x80000211f0000000 && wrmsr 0x150 0x80000311f0000000 && wrmsr 0x150 0x80000411f0000000'
I tried adding the following to /etc/rc.local

Code: Select all

wrmsr 0x150 0x80000011f0000000 && wrmsr 0x150 0x80000111f0000000 && wrmsr 0x150 0x80000211f0000000 && wrmsr 0x150 0x80000311f0000000 && wrmsr 0x150 0x80000411f0000000
exit 0
When I boot...it's not working. After bootup, If in a terminal I type

Code: Select all

sudo /etc/rc.local
it works just fine

I also tried adding sleep 10 before the commands. That didn't work either.
Last edited by SpookyWatcher on Mon Jan 01, 2018 10:09 pm, edited 1 time in total.

User avatar
xenopeek
Level 24
Level 24
Posts: 24635
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Need sudo command(s) to run on boot

Post by xenopeek »

I think you need to enable rc.local service to run on boot. Command:
sudo systemctl enable rc-local.service
Image

Mute Ant
Level 14
Level 14
Posts: 5132
Joined: Tue Sep 03, 2013 7:45 pm
Location: Norfolk UK

Re: Need sudo command(s) to run on boot

Post by Mute Ant »

If the kernel runs the file /etc/rc.local at boot time it is not supposed to use bash. The first line sets the interpreter...

#!/bin/sh -e

The -e option causes the shell to immediately exit if there's an error. You can test it for run-ability and see the error-code that comes back...

sudo sh /etc/rc.local ; echo $?
While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named "manual".

SpookyWatcher
Level 3
Level 3
Posts: 182
Joined: Fri May 10, 2013 4:06 pm

Re: Need sudo command(s) to run on boot

Post by SpookyWatcher »

xenopeek wrote:I think you need to enable rc.local service to run on boot. Command:
sudo systemctl enable rc-local.service
I did that...one of the first steps.

As a test I changed my /etc/rc.local to very simple:

Code: Select all

touch /home/myuser/Documents/test.txt
exit0
and it's not even doing that.

SpookyWatcher
Level 3
Level 3
Posts: 182
Joined: Fri May 10, 2013 4:06 pm

Re: Need sudo command(s) to run on boot

Post by SpookyWatcher »

Mute Ant wrote:If the kernel runs the file /etc/rc.local at boot time it is not supposed to use bash. The first line sets the interpreter...

#!/bin/sh -e

The -e option causes the shell to immediately exit if there's an error. You can test it for run-ability and see the error-code that comes back...

sudo sh /etc/rc.local ; echo $?
With my new simple command of:

Code: Select all

sleep 1
touch /home/myusername/Documents/test.txt
exit 0
sudo sh /etc/rc.local ; echo $? returned a

Code: Select all

0
and my test.txt is there. But still not running on boot. As a precaution I redid:

Code: Select all

sudo systemctl enable rc-local.service

User avatar
karlchen
Level 21
Level 21
Posts: 12726
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: Need sudo command(s) to run on boot

Post by karlchen »

Hi, SpookyWatcher.

Try invoking executable files with their complete pathnames instead of assuming they will be found by following the $PATH variable.
Example:
/usr/bin/touch instead of touch only.

Also check that the file /etc/rc.local has been marked as executable. (although I assume "sudo systemctl enable rc-local.service" should take care of this. But does it do so)

Karl
Image
Linux Mint 19.2 64-bit Cinnamon, Total Commander 9.22a 64-bit
Haß gleicht einer Krankheit, dem Miserere, wo man vorne herausgibt, was eigentlich hinten wegsollte. (Goethe)

SpookyWatcher
Level 3
Level 3
Posts: 182
Joined: Fri May 10, 2013 4:06 pm

Re: Need sudo command(s) to run on boot

Post by SpookyWatcher »

karlchen wrote:Hi, SpookyWatcher.

Try invoking executable files with their complete pathnames instead of assuming they will be found by following the $PATH variable.
Example:
/usr/bin/touch instead of touch only.

Also check that the file /etc/rc.local has been marked as executable. (although I assume "sudo systemctl enable rc-local.service" should take care of this. But does it do so)

Karl
Made the change. Now the rc.local looks like this:

Code: Select all

  
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
sleep 1
/usr/bin/touch /home/myusr/Documents/test.txt
exit 0
Also:

Code: Select all

ls -l /etc/rc.local
Returns:

Code: Select all

-rwxr-xr-x 1 root root 357 Jan  1 15:49 /etc/rc.local
So it looks executable...am I right in the way I read it? But even that simple command is not working on bootup.

Pippin
Level 4
Level 4
Posts: 359
Joined: Wed Dec 13, 2017 11:14 am
Location: The Shire

Re: Need sudo command(s) to run on boot

Post by Pippin »

#!/bin/sh -e
is on the first line? In posted code it isn`t.
Peer review = Ossification of current assumptions, the censorship of competing hypotheses.

Mathematical proofs = Elegant consistencies within a synthetic man-made universe.
Models are not reality, no matter how elegant.

SpookyWatcher
Level 3
Level 3
Posts: 182
Joined: Fri May 10, 2013 4:06 pm

Re: Need sudo command(s) to run on boot

Post by SpookyWatcher »

I finally fixed it....Somehow I borked up the msr-tools.

I have to sudo modprobe msr each boot for some reason now. Somehow I screwed something up and msr-tools driver isn't loading without sudo modprobe msr. Tried uninstalling and reinstalling...but still have to modprobe it.

So I fixed it all by

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
modprobe msr
/usr/sbin/wrmsr 0x150 0x80000011f0000000
/usr/sbin/wrmsr 0x150 0x80000111f0000000
/usr/sbin/wrmsr 0x150 0x80000211f0000000
/usr/sbin/wrmsr 0x150 0x80000311f0000000
/usr/sbin/wrmsr 0x150 0x80000411f0000000

exit 0

And now all my stuff (cpu, cpu cache, gpu, analogue etc) are all running at -125mV undervolt. All running stable running Unigine-heaven and Other AAA titles.
.
.
.

Post Reply

Return to “Newbie Questions”