+ All Categories
Home > Technology > 1.3 runlevels, shutdown, and reboot v3

1.3 runlevels, shutdown, and reboot v3

Date post: 18-Jul-2015
Category:
Upload: acacio-oliveira
View: 45 times
Download: 3 times
Share this document with a friend
Popular Tags:
36
Core Linux for Red Hat and Fedora learning under GNU Free Documentation License - Copyleft (c) Acácio Oliveira 2012 Everyone is permitted to copy and distribute verbatim copies of this license document, changing is allowed System Administration
Transcript

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

System Administration

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Exam Objectives

Key Knowledge Areas

Set the default runlevel. Change between run levels including single user mode. Shutdown and reboot from the command line. Alert users before switching runlevels or other major system event. Properly terminate processes.

System Architecture

Change runlevels and shutdown or reboot system

Terms and Utilities

/etc/inittab shutdown init /etc/init.d telinit

2

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Runlevels

3

Runlevels define what tasks are accomplished in the current state (runlevel) of a Linux system.

Every Linux system supports 3 basic runlevels, plus 1 or more runlevels for normal operation.Basic Linux runlevelsLevel Purpose0 Shut down (or halt) the system1 Single-user mode; usually aliased as s or S6 Reboot the system

Common Linux runlevelsLevel Purpose2 Multiuser mode without networking3 Multiuser mode with networking5 Multiuser mode with networking and the X Window System

- Slackware uses runlevel 4 for full system running X Window system. - Debian and Ubuntu, use a single runlevel for any multiuser mode, (runlevel 2)consult documentation for the distribution

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Default runlevel

4

When system starts, default runlevel is determined from id: entry in /etc/inittab.

Ex:

yourname@yourcomp~> grep "^id:" /etc/inittab

id:5:initdefault:

Entry for Fedora 8 or openSUSE 11.2, with runlevel 5 for the X Window System.

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Changing runlevels

5

To make a permanent change in runlevel, •edit /etc/inittab and change the default level

To make one boot in other runlevel (exemple: to edit the Linux System, or to install or build kernel modules).•At boot time by editing the kernel cmdline in GRUB or add a parameter to LILO;•Use a single digit to specify desired runlevel.

each runlevel corresponds to scripts /etc/rc.d/rc?.d/S* (? for number 0 to 6).

When there’s change in runlevel, init runs a script which stops all extra processes in the current runlevel, and starts required processes from the new runlevel

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Changing runlevels

6

Ex 1: Changin runlevels at boot time - enter ‘e’ command to edit.

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Changing runlevels

7

Ex 2: In menu with root, kernel, initrd - select kernel and press 'e' to edit

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Changing runlevels

8

Ex 3:

In end of line - add space and digit runlevel '3'. Remove 'quiet' if you wish, or modify any other parameters if needed

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Changing runlevels

9

To change runlevel without rebooting the system. The command used is telinit.

Use 1st the command runlevel to show previous runlevel and current one. If first output is 'N': the runlevel has not been changed since boot.

Ex: yourname@yourcomp~> runlevel

N 3

yourname@yourcomp~> telinit 4

Confirm the new runlevel after the change. Again with runlevel command

Ex: yourname@yourcomp~> runlevel

3 4

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

telinit and init

10

telinit is a symbolic link to init

Since init runs as PID 1 at boot time the init executables know if the command invoked on prompt is the init or telinit and behaves accordingly.

As a symbolic link:you may use init5 instead of telinit5 to switch to runlevel 5 or any other.

Ex: yourname@yourcomp~> ls -l $(which telinit)

lrwxrwxrwx 1 root root 4 2008-04-01 07:50 /sbin/telinit -> init

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Single-user mode

11

Single-user mode (runlevel 1)is selected to:Recover a filesystem or database, or install and test new hardware.

System environment:•shell with a minimal system;•Usually without networking; •Without daemons running (or very few); •Goes straight into a shell prompt as root, or must log with authentication.

Ex: yourname@yourcomp~> telinit 1

