The correct way to do this in Ubuntu is:
- Copy /etc/init.d/skeleton to scriptname and edit it to your needs.
- Make it executable.
- Install your script into the Debian runlevels via this command.
sudo update-rc.d scriptname defaults
- Check that links to your script exist in other runlevels, e.g rc2.d, rc3.d. You can also confirm that this script is properly installed through the Administration->Bootup Manager GUI.
Check /etc/init.d/README for more detailed instructions and links to the specification document. You can also impose finer control over which run-levels your scripts runs on, and the priority it should get called at:
$ sudo update-rc.d dummy defaults Adding system startup for /etc/init.d/dummy ... /etc/rc0.d/K20dummy -> ../init.d/dummy /etc/rc1.d/K20dummy -> ../init.d/dummy /etc/rc6.d/K20dummy -> ../init.d/dummy /etc/rc2.d/S20dummy -> ../init.d/dummy /etc/rc3.d/S20dummy -> ../init.d/dummy /etc/rc4.d/S20dummy -> ../init.d/dummy /etc/rc5.d/S20dummy -> ../init.d/dummy $ sudo update-rc.d -f dummy remove Removing any system startup links for /etc/init.d/dummy ... /etc/rc0.d/K20dummy /etc/rc1.d/K20dummy /etc/rc2.d/S20dummy /etc/rc3.d/S20dummy /etc/rc4.d/S20dummy /etc/rc5.d/S20dummy /etc/rc6.d/K20dummy $ sudo update-rc.d -n -f dummy start 20 2 3 4 5 . Adding system startup for /etc/init.d/dummy ... /etc/rc2.d/S20dummy -> ../init.d/dummy /etc/rc3.d/S20dummy -> ../init.d/dummy /etc/rc4.d/S20dummy -> ../init.d/dummy /etc/rc5.d/S20dummy -> ../init.d/dummy $ sudo update-rc.d -n -f dummy stop 20 0 6 . Adding system startup for /etc/init.d/dummy ... /etc/rc0.d/K20dummy -> ../init.d/dummy /etc/rc6.d/K20dummy -> ../init.d/dummy
Edit: The first step initially said to follow a template I provided with the answer, but I later realized that a standardized template exists so I’ve modified the answer accordingly.
(UBUNTU 9.10) There is already a script titled “ondemand” in the init.d that sets the cpu frequency, and if yours is not set after it does it’s magic then yours will not work. An easy fix is if you edit the line that says “echo -n ondemand > $CPUFREQ” and change ondemand to powersave it will save you the headache of making your own.
On a simple case like this one I would add a line with the command to /etc/rc.local, before the “exit 0”.
For more complex init scripts, follow nagul answer.
Write a script to execute your command, then put the script in your /etc/init.d directory.
It’ll then be run at startup
Follow the steps:
1. edit /etc/rc.local : sudo gedit /etc/rc.local 2. add the line berofe exit 0: cpufreq-selector -f 2200000 [add sudo if it need] 3. save the file and exit 4. you can run the for current session : sudo /etc/rc.local 5. From next session this script will automatically run