+ All Categories
Home > Documents > 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

Date post: 28-Dec-2015
Category:
Upload: roy-stone
View: 229 times
Download: 1 times
Share this document with a friend
53
1 itec 400 System Startup/Shutdown George Vaughan Franklin University
Transcript
Page 1: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

1

itec 400System Startup/Shutdown

George Vaughan

Franklin University

Page 2: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

2

Topics

• System Startup

• System Shutdown

Page 3: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

3

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”.

Page 4: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

4

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.

Page 5: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

5

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?

Page 6: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

6

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.

Page 7: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

7

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.

Page 8: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

8

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

Page 9: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

9

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?

Page 10: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

10

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

Page 11: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

11

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.

Page 12: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

12

Step 1: Find and Load the Kernel

• Finding and Loading The Kernel has several steps of its own:

a. Power Switch turned On

b. BIOS

c. Master Boot Record (MBR)

d. Boot Loader

e. Kernel Loaded

f. Drivers Loaded

Page 13: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

13

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).

Page 14: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

14

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.

Page 15: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

15

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).

Page 16: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

16

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.

Page 17: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

17

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.

Page 18: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

18

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).

Page 19: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

19

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.

Page 20: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

20

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

Page 21: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

21

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.

Page 22: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

22

Step 2: Kernel Execution

• Kernel Execution also is composed of several steps:

a. Memory Size Determination

b. Hardware Configuration

c. Kernel Data Structure Initialization

d. Mount root partition

e. Hand Crafted Init Process

Page 23: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

23

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.

Page 24: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

24

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.

Page 25: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

25

Step 2c: Kernel Data Structure Initialization

• Before the kernel can allow processes to exist, it must initialize various data structures used for process management

Page 26: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

26

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.

Page 27: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

27

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.

Page 28: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

28

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).

Page 29: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

29

Step 3: Init Process Execution

• The init process performs the following steps by running /etc/rc.d/rc.sysinit script during system boot:

a. Set system clockb. Check and Mount ROOT file systemc. Activate Paging Mechanism (virtual memory)d. Start RAID devices (if any)e. 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

Page 30: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

30

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)

Page 31: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

31

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.

Page 32: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

32

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.

Page 33: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

33

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.

Page 34: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

34

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.

Page 35: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

35

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.

Page 36: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

36

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.

Page 37: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

37

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.

Page 38: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

38

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).

Page 39: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

39

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 multi-user mode:

type: control-d (^d)

Page 40: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

40

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.

Page 41: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

41

Directory and File Structure for Run Commands and Run Levels

Directory

File

Legend

/

sbin

rc.dinittab init.d

httpd

example

init

rc1.d rc6.drc2.d rc3.d rc4.d rc5.d

S85httpdK15httpd

examples

symbolic links

rc

etc

Page 42: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

42

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.

Page 43: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

43

Run Levels

• How do you know current and previous run levels?– Linux: use “runlevel” or “who -r” command.

Example:# runlevelS 5# who -rrun-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)

Page 44: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

44

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.

Page 45: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

45

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.

Page 46: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

46

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-alt-delete.

Page 47: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

47

inittab (Sample Subset- Cont.)0014: # Run gettys in standard runlevels0015: 1:2345:respawn:/sbin/mingetty tty10016: 2:2345:respawn:/sbin/mingetty tty20017: 3:2345:respawn:/sbin/mingetty tty30018: 4:2345:respawn:/sbin/mingetty tty40019: 5:2345:respawn:/sbin/mingetty tty50020: 6:2345:respawn:/sbin/mingetty tty60021:0022: # Run xdm in runlevel 50023: # xdm is now a separate service0024: 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.

Page 48: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

48

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.

Page 49: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

49

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)

Page 50: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

50

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

Page 51: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

51

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

Page 52: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

52

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.

Page 53: 1 itec 400 System Startup/Shutdown George Vaughan Franklin University.

53

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 Internalshttp://www.faqs.org/docs/kernel_2_4/lki.html#toc2


Recommended