Pages

May 15, 2011

Linux:Startup and run levels Part 1

Earlier in my post we have seen about Linux Boot process http://subramanyaachar.blogspot.com/2011/05/linuxboot-process.html
Before going further lets see the steps involved in boot up process

  1. The LILO boot loader starts the kernel
  2. The Linux kernel configured by lilo or rdev decompresses and must find and mount the root filesystem. If LILO or the kernel were not configured properly there can be a problem here.
  3. The kernel after loading the root filesystem, starts the "init" program which may be located in /sbin/init. Reads /etc/inittab for configuration information.
  4. /etc/inittab - init reads this file for configuration information. This file determines the starting run level and contains a line like:
    si::sysinit:/etc/rc.d/rc.sysinit
  5. /etc/rc.d/rc.sysinit - In this case this entry in "/etc/inittab" causes the script file "/etc/rc.d/rc.sysinit" to be run.
    To add terminals or dial in modem lines on a system, add more lines in the /etc/inittab file, one for each terminal or dial in line similar to the following:
    7:2345:respawn:/sbin/mingetty tty7
  6. One of /etc/rc.d/rc or /etc/rc or /etc/init.d/rc is started from inittab which does initialization commands for boot at the set runlevel. This is done by running startup and shutdown scripts for various services to be run at the given run level.
  7. /etc/rc.local is started from one of the startup scripts in the rc script file. This is where you should add custom features for your system.
  8. getty - Init starts a separate getty (or mingetty) for each terminal for which logins are to be allowed. Getty is restarted by init after each user has logged out so new users can log in. Network logins are not done by getty but by a different deamon per way of logging in (telnet or rlogin handled by the inetd internet super daemon).
  9. Getty outputs the welcome message in /etc/issue, reads the username and runs the login program. If the user is telnetting, the message in /etc/issue.net is first output.
  10. The login program reads the password and runs the shell if the username and password are correct. The shell is based on entries in the /etc/passwd file and will run at the user's privilege level rather than with root privileges.
  11. The shell (such as bash) runs the /etc/profile script file. However in the case of a system with shadow passwords, environment strings can be set first in a file called /etc/login.defs. Also a users resources can be limited in a file called /etc/limits. The $HOME/.bash_profile script is then run, but if it is missing /etc/.profile is run.
In /etc/rc.d/rc0.d are kill and start scripts for various services. The kill scripts start with the letter "K" and the startup scripts start with the letter "S".
 rc.d scripts can be helpful when it comes to controlling the services to be run on your PC


Lets now dive into  init, getty, login, the shell, startup scripts, and the mounting of file systems.
Init
The init process reads the file "/etc/inittab" and uses this file to determine how to create processes.
Snap of inittab

System initialization.
2) si::sysinit:/etc/rc.d/rc.sysinit 
tells init to run the program "/etc/rc.d/rc.sysinit" during system boot, before any other processes.
This is responsible of running many scripts which in turn starts up many system and network services

Snap of rc.sysinit
  • /etc/sysconfig/network - Controls the initial network configuration. An example file:
    NETWORKING=yes
    FORWARD_IPV4="yes"
    HOSTNAME="mdct-dev3"
    GATEWAY="10.1.0.25"
    GATEWAYDEV="eth0"
    
  • /etc/sysconfig/keyboard - The variable KEYTABLE is defined with a line like:
    KEYTABLE="us"

Since some functions are interdependent on other functions there is some required order in which these scripts must be run in order to bring the system up and to bring it gracefully down. Each runlevel has its own set of start(S) and kill(K) scripts but all these scripts are supported in the directory /etc/rc.d/init.d.
The script file /etc/rc.d/rc is run for the appropriate runlevel (typically 3 or 5) 
Next in the init is to proceed to login 
1:2345:respawn:/sbin/mingetty tty1
this is done by by a program, usually getty or mingetty, 
Steps

  1. The init process spawns the getty process.
  2. The getty process invokes the login process when the user enters their name and passes the user name to login.
  3. The login process prompts the user for a password, checks it, then if there is success, the user's shell is started. On failure the program displays an error message, ends and then init will respawn getty.
  4. The user will run their session and eventually logout. On logout, the shell program exits and we return to step 1.

To be continued...

No comments: