Linux Bootup

Kernel

The kernel creates a process with process id 0 which eventually gets converted into the swapper process. The kernel then optionally runs the initrd (which stands for init RAM disk) which is a temporary filsystem in the the RAM for kernel unil the filesystem on the hard-disk in initialised.

The process 0 would then invoke the init process (usually located in /sbin/init)

Init

All the processes are invoked directy or indirectly by the init process (with the exceptio of pager process.) init process has the process id of 1. The init when started will take care of the following things:

    1. Checks the filesystem integrity
    2. Starts vital programs and determines the run level from /etc/inittab file. The inittab file is a configuration file and contains entries where each entry is a line of the following format
    3. id:runlevels:action:process
    4. If the system's current runlevel is equal to the runlevel in the entry then the action or process in the entry would be executed.
    5. Following is the description of the each field:
            1. id
            2. runlevels
            3. action
            4. process
            1. a string identifier which is used to identify the entry. The id should be unqiue for all the entries.
            2. This field specifies for which run-levels this field is to be considered for. Currently there are 7 runlevels defined (from 0-6) and multiple runlevels can be defined in this field e.g. a value of 125 in this field means that the entry is significant for run evels 1,2, and 5.
            3. This field specifies an action which needs to be taken if this entry is significant. What this means that if the urrent run-level of the system is same as the runlevel specified in the runlevel field for this entry then the action needs to be taken. Following values are allowed for the action field:
            4. Specifies the process to be executed. If the process starts with the '+' character, init will not do utmp and wtmp accounting for that process. This is needed for gettys that insist on doing their own utmp/wtmp housekeeping (a historic bug).
      1. Determining system's runlevel
    1. Typically the first line in the inittab file would be with initdefault action in order to set the runlevel for the system. It would normally look something lke the following id:5:initdefault:
    2. The runlevel choosen with the inidefault will cause the system to boot with different capabilities. Following are the general capabilities configured with different runlevels.
    1. The linux file system is typically setup with bunch of directories for each runlevel and there are couple of scripts placed in the directories which are expected to be executed if the system boots up in that specific runlevel. These directories are
    2. The inittab would also contain entries for executing the scripts in these directries by calling the rc proces. l0:0:wait:/etc/rc.d/rc 0 l1:1:wait:/etc/rc.d/rc 1 l2:2:wait:/etc/rc.d/rc 2 l3:3:wait:/etc/rc.d/rc 3 l4:4:wait:/etc/rc.d/rc 4 l5:5:wait:/etc/rc.d/rc 5 l6:6:wait:/etc/rc.d/rc 6 The rc process gets told about the run-level via the command line argument and it runs the scripts in the directory specific to that run-level. Each run-level has its own directory where several scripts are placed. Some of the scripts are executed at startup while some of them are executed at shutdown time. Start up scripts start with 'S' and shutdown scripts start with 'K'.
    3. The inittab file also contains entries for terminal initialization. 1:2345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 e.g. the above four lines specify the system to spawn four tty consoles. TTY console are normally the console screens that display the characters. It is typical to find more than one consoles configured for a single system even if there is only one monitor connected to the system. Second console can be accessed by pressing CTRL+ALT+2. Similarly third console can be accessed by pressing CTRL+ALT+3.
      1. TTY Initialization
    4. init will spawn getty processes (by doing a fork and exec). getty initalizes itself, displays the login prompt and then requests for the username.
    5. Once the username has been provided, it invokes the program login.
    6. The login program will call the getpass program to input and validate the password. If getpass fails validation, login program will exit. This will be noticed by init and it will do another fork because the entry for getty in the inittab file had respawn action
    7. If the getpass program succeeds, then login will proceed to log-in the user by doing the following
        • Change to user's home directory (as specified in the /etc/passwd file)
        • Change the ownership and permissions of terminal to user
        • c. Set group ids and user id of the tty
        • Initialize the environment variables (such as PATH, HOME, SHELL, etc.)
        • Invoke the shell specified in the /etc/passwd file for the user