Saturday, 1 December 2012

Run anything on startup in ubuntu

Sometimes we might want some set of things to happen on startup. If it is a simple application/script we can simply add to startup applications. However this fails if we need to be root to run that. Today i will show you how it is done.
Say I want to mount a set of disk drives on startup.

  1.  Open Terminal and type
  2. Type the set of commands you want to run on startup in this file. Here it is
    mount /dev/sda2 /home/alse/Ambusher
    mount /dev/sda3 /home/alse/C
  3. Save and close the file. Now change permissions of the file.
    $ chmod +rwx
  4. Then move it to /etc/init.d
    $ sudo mv /etc/init.d/
  5. Add to rc.d
    $ sudo update-rc.d defaults
Now will run on startup.

Now I will show you how to remove something which you have already added
Suppose say i want to remove from rc.d. Type
$ sudo update-rc.d -f remove


Now you can just execute the script by adding in /etc/rc.local