Unix Administration CSIE.NCKU 1 Unix Startup procedure Boot strap Kernel Initialization, Hardware...
-
date post
20-Dec-2015 -
Category
Documents
-
view
236 -
download
0
Transcript of Unix Administration CSIE.NCKU 1 Unix Startup procedure Boot strap Kernel Initialization, Hardware...
1Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
Unix Startup procedureBoot strap
Kernel Initialization,Hardware probing.
Creation ofSwapper&init
Init executesrc scripts
Init reads terminalconfiguration file
Getty process started
(BSD)/etc/ttys
(System V)/etc/inittab
ROM
Single User Mode
single ormulti-user?
Getty process started
2Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
3Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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 performs some additional hardware probing.
4Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
Kernel Initialization Test RAM & reserve part of RAM for
kernel, or print available RAM initialize its internal data structures,
5Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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 the following so called spontaneous
processes, because they are not created by fork().– PID=0: swapper/sched (BSD/Sys V)– PID=1,init/init – PID=2,pagedaemon/various handler (BSD/System V)– Under Linux
• no visible PID 0, • init & kflushd,kupdate, kpiod, kswapd
6Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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 executing 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)
7Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
8Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
9Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
Operator Intervention,manual boot only(RH) 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 RedHat)
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 /, /bin,/sbin,/etc – the daemon processes like mail will not work correctly
.
– (Red Hat automatically mount all the filesystems)
fsck must be run by hand, if required.
10Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
11Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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
12Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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
13Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
14Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
15Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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
16Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.)
17Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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
18Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
19Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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)'
20Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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,
21Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
22Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
23Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
24Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
25Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
26Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
27Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
28Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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,
29Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
30Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
31Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
32Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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
33Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
34Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
35Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
36Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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,
37Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
38Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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
39Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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, • 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.
40Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
41Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
42Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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
43Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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)
44Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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
45Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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
46Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
47Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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
48Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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
49Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
Boot Up Sequence in x86 Linux
MBR
BIOS
LILO LinuxKernelLinuxKernel
init
getty
xdm X-login
Consolelogin
Shell
Other OSOther OS
run level 3
run level 5
First 512-bytesegment of thefirst boot disk
50Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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). 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 modeinit=/sbin/init tells kernel to use /sbin/init as its init program.
51Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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
52Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
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.
53Unix AdministrationUnix Administration CSIE.NCKUCSIE.NCKU
RunLevel-Red Hat The following runlevels are defined in Red Hat
Linux: 0 — Halt 1 — Single-user mode 2 — Not used (user-definable) 3 — Full multi-user mode 4 — Not used (user-definable) 5 — Full multi-user mode (with an X-based login
screen) . 6 — Reboot