Presentation is loading. Please wait.

Presentation is loading. Please wait.

System Startup & Shutdown Objectives –to interpret the Unix startup and shutdown configuration files –to be able to create a customised run level Contents.

Similar presentations


Presentation on theme: "System Startup & Shutdown Objectives –to interpret the Unix startup and shutdown configuration files –to be able to create a customised run level Contents."— Presentation transcript:

1 System Startup & Shutdown Objectives –to interpret the Unix startup and shutdown configuration files –to be able to create a customised run level Contents –bootstrap procedure –single and multi-user run levels –system startup files (rc files) –standard system processes –clean shutdown procedure –maintenance mode Practicals –to modify the startup sequence of a Unix system Summary

2 Standard Boot Process The system boot process is hardware-specific –often an automatic boot from hardware into multi-user Unix –high security systems require PROM password for manual boot Once loaded the Unix kernel starts running –initialise devices, virtual memory, etc. –initialise internal tables (processes, files, etc.) –creates scheduler process (number 0) –runs the first process (number 1) /sbin/init System initialisation performed by /sbin/init is user configurable Solaris & AIX bios b boot standard system b -s boot to single user mode b diag boot named program (diagnostics) b unix.bak -s boot backup kernel Solaris & AIX bios b boot standard system b -s boot to single user mode b diag boot named program (diagnostics) b unix.bak -s boot backup kernel

3 Startup Flow Control run level 0 boot run level 1 single-user maintenance run level 2 multi-user run level 3 multi-user & DFS run level 4 multi-user user defined

4 RedHat Run-Levels Run levels are standard under RedHat Unix: 0bootstrap or power down levels 1administration mode 2not used 3multi-user with DFS & networking 4not used 5X-Windows 6halt & reboot s/Ssingle-user mode a/b/cpseudo states (rarely used) Use the -r option to who to get the current run level # who -r. run level 3 Jan 01 7:31 3 0 S 3 # shutdown -i6 -g60 clean reboot in 60 seconds # who -r. run level 3 Jan 01 7:31 3 0 S 3 # shutdown -i6 -g60 clean reboot in 60 seconds

5 The init Control file: /etc/inittab The init process uses /etc/inittab as its control 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) # #id:3:initdefault: # Console Text Mode id:5:initdefault: # Console GUI Mode Processes run from /etc/inittab are daemons –standard I/O attached to /dev/null –I/O usually be redirected to a log file or perhaps the console

6 Structure of /etc/inittab Each line has 4 fields separated by colons id : level : action : process id unique identifier for line - up to four alphanumerics level run level(s) to activate process action keyword for how to run process command full pathname and parameters of command to be executed Main inittab action keywords are: off don't run the command wait run command and wait for completion once run command, but don't wait respawn run command. If process exits, then repeat the command sysinit run command at first init boot run command at boot-timebut don't wait bootwait like boot, but wait for completion initdefault defines default boot-level

7 Exercise - /etc/inittab What processes are run at system startup What processes are run at system shutdown # more /etc/inittab id:3:initdefault: si::sysinit:/etc/rc.d/rc.sysinit 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 ca::ctrlaltdel:/sbin/shutdown -t3 -r now pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure!” pr:12345:powerokwait:/sbin/shutdown -c "Power Restored” 1:2345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2 # more /etc/inittab id:3:initdefault: si::sysinit:/etc/rc.d/rc.sysinit 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 ca::ctrlaltdel:/sbin/shutdown -t3 -r now pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure!” pr:12345:powerokwait:/sbin/shutdown -c "Power Restored” 1:2345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2

8 Run Command Scripts The run command scripts invoked by init via /etc/inittab Each rc script in /etc/rc.d/ controls changes to named run level Each script runs startup programs in directory /etc/rc?.d rc 0 looks in /etc/rc0.d for levels 0 rc 1 looks in /etc/rc1.d for level 1 rc 2 looks in /etc/rc2.d for levels 2 & 3 rc 3 looks in /etc/rc3.d for level 3 Startup program names of form sNNname s S to start process or K to kill process at this run level NN sequence number name name of script in /etc/init.d –All startup programs in runlevels are links to /etc/rc.d/init.d

9 # more /etc/init.d/inet case "$1" in start)......;; stop)......;; esac # ln init.d/inet rc0.d/K69inet # ln init.d/inet rc2.d/S69inet # init 2 # init 0 # more /etc/init.d/inet case "$1" in start)......;; stop)......;; esac # ln init.d/inet rc0.d/K69inet # ln init.d/inet rc2.d/S69inet # init 2 # init 0 RC Script Details # sh S69inet start # sh K69inet stop

