You are on page 1of 17

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

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

In order to boot a system boot loader is needed


SysLINUX
LILO (ctrl + x = boot prompt)
GRUB (select kernel and press e = edit boot)

boot:
boot:linux
linuxroot=/dev/hda1
root=/dev/hda1
boot:
boot:linux
linuxsingle
single

Boot prompt arguments is optional


Used to boot into single user mode whenever needed
To set kernel arguments at boot like boot disks, network, kernelfile

Once loaded the Unix kernel starts running

initialise devices, virtual memory, etc.


initialise internal tables (processes, files, etc.)
creates scheduler process (number 0 invisable in SuSE and RedHat)
runs the first process (number 1) /sbin/init

System initialisation performed by /sbin/init is user configurable

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

SuSE / RedHat Run-Levels


Run levels are standard under RedHat Unix:
0
1
2
3
4
5
6
s/S
a/b/c

System HALT
Single user mode or administration mode
Local multiuser without remote network (e.g. NFS)
Full multi-user with networking
not used
Full multi-user with networking xdm (X-Windows)
System reboot
single-user mode
pseudo states (rarely used)

Use the -r option to who to get the current run level


## who
who -r
-r
run-level
last=S
run-level 55 Sep
Sep 25
25 10:35
10:35
last=S
## shutdown
shutdown-h
-h+10
+10"Memory
"Memoryupgrade.
upgrade.Please
Pleaselog
logof
of
clean
cleanHALT
HALTinin10
10minutes
minuteswith
withwarning
warningmessage:
message:Memory
Memoryupgrade.
upgrade.

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

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
wait
once
respawn

don't run the command


run command and wait for completion
run command, but don't wait
run command. If process exits, then repeat the command

sysinit
run command at first init
boot
run command at boot-time
but don't wait
bootwait
like boot, but wait for completion
initdefault defines default boot-level

Exercise - /etc/inittab
What processes are run at system startup
What processes are run at system shutdown
## more
more /etc/inittab
/etc/inittab
id:5:initdefault:
id:5:initdefault:
si::bootwait:/etc/init.d/boot
si::bootwait:/etc/init.d/boot
l0:0:wait:/etc/rc.d/rc
l0:0:wait:/etc/rc.d/rc 00
l1:1:wait:/etc/rc.d/rc
l1:1:wait:/etc/rc.d/rc 11
l2:2:wait:/etc/rc.d/rc
l2:2:wait:/etc/rc.d/rc 22
l3:3:wait:/etc/rc.d/rc
l3:3:wait:/etc/rc.d/rc 33
#l4:4:wait:/etc/rc.d/rc
#l4:4:wait:/etc/rc.d/rc 44
l5:5:wait:/etc/rc.d/rc
l5:5:wait:/etc/rc.d/rc 55
l6:6:wait:/etc/rc.d/rc
l6:6:wait:/etc/rc.d/rc 66
ls:S:wait:/etc/init.d/rc
ls:S:wait:/etc/init.d/rc SS
~~:S:respawn:/sbin/sulogin
~~:S:respawn:/sbin/sulogin
ca::ctrlaltdel:/sbin/shutdown
ca::ctrlaltdel:/sbin/shutdown -r
-r -t
-t 44 now
now
pf::powerwait:/etc/init.d/powerfail
pf::powerwait:/etc/init.d/powerfail
pn::powerfailnow:/etc/init.d/powerfail
pn::powerfailnow:/etc/init.d/powerfail now
now
po::powerokwait:/etc/init.d/powerfail
po::powerokwait:/etc/init.d/powerfail
1:2345:respawn:/sbin/mingetty
1:2345:respawn:/sbin/mingetty tty1
tty1
2:2345:respawn:/sbin/mingetty
2:2345:respawn:/sbin/mingetty tty2
tty2

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
rc
rc
rc

0
1
2
3

looks in
looks in
looks in
looks in

/etc/rc0.d
/etc/rc1.d
/etc/rc2.d
/etc/rc3.d

for levels 0
for level 1
for levels 2 & 3
for level 3

Startup program names is formed like:


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/init.d

RC Script Details (Start and Stop)

## sh
sh S14xinet
S14xinet start
start

## more
more /etc/init.d/xinet
/etc/init.d/xinet
case
case "$1"
"$1" in
in
start)
start) ...
...
...;;
...;;
stop)
stop) ...
...
...;;
...;;
esac
esac
## Adding
Adding xinetd
xinetd
## ln
ln init.d/xinet
init.d/xinet rc3.d/K08xinet
rc3.d/K08xinet
## ln
init.d/xinet
rc3.d/S14xinet
ln init.d/xinet rc3.d/S14xinet
## init
init 33
## init
init 00

## sh
sh K08halt
K08halt stop
stop

Set Programs Run At Each runlevel


