310 likes | 529 Views
Booting and boot levels. …The Boot Process. Linux uses the init command and a directory structure based on run-levels to start running the system and loading processes. The Initialisation Process….
E N D
…The Boot Process • Linux uses the init command and a directory structure based on run-levels to start running the system and loading processes
The Initialisation Process… • System States (or run levels) on early UNIX systems grew out of a need to separate how the system ran depending on the maintenance being performed • Usually, this meant that to add new hardware (or software) a system reboot was necessary • Today, with hot swappable devices, it is not strictly necessary to reboot systems in order to install new hardware or software
…The initialisation Process… • The /etc/inittab file contains settings for the init process and also defines the run levels for a Linux system
/etc/inittab file # Default runlevel. The runlevels used by RHS are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) #
init process • init is sometimes referred to as the ‘father of all processes’ • init is responsible for creating processes from a script stored in /etc/inittab • Linux init command is compatible with the System V init command • init starts as the last step of the kernel booting • init is the first command that initialises and configures the system for use
init process • Init works by parsing the /etc/inittab file and by running scripts in the /etc/rc.d directories depending on the required run level • Each individual script is designed to start or stop and individual service such as networking, mail, news, web, nfs, dhcp etc.
/etc/rc.d directory • The /etc/rc.d directory contains the following files: rc, rc.local, rc.sysinit • And the following directories: init.d rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d
Startup Scripts • One of the most important scripts in /etc/inttab is rc.sysinit • When init parses the inittab file, rc.sysinit is the first script found and executed
rc.sysinit script • Sets some initial $PATH variables • Configures Networking • Sets up Swapping for Virtual Memory • Sets the system hostname • Checks root file systems for possible repairs • Checks root filesystem quotas • Turns on user and group quotas for root file system
rc.sysinit script • Remounts the root filesystem read/write • Clears the mounted filesystems table /etc/mtab • Enters the root filesystem into mtab • Readies the system for loading modules • Finds module dependencies • Checks filesystems for possible repairs • Mounts all other file systems
rc.sysinit script • Deletes UUCP lock files • Deletes stale subsystem files • Deletes stale pid files • Sets the system clock • Turns on swapping • Initialises the serial ports • Loads Modules
rc.local script • After the rc.sysinit script is run, init runs the rc.local script to carry out any site-specific operations that may be required upon system startup • rc.local may examine the local system and create a message for the login prompt based on the hardware and software versions found • If it does, it will put such details in the file /etc/issue which may be displayed on login
Run Level 0: • /etc/rc.d/rc0.d • Starts the shutdown sequence • Kills All Processes • Turns off Virtual Memory File Swapping • Unmounts swap and mounted file systems
Run Level 1: • /etc/rc,d/rc1.d • Single user mode, or administrative state • Used by sys admins while performing software maintenance • Nobody else can log in • Networking is turned off, but file systems are mounted
Run Level 2: • /etc/rc.d/rc2.d • Multiuser state • Networking is enabled, NFS is disabled
Run Level 3: • /etc/rc.d/rc3.d • Usually the default run level specified as the first line in the /etc/inittab file • Remote file sharing is enabled along with all other desired services
Run Level 4: • /etc/rc4.d • Usually empty, not used • If you want to define your own run level, this can be used to set up the appropriate links
Run Level 5: • /etc/rc.d/rc5.d • Similar to the default run level, but with the named (internet DNS server) • Usually the default run level for X11
Run Level 6: • /etc/rc5.d • Reboot run level • Contains links similar to level 0, but logic in the halt script in init.d determines whether the system is being shut down or rebooted
Run Levels… • Each run-level is defined by the services (daemons) that are normally running in that level • The services to stop and start for each run level are defined in the rcX.d directories mentioned above • These directories contain symbolic links to master scripts contained in the /etc/rc.d/init.d directory
…Run Levels… • The symbolic links contained in the rcX.ddirectories must be named so as to start with capital K or capital S • For example: rc3.d contains the following symbolic links: K05saslauthd K87portmap S10network S25netfs S80sendmail S95anacron • Any other files or symbolic links contained in the rcX.d directories will be ignored by the rc script
…Run Levels… • In addition to the inclusion of K or S at the start of the symbolic links, the file names also carry a number between 00 and 99 • The combination of K or S followed by a number means that when the files are listed alphabetically, they appear in a particular order • This order determines the order in which the scripts are run by the rc script
…Run Levels • When a symbolic link beginning with K is encuntered, rc runs that script with the stop parameter • When a symbolic link beginning with S is encountered, rc runs that script with the start parameter
/etc/rc/d/init.d directory • This directory contains the master copies of all the scripts that may contain symbolic links in the rcX.d directories
Adding Services to Run Levels • If we want a service to start in a given run level we must: • Create or copy the start/stop/status script to the /etc/rc.d/init.d directory • Create a symbolic link in the required run level directory to start the script in the appropriate sequence ln -s /etc/rc.d/init.d/isdn /etc/rc.d/rc3.d/S20isdn
Init Specify the run-level to put the machine into
Shutdown • shutdown [-krhfnc] [-t secs] time [warning message] • -k: Don’t really shut down, just warn • -r: reboot after shutdown • -h: halt after shutdown • -f: do a ‘fast’ reboot • -n: do not go through ‘init’ but go down real fast • -c: cancel a running shutdown • -t <sec>: delay between warning and kill signal • Shutdown –t60 –r now
Halt • Notifies the kernel of a shutdown or reboot
Reboot • Symbolic link to halt