10 Set Programs Run At Each runlevel Check, set and move program’s to various runlevels Switch Off Sendmail In Levels 3 and 5 # chkconfig --level 35 sendmail off Switch On Sendmail Starting Up In Levels 3 and 5 # chkconfig --level 35 sendmail on # chkconfig --list keytable 0:off 1:on 2:on 3:on 4:on 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off syslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off gpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off kudzu 0:off 1:off 2:off 3:on 4:on 5:on 6:off wlan 0:off 1:off 2:on 3:on 4:on 5:on 6:off sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off random 0:off 1:off 2:on 3:on 4:on 5:on 6:off... # chkconfig --list keytable 0:off 1:on 2:on 3:on 4:on 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off syslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off gpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off kudzu 0:off 1:off 2:off 3:on 4:on 5:on 6:off wlan 0:off 1:off 2:on 3:on 4:on 5:on 6:off sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off random 0:off 1:off 2:on 3:on 4:on 5:on 6:off...

11 Manually start and stop services Check if service is running Stop service Start service Reload service after reconfiguring # service vsftpd status vsftpd (pid 6070) is running... # service vsftpd stop Shutting down vsftpd: [ OK ] # service vsftpd start Starting vsftpd for vsftpd: [ OK ] # service vsftpd reload Shutting down vsftpd: [ OK ] Starting vsftpd for vsftpd: [ OK ] # service vsftpd reload Shutting down vsftpd: [ OK ] Starting vsftpd for vsftpd: [ OK ]

12 Changing run levels Use init to change run levels if users not logged –use to switch to multi-user from single user –use to switch between multi-user levels Use shutdown to close down the system –warns users what is happening –performes a lot of housekeeping routines –issues the init command # init 2 switch to run level 2 # init 3 now switch to run level 3 # shutdown default system shutdown # init 2 switch to run level 2 # init 3 now switch to run level 3 # shutdown default system shutdown

13 System Shutdown Use /sbin/shutdown when closing down a Unix system shutdown [-y] [-g N ] [-i M ] -y pre-answer yes to confirmation question -g N grace period in seconds (default 60) -i M shutdown level (default S) –wall is used to send broadcasts at set intervals until system shutdown –shutdown is started by init changing to new run level –any process left running are sent a TERM signal –any still running are sent a KILL signal WARNING: databases cannot normally close down quickly enoughwhen receiving a TERM signal during shutdown # shutdown -i6 -g0 -y reboot the system now # shutdown -i0 -g3600 halt system in one hour # shutdown -i6 -g0 -y reboot the system now # shutdown -i0 -g3600 halt system in one hour

14 BSD Derived Systems (AIX, OSF/1) Only one multi user level –boot up direct to multi-user –boot to single user and go to multi-user on exit from single user root shell –cannot use init to change levels Use shutdown and specify time to exit from multi user Startup/shutdown controlled by command scripts in /etc –scripts must be modified using a text editor –require knowledge of script programming –look for files: rc, rc.local, rc.single, rc.tcpip, rc.boot, rc.shutdown # shutdown -r now reboot the system now # shutdown -h 17:00 halt system at 5pm # shutdown -r now reboot the system now # shutdown -h 17:00 halt system at 5pm # shutdown now password: # sync # halt # shutdown now password: # sync # halt # poweroff

15 Maintenance mode Maintenance mode is used to get out of trouble –the system won't boot due to password/kernel/init problems If the system is alive and well, use shutdown to run level 1 Otherwise reboot to single user mode –if you have to power cycle the system wait for the disk activity lights to stop blinking If the system won’t boot, insert the installation (boot) media, and boot from this instead –ensure that you do not attempt to reinstall the system at this point –this will give you a system where Unix is running in memory using the installation media as a filesystem. The hard disk may now be able to be fixed (if you are lucky!)

16 Summary Unix systems start up through a clearly defined sequence The first configurable stage is with the init process using /etc/inittab Run levels provide additional configuration through the run command scripts Link and remove files from the /etc/rc*.d directories to enable/disable sub-systems for different run levels Shutdown Unix using the shutdown command AIX and OSF/1 (BSD) use a different mechanism to RH9, SVR4 (SVR3.2) systems


Download ppt "System Startup & Shutdown Objectives –to interpret the Unix startup and shutdown configuration files –to be able to create a customised run level Contents."

Similar presentations


Ads by Google