L120: Linux System Administration II



Yüklə 1,05 Mb.
səhifə3/16
tarix11.10.2017
ölçüsü1,05 Mb.
#4275
1   2   3   4   5   6   7   8   9   ...   16

Booting Linux



Prerequisites

None



Goals

    • Manage services (e.g mail, webserver, etc) using runlevels

    • Understand the role of the init process and its configuration file /etc/inittab

    • Recognise the three phases of the booting process: Bootlloader, Kernel and Init


Overview
Taking a closer look at the booting process helps troubleshooting when dealing with both hardware and software problems.
We first focus on the role of the init program and its' associated configuration file /etc/inittab. The role of LILO or GRUB is investigated in greater depth. Finally we summarise the booting process. The document "From Power to Bash Prompt" written by Greg O'Keefe as well as the boot(7) manpage are both good references for this module.

1. Understanding Runlevels

Unlike most non-UNIX operating systems which only have 2 modes of functionality (on and off), UNIX operating systems, including Linux, have different runlevels such as "maintenance" runlevel or "multi-user" runlevel, etc.


Runlevels are numbered from 0 to 6 and will vary from one Linux distribution to another. The description for each runlevel functionality is sometimes documented in /etc/inittab.


Example Linux runlevels

Runlevel 0 shuts down the machine safely

the operating system will also attempt to poweroff the system if possible



Runlevel 1 is single user mode

only one terminal is available for the (single) user root

all other users are logged out


Runlevel 2 is multi-user mode, but does not start NFS

most network services like email or web services are also stopped



Runlevel 3 is full multi-user mode. Selected network services are all on

Runlevel 4 is not defined and generally unused

Runlevel 5 is like runlevel 3 but runs a Display Manager as well

Runlevel 6 restarts the machine safely

Highlighted runlevels 0, 1 and 6 offer to the same functionalities for all Linux flavours.



INIT Controls Runlevels
Both init and telinit are used to switch from one runlevel to another. Remember that init is the first program launched after the kernel has accessed the root device.
At boot time init is instructed which runlevel to reach in /etc/inittab with the line:


id:5:initdefault:

When the system is started it is possible to change runlevels by invoking init (or telinit which is a symbolic link pointing at init).

For example we switch to runlevel 4 with either of the next commands:




init 4

telinit 4



The PID for init is always '1'. It is possible to find out which runlevel the system is currently in with the command runlevel




runlevel

N 5

The first number is the previous runlevel (or N if not applicable) and the second number is the current runlevel.




2. Services and Runtime Control Scripts

Each runlevel is characterised by a set of services that are either started or stopped. The services are controlled by runtime control scripts kept in /etc/rc.d/init.d or /etc/init.d. Each rc-script will control the daemon associated with the service using an argument.


Example: restarting the apache server:


/etc/rc.d/init.d/httpd restart



Expected arguments

restart

do stop the start

stop

stop the daemon associated with the service

start

start the service

status

return the status of the services (running or stopped)



Typical services in /etc/rc.d/init.d/

ls /etc/rc.d/init.d/

anacron

cups

identd

kadmin

krb5kdc

mcserv

nscd

random

smb

xfs

apmd

dhcpd

innd

kdcrotate

kudzu

named

ntpd

rawdevices

snmpd

xinetd

arpwatch

functions

ipchains

keytable

ldap

netfs

pcmcia

rhnsd

squid




atd

gpm

iptables

killall

linuxconf

network

portmp

rwhod

sshd




autofs

halt

irda

kprop

lpd

nfs

pgsql

sendmail

syslog




crond

httpd

isdn

krb524

marsrv

nfslock

pppoe

single

tux



Once a service is started it will run until a new runlevel is started.



Selecting Services per Runlevel

We will follow what happens when we switch from one runlevel to another.


Say you want to be in runlevel 2, you would type:



/sbin/init 2

This in turn forces init to read its configuration file /etc/inittab. We will look at this file in detail in the next section. For now we are concerned with the single line in /etc/inittab that will start all the services::