yourname@yourcomp~> telinit S

Remember:

telinit 1 or init switch to Single-user mode for admin will stop multiuser activity.Its a abrupt process - can cause users to lose work and processes to terminate abnormally.

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Clean shutdown

12

Preferred method to shut down or reboot the system is the shutdown command

Process:1.Sends warning message to all logged-in users and blocks any further logins.2.Signals init to switch runlevels.3. init process then sends all running processes a SIGTERM signal, giving them chance to save data and terminate properly.4.After 5 sec, or another delay specified, init sends a SIGKILL signal to forcibly end each remaining process.

By default, shutdown switches to runlevel 1 (single-user mode). Specify -h option to halt system, -r option to reboot.

Standard message is issued in addition to any message you specify

Shutdown time may be: Absolute in hh:mm format, Relative time in n (n=number minutes until shutdown) +0= Now

Cancel delayed shutdown: press Ctrl-c or command shutdown -c.

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Clean shutdown

13

Ex: yourname@yourcomp~# shutdown 5 File system recovery neededBroadcast message from root (pts/1) (Tue Jan 4 08:05:24 2011):File system recovery neededThe system is going DOWN to maintenance mode in 5 minutes!^CShutdown cancelled.

yourname@yourcomp~# shutdown -r 10 Reloading updated kernel&[1] 18784

