Booting and Shutting Down Linux- and UNIX-based Operating Systems Rithy Chhay CMSC 691X – Gary Burt June 4, 2002 Overview Bootstrapping Booting PC’s Booting in Single-User Mode Startup Scripts Rebooting and Shutting Down Bootstrapping The process in which the kernel is loaded into memory and begins to execute. Bootstrap spawns the init process which executes “rc files” which check and mount the file system and start system daemons. The system can be booted two ways: – Automatically Ordinarily, systems are booted this way. – Manually Used by system administrators for setup or troubleshooting. Computer is in “Single-User Mode”. The Boot Process There are generally six distinct phases of booting up a system – Loading and Initializing the kernel – Device Detection and Configuration – Creation of Spontaneous System Processes – Operator Intervention (Manual Boot Only) – Execution of System Startup Scripts – Multi-user Operation Kernel Initialization The UNIX kernel is a program. The kernel usually resides in the root partition of the UNIX file system. Most Linux distributions call this partition either “/vmlinuz” or “/boot”. Other UNIX flavored systems may call this partition “/unix”, “/vmunix”, or “/kernel”. Almost every vendor of Linux or UNIX calls their kernel pathname something different. Hardware Configuration The kernel inspects the installed hardware on the system and attempts to mount the proper drivers for each device that you tell the kernel it should expect to find This is visually noticeable during the cryptic messages that appear on the screen while the computer boots Devices that have missing drivers or that did not respond during boot-up will be disabled and will not be accessible to UNIX until the system is rebooted. System Processes After basic initializations have been completed, processes which are NOT created by the UNIX fork mechanism execute. The number of these processes vary in the various flavors of UNIX and Linux, but init is the common process throughout them all. The purpose of these system processes is to handle tasks that the kernel would handle but have been created separately for scheduling or architectural reasons. At this point, the bootstrapping process is complete, but none of the processes that handle basic operations have been created. Those processes are taken cared of by init. Operator Intervention (Manual Boot) A command-line flag is brought up to signal init to go into single-user mode. From here you can choose which scripts to run, but only the root partition is mounted so you must first mount other partitions before you can start processed off of those partitions. Daemons do not typically run in single-user mode. Many single-user environments are mounted as read-only by default, therefore if “/tmp” is apart of the root partition then programs that need to write to that location, will not work. Normally, the filesystem is checked automatically by fsck, but you must do this manually during single-user mode. After the single-user shell has completed, the system will resume automated boot-up. Multi-user Operation After Initialization scripts have ran, the system is fully operational, but additional processes have to run in order to allow multiple users to log on to the system. The getty process listen for logins which is spawned from init. Graphical login systems include xdm, gdm, and dtlogin. Booting PC’s PC’s have simplistic ROM codes compared to firmware found on UNIX machines. UNIX firmware generally knows what devices are installed, how to configure them and use them on a basic level. Once booting begins, your machine will try to load the first 512-byte segment from disk. This segment is known as the MBR (Master Boot Record). MBR and LILO The MBR is what loads the kernel from disk. A popular Linux boot loader is LILO. LILO can be installed on either the MBR or the boot record of the Linux root partition. Installing LILO on the boot record allows you to use a different boot loader for another operating system like Windows XP. LILO can be configured through the “lilo” command. Its contents are stored at “/etc/lilo.conf”. See the man pages for more details on how to configure LILO. Other Boot Loaders GRUB, LOADLIN, boot0cfg & disklabel are other boot loaders from either different flavors of UNIX or Linux or third party boot loaders which offer various options. UNIX and UNIX-based systems for non-PC hardware machines generally have proprietary system specific schemes for booting their kernels. Startup Scripts These are scripts which are run by init to complete the bootstrap process. Generally speaking, there are two types of system startup scripts. – System V style scripts Used by most UNIX systems like Solaris, HP-UX and most distributions of Linux. – BSD style scripts Used by flavors of BSD such as FreeBSD, NetBSD, OpenBSD and BSDi. System V Style Scripts These startup scripts are typically centrally located in the init.d directory located under “/etc”. – RedHat Linux stores these files under the “/etc/rc.d” directory. – HP-UX stores these files under the “/sbin” directory. Generally, each startup script can accept two command line arguments; start and stop. – Start instructs the script to begin when it is suppose to – Stop instructs the script to end when it is suppose to Run Level States There are “run level” states in which represent a particular complement of services that the system should be running. – – – – 0: system shutdown 1 or S: single-user mode 2 – 5: multi-user mode 6: reboot Each run level has its own set of startup scripts. Typically these state directories are designated rcn.d where n represents the specific run level directory. – i.e. The scripts for run level 4 would be located in the rc4.d directory. Refer to the man pages regarding specific details for your operating system’s startup scripts. Shutting Down UNIX UNIX systems must be gracefully powered down. Failure to properly shut down can cause damage to the system. There are various was to shut down a UNIX system; generally a command to shut down the system is issued from the command line. Here are a few commands: – shutdown: Broadcasts a message to all users logged in prompting a system shut down. – halt: Performs essential duties required to bring the system down, waits for the filesystem writes to complete then halts the kernel. – reboot: Executes identically to halt with the excepting that it causes to system to restart from scratch rather than halting the kernel. – kill init: This is not recommended but will cause the system to shutdown. Since init is the parent of all processes, all child processed will be terminated when init is killed.