L2:2:wait:/etc/rc.d/rc 2

The “/etc/rc.d/rc 2” command will start scripts in /etc/rc.d/rc2.d starting with an S and will stop of services starting with a K. The next sample listing shows that the httpd deamon will be stopped, while the syslogd daemon





ls /etc/rc.d/rc2.d/ -l | egrep "httpd|syslog"

lrwxrwxrwx 1 root root 15 Mar 23 21:01 /etc/rc.d/rc2.d/K15httpd -> ../init.d/httpd

lrwxrwxrwx 1 root root 16 Mar 20 20:03 /etc/rc.d/rc2.d/S12syslog -> ../init.d/syslog

One can also see that the scripts are symbolic links pointing to the rc-scripts in /etc/rc.d/init.d.


Therefore, if you don't want a process to run in a given runlevel N you can delete the corresponding symlink in /etc/rc.d/rN.d beginning with a S and add one beginning with a K.

Runtime Editors
A runtime editor will automatically manage these symbolic links allowing a system administrator to switch a service on or off per runlevel as needed. Once again different distributions use different tools. Since the LPI certification is vendor independent none of these tools are examinable.

3. The joys of inittab

As promised we next take a closer look at /etc/inttab.


The file has the following structure:


id : runlevel : action : command




The /etc/inittab file

id:3:initdefault:

# System initialization.

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

-----------------------snip----------------------------------

# Trap CTRL-ALT-DELETE

ca::ctrlaltdel:/sbin/shutdown -t3 -r now

-----------------------snip----------------------------------

# Run gettys in standard runlevels

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:respawn:/etc/X11/prefdm –nodaemon

The id field can be anything. If a runlevel is specified then the command and the required action will be performed only at that specific runlevel. If no number is specified then the line is executed at any run level.


Recognisable features in the /etc/inittab file:
The default runlevel: this is set at the beginning of the file with the id id and the action initdefault. Notice that no command is given. This line simply tells init what the default runlevel is.

First program called by init: /etc/rc.d/rc.sysinit. This script sets system defaults such as the PATH variable, determines if networking is allowed, the hostname, etc ...
Default runlevel services: If the default runlevel is 3 then only the line "l3" will be executed. The action is "wait", no other program is launched until all services in run level 3 are running.
The getty terminals: The lines with id's 1-to-6 launch the virtual terminals. This is where you can alter the number of virtual terminals.
Runlevel 5: The final line in inittab launches the Xwindow manager if runlevel 5 is reached.


Remarks:
1. You can set a modem to listen for connections in inittab. If your modem is linked to /dev/ttyS1 then the following line will allow data connections (no fax) after 2 rings:
S1:12345:respawn:/sbin/mgetty -D -x 2 /dev/ttyS1

2. When making changes to /etc/inittab you need to force init to reread this configuration file. This is most easily done using:




/sbin/init q

4. GRUB


During boot-up, boot loaders need to know where the kernel is (usually in /boot) and which device is the root-device.





BOOTLOADER ----> KERNEL ----> / ----> /sbin/init

Alternatively, a boot loader can load a RAM disk into memory containing scripts and kernel modules needed to access the root device. This will be the case when the root-device is handled by non-resident (also called dynamic) modules.





BOOTLOADER -----> INITRD ----> KERNEL ----> / ----> /sbin/init



Common dynamic modules

ext3

Third extended filesystem type

lvm

Logical volume support

raidx

software raid level x support

scsi

SCSI support



  • Installing GRUB

The GRUB boot loader is installed with the command grub-install. Configuration options are stored in the file /boot/grub/menu.lst or /boot/grub/grub.conf. Unlike LILO, GRUB is a small shell that can read certain filesystem. This allows GRUB to read information in the grub.conf or menu.lst files.


Main sections in /boot/grub/grub.conf:or menu.lst

1. General/Global


default image that will boot by default (the first entry is 0)

timeout prompt timeout in seconds
2. Image
title name of the image

root where the 2nd stage bootloader and kernel are e.g (hd0,0) is /dev/hda

