Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Revision no.

: PPT/2K403/02

The Runlevel Concept


Revision no.: PPT/2K403/02

The Runlevel Concept


2

• Booting Sequence.

• The init program.

• The Run-levels.

• The File /etc/initab.

• The init Scripts

• Changing the Run-levels.

• /etc/sysconfig/ * and SuSEconfig

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

Booting Sequence
3

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

Booting Sequence (contd.)


4

– BIOS- Grub – Kernel : The first three significant steps when Linux
computer is started.
– The kernel uncompress itself and organizes the subsequent
booting of the system.
– It searches for the RAM disk, providing one is available.
– This depends on whether GRUB (Grand Unified Bootloader) has
loaded initrd (/boot/initrd).
– If initrd exists, it is integrated into kernel.
– Then linuxrc is started, it loads the modules required to mount the
root file system.

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

Booting Sequence (contd.)


5

– When this script is finished, the kernel removes initrd from the
system.

– If no initrd exists, the drivers to mount the file system are already
in the kernel.

– The kernel can now boot from hard drive and starts the first
process: init .

– This starts all further processes and scripts required to initialize


the system.

– The system is then up and running.

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

The init Program


6

– Initialization of the system is done by /sbin/init, started by the


kernel as the first process of the system.

– init thus controls the entire booting of the system as well as the
shutting down, because init is the last process running, ensuring
that all other processes are correctly ended.

– The central configuration file of init is /etc/inittab.

– This file determines what is to be happen in the individual run-


levels.

– Various scripts are started by init ,are located in the directory


/etc/init.d .

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

The Runlevel
7

– Which runlevel system starts in when it is booted is defined in the


file /etc/inittab by entry initdefault.
– The standard runlevel is normally 3 or 5.
– The system administrator can also changed to another runlevel at
later time, for example :
• localhost:- # init 1
– The available runlevels are:
• Runlevel Meaning
• 0 Halt
• 1 Single user mode.
• 2 Multiuser mode without Network server services.
• 3 Multiusermode with network(standard).
• 4 Free.
• 5 Multiuser mode with network and display manager..
• 6 Reboot.
© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

The File /etc/inittab


8

– The init process ensures that all actions specified there are
carried out.
– The format of this file is :
• id:runlevel:action:process
– id is unique name for the entry in /etc/inittab; it can be up to four
characters in length.
– runlevel refers to one or more runlevels in which this entry should be
evaluated.
– action describes what init is to do.
– process is the process connected to this entry.

– The /etc/inittab contains the following entries:


• id:5:initdefault :

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

The File /etc/inittab (contd.)


9

– The next entries describes the actions for runlevels 0 to 6


• 10:0:wait:/etc/init.d/rc 0
• 11:0:wait:/etc/init.d/rc 1
• 12:0:wait:/etc/init.d/rc 2
• 13:0:wait:/etc/init.d/rc 3
• 14:0:wait:/etc/init.d/rc 4
• 15:0:wait:/etc/init.d/rc 5
• 16:0:wait:/etc/init.d/rc 6
– wait means that when changing to the level, the appropriate
command is carried out and init waits until it has been completed.
– wait also means that further entries for level are only performed
after this process is completed.

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

The File /etc/inittab (contd.)


10

– Linux also has Ctrl + Alt +Del key combination for restarting.
• ca:ctrlaltdel:/sbin/shutdown –r –t 4 now
– Following block describes in which runlevels getty
processes (login processes) are started.
• 1.2345:respawn:/sbin/mingetty –noclear tty1
• 2:2345:respawn:/sbin/mingetty tty2
• 3:2345:respawn:/sbin/mingetty tty3
• 4:2345:respawn:/sbin/mingetty tty4
– The getty processes provide the login prompt and in return
expect a user name as input.
– If the line is disabled, no further login is possible at
corresponding virtual console.

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

The init Scripts


11

• In the directory /etc/init.d, all the scripts used to start and stop
services are located.
– These scripts are called in different ways :
• Called up directly by init when the system is booted or when the
system is shut down.
• Called up indirectly by init when changing the runlevel.
• Called up directly by /etc/init.d/script start or stop

– Each of these scripts in /etc/init.d/ is run both as start script and


stop scripts.
– For this reason they must understand different parameters as
shown ;

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

The init Scripts (contd.)


12

Parameter Description
– start Starts a service that is not running
– stop Stops the service that is running
– restart Stops the service that is running and starts
again.
– reload Rereads the configuration of the service without
stopping and restarting the service.
– status Displays the current status of the Service

– Important scripts are briefly described below:


• boot
– This scripts is started directly by init when the system starts.
– It evaluates the directory /etc/init.d/boot.d and starts all scripts linked to
file names with an “S” at the beginning of their names.

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

The init Scripts (contd.)


13

– These scripts perform a number of tasks:


» The kernel daemon is started, which takes over the automatic loading
of kernel modules
» The file systems are checked.
» Superfluous files in /var/lock/ are deleted.
» The system time is set.
» Plug and play hardware is configured.
• halt
– This script is run if runlevel 0 or 6 is started.It is called up either with
halt(shutdown) or with reboot .

• rc
– This scripts is responsible for the correct change from one runlevel to
another one.
– It runs the stop scripts for the current runlevel then the start scripts for
new one.

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

Changing the Runlevel


14

– When the runlevel is changed, first the stop scripts of the current
runlevel are run, then the start scripts of new runlevel.
– These scripts for each runlevel are located in the directories
/etc/init.d/rcrunlevel.d .
– All the start scripts begin with an “S”and stop scripts with “K”.
– The following example illustrates how changes from runlevel 3 to
runlevel 5 takes place.
• The system is running in runlevel 3. If the administrator (root) now
enters init5.
• init consults the configuration file /etc/inittab to find out which script
to run when changing to this runlevel: /etc/init.d/rc with parameter 5.

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

Changing the Runlevel (contd.)


15

• Now programs rc compares all the stop scripts of runlevel with the
start scripts of runlevel 5.If there is not matching , stop scripts is
started, ending the service.
• Then the start scripts of runlevel 5 are compared with the stop scripts
of runlevel 3.
• If there is no matching, start script is started, starting the service.

– If you want inittab to be reread without changing the runlevel,


enter init q .
– init will then just load /etc/inittab again,look for the changes in it
and modify the runlevel according to it.

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

shutdown and halt


16

– There are some useful commands for properly shutting down the
system or restarting it:
Command Description
• halt Ensures an immediate, controlled system
halt.
• poweroff Same effect a halt,except that machine is
switched off automatically if possible.
• reboot Reboots the system.
• shutdown –h time Shuts down the system after the specified
time.with option –r instead of –h, the
system is rebooted.without option it changes to
runlevel 1.
– The shutdown command can also be given with warning message,
# shutdown +5 The new hard drive arrived
– The shutdown command can be revoked by, shutdown -c

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

/etc/sysconfig/* and SUSE config


17

– The configuration of SUSE Linux is generally controlled by the


files in the directory /etc/sysconfig .
– If changes are made to the files in the directory /etc/sysconfig,
SuSEconfig(/sbin/SuSEconfig) must be started.
– SuSEconfig is divided into number of scripts.
– These are located in the directory /sbin/conf.d and their names all
begin with SuSEconfig.
– After the corresponding file in the directory /etc/sysconfig has
been edited and SuSEconfig run, all files are updated, the services
involved still need to be reinitialized.

© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute
Revision no.: PPT/2K403/02

18

Design & Published by:


CMS Institute, Design & Development Centre, CMS House, Plot No. 91, Street No.7,
MIDC, Marol, Andheri (E), Mumbai –400093, Tel: 91-22-28216511, 28329198
Email: courseware.inst@cmail.cms.co.in
www.cmsinstitute.co.in
© CMS INSTITUTE, 2004. All rights reserved. No part of this material may be reproduced, stored or emailed without the prior permission of Programme Director, CMS Institute

You might also like