Está en la página 1de 35

Linux Based Networks Zahid Shafique, Instructor

Linux Based Networks


Punjab University College of Information Technology

Instructor: Zahid Shafique


<z_shafique@hotmail.com>

Startup & Shutdown Class Meeting # Slide : 1


Linux Based Networks Zahid Shafique, Instructor

System Startup and Initialization

In this section we're going to talk about exactly what happens when the
system boots.

Understanding this process and the files involved is important for


performing various kinds of system configuration.

Startup & Shutdown Class Meeting # Slide : 2


Linux Based Networks Zahid Shafique, Instructor

The Booting Process


• Most UNIX systems support either automatic or manual mode
on the booting process.
• During the boot process the operating system is loaded into
memory and executed.
– Loading and initialization of the kernel.
– Device detection and configuration.
– Creation of spontaneous system processes.
– Operator intervention (manual boot only).
– Execution of system startup scripts.
– Multi-user operation.
• An administrator has little control over most of the steps.
• Most bootstrap configuration is achieved by editing the
system startup scripts.

Startup & Shutdown Class Meeting # Slide : 3


Linux Based Networks Zahid Shafique, Instructor

Steps in the Boot Process


• Kernel Initialization
– The first bootstrapping task.
– The pathname of the kernel is vendor-dependent, eg /unix, /vmunix,
/kernel/genunix, /boot/vmlinux.
• Hardware Configuration
– Check out the machine' s environment to see what hardware is
present. (base on the information during constructing the kernel)
• System Processes
– The kernel creates "spontaneous" processes (not fork process):
swapper – process 0 (sched for System-V-ish),
init – process 1,
pagedaemon – process 2
– Only init is a full-fledged user process. Kernel's role in bootstrapping
is completed at this point.
Startup & Shutdown Class Meeting # Slide : 4
Linux Based Networks Zahid Shafique, Instructor

Steps in the Boot Process


• Operator Intervention (manual boot only)
– The init process is notified via command-line flag passed in by the
kernel. (eg. typing ‘I’ during the boot up or single-user mode in RH)
– Entering a shell if root password is correctly entered or continuing
with the boot process if ^D or exit is pressed.
– Able to execute all commands except those mounted on other file
system than / and the daemon processes like mail. (Red Hat
automatically mount all the file systems)
– fsck must be run by hand, if required.
• Startup Scripts
– The init process runs sh to interpret the scripts.
– They are kept in /etc directory and have names starting with rc
(BSD), and /etc/init.d, /etc/rc1.d… (ATT).
• Multi-User Operation
– The init spawns the several getty (mgetty in Red Hat) processes to
listen the users' login request.
Startup & Shutdown Class Meeting # Slide : 5
Linux Based Networks Zahid Shafique, Instructor

Kernel Boot Messages


The first step is booting the kernel.

This can be done from floppy or hard drive.

As the kernel loads into memory, it will print messages to the


system console.

These messages are all printed by the kernel itself, as each device
driver is initialized.

The exact messages printed depend on what drivers are compiled


into our kernel and what hardware you have on your system.

Startup & Shutdown Class Meeting # Slide : 6


Linux Based Networks Zahid Shafique, Instructor

20480 bytes for swap cache allocated


Console: colour EGA+ 80x25, 8 virtual consoles
Serial driver version 4.00 with no serial options enabled
tty00 at Ox03f8 (irq =4) is a 16450
tty0l at Ox02f8 (irq =3) is a 16450
tty03 at Ox02e8 (irq =3) is a 16550A
snd2 <SoundBlaster Pro 3.2> at 0x220 irq 5 drq 1
sndl <Yamaha OPL-3 FM> at 0x388 irq 0 drq 0
Drive 0: CR-52x-x (2.11)
SBPCD: 1 SoundBlaster cdrom drive(s) at 0x0230..
Calibrating delay loop.. ok - 33.22 BogoMips
Memory: 19312k/20480k available (476k kernel code, 384k reserved, 308k data)
This processor honours the WP bit even when in supervisor mode. Good.
Floppy drivels): fd0 is 1.44M
Swansea University Computer Society NET3.016
Checking 386/387 coupling... Ok, ffu using exception 16 error reporting.
Linux version 1.1.37 (root@loomer) #4 Fri Sep 30 00:08:33 EOT 1994
Partition check:
hda: Maxtor 7213 AT (202MB IDE W/64KB Cache, MaxMult=32, CHS=683/16/38) - hda: hdal
hda2
hdb: MDC AC140M (40MB IDE W/31KB Cache, MaxMult=8, CHS=977/5/17)
hdb: hdbl hdb2
Startup & Shutdown Class Meeting # Slide : 7
Linux Based Networks Zahid Shafique, Instructor

