views:

81

answers:

2

Can't I run myScript by appending a line to the entry of Linux in /boot/grub/menu.lst as:

title           Ubuntu 9.04, kernel 2.6.28-11-generic
uuid            b20f1720-b3f5-4162-bc92-ab2deb8d5d04
#kernel         /boot/vmlinuz-2.6.28-11-generic root=UUID=b20f1720-b3f5-4162-kernel/boot/vmlinuz-2.6.28-11-generic root=UUID=b20f1720-b3f5-4162-bc92-ab2deb8d5d04 ro
initrd          /boot/initrd.img-2.6.28-11-generic
/home/baltoros/Desktop/myScript

Is it even possible to run myScript at this point of time?

+1  A: 

If you want to run a script as part of the boot process, you want to do that with init.

In the appropriate runlevel (most likely 5 if you are run a GUI, but 3 if you are only booting to the command line) directory, you will want to add an S## script.

On my main system, that would be:

/etc/rc.d/rc5.d/S00whatever 

and add your script commands there. Because I used a number of 00, your script will be run very early in the boot process. Because of this, very few services will have started (for example, the network will not have been initialized). If you just want to run the script as part of booting and don't really need it early in the boot process, you'd want to use a higher number:

/etc/rc.d/rc5.d/S98whatever
R Samuel Klatchko
So..is there any particular place where I may add init=/home/myScriptI ran myScript as a startup but I want it to run before almost everything. I have noticed that myScript run after a lot of checks are performed whereas I want that as soon as the Linux entry is selected from grub myScript should run. Any idea if I can do that from GRUB?
baltusaj
That's not a very "Ubuntu" way of adding init scripts.
Brian McKenna
@baltusaj - use the S00whatever option. Your script will be run shortly after the kernel has started but early in the full boot process.
R Samuel Klatchko
Yeah I tried that but I am still not happy with the time it start. I think I need to look for a different kernel now which takes less time in booting. :) Thanks a lot for your help
baltusaj
A: 

In the odd cases where you need the kernel to load something other than 'init' (which in turn, invokes the rc scripts), you can append an init=/path/to/program on the kernel line in grub, which tells the kernel the first program to run.

For instance:

kernel /boot/vmlinuz-2.6.xx root=/dev/sda3 ro init=/bin/bash

... would run bash instead of init, meaning no rc scripts would be run. Bash would have PID 1, just like init normally does.

This is useful for kiosks, mobile devices and other things that manage their services independently (or, none at all).

Otherwise, as others have said, just write an init script and name it to coincide with what point in the boot process you wish it to run.

Tim Post