1.106.2 Change runlevels and shutdown or reboot system Weight 3 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Linux Professional Institute Certification — 102 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system Angus Lees gus@inodes.org Geoffrey Robertson ge@ffrey.com Nick Urbanik nicku@nicku.org This document Licensed under GPL—see section ?? 2005 July Outline 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals Shutting down the system Using init to change mode of system Runlevels inittab Shutting down the system Topic 106 Boot, Initialization, Shutdown and Runlevels [6] Where we are up to 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels 1.106.1 Boot the system [3] 1.106.2 Change runlevels and shutdown or reboot system [3] inittab Shutting down the system Description of Objective 1.106.2 Change runlevels and shutdown or reboot system 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective Candidates should be able to manage the runlevel of the system. This objective includes changing to single user mode, shutdown or rebooting the system. Candidates should be able to alert users before switching runlevel, and properly terminate processes. This objective also includes setting the default runlevel. init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system Key files, terms, and utilities include: 1.106.2 Change runlevels and shutdown or reboot system 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system /etc/inittab — Configuration file for /sbin/init shutdown — command to reboot or shut system down init — first process started by the kernel with process ID equal to 1 /sbin/init 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes “init” is the process started by the kernel after booting. It is up to init to start the rest of the system. The usual “SysV init” does this according to /etc/inittab. The kernel also treats process ID 1 (init) specially: PID 1 is skipped by various “kill all” operations, etc “orphaned” child processes are adopted by PID 1 Using init to change mode of system Runlevels inittab Shutting down the system Telling init what to do 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective By sending signals directly (as root) or by running various commands, which relay to init: telinit Tell init to reload inittab, re-exec itself or switch runlevels shutdown Initiate a shutdown by doing some book-keeping and then signalling init halt, reboot, poweroff Tools used to initiate or finalise special kinds of shutdown runlevel Find out current or previous runlevel init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system Runlevels The Linux Standards Base (http://refspecs. freestandards.org/LSB_3.0.0/LSB-Core-generic/ LSB-Core-generic/runlevels.html) defines the following standard runlevels that all distributions should follow to be compliant: 0 1 2 3 4 5 6 halt single user mode multiuser with no network services exported normal/full multiuser reserved for local use, default is normal/full multiuser multiuser with a display manager or equivalent reboot 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system Passed through via kernel command line, telinit or default in /etc/inittab. /etc/inittab id : runlevels : action : process # /etc/inittab: init(8) configuration. id:5:initdefault: # System initialization. si::sysinit:/etc/rc.d/rc.sysinit # /etc/init.d executes the S and K scripts # scripts when change runlevel. 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 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals Shutting down the system /etc/init.d/rc runs all the “K” scripts in /etc/rcN.d/, followed by the “S” scripts. /etc/inittab 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals # Trap CTRL-ALT-DELETE ca::ctrlaltdel:/sbin/shutdown -t3 -r now # # # # # # # When our UPS tells us power has failed, assume we have a few minutes of power left. Schedule a shutdown for 2 minutes from now. This does, of course, assume you have powerd installed and your UPS connected and working correctly. Shutting down the system pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down" # If power was restored before the shutdown kicked in, cancel it. pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled" Outline 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals Shutting down the system Runlevels inittab Starting terminals Shutting down the system /etc/inittab 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context # Run gettys in standard runlevels #co:2345:respawn:/sbin/agetty ttyS0 38400 vt100 1:2345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5 6:2345:respawn:/sbin/mingetty tty6 # Run xdm in runlevel 5 x:5:once:/etc/X11/prefdm -nodaemon #co:2345:respawn:/sbin/agetty ttyS0 38400 vt100 S1:2345:respawn:/sbin/mgetty ttyS1 Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals Shutting down the system /etc/inittab 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes # Example how to put a getty on a serial line (for a terminal) Using init to change mode of system # Runlevels #T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100 inittab #T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100 Starting terminals # Example how to put a getty on a modem line. # #T3:23:respawn:/sbin/mgetty -x0 -s 57600 ttyS3 Shutting down the system Initiating a shutdown 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective shutdown [options] time [message]Popular options: -r Reboot -h Halt -c Cancel a running shutdown “time” can be HH:MM (eg 17:30) or +minutes (eg +5) or “now” Examples: shutdown -r now shutdown -h 17:30 Scheduled hardware maintenance init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system Topics Covered Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals Shutting down the system 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system Topics Covered Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals Shutting down the system 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system Topics Covered Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals Shutting down the system 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system Topics Covered Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals Shutting down the system 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system Topics Covered Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals Shutting down the system 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system Topics Covered Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals Shutting down the system 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system Topics Covered Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals Shutting down the system 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system Topics Covered Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Starting terminals Shutting down the system 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system License Of This Document 1.106.2 Change runlevels and shutdown or reboot system Weight 3 Angus Lees Context Objective Copyright c 2005, 2003 Angus Lees , Geoffrey Robertson and Nick Urbanik . Permission is granted to make and distribute verbatim copies or modified versions of this document provided that this copyright notice and this permission notice are preserved on all copies under the terms of the GNU General Public License as published by the Free Software Foundation—either version 2 of the License or (at your option) any later version. init: the mother of all processes Using init to change mode of system Runlevels inittab Shutting down the system