Here's a quick rundown on what they mean.


20480 bytes for swap cache allocated

First, we see that 20 KB have been allocated by the kernel for the "swap
cache,“

Which is used to speed up operations when swapping pages to and from


disk.

Startup & Shutdown Class Meeting # Slide : 8


Linux Based Networks Zahid Shafique, Instructor

Console: color EGA+ 80x25, 8 virtual consoles

Then the console type is printed; note that this involves only the text
mode being used by the kernel, not the capabilities of your video card.

(Even an SVGA video card is reported as Ega+ as far as the console text
mode is concerned.)

Startup & Shutdown Class Meeting # Slide : 9


Linux Based Networks Zahid Shafique, Instructor

ttyOO at Ox03f8 (irq =4) is a 16450

means that the first serial device (/dev/ttyOO, or COM1) was detected at

address Ox03f8, IRQ 4, using 16450 UART functions.

Startup & Shutdown Class Meeting # Slide : 10


Linux Based Networks Zahid Shafique, Instructor

snd2 <SoundBlaster Pro 3.2> at 0x220 irq 5 drq 1

Next, the sound-card driver is initialized; the names and addresses for the
various sound devices are printed

And so on

Startup & Shutdown Class Meeting # Slide : 11


Linux Based Networks Zahid Shafique, Instructor

init and inittab