[yourname@yourcomp~# Broadcast message from root (pts/1) (Tue Jan 4 08:05:53 2011):

Reloading updated kernelThe system is going DOWN for reboot in 10 minutes!

yourname@yourcomp~# fgshutdown -r 10 Reloading updated kernel^CShutdown cancelled.

yourname@yourcomp~# shutdown -h 23:59&[1] 18788

[root@pinguino ~]# shutdown –c

Shutdown cancelled.[1]+ Done shutdown -h 23:59

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Clean shutdown

14

Ex:

If time till shutdown exceeds 15 min., message is not sent until 15 minutes before the event.

yourname@yourcomp~# date;shutdown -t60 17 Time to do backups&Tue Jan 4 08:12:55 EST 2011[1] 18825

yourname@yourcomp~# dateTue Jan 4 08:14:13 EST 2011

yourname@yourcomp~#Broadcast message from root (pts/1) (Tue Jan 4 08:14:55 2011):Time to do backupsThe system is going DOWN to maintenance mode in 15 minutes!

If shutdown is canceled, use wall command to send a warning to all users alerting them that the system is not going down.

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Halt, reboot, and poweroff

15

halt command: halts the system

If any of these 3 commands are called when system is not in runlevel 0 or 6, then the corresponding shutdown command will be invoked instead.

poweroff command: Is a symbolic link to halt command, which halts the system and attempts to power it off.

reboot command: Is a symbolic link to halt command,which halts the system and then reboots it.

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

inittab

16

When /sbin/init is started by kernel, it reads /etc/inittab for the startup sequence. The lines in /etc/inittab determine the startup behaviour of your system.

Common inittab Actions

Respawn Restart process whenever it terminates. Usually used for getty processes, that monitors logins.

Wait Start process once when specified runlevel is entered and wait for its termination before init proceeds.

once Start the process once when the specified runlevel is entered.

Initdefault Specifies the runlevel to enter after system boot.

ctrlaltdel Execute associated process when init receives the SIGINT signal. example: when someone on the system console presses CTRL-ALT-DEL.

Common initab Format [id:runlevels:action:process]

Id: unique identifier of one to four characters. Older versions limited to two characters.

runlevels: lists runlevels for which action for this id should be taken. If no runlevels are listed, do action for all runlevels.

action: describes which of several possible actions should be taken.

process tells which process, if any, should be run when action on this line is performed.

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

inittab

17

Ex:Part 1

##inittab This file describes how the INIT process should set up# the system in a certain run-level.##Author: Miquel van Smoorenburg, <[email protected]># Modified for RHS Linux by Marc Ewing and Donnie Barnes## 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:5:initdefault:

Before thinking runlevels, init runs the sysinit script.

# System initialization.si::sysinit:/etc/rc.d/rc.sysinit

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

inittab

18

Ex:Part 2 l0:0:wait:/etc/rc.d/rc 0

l1:1:wait:/etc/rc.d/rc 1l2:2:wait:/etc/rc.d/rc 2l3:3:wait:/etc/rc.d/rc 3l4:4:wait:/etc/rc.d/rc 4l5:5:wait:/etc/rc.d/rc 5l6:6:wait:/etc/rc.d/rc 6

For actual runlevel chosen (before in id:5:initdefault), a script is run – in this case /etc/rc.d/rc 5.

Trap CTRL-ALT-DELETEca::ctrlaltdel:/sbin/shutdown -t3 -r now

Trapping Ctrl-Alt-Delete for keyboard system reboot.

# Run gettys in standard runlevels1:2345:respawn:/sbin/mingetty tty12:2345:respawn:/sbin/mingetty tty23:2345:respawn:/sbin/mingetty tty34:2345:respawn:/sbin/mingetty tty45:2345:respawn:/sbin/mingetty tty56:2345:respawn:/sbin/mingetty tty6# Run xdm in runlevel 5x:5:respawn:/etc/X11/prefdm -nodaemon

In runlevel 2 ,3 , 4, 5, init verifies if the /etc/inittab as the following programs running: (mingetty handles terminal login, and mgetty handles modem dialin access)

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

inittab

19

Ex:Part 3 # 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.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"

Power failure settings.

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Initialization scripts

20

Scripts used by init for: starting the system; shutting down; changing runlevels are typically in /etc/init.d or /etc/rc.d directory.

There’s a series of symbolic links in rcn.d directories. One directory for each runlevel n, They control if the script is started and stopped when entering a runlevel.

/etc/rc.d/rc 0/etc/rc.d/rc 1/etc/rc.d/rc 2/etc/rc.d/rc 3/etc/rc.d/rc 4/etc/rc.d/rc 5/etc/rc.d/rc 6

man init and man inittab

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Init scripts

21

Ex: yourname@yourcomp~# find /etc -path "*rc[0-9]*.d/???au*"/etc/rc.d/rc2.d/S27auditd/etc/rc.d/rc2.d/K72autofs/etc/rc.d/rc4.d/S27auditd/etc/rc.d/rc4.d/S28autofs/etc/rc.d/rc5.d/S27auditd/etc/rc.d/rc5.d/S28autofs/etc/rc.d/rc0.d/K72autofs/etc/rc.d/rc0.d/K73auditd/etc/rc.d/rc6.d/K72autofs/etc/rc.d/rc6.d/K73auditd/etc/rc.d/rc1.d/K72autofs/etc/rc.d/rc1.d/K73auditd/etc/rc.d/rc3.d/S27auditd/etc/rc.d/rc3.d/S28autofs

yourname@yourcomp~# cd /etc/rc.d/rc5.dyourname@yourcomp rc5.d# ls -l ???a*lrwxrwxrwx 1 root root 16 2008-04-07 11:29 S27auditd -> ../init.d/auditdlrwxrwxrwx 1 root root 16 2008-04-01 07:51 S28autofs -> ../init.d/autofslrwxrwxrwx 1 root root 15 2008-04-01 14:03 S44acpid -> ../init.d/acpidlrwxrwxrwx 1 root root 13 2008-04-01 07:50 S95atd -> ../init.d/atdlrwxrwxrwx 1 root root 22 2008-04-01 07:54 S96avahi-daemon -> ../init.d/avahi-daemonlrwxrwxrwx 1 root root 17 2008-11-17 13:40 S99anacron -> ../init.d/anacron

The links have: K (stopped) or S (Started); two-digit number (priority), name of service

Here audit and autofs services have Knn entries in all runlevels and Snn entries for runlevels 3 and 5. S indicates that the service is started when that runlevel is entered, K indicates that it should be stopped.

nn component of link name indicates priority order in which the service should be started or stopped. In example, audit is started before autofs, and it is stopped later.

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

/etc/rc.d/rc.sysinit

22

Important tasks include:

•Activate udev and selinux•Sets kernel parameters in /etc/sysctl.conf•Sets the system clock•Loads keymaps•Enables swap partitions•Sets hostname•Root filesystem check and remount•Activate RAID and LVM devices•Enable disk quotas•Check and mount other filesystems•Cleans up stale locks and PID files

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

/etc/rc.d/rc

23

Initializes the default run level per the /etc/inittab file initdefault line such as id:3:initdefault:

10:0:wait:/etc/rc.d/rc 011:1:wait:/etc/rc.d/rc 112:2:wait:/etc/rc.d/rc 213:3:wait:/etc/rc.d/rc 3 (default)14:4:wait:/etc/rc.d/rc 415:5:wait:/etc/rc.d/rc 516:6:wait:/etc/rc.d/rc 6

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

System V run levels

24

Run level defines which services to start

Each run level has a corresponding directory:/etc/rc.d/rcX.d

The System V init scripts reside in:/etc/rc.d/init.d

Symbolic links in the run level directories call theinit.d scripts with a start or stop argument

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

/etc/rc.d/rc.local

25

/etc/rc.d/rc.local

•Run after the run level specific scripts

•Common place for custom modification

•In most cases it is recommended that you create a System V init script in /etc/rc.d/init.d unless the service you are starting is so trivial it doesn't warrant it.

•Existing scripts can be used as a starting point.

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Controlling Services

26

Red Hat utilities to control default service startup

•system-config-services: graphical utility that requires an X interface•ntsysv: ncurses based utility usable in virtual consoles•chkconfig: fast, versatile cmd line utility and usable with scripts and Kickstart installations

Red Hat utilities to control services manually

•service: immediately start or stop a standalone service•chkconfig immediately starts and stops xinetd managed services

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Init vs. Upstart

27

Traditional method of booting a Linux system is based on UNIX System V init process.For systems where everything is known and connected when the system starts it works well

1st Involves loading initial RAM disk (initrd)

2nd passing control to a program called init (init program is installed as part of sysvinit package)

3rd init program runs a series of scripts in a predefined order to bring up the system.If something that is expected is not available, the init process typically waits for it.

Modern systems with hot-pluggable devices, network file systems, present new challenges.waiting for hardware that may come available later, is not desirable.

An alternative initialization process was first introduced in Ubuntu 6.10 ("Edgy Eft") in 2006. It’s called upstart Has supplanted the init process in Ubuntu, Fedora, and others, with vestiges of init remaining and still in use

http://upstart.ubuntu.com/

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Upstart

28

In contrast to the static init scripts the upstart system is driven by events.

Events triggered by hardware changes, started or stoped tasks, by processes on the system.

Example:connecting a USB drive might cause udev service to send a block-device-added event, which would cause a defined task to check /etc/fstab and mount the drive.

upstart initialization program replaces /sbin/init.

•Upstart jobs are defined in /etc/init directory and subdirectories.

•upstart system will process /etc/inittab and System V init scripts.

New RHL-Fedora /etc/inittab contains only id entry for initdefault; New Ubuntu does not have /etc/inittab (must create one to specify a default runlevel).

Events are used to trigger tasks or services (known as jobs).

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Upstart

29

init loads the inittab, specifying what the default runlevel should be, then additional configuration files specify what software needs to be started.

init starts running all of the specified startup scripts at this point.Services are started by init, including network configurations, X Windows, network services, databases, etc.

Eventually, login processes are started and the boot process is complete!

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Upstart

30

RHEL 6 marks Red Hat’s departure from old style SystemV initialization framework. Time to [mostly] forget about inittab!

RHEL 6 now uses Upstart to handle startup, shutdown and service management.http://upstart.ubuntu.com

The only configuration /etc/inittab provides is what default runlevel should be, as Upstart supports notion of runlevels to ease transition from SysV style initialization to Upstart.

Configuration files for Upstart are under: /etc/initFiles in this directory detail configuration for certain global events, like ctrl-alt-delete, as well as maintaining TTY gettys, handling runlevels and more.

A runlevel defines what services are running...

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Upstart

31

RH Runlevels:System startup

0: OS stopped, machine halted ( usually powers off as well )

1: Single user mode - for maintenance

2: Multiuser, no NFS shares

3: Full multiuser, TUI

4: Unused

5: Full multiuser, GUI

6: Reboot

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Upstart flow operation

32

At bootup, the kernel starts /sbin/init. After /sbin/ init loads configuration files and is ready, the first event is emitted: startup

startup event causes /etc/init/rcS.conf to fire, which in turn runs /etc/rc.d/rc.sysinit. After rc.sysinit finishes, rcS.conf uses /etc/inittab to determine the default runlevel, then

runs telinit to that runlevel.

telinit emits the runlevel event, which fires off /etc/init/rc.conf

rc.conf fires off the familiar /etc/rc.d/rc script with the appropriate runlevel to fire off all of the startup scripts in the appropriate /etc/rcX.d directory.

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

init scripts

33

What is actually running in a runlevel is defined by init scripts for that level.Standard location for the init scripts is: /etc/rcX.dWhere X corresponds to the runlevel

Example: /etc/rc5.d contains all of the init scripts that, combined, provide runlevel 5 service

Files in rc directories start with either an S or K:

•S means to start the service, ie run the command with “start” as an argument•K means to kill the service, ie run the command with “stop” as an argument

After S or K, there is two digit number used for ordering the execution of the scripts

So when init process “enters” a runlevel, the steps are:1.Run all of the Kill scripts, in order, with “stop” as an argument2.Run all of the Start scripts, in order, with “start” as anargument

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

init scripts

34

If you look closely, you will see that /etc/rcX.d actually holds a collection of symbolic linksThe actual script files are stored in /etc/init.d

The main reason for this is so that there is only one copy of each init script, reducing the chance that a script change won’t be reflected in all runlevels.

You can run scripts directly, or use service command to start/stop various components of OS.

You can manage links to init scripts manually, or you can use the chkconfig cmd:

chkconfig --listList all processes and display their default status in eachrun-level.

chkconfig [--level levels] name <on|off|reset>will modify chkconfig configuration for a particular service, setting it on/off for the given runlevels.

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Runlevels , shutdown, and reboot

Upstart

35

Upstart has command initctl Gives interaction with upstart init daemon. (start or stop jobs, list jobs, get status of jobs, emit events, restart init process)

Ex: yourname@yourcomp~# initctl listrc stop/waitingtty (/dev/tty3) start/running, process 1486tty (/dev/tty2) start/running, process 1484tty (/dev/tty6) start/running, process 1492tty (/dev/tty5) start/running, process 1490tty (/dev/tty4) start/running, process 1488plymouth-shutdown stop/waitingcontrol-alt-delete stop/waitingsystem-setup-keyboard start/running, process 1000readahead-collector stop/waitingvpnc-cleanup stop/waitingquit-plymouth stop/waitingrcS stop/waitingprefdm start/running, process 1479init-system-dbus stop/waitingck-log-system-restart stop/waitingreadahead stop/waitingck-log-system-start stop/waitingstart-ttys stop/waitingreadahead-disable-services stop/waitingck-log-system-stop stop/waitingrcS-sulogin stop/waitingserial stop/waiting

Core

Lin

ux fo

r Re

d H

at a

nd F

edor

a le

arni

ng u

nder

GN

U F

ree

Doc

umen

tatio

n Li

cens

e -

Copy

left

(c) A

cáci

o O

livei

ra 2

012

Ev

eryo

ne

is p

erm

itte

d to

co

py

and

dis

trib

ute

verb

atim

co

pie

s o

f th

is li

cen

se d

ocu

me

nt,

cha

ngin

g is

allo

wed

Fim de sessão

36


Recommended