unix startup procedure

52
1 www.mi.chu.edu .tw unix.administr ation Unix Startup procedure Boot strap Kernel Initialization, Hardware probing. Creation of Swapper&init Init executes rc scripts Init reads terminal configuration file Getty process started (BSD) /etc/ttys (Sys V) /etc/inittab ROM Single User Mode single or multi-user? Getty process started

Upload: yahto

Post on 19-Jan-2016

17 views

Category:

Documents


0 download

DESCRIPTION

ROM. Unix Startup procedure. Boot strap. Kernel Initialization,. Single User Mode. Hardware probing. Creation of. Init executes. Swapper&init. rc scripts. single or. multi-user?. / etc/ttys. Init reads terminal. / etc/inittab. ( BSD ). configuration file. ( Sys V). - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Unix Startup procedure

1 www.mi.chu.edu.twunix.administration

Unix Startup procedureBoot strap

Kernel Initialization,Hardware probing.

Creation ofSwapper&init

Init executesrc scripts

Init reads terminalconfiguration file

Getty process started

(BSD)/etc/ttys

(Sys V)/etc/inittab

ROM

Single User Mode

single ormulti-user?

Getty process started

Page 2: Unix Startup procedure

2 www.mi.chu.edu.twunix.administration

ROM & Boot strap ROM: that contains a program the machine

executes when the power first comes on.– IBM PC– UNIX hardware has some form of prompt to

allow administrator to• specify where to boot the machine from (boot

partition corrupt, then from another HD, CD-ROM, floppy, tape drive)

• come up in single user or multi-user mode.

Page 3: Unix Startup procedure

3 www.mi.chu.edu.twunix.administration

ROM & Bootstrapping The Bootstrap Program

– The code stored in the boot block is referred to as a bootstrap program, executed by ROM

– responsible for locating and loading the kernel of UNIX operating system into memory from disk.

– On some systems, it also perform some additional hardware probing.System Filename

/vmunix BSD/unix SysV/vmlinuz Linux

Page 4: Unix Startup procedure

4 www.mi.chu.edu.twunix.administration

Kernel Initialization Test RAM & reserve part of RAM for

Kernel, or print available RAM initialise its internal data structures,

Page 5: Unix Startup procedure

5 www.mi.chu.edu.twunix.administration

Kernel Initialization perform some further hardware checking for

major devices supposed to be connected, probe bus for devices and ask drivers. If no

positive response, disable it. Create spontaneous processes, so called

because they are not created by fork().– process 0,swapper/sched & 1,init/init &

2,pagedaemon/various handler for BSD/System V– no visible process 0 & 1, init & kflushd,kupdate,

kpiod, kswapd

Page 6: Unix Startup procedure

6 www.mi.chu.edu.twunix.administration

System Processes process 0 (swapper) & process 1 (init).

– swapper process is actually part of the kernel and is not a "real" process.

– init process is the ultimate parent of all processes that will execute on a UNIX system.

• Going into multi-user mode,init process must execute many system startup scripts. These startup scripts are Bourne shell scripts stored under the /etc directory.

• One of the last steps performed by init is to enable user logins (getty processes).

Page 7: Unix Startup procedure

7 www.mi.chu.edu.twunix.administration

Single/Multi-User All UNIX machine can be in 2 basic states

– multi-user mode• standard mode for a UNIX machine.

• Multiple users are allowed to log in, all the daemons and all the services provided by the machine are available.

– single user mode.• system maintenance mode.

• In single user mode only the bare minimum of services are available.

Page 8: Unix Startup procedure

8 www.mi.chu.edu.twunix.administration

Single/Multi-User– single user mode.

• Only one user (the root user) will be able to log in, only the root file system will be mounted automatically (others may be able to be mounted manually) and most of the daemons and services will not be available.

two reasons to come up in single user mode– root wanted to perform system maintenance.– the boot procedure has failed, caused by some

errors in the initialisation files or by fsck detecting errors that it could not fix by itself.

Page 9: Unix Startup procedure

9 www.mi.chu.edu.twunix.administration

Operator Intervention,manual boot only The init process is notified via command-line