Once the device drivers are initialized, the kernel executes the program
init, which is found in /etc, /bin, or /sbin (it's /sbin/init on most systems).

init is a general-purpose program that spawns new processes and restarts


certain programs when they exit.

For example, each virtual console has a getty process running on it,
started by init. When you exit from a login session on one of the virtual
consoles, the getty process exits, and init starts a new one, allowing you
to log in again.

Startup & Shutdown Class Meeting # Slide : 12


Linux Based Networks Zahid Shafique, Instructor

init and inittab (cont…)

init is also responsible for running a number of programs and scripts


when the system boots.

Everything init does is controlled by the file /etc/inittab.

Startup & Shutdown Class Meeting # Slide : 13


Linux Based Networks Zahid Shafique, Instructor

Let's take a look at a sample /etc/inittab


#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
# 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:3:initdefault:

Startup & Shutdown Class Meeting # Slide : 14


Linux Based Networks Zahid Shafique, Instructor

sample /etc/inittab
# 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

# Things to run in every runlevel.


ud::once:/sbin/update

Startup & Shutdown Class Meeting # Slide : 15


Linux Based Networks Zahid Shafique, Instructor

# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -h now
# 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"

# 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
# xdm is now a separate service
x:5:respawn:/etc/X11/prefdm -nodaemon

Startup & Shutdown Class Meeting # Slide : 16


Linux Based Networks Zahid Shafique, Instructor

id: 3: initdefault:

First, we see that the default runlevel is set to 3.

The action field for this entry is initdefault, which causes the given
runlevel to be set to the default.

Startup & Shutdown Class Meeting # Slide : 17


Linux Based Networks Zahid Shafique, Instructor

/etc/rc.d/rc.sysinit file

The next entry tells init to execute the script /etc/rc.d/rc.sysinit when the
system boots.

The action field is sysinit, which specifies that this entry should be
executed when init is first started at system boot.

This file is simply a shell script containing commands to handle basic


system initialization

For example, swapping is enabled, file systems are checked and


mounted, and the system clock is synchronized with the CMOS clock.

You can take a look at this file on your system;

Startup & Shutdown Class Meeting # Slide : 18


Linux Based Networks Zahid Shafique, Instructor

/etc/rc.d/rc

Next, we see that the script /etc/rc.d/rc is executed when


entering any of the run-levels 0 through 6, with the appropriate
runlevel as an argument,

rc is a generic startup script which executes other scripts as


appropriate for that runlevel.

The action field here is wait, which tells init to execute the given
command, and to wait for it to complete execution before doing
anything else.

Startup & Shutdown Class Meeting # Slide : 19


Linux Based Networks Zahid Shafique, Instructor

/etc/rc.d/rcN.d directories
If you look at the code for /etc/rc.d/rc (it should be a shell script) you'll
see that it runs a series of scripts in /etc/rc.d/rcN.d where N is the
runlevel being started.
For runlevel 3, scripts in /etc/rc.d/rc3.d would be used.

These scripts all have filenames of the form Snnxxxx or Knnxxxx,


where nn is a number from 00 to 99,
and xxxx is the name of some system service.
The numbers nn are used to enforce an ordering on the scripts as they are
executed;
The name xxxx is simply used to identify which system service the script
corresponds to.
Scripts beginning with S are used to start system services,
and those beginning with K are used to kill (or stop) system services.

Startup & Shutdown Class Meeting # Slide : 20


Linux Based Networks Zahid Shafique, Instructor

/etc/rc.d/rc.local

Another important system configuration script is /etc/rc.d/rc.local,


which is executed after the other system-initialization scripts are
run.
How is this accomplished? Generally, a symbolic link to rc.local is
made in each /etc/rc.d/rcN.d directory with the name S99local.
Since 99 is the largest numerical order any of the S scripts can
have, it is executed last. You can edit rc.local to accomplish any
peculiar or otherwise out-of-place system commands at boot time,
or if you're not sure where else they should be executed.

Startup & Shutdown Class Meeting # Slide : 21


Linux Based Networks Zahid Shafique, Instructor

Most of the scripts accept arguments that control


their operations. The most common arguments
are:
• start
• stop
• restart
• reload
• status

Startup & Shutdown Class Meeting # Slide : 22


Linux Based Networks Zahid Shafique, Instructor

Manually starting and stopping service


We can manually start and stop service

/etc/rc.d/init.d/smb stop

/etc/rc.d/init.d/smb restart

Startup & Shutdown Class Meeting # Slide : 23


Linux Based Networks Zahid Shafique, Instructor

Associating Services with Run levels


We can associate a service with its runlevel by

• Creating and manipulating symbolic links .


• checkconfig utility.
• Setup tool.

Startup & Shutdown Class Meeting # Slide : 24


Linux Based Networks Zahid Shafique, Instructor

Chkconfig tool
• Checkconfig tool lets you:
– List installed services
– Add a service
– Delete a service
– Associate a service with a runlevel

Startup & Shutdown Class Meeting # Slide : 25


Linux Based Networks Zahid Shafique, Instructor

Listing Services

#chkconfig --list

#chkconfig –list | sort

Startup & Shutdown Class Meeting # Slide : 26


Linux Based Networks Zahid Shafique, Instructor

Adding a service
• To add a service, you must first ensure that the
associated init.d script contains special
comments.
• The comment line contains the tokens
#chkconfig
And then lists the run level

#chkconfig 25 20 80

Startup & Shutdown Class Meeting # Slide : 27


Linux Based Networks Zahid Shafique, Instructor

Adding a service

#chkconfig - -add name

#chkconfig - -add smb

Startup & Shutdown Class Meeting # Slide : 28


Linux Based Networks Zahid Shafique, Instructor

Deleting a service

#chkconfig - -del name

#chkconfig - -del smb

Startup & Shutdown Class Meeting # Slide : 29


Linux Based Networks Zahid Shafique, Instructor

Associating a service with run level

#chkconfig - -level levels name

#chkconfig - - level 35 smb on

#chkconfig - - level 35 smb off

Startup & Shutdown Class Meeting # Slide : 30


Linux Based Networks Zahid Shafique, Instructor

What if the System won't Boot?


• Hardware problems
– Check power supply to each component (cord/switch).
Check cables. Recycle power on all components.
– If the kernel gets to probing devices and one doesn't
appear then it is broken or improperly connected. Try to
run hardware diagnostics.
• Damaged file systems
– Soft: scrambled or lost information on disk.
• Try to boot the system from an alternative boot partition. OR
• Try to boot into single user mode, then use fsck and hope it will fix
the problem. In particular, if you get messages about inodes,
superblock, maps or filesystems, this may solve the problem.
• Try to boot from distribution media and mount the other filesystems,
dump them and reload the operating system.
– Hard: disk head crash.
• Buy a new disk and restore backup. (or RAID)

Startup & Shutdown Class Meeting # Slide : 31


Linux Based Networks Zahid Shafique, Instructor

What if the System won't Boot?


• Defective boot blocks
– Many Unix systems read a boot block (MBR) first before
the kernel. If this is damaged try to boot from
distribution media (or another disk).
– Try to reinstall the boot block with /sbin/lilo command.
• Improperly configured kernel
– happen after a kernel rebuild or updated.
– Make sure to keep the old kernel where you can boot
from it.
• Errors in startup scripts
– Happen when you modify the scripts.
– Remember to backup your scripts before make change.
Startup & Shutdown Class Meeting # Slide : 32
Linux Based Networks Zahid Shafique, Instructor

Today’s Agenda

Startup & Shutdown Class Meeting # Slide : 33


Linux Based Networks Zahid Shafique, Instructor

Exercise:

Startup & Shutdown Class Meeting # Slide : 34


Linux Based Networks Zahid Shafique, Instructor

Homework
• Homework this week:

• Next week:

Startup & Shutdown Class Meeting # Slide : 35

También podría gustarte