Presentation - Franklin University

Download Report

Transcript Presentation - Franklin University

itec 400
System Startup/Shutdown
George Vaughan
Franklin University
1
Topics
• System Startup
• System Shutdown
2
Booting A System
•
•
•
Booting a system is the sequence of
events necessary to start a computer.
The services normally available on a
running system do not yet exist when a
system starts.
Therefore, the system must “pull itself up
by its own bootstraps”.
3
Booting A System
• An operating system like Linux/Unix is
complex with many subsystems.
• For Linux to run properly, many of these
subsystems dependent on each other
must be running concurrently.
• When Linux/Unix starts, many of these
subsystems are not yet available.
• Therefore, special procedures are needed
to get Linux/Unix into a running state.
4
Booting A System
• A car is a similar example:
– In order for the engine to run, it needs the
services of the alternator to generate
electricity for the spark plugs.
– However, for the alternator to generate
electricity, it needs the services of the engine
to spin its rotor.
– If the alternator and engine need each other
to function how can we start the engine?
5
Booting A System
• The car, like the an operating system
needs a special procedure to get the car
into a running state.
• In the case of the car, we use a starter
motor which turns over the engine which
then spins the rotor on the alternator.
• Once the engine has started, the starter
motor turns off and no longer plays a role.
6
Booting A System
• In this lecture, we will study the sequence of
events and special procedures needed to get an
operating system like Linux and Unix in running
order.
• The book has a nice presentation on Sun
Solaris.
• The lecture will focus on Red Hat Linux running
on an Intel x86 processor.
• Both Red Hat Linux and Solaris are based on
the Unix System V boot process and therefore
share a very similar boot sequence.
7
Boot Sequence Summary
• Below is a very High Level view of the
Linux/Unix boot sequence:
1.Find and Load the Kernel
2.Kernel Execution
3.Init Process Execution
• Step 1 is dependent on the hardware
• Steps 2 and 3 are platform independent
• Lecture devote many slides to each step
8
What is the Kernel?
• We will spend quite a bit of time studying
how the Kernel is located and executed in
the boot process.
• But, what is the kernel?
• Why is there so much attention paid
loading and executing the kernel?
• Is the kernel yet another Unix or Linux
Process?
9
What is the Kernel?
• The kernel is the heart of an operating system.
– It is in memory all the time
– It is NOT a Unix/Linux process
– It is the software that creates the environment for
processes to exist. Processes cannot exist without the
kernel
– It manages process scheduling
– It manages file system access
– It manages virtual memory
– It manages inter-process communication
– It manages user privileges
10
What is the Kernel?
• Technically, when we talk about Linux or Unix, we are
talking about the kernel itself.
• Everything else that we think of in Unix and Linux are
applications and libraries running on top of the kernel.
• In Red Hat Enterprise Linux, the kernel is located at:
/boot/vmlinuz-*
• The objective of the first step in the boot sequence is to
find and execute this file on disk.
• Remember, since the operating system is not yet
functional, the computer cannot use the O.S. to
locate and load the kernel.
• Hence we need something like the starter motor in a car.
11
Step 1: Find and Load the Kernel
•
Finding and Loading The Kernel has
several steps of its own:
a.
b.
c.
d.
e.
f.
Power Switch turned On
BIOS
Master Boot Record (MBR)
Boot Loader
Kernel Loaded
Drivers Loaded
12
Step 1a: Power Switch turned On
• When the computer is first turned on, there is nothing but
random values in its RAM (Random Access Memory).
• When the computer is first turned on, the CPU goes into
RESET mode.
• Upon reset, the CPU is preprogrammed to begin
execution at hex address location 0xfffffff0.
• Address 0xfffffff0 is mapped to ROM (Read Only
Memory).
• This ROM address location contains a set of routines
burned into a ROM (Read Only Memory) chip.
• In the x86 architecture, these routines in ROM are
referred to as the BIOS (Basic Input/Output System).
13
Step 1b: BIOS
• As mentioned previously, the BIOS is a set
of Input and Output routines.
• The BIOS is used by MS-DOS for low
level I/O control (device drivers).
• In the case of Linux, the BIOS is only used
during the boot sequence.
• After Linux is booted, it uses its own set of
routines for low level I/O control.
14
Step 1b: BIOS
• Since we don’t have a running O.S. yet,
the I/O routines in the BIOS are the only
method we have for accessing the disk.
• The BIOS will attempt to load the whatever
it finds on track 0, sector 1 of the boot
device (usually a hard disk).
• Track 0, sector 1 is called the “Master Boot
Record” (MBR).
15
Step 1c: Master Boot Record
• The Master Boot Record (MBR) is only 512
bytes in size.
• The MBR contains:
– Disk Partition Table (defining where and how big the
partitions are on the given disk)
– Executable code which is the first part of the boot
loader.
• The MBR is independent of any O.S. (since the
boot loader it contains is executed before any
O.S. is running)
• The MBR lives outside of any disk partition.
16
Step 1d: Boot Loader
• The Boot Loader is responsible for loading
the kernel into memory.
• In most Linux distributions, there are 2
different boot loaders to chose from:
– lilo (LInux Loader): This is the older boot
loader.
– GNU GRUB (GRand Unified Boot loader) .
More flexible, more complex.
17
Step 1d: Boot Loader
• More sophisticated boot loaders like LILO and
GRUB can be configured to support multiple
OSs.
• For example, I use GRUB to allow me the choice
of either booting Linux or Windows.
• A boot loader maybe used to allow one a choice
of booting different versions of the same OS.
• Boot Loaders are independent of OS type
(again, because there is no OS running yet).
18
Step 1d: Boot Loader
• Remember that the boot loader is the executable code in
the MBR.
• Remember that the boot loader must share the 512 byte
MBR with the partition table.
• Boot loaders like LILO and GRUB are too big to fit in the
MBR.
• So LILO and GRUB are each divided into 2 parts:
– One part fits in the MBR. It locates the second part of the MBR.
Its role is to locate the second (larger) part of the boot loader.
– The second part of the boot loader lives outside of the MBR. It
lives in the first sector of the “Active” partition known as the “Boot
Sector”. This second part of the boot loader does the real work of
locating and loading the kernel.
19
Step 1e: Kernel Loaded
• Once the boot loader is loaded into a memory, it
usually offers the user a choice of OS kernels
(e.g. Windows or Linux) to boot from.
• The user either specifies a kernel or, after a
timeout, the boot loader will load the default
kernel
• The default is user configurable.
• In the case of GRUB and Red Hat Linux, the
GRUB configuration file is located at:
/boot/grub/grub.conf
20
Step 1f: Drivers Loaded
• A RAM disk image is loaded into memory
– it is named “initrd” and is located at:
/boot/initrd-2.4.20-8.img
• “initrd” contains a set of hardware drivers
which are needed to boot the system.
• Once the boot loader has loaded the
drivers, it turns execution over to the
kernel.
21
Step 2: Kernel Execution
•
Kernel Execution also is composed of
several steps:
a.
b.
c.
d.
e.
Memory Size Determination
Hardware Configuration
Kernel Data Structure Initialization
Mount root partition
Hand Crafted Init Process
22
Step 2a: Memory Size
Determination
• At this step, the kernel determines the
total amount of RAM available on the
machine.
• The amount of memory available to user
processes will be less than this because
the kernel will use some of this memory for
its own data structures.
23
Step 2b: Hardware Configuration
• In this phase, the kernel attempts to
configure the system hardware based on:
– Kernel configuration information
– Probing the system bus
– Querying drivers for information
• Devices that are missing drivers or do not
respond to probes are disabled.
24
Step 2c: Kernel Data Structure
Initialization
• Before the kernel can allow processes to
exist, it must initialize various data
structures used for process management
25
Step 2d: Mount root partition
• The kernel mounts the root partition in
“read-only” mode.
• This done so the root partition can still be
checked for errors. A partition should not
be checked for errors in “read-write” mode.
26
Step 2e: Hand Crafted Init Process
• After the hardware is configured, the kernel starts a few
“spontaneous” processes in the user memory.
• These processes are referred to as “spontaneous” or
“hand crafted” because they are created by the kernel
and not by with the “fork” mechanism used to create all
other processes.
• Of these processes, the most important is ‘init’ which has
a process ID of 1.
• Unlike Solaris, Linux does not have a process with PID
0.
• Once the System processes have been created, the
kernel has completed its role in the boot sequence.
27
init Process
• The init process is an extremely important
process.
• All future processes on a running system are
descendents of the init process during the
system life cycle.
• Init has 2 roles:
– The init process plays an important role during
system startup (which we will see in a moment)
– The init process is the ultimate parent process in a
running system (it never goes away).
28
Step 3: Init Process Execution
•
The init process performs the following steps
by running /etc/rc.d/rc.sysinit script during
system boot:
a.
b.
c.
d.
e.
•
Set system clock
Check and Mount ROOT file system
Activate Paging Mechanism (virtual memory)
Start RAID devices (if any)
Check and Mount Other File Systems
The init process performs the following steps
by using /etc/inittab during system boot:
f. Execution of Run Commands (abbreviated rc)
g. Switch to Multi-User Mode
29
Step 3a: Set System Clock
• Set system clock settings such as Local
Time Zone and whether Universal
Coordinated Time (UTC) is to be used.
• Use settings to set hardware clock
(/sbin/hwclock)
30
Step 3b: Check and Mount ROOT
file system
• Depending on file system types, various file
systems may need to be checked for integrity
(broken file pointers, disconnected inodes, etc)
• File system problems may have been introduced
if the machine if it previously shut down by loss
of power.
• Init runs the command “fsck” (File System
ChecK).
• “fsck” can fix most file system problems –
however, some problems may require manual
intervention.
31
Step 3b: Check and Mount ROOT
file system
• If “fsck” found problems with the ROOT file
system that it could not fix, the
administrator will be given a limited shell to
manually fix the problems.
• If there were no problems or the problems
have been fixed, the ROOT filesystem is
mounted in “read-write” mode.
32
Step 3c: Activate Paging
Mechanism
• Swap device(s) are turned on to support Paging
and Swapping.
• Paging and Swapping are used to support
Virtual Memory.
• Virtual Memory is a technique used to trick the
processor into thinking it has a lot more memory
than really exists.
• Virtual Memory does this using disk space (the
swap device) as if it were extra memory.
33
Step 3d: Start RAID devices (if any)
• RAID devices are activated.
• RAID stands for Redundant Array of
Independent Disks.
• RAID is a technique of grouping disks together
to improve reliability and/or performance.
• In a RAID system it is possible for a disk drive to
go bad without any loss of data.
• We will study RAID systems in a future lecture.
34
Step 3e: Mount local disk partitions
• “fsck” is used to check the integrity of the
remaining filesystems.
• If “fsck” found problems with the a file
system that it could not fix, the
administrator will be given a limited shell to
manually fix the problems.
• If there were no problems or the problems
have been fixed, the remaining filesystems
are mounted in “read-write” mode.
35
Step 3f: Execution of Run
Commands
• A series of scripts called “Run Commands” are executed
in a controlled order by init.
• Init uses a special configuration file called “inittab” to
control order of execution of “Run Commands”.
• “inittab” defines what Run Commands are executed at
which “Run Level”. Run Levels will be defined later.
• Run Commands are used to start services such as web
servers, FTP Servers, print servers, etc.
• Run Commands are also called “rc” files (for “runcom” or
“run command”). Comes from CTSS OS (circa 1965, see
“Origins of Unix”, lecture 1).
• We will see more about Run Commands, and the inittab
later in this lecture.
36
Step 3g: Switch to Multi-User Mode
• After the Run Commands have completed, we
now have a fully running operating system.
• Since all services are now available, we can
allow other users to login.
• When the Run Commands are complete, init
creates the getty (or mingetty) processes.
• The getty processes are what allow users to log
onto the system.
• The operating system has now completed the
boot process.
37
Notes On Single User Mode
• As mentioned previously the boot process may require
administrator intervention.
• Single User Mode allows for manual intervention during
the boot process.
• Single User Mode (also known as the Maintenance
Mode) is a restricted mode used for repairing a system
that won’t boot normally.
• If the system was booted in ‘Single User Mode’, the init
process is notified before it executes the Run
Commands.
• Control is then passed to sulogin (single user login).
38
Notes Single User Mode
• init may also switch to single user mode if
a file system fails a system integrity test
that cannot be automatically handled by
fsck.
• To continue boot process to default multiuser mode:
type: control-d (^d)
39
Some Missing Details
•
•
•
•
•
Run Levels
inittab
Run Commands
how to get to single user mode
The next slide provides a directory map of
the files that play a role in Run Commands
and Run Levels.
40
Directory and File Structure for Run
Commands and Run Levels
/
etc
sbin
init
inittab
init.d
example
rc1.d
rc3.d
rc4.d
rc5.d
rc6.d
rc
examples
Legend
Directory
rc2.d
httpd
K15httpd
S85httpd
File
symbolic links
41
Run Levels
•
•
•
“System V” Unix systems and Linux maintain a concept of run-levels.
The book describes System V run-levels.
In Linux, the run-levels are defined as follows:
– 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 (Graphical User Mode)
– 6 - reboot (Do NOT set initdefault to this)
•
•
For servers, the default run level for multi-user mode is typically 3.
For workstations, the default run level for multi-user mode is typically 5.
42
Run Levels
• How do you know current and previous run
levels?
– Linux: use “runlevel” or “who -r” command.
Example:
# runlevel
S 5
# who -r
run-level 5
May 12 12:08
last=S
– Solaris: use “who –r” command
• How do you change run levels?
– For both Linux and Solaris, use the “telinit” command:
telinit 6 (reboot the system)
43
inittab
• The file /etc/inittab defines what Run
Commands are to be executed at each
run level.
• Used to guide the init process.
• The init process is the process that
actually executes the Run Commands
defined for a given level.
• The command “telinit –q” causes the init
process to re-read inittab.
44
inittab
•
An example of inittab syntax:
l3:3:wait:/etc/rc.d/rc 3
•
Each line contains 4 fields (not all fields need
to be defined).
1. id: inittab entry id (can be null)
2. run-levels: The run levels that this entry applies to
(can be more than one).
3. action: (wait, respawn, once, etc.)
4. process
•
•
The “rc” is the master script used to run all the
start scripts for a given run level.
“rc” is located in /etc.
45
inittab (Sample Subset)
0001: id:5:initdefault:
•
0002:
•
0003: l0:0:wait:/etc/rc.d/rc 0
0004: l1:1:wait:/etc/rc.d/rc 1
0005: l2:2:wait:/etc/rc.d/rc 2
0006: l3:3:wait:/etc/rc.d/rc 3
0007: l4:4:wait:/etc/rc.d/rc 4
•
0008: l5:5:wait:/etc/rc.d/rc 5
0009: l6:6:wait:/etc/rc.d/rc 6
0010:
0011: # Trap CTRL-ALT-DELETE
0012: ca::ctrlaltdel:/sbin/shutdown -t3 -r now
Line 1: define the default target
runlevel
Lines 3-9:
– run the rc script for each runlevel
using the runlevel as the
argument
– “wait” forces init to wait until
process terminates
Line 12: define what happens
when the user presses control-altdelete.
46
inittab (Sample Subset- Cont.)
0014: # Run gettys in standard runlevels
0015: 1:2345:respawn:/sbin/mingetty tty1
0016: 2:2345:respawn:/sbin/mingetty tty2
0017: 3:2345:respawn:/sbin/mingetty tty3
0018: 4:2345:respawn:/sbin/mingetty tty4
0019: 5:2345:respawn:/sbin/mingetty tty5
0020: 6:2345:respawn:/sbin/mingetty tty6
0021:
0022: # Run xdm in runlevel 5
0023: # xdm is now a separate service
0024: x:5:respawn:/etc/X11/prefdm nodaemon
•
Lines 15-20:
– start mingetty for all 6 terminal
ports for all run levels 2 through
5.
– If a mingetty process dies,
restart it.
•
Line 24: start the X display
manager at level 5. If it dies, init
will restart it.
47
Run Commands
• Run Commands are run by /etc/rc.d/rc (shell script)
• Most of the boot configuration is done by adding/deleting
or changing Run Commands.
• Run Commands are shell scripts
• All Run Commands for a given run-level are located in a
unique directory.
• For example, the Run Commands for run level 3 are
located in: /etc/rc.d/rc3.d
• All scripts either begin with ‘K’ for kill or ‘S’ for start.
• Kill scripts are used for shutting down certain services
when we enter given run level.
48
Run Commands
• Start scripts are used for starting certain
services when we enter given run level.
• After ‘K’ or ‘S’, the script contains to digits to
identify order of execution.
• After the 2 digit sequencer follows the rest of the
name.
• Examples in /etc/rc.d/rc3.d:
– K15httpd (kill http daemon (web server) )
– S60lpd (start line printer daemon)
• Many scripts use configuration files in
/etc/sysconfig (RH Linux) or /etc/default (Solaris)
49
How To Get To Single User Mode
• At cold start:
– LILO: At the LILO prompt, type: linux single
– GRUB: see page 136 in text
• Running system (execute as root):
– type: telinit 1
– or type: telinit s
50
System Shutdown
• Don’t just kill the power.
• We want to go through the run levels in
reverse order.
• “shutdown” - safest, most considerate,
most thorough:
shutdown –h 08:00 “System Going Down”
shutdown –h +20 “System Going Down”
shutdown –now
51
System Shutdown
• “halt” – simpler than shutdown
• “reboot” – just like halt except it also
reboots the system.
• telinit 6 - reboot the system
• telinit 1 – go to single user mode.
52
References
• Essential System Administration, Aeleen Frisch, 2002
• Linux Administration Handbook, Evi Nemeth, et. al., 2002
• Understanding The Linux Kernel, Daniel Bovet and Marco Cesati,
2001
• The GNU GRUB Boot loader, Jaswinder Singh Kohli,
http://www.linuxgazette.com/issue64/kohli.html,
• Operating System User's Guide,
http://osr5doc.ca.caldera.com:457/OSUserG/CONTENTS.html
• Red Hat Linux 9: Red Hat Reference Guide,
http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/ref-guide/
• Linux Kernel 2.4 Internals
http://www.faqs.org/docs/kernel_2_4/lki.html#toc2
53