flag passed in by kernel. (e.g. typing ‘I’ during 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 filesystem than / and the daemon processes like mail. (Red Hat automatically mount all the filesystems)

fsck must be run by hand, if required.

Page 10: Unix Startup procedure

10 www.mi.chu.edu.twunix.administration

Startup Scripts 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.

Page 11: Unix Startup procedure

11 www.mi.chu.edu.twunix.administration

System V Run Levels Later versions of System V based Unix

added a number of different run levels shown in Table.

Run level

classify the scripts into groups by level

command “who -r” can be used to display the run level

Page 12: Unix Startup procedure

12 www.mi.chu.edu.twunix.administration

System V Run LevelsState Function

0 prepare the machine for turning off power, if themachine can turn the power off tell it to do so

1 system administrator mode, all file systemsmounted, only small set of kernel processesrunning, single user mode

2 multi-user mode

3 multi-user mode with remote file sharing,processes, and daemons

4 user definable system state

5 shutdown to ROM

6 shutdown and reboot

s,S single-user mode, only root file system mounted

Page 13: Unix Startup procedure

13 www.mi.chu.edu.twunix.administration

System V Run Levels (cont.) As system boots, it will move through the

various run levels (s, 1, 2, 3) under the control of init.

Each run level has associated with it various initialisation scripts that will be executed as the machine enters that run level.

On SysV based machines init goes through run levels is controlled by file /etc/inittab.

Page 14: Unix Startup procedure

14 www.mi.chu.edu.twunix.administration

System V Run Levels (cont.) Entry format of /etc/inittab id:run-state:action:process When init receives notification of an

event, it examine inittab and execute the process specified for that event, controlled by action.

Page 15: Unix Startup procedure

15 www.mi.chu.edu.twunix.administration

System V Run Levels (cont.) Entry format of /etc/inittab id:run-state:action:process

Label Explanationid one or two characters to uniquely

identify the entrystate indicates the run level at which the

process should be executedaction this tells init how to execute

processprocess the full path of a program to execute

for this entry

Page 16: Unix Startup procedure

16 www.mi.chu.edu.twunix.administration

System V Run Levels (cont.) Example values for action include respawn:If process doesn’t exist, create it

but don't wait for termination,carry on immediately. If at any stage the process terminates, restart it (getty for terminals).

Wait:start the process and wait for the process to finish.The process is never executed again until the system receives notification of the event again (This is how system execute initialisation scripts.)

Page 17: Unix Startup procedure

17 www.mi.chu.edu.twunix.administration

System V Run Levels (cont.) once: start the process when entering the

run level, but not wait for it to complete, not restart it if it dies

boot: process the entry only on boot up sysinit: process the entry before

accessing the console and wait for it to complete

Page 18: Unix Startup procedure

18 www.mi.chu.edu.twunix.administration

System V Run Levels (cont.) initfefault: process whem init is

initially invoked - sets the default run-level to enter

bootwait:Execute the process only when the system first goes multi-user and wait for its finish.

powerfail:Execute only when init receives a power fail signal.

Page 19: Unix Startup procedure

19 www.mi.chu.edu.twunix.administration

The /etc/inittab file in SunOSap::sysinit:/sbin/autopush -f /etc/iu.apap::sysinit:/sbin/soconfig -f /etc/sock2pathfs::sysinit:/sbin/rcS >/dev/console 2<>/dev/console </dev/consoleis:3:initdefault:p3:s1234:powerfail:/usr/sbin/shutdown -y -i5 -g0 >/dev/console 2<>/dev/consoles0:0:wait:/sbin/rc0 >/dev/console 2<>/dev/console </dev/consoles1:1:wait:/usr/sbin/shutdown -y -iS -g0 >/dev/console 2<>/dev/console</dev/consoles2:23:wait:/sbin/rc2 >/dev/console 2<>/dev/console </dev/consoles3:3:wait:/sbin/rc3 >/dev/console 2<>/dev/console </dev/consoles5:5:wait:/sbin/rc5 >/dev/console 2<>/dev/console </dev/consoles6:6:wait:/sbin/rc6 >/dev/console 2<>/dev/console </dev/consolefw:0:wait:/sbin/uadmin 2 0 >/dev/console 2<>/dev/console </dev/consoleof:5:wait:/sbin/uadmin 2 6 >/dev/console 2<>/dev/console </dev/consolesc:234:respawn:/usr/lib/saf/sac -t 300co:234:respawn:/usr/lib/saf/ttymon -g -h -p "`uname -n` console login: " -T sun

-d /dev/console -l console -m ldterm,ttcompatml:23456:once:su abaqus57 -c '(umask 022; /usr/local/abapre/bin/flexlm lmgrd)'

ap::sysinit:/sbin/autopush -f /etc/iu.apap::sysinit:/sbin/soconfig -f /etc/sock2pathfs::sysinit:/sbin/rcS >/dev/console 2<>/dev/console </dev/consoleis:3:initdefault:p3:s1234:powerfail:/usr/sbin/shutdown -y -i5 -g0 >/dev/console 2<>/dev/consoles0:0:wait:/sbin/rc0 >/dev/console 2<>/dev/console </dev/consoles1:1:wait:/usr/sbin/shutdown -y -iS -g0 >/dev/console 2<>/dev/console</dev/consoles2:23:wait:/sbin/rc2 >/dev/console 2<>/dev/console </dev/consoles3:3:wait:/sbin/rc3 >/dev/console 2<>/dev/console </dev/consoles5:5:wait:/sbin/rc5 >/dev/console 2<>/dev/console </dev/consoles6:6:wait:/sbin/rc6 >/dev/console 2<>/dev/console </dev/consolefw:0:wait:/sbin/uadmin 2 0 >/dev/console 2<>/dev/console </dev/consoleof:5:wait:/sbin/uadmin 2 6 >/dev/console 2<>/dev/console </dev/consolesc:234:respawn:/usr/lib/saf/sac -t 300co:234:respawn:/usr/lib/saf/ttymon -g -h -p "`uname -n` console login: " -T sun

-d /dev/console -l console -m ldterm,ttcompatml:23456:once:su abaqus57 -c '(umask 022; /usr/local/abapre/bin/flexlm lmgrd)'

Page 20: Unix Startup procedure

20 www.mi.chu.edu.twunix.administration

The Startup Scripts Init’s responsible run sys. startup scripts. scripts are executed after the kernel initialised

but before normal users are allowed to log on. These scripts will typically

– check the integrity of the machine’s file systems using fsck,

– mount the file systems,– designate paging and swap areas,– check disk quotas,

Page 21: Unix Startup procedure

21 www.mi.chu.edu.twunix.administration

The Startup Scripts– clear out temporary files in /tmp and others,– start up system daemons for printing, mail,

accounting, system logging, networking, cron,– enable user logins by running getty processes,

a number of other tasks.

BSD format: usually called /etc/rc and perhaps /etc/rc.local.

System V:init reads the file /etc/inittab and as the system enters each associated run level it runs a specified shell script.

Page 22: Unix Startup procedure

22 www.mi.chu.edu.twunix.administration

BSD Startup Scripts Most BSD systems will have at least

– /etc/rc• The system startup script that is executed as the system

goes multi-user. It will typically run /etc/rc.local.

– /etc/rc.local.• The startup script that contains procedures deemed to be

specific to your local site.

Some systems will add additional scripts /etc/rc.boot, /etc/rc.single that are run under various circumstances.

Page 23: Unix Startup procedure

23 www.mi.chu.edu.twunix.administration

SysV Startup Scripts– Under SysV, /etc/inittab informs init

which startup scripts it should execute. Each run level associate a particular startup script.

– generally the format /etc/rcL (these files may be located in /sbin on later versions).

– The purpose of these scripts is to execute all the shell scripts stored in a directory called with the name /etc/rcL.d.

Page 24: Unix Startup procedure

24 www.mi.chu.edu.twunix.administration

SysV Startup Scripts• i.e.: When system enters run level 3 init will

execute /etc/rc3 (/sbin/rc3 on later machines). This script will in turn execute all the scripts in /etc/rc3.d.

– The rcL.d directories will contain scripts with filenames that either start with, an K, or S

• The "K files" are used to kill processes.

• The "S files" are used to start processes and other initialisation procedures.

– init will execute all the "K files" in a directory in alphabetical order first and then execute all the "S files" in alphabetical order.

Page 25: Unix Startup procedure

25 www.mi.chu.edu.twunix.administration

The init Process in SunOS Init executes the scripts for entries with sysinit in the

action field, eg /sbin/rcS, and then /sbin/rc2, /sbin/rc3, … according the run level.

Those rc scripts will execute the scripts in the directories /etc/rcS.d/, /etc/rc2.d/, /etc/rc3.d/, … respectively.

The scripts in the /etc/rc#.d/ directories begin with either the letter K or S. These scripts have names of the form:

[K,S][00 - 99]filename

– The K (kill) files are run first for killing the existing processes,

– The S (start) files run next to start the various daemons needed for that run level.

Page 26: Unix Startup procedure

26 www.mi.chu.edu.twunix.administration

Why Won't My System Boot? Possible reasons include

– hardware problems,• Both hardware failure and problems caused by human

error (e.g. the power cord isn't plugged in, the drive cable is the wrong way around)

– defective boot floppies, drives or tapes,– damaged file systems,– improperly configured kernels,

• A kernel configured to use SCSI drives won't boot on a system that uses an IDE drive controller.

– errors in the rc scripts.

Page 27: Unix Startup procedure

27 www.mi.chu.edu.twunix.administration

Why Won't My System Boot? Solution: Systems Administration

maxim:Always keep a separate working method for booting the machine into at least single user mode.

a boot floppy, CD-ROM or tape, format doesn't matter. What does matter that at anytime you can bring the system up in at least single user mode so you can perform some repairs.

Page 28: Unix Startup procedure

28 www.mi.chu.edu.twunix.administration

Hardware Problems Some guidelines to solving hardware

problems– check the power supply and its connections,

• Don’t laugh, there are many cases I know of in which the whole problem was caused by the equipment not being plugged in properly or not at all.

– check the cables and plugs on the devices,– check any fault lights on the hardware,

Page 29: Unix Startup procedure

29 www.mi.chu.edu.twunix.administration

Hardware Problems– power cycle the equipment (power off, power

on),there is an old Systems Administration maxim. If something doesn’y work turn it off, count to 10 very slowly and turn it back on again (usually with the fingers crossed).

– try rebooting system without selected pieces of hardware,

– It may be only one faulty device that is causing the problem. Try isolating the problem device.

– use any diagnostic programs that are available, or as a last resort, call a technician or a vendor.

Page 30: Unix Startup procedure

30 www.mi.chu.edu.twunix.administration

Hardware Problems Damaged File Systems

– First always have backups of all file systems so that you can quickly recover some information.

– Try using fsck to fix the problem. – If worse comes to worse resort to your backups.

Improperly Configured Kernels– Reasons why you might change the kernel will be

discussed in a later chapter. – When you do change the kernel you should always

keep a backup working version of kernel that you can use to reboot the system.

Page 31: Unix Startup procedure

31 www.mi.chu.edu.twunix.administration

Daemons A daemon is a process that runs in

background, is independent of control from all terminals, and spends much of its time waiting for some event to occur.

Once the event occurs the daemon wakes up and performs some predefined action.

The action is sometimes controlled by a configuration file.

Page 32: Unix Startup procedure

32 www.mi.chu.edu.twunix.administration

Daemons Ways to start a daemon

– from rc, start up script, root – From inet superserver– from cron– from at command– use & sign– <error messages to syslogd>

common daemons on a UNIX machine.– Init: itself can be classed as a daemon.– Inetd:the main network server

Page 33: Unix Startup procedure

33 www.mi.chu.edu.twunix.administration

Daemons– named:Name server, provides dynamic hostname

data for TCP/IP networking– timed:Time daemon used to synchronise

different system clocks– sendmail:the mail daemon, responsible for

delivering mail locally and to remote hosts– nfsd:nfs file exporting daemon– ypbind&ypserv:NIS (yellow pages) daemons– syslogd:System logging daemon, records

various events.

Page 34: Unix Startup procedure

34 www.mi.chu.edu.twunix.administration

Shutting the System Down You should not just simply turn a UNIX

computer off or reboot it. Doing so will usually cause some sort of damage to system especially to file system.

tasks that have to be performed for a UNIX system to be shutdown cleanly– tell the users the system is going down,

• Telling them 5 seconds before pulling the plug is not enough. Wherever possible the users should know at least a couple of days in advance that the system is going down.

Page 35: Unix Startup procedure

35 www.mi.chu.edu.twunix.administration

Shutting the System Down– signal all the currently executing processes that

it is time for them to die,• Hopefully these processes will all die gracefully

(given some time) and will not do anything nasty to the system in the process.

– place the system into single user mode, and– perform sync to flush the file systems buffers

so that the physical state of the file system matches the logical state.

Page 36: Unix Startup procedure

36 www.mi.chu.edu.twunix.administration

Shutting the System Down– Some of the reasons why you may wish to shut a

UNIX system down include general housekeeping,

• Every reboot will perform some important housekeeping tasks, including deleting files from the temporary directories and performing checks on file systems.

• Rebooting will get rid of zombie processes.

general failures (problems that can only be solved by shutsown) include:

• hanging logins,

• unsuccessful mount requests,

Page 37: Unix Startup procedure

37 www.mi.chu.edu.twunix.administration

Shutting the System Down• dazed devices,

• runaway processes filling up disk space or CPU time,preventing useful work being done

system maintenance and additions.• There are some operations that only work if the

system is rebooted or if the system is in single user mode, i.e. adding a new device.

Page 38: Unix Startup procedure

38 www.mi.chu.edu.twunix.administration

Shutting the System Down The following command is an example of what

not to do. shutdown -g0– On a SVR4 box this results in a message like this

appearing on user's terminal

THE SYSTEM IS BEING SHUT DOWN NOW!

Log off now or risk your files being damaged.

Guidelines of how and when to perform shutdowns

Page 39: Unix Startup procedure

39 www.mi.chu.edu.twunix.administration

Shutting the System Down shutdowns should be scheduled,

• If users know the system is coming down at specified times they can organise their computer time around those times.

perform a regular shutdown once a week, and• A guideline, so that the housekeeping tasks discussed

above can be performed. If it's regular the users get to know when the system will be going down.

use /etc/motd: the message users see when they first log onto a system use it to inform users of the next scheduled shutdown.

Page 40: Unix Startup procedure

40 www.mi.chu.edu.twunix.administration

Shutting Down/ Rebooting the shutdown command: The most used

– The command can display messages at preset intervals warning the users that the system is coming down.

the BSD haltcommand – Logs the shutdown, kills the system processes,

executes sync and halts the processor.

the BSD rebootcommand– Similar to halt but causes the machine to

reboot rather than halting.

Page 41: Unix Startup procedure

41 www.mi.chu.edu.twunix.administration

Commands Shutting Down/ Rebooting sending init a TERM signal

– init will usually interpret a TERM signal (signal number 15) as a command to go into single user mode. It will kill user processes and daemons. The command is kill -15 1 (It may not work or be safe on all machines.)

BSD fasthalt or fastboot commands– Shell scripts which create a file /fastboot before

calling halt or reboot. When the system reboots and it finds a file /fastboot it will not perform a fsck on the file systems.

Page 42: Unix Startup procedure

42 www.mi.chu.edu.twunix.administration

The AT&T shutdown The format is shutdown -ggrace_period -iinit_state [-y]

– grace_period: # of seconds to wait before beginning the shutdown (default of 60)

– init_state: The init state (run level) to put the system into.

some cases ask for confirmation just before performing the shutdown. This question can be pre-answered by using -y option.

Shutdown -y -g120 -i0

Page 43: Unix Startup procedure

43 www.mi.chu.edu.twunix.administration

The BSD shutdown The format is shutdown [-fhknr]time [warning-message]

– actually calls on the halt command to perform the actual work of halting the system.

– It just displays messages before calling halt.

Parameters Meaning:– f:file systems will not be checked on system

restart (create /fastboot file)– k:simulate shutdown, WON'T actually do it– h:simply halt the system (same as halt)

Page 44: Unix Startup procedure

44 www.mi.chu.edu.twunix.administration

The BSD shutdown Command– r:reboot the system (same as reboot)– n:don't execute sync before shutting down– time:has two formats either

•+number:system down in number mins•hour:min: in 24 hour format

• Warning messages are displayed at periodic intervals and logins are disabled five minutes before shutdown

– warning-message: message to display to the users

Page 45: Unix Startup procedure

45 www.mi.chu.edu.twunix.administration

The BSD shutdown The halt and reboot commands are actually

used by the shutdown command. The halt command performs a sync on the

disks and stops the processors. The format of halt is.

halt [-nqy]– -n:don't sync the disks before stopping– -q:do a quick halt (create /fastboot file so that

file systems are not fscked on reboot)– -y:halt the system

Page 46: Unix Startup procedure

46 www.mi.chu.edu.twunix.administration

The BSD shutdown reboot shuts system down and restarts it:

reboot [-dnq][boot arguments]– -d:dump a copy of the kernels memory (system

core) before rebooting (some machines recognize this but don't do anything)

-n avoid the sync call. -q reboot quickly and ungracefully boot arguments:specify how system should

restart (e.g. single user mode). Some machines ignore these arguments.

Page 47: Unix Startup procedure

47 www.mi.chu.edu.twunix.administration

Sun PROM and SGI Indy Sun PROM Interact with PROM by holding down the

“STOP” key (L1 key on older KB) and pressing “a” key

“break” key if terminal keyboard ok prompt specify boot device: b device(controller#,unit#,file#)pathname

args OR

Page 48: Unix Startup procedure

48 www.mi.chu.edu.twunix.administration

Sun PROM and SGI Indy boot device(controller#,unit#,file#)pathname args

example:– ok boot or ok boot -s

ok probe-scsi SGI Indy PROM printenv setenv >> boot dksc(controller#,unit#,file#)pathname

Page 49: Unix Startup procedure

49 www.mi.chu.edu.twunix.administration

Boot Up Sequence in x86 Linux

MBR

BIOS

LILO LinuxKernelLinuxKernel

init

getty

xdm X-login

Consolelogin

Shell

Other OSOther OS

runlevel 3

runlevel 5

First 512-bytesegment of thefirst boot disk

Page 50: Unix Startup procedure

50 www.mi.chu.edu.twunix.administration

Using LILO in Linux LILO (LInux LOader) is a separate boot loader which resides on

your hard disk. (it is not an OS) It is executed when the system boots from the hard drive (Master

Boot Record, MBR). It also serves as a general-purpose boot manager capable of booting

MS-DOS, or Windows. Installing and Reconfiguring LILO:

– Editing the lilo.conf file

– Run the /sbin/lilo command to update the boot sector and create the /boot/map file.

Examples of LILO’s boot time options:root=/dev/foo tells kernel to use /dev/foo as the root device.

single enter single user mode

init=/sbin/init tells kernel to use /sbin/init as its init program.

Page 51: Unix Startup procedure

51 www.mi.chu.edu.twunix.administration

The /etc/lilo.conf file# Tell LILO to modify the boot record on /dev/had (the first non-SCSI# hard drive). If you boot from a drive other than /dev/had, change the# following line.boot=/dev/hda

# /boot/map contains information the LILO uses during the boot processmap=/boot/map

# Set the delay in milli-seconds. This is the time you have to press# the 'SHIFT' key to bring up the LILO Boot: prompt if you haven't# specified the 'prompt directive'delay=60

# Name of the boot loader.install=/boot/boot.b

# This forces LILO to prompt you for the OS you want to boot. A 'TAB'# key at the LILO: prompt will display a list of the OSs available to# boot according the the names given in the 'label=' directive below.prompt

# Tell LILO to wait for .10 seconds before booting the first image.timeout=50

Page 52: Unix Startup procedure

52 www.mi.chu.edu.twunix.administration

The /etc/lilo.conf file (con't)# Set the default booting image.

default=linux

# Different entries of OSs

password=Linux # password for entering the boot image (case-sensitive)

image=/boot/vmlinuz-2.2.12-20

label=linux

initrd=/boot/initrd-2.2.12-20.img #file for initial RAM disk

read-only # mount read only

root=/dev/hda1 # location of root partition

restricted # require password only for command line input

Other=/dev/hda2

label=msdos

table=/dev/hda # location of partition table for /dev/hda2

• Read the files under /usr/share/doc/lilo-21.4.4 directory for more information.