hard to find info about init
atoponce at ubuntu.com
Wed Nov 12 12:22:56 UTC 2008
On Tue, Nov 11, 2008 at 05:08:36PM -0800, jim wrote:
> i wanna know, please, and will be
> grateful to the personnages who clue
> me in.
What you want to be Googling for is the "Linux boot process". This is
highly documented all over the web, and you'll probably even find a
article or two on my blog. However, I'll give you the low-down here on
When the power button is pressed on x86-based hardware, your motherboard
BIOS initializes, and runs a program called POST. POST is doing some
very basic hardware checks to make sure you have a usable system. It
checks for the existence of RAM, an input device (usually a keyboard),
an output device (usually a video card), a bootable device (floppy, hdd,
network, etc) and so forth.
If POST passes, it looks for the first 512 bytes of the bootable device,
and executes the MBR. In our case, this is generally GRUB, but it could
be LILO, SILO, or some others. Contained within those 512 bytes is the
initial program loader (IPL) in the first 446, which is our GRUB binary,
the partition table in the next 64, then a signature in the last 2.
GRUB exists in a few stages, which is repsonsible for communicating with
the BIOS to determine drives, making drive assignments, then locating
the kernel and initial ramdisk on our bootable partition/drive. Once
located, through the help of the /boot/grub/menu.lst, the kernel is then
executed, and the initial ramdisk is loaded as well, in case the kernel
The kernel's job is to check for all the hardware on the machine, and
load the necessary drivers to make the hardware function. These drivers
are known as kernel modules, and are found in /lib/modules/$(uname -r).
Once the kernel is done loading all the necessary drivers to communicate
with hardware, software can now take advantage of that hardware. As
such, the kernel launches init. Now, a word about init. Generally, this
is System V Init on most GNU/Linux machines. However, on Ubuntu and most
recently Fedora, this has been replaced with Upstart. Upstart is 100%
fully backwards compatible with init. As such, as you have already
noticed, when you run 'ps', you'll noticed that 'init' is PID 1, not
Upstart. Well, technically speaking, that init binary is Upstart.
The first thing Upstart needs to do is determine it's default runlevel.
Because Ubuntu is Debian-based, Debian developers like the SysV Init
system, but can't stand the concept of runlevels. As such, there are
only 4 different runlevels, vs 7 on Fedora/Red Hat. They are as follows:
0: shut down
1: single user mode
2-5: multi user mode
To find the runlevel that Ubuntu needs to boot into, Upstart reads
/etc/event.d/rc-default. You'll notice that file is just a Bourne shell
script, and the logic states, that if an /etc/inittab exists, it will
read that instead for it's default runlevel. As you can tell, the
default runlevel is '2', which is multi user mode.
Now that we've determined our default runlevel, we read the necessary
file for that runlevel. Because we're booting into runlevel 2, then we
read the /etc/event.d/rc2 file. Again, this file is just a Bourne shell
script, and we notice that it calls the program '/etc/init.d/rc 2'. This
function will enter the /etc/rc2.d/ directory, and execute all the
scripts found there.
If you look closely, you'll notice that there are only 'K' and 'S' files
in that directory. These are known as "K-scripts" and "S-scripts".
Upstart reads these files in lexecographical order, meaning that it
starts with "K00" first, and ends with "S99". As you can probably
imagine, the K-scripts kill a process and the S-scripts start a process.
These scripts are just calling their appropriate init-script in
/etc/init.d/. In fact, if you look even more closely, you'll notice that
all the files in /etc/rc2.d/ are symbolic links to the files in
/etc/init.d/. This is intentional. If it is an S-script, then it calls
the /etc/init.d/ file with the 'start' option, and if it is a K-script,
then it calles the /etc/init.d/ files with the 'stop' option. So, as it
sits, every init script must contain at least two arguments: start and
After the init scripts are executed, then your ttys are setup, and
managed, by reading the /etc/event.d/tty* files. At this point, you have
a booted running Ubuntu system, from which you can login to, and start
I know that was lengthy, but I hope that helps. If you have any
questions, let me know.
,-O Aaron Toponce
O } Ubuntu Member
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 489 bytes
Desc: Digital signature
More information about the ubuntu-server