Check, set and move programs to various runlevels
## chkconfig
chkconfig --list
--list
SuSEfirewall2_setup
SuSEfirewall2_setup 0:off
0:off
atd
0:off
atd
0:off
cron
0:off
cron
0:off
network
0:off
network
0:off
syslog
0:off
syslog
0:off
gpm
0:off
gpm
0:off
cups
0:off
cups
0:off
nfs
0:off
nfs
0:off
portmap
0:off
portmap
0:off
xinetd
0:off
xinetd
0:off
.. .. ..

1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off
1:off

2:off
2:off
2:off
2:off
2:on
2:on
2:on
2:on
2:on
2:on
2:on
2:on
2:on
2:on
2:off
2:off
2:off
2:off
2:off
2:off

3:on
3:on
3:off
3:off
3:on
3:on
3:on
3:on
3:on
3:on
3:on
3:on
3:on
3:on
3:on
3:on
3:on
3:on
3:on
3:on

4:on
4:on
4:off
4:off
4:off
4:off
4:off
4:off
4:off
4:off
4:off
4:off
4:off
4:off
4:off
4:off
4:off
4:off
4:off
4:off

5:on
5:on
5:off
5:off
5:on
5:on
5:on
5:on
5:on
5:on
5:off
5:off
5:on
5:on
5:on
5:on
5:on
5:on
5:on
5:on

6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off
6:off

Switch Off SuSEfirewall2_setup Starting Up In Levels 3 and 5


# chkconfig --level 35 SuSEfirewall2_setup off

Switch On SuSEfirewall2_setup Starting Up In Levels 3 and 5


# chkconfig --level 35 SuSEfirewall2_setup on

Manually start and stop services


Check if service is running
## /etc/init.d/xinetd
/etc/init.d/xinetd status
status
Checking
for
service
xinetd:
Checking for service xinetd: running
running

Stop service
## /etc/init.d/xinetd
/etc/init.d/xinetd stop
stop
Shutting
down
xinetd:
Shutting down xinetd: done
done

Start service
## /etc/init.d/xinetd
/etc/init.d/xinetd start
start
Starting
INET
services.
Starting INET services. (xinetd)
(xinetd) done
done

Reload service after reconfiguring


## /etc/init.d/xinetd
/etc/init.d/xinetd reload
reload
Reload
INET
services
(xinetd).
Reload INET services (xinetd). done
done

Exercise - System Startup


What subsystems are started up at run level 3
What subsystems are stopped going from level 3 to 2
## grep
grep '[23]'
'[23]' /etc/inittab
/etc/inittab

id:3:initdefault:
id:3:initdefault:
l2:2:wait:/etc/rc.d/rc
l2:2:wait:/etc/rc.d/rc 22
l3:3:wait:/etc/rc.d/rc
l3:3:wait:/etc/rc.d/rc 33
ca::ctrlaltdel:/sbin/shutdown
ca::ctrlaltdel:/sbin/shutdown -t3
-t3 -r
-r now
now
pf::powerfail:/sbin/shutdown
pf::powerfail:/sbin/shutdown -f
-f -h
-h +2
+2 "Power
"Power Failure!"
Failure!"
pr:12345:powerokwait:/sbin/shutdown
pr:12345:powerokwait:/sbin/shutdown -c
-c "Power
"Power Restored"
Restored"
1:2345:respawn:/sbin/mingetty
1:2345:respawn:/sbin/mingetty tty1
tty1
2:2345:respawn:/sbin/mingetty
2:2345:respawn:/sbin/mingetty tty2
tty2

## ls
ls rc[23].d
rc[23].d
rc2.d:
rc2.d:
K20nfs
K55xdm
S40lp
K20nfs
K55xdm
S40lp
K33oracle
S33acct
K33oracle S05cron
S05cron
S33acct .. .. .. ..
rc3.d:
rc3.d:
S22nfs
S56xinetd
S22nfs
S56xinetd
S30oracle
S30oracle .. .. ..

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
init 22
switch
switchtotorun
runlevel
level22
## init
init 33
now
nowswitch
switchtotorun
runlevel
level33
## shutdown
shutdown
default
defaultsystem
systemshutdown
shutdown

System Shutdown
Use /sbin/shutdown when closing down a Unix system
shutdown [-tN ] [+M ] [-h ] [-r ] [-c ] time message

+M
wait period in seconds (now=0)
-tN wait period in seconds between message and action
-h
shutdown to halt -c
Cancel shutdown
-r
shutdown and reboot
time absolute time hh:mm
message
shutdown message
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
## shutdown
shutdown r
r now
now
reboot
rebootthe
thesystem
systemnow
now
## shutdown
shutdown +3600
+3600 -r
-r
halt
haltsystem
systemininone
onehour
hour

WARNING: databases cannot normally close down quickly


enough when receiving a TERM signal during shutdown

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
shutdown -r
-r now
now
reboot
rebootthe
thesystem
systemnow
now
## shutdown
shutdown -h
-h 17:00
17:00
halt
haltsystem
systematat5pm
5pm

## shutdown
shutdown now
now
password:
password:
## sync
sync
## sync
sync
## halt
halt

## halt
halt
## poweroff
poweroff
## reboot
reboot

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 wont 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!)

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/init.d/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 SVR4 (SVR3.2) systems

You might also like