kernel path for the kernel starting from the previous root e.g /vmlinuz

ro read-only

root the filesystem root

initrd path to the initial root disk



  • Bootloader Options

It is possible to give parameters at boot time to GRUB. Both loaders have a limited interface which can read user input.


Once the GRUB boot loader has successfully started you will see the main menu screen with a list of menu titles.
Do the following:
1. press 'e' to edit a given menu title

2. scroll down to the line containing 'kernel' and press 'e' again

3. you can add any options here

4. to boot with the current options type 'b' – Otherwise just press return to get the unaltered line back


Notice that pressing the ESC key will bring you back to a previous stage. You can navigate back to the main menu this way.
Alternatively the boot loader configuration files (lilo.conf or grub.conf) can be used to save these option



  • Passing init parameters:

Boot loaders can passe the runlevel parameter to init. Once the kernel is loaded, it will start /sbin/init by default which then takes over the booting process.


Common runlevels are s,single,S,1,2,3,4,5
If no parameters are given, init will launch the default runlevel specified in /etc/inittab.



  • Passing Kernel parameters:

Kernel options are of the form item=value.




Common kernel parameters

acpi=

enable/disable ACPI

init=

tell the kernel which program to start from the root device

mem=

specify amount of RAM to use

root=

specify the root device




Warning! The boot loader kernel parameters are passed to the resident kernel modules only.

In /etc/lilo.conf kernel parameters are declared with the append option.


Examples

append=”pci=bisoirq”

append=”ram=16M”

append=”/dev/hdc=ide-scsi” (for CD writers)


During bootup all kernel messages are logged to /var/log/dmesg by default. This file can either be read or flushed to stdout with the /bin/dmesg utility.



5. From boot to bash

We can now attempt to go through each stage of the booting process.


1. Boot Loader stage:
If the bootloader is successful it will start it's second stage which displays a prompt or a splash image with a list of operating systems or kernels to boot

If an initial ram disk is specified it is loaded here.

The kernel is loaded into memory

2. Kernel Stage
The kernel is loaded from the medium, specified in the lilo.conf/grub.conf configuration file. As it loads it is decompressed. If an initial ramdisk is loaded, extra modules are loaded here
The kernel will scan the hardware in the system: CPU, RAM, PCI bus, etc

The kernel then mounts the root device as read-only.

From here on programs in /bin and /sbin are made available.

The kernel then loads /sbin/init - the first 'userspace' process.


3. The INIT stage
Init reads /etc/inittab and follows the instructions

the default runlevel is read

the rc.sysinit is run:

- alll local filesystems are mounted or, if needed, an integrity check (fsck) is performed in accordance with entries in /etc/fstab

- quotas are started, etc ...

next init goes into the default runlevel /etc/rc.d/rc N

the gettys start and the boot process is over
The prompt to login is now managed by the gettys on the ttys. After the user has typed in their username and pressed return;
/bin/login is started.
T
he user is prompted by /bin/login for the password. The user enters a password and presses return.

The password the user is compared to the password in /etc/passwd or /etc/shadow.


6. Exercises and Summary



Files


Files

Description

/etc/init.d

directory containing all the scripts used to stop and start services at boot time

/etc/inittab

inittab(5) - The inittab file describes which processes are started at boot-up and during normal operation. Init distinguishes multiple runlevels, each of which can have its own set of processes that are started


Commands


Commands

Description

init

init(8) – is the parent of all processes. Its primary role is to create processes from a script stored in the file /etc/inittab

shutdown

shutdown(8) – brings the system down in a secure way. All logged-in users are notified that the system is going down, and login(1) is blocked. It is possible to shut the system down immediately or after a specified delay. All processes are first notified that the system is going down by the signal SIGTERM. This gives programs like vi(1) the time to save the file being edited, mail and news processing programs a chance to exit cleanly, etc. shutdown does its job by signalling the init process, asking it to change the runlevel


References
Take a look at the boot(7) manpage, it covers most of what we did in this module


Yüklə 1,05 Mb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9   ...   16




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©www.genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə