1 / 52

Unix Startup procedure

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

yahto
Télécharger la présentation

Unix Startup procedure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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) Getty process started Getty process started 1

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

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

  4. Kernel Initialization • Test RAM & reserve part of RAM for Kernel, or print available RAM • initialise its internal data structures, 4

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

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

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

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

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

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

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

  12. State Function prepare the machine for turning off power, if the 0 machine can turn the power off tell it to do so system administrator mode, all file systems 1 mounted, only small set of kernel processes running, single user mode multi-user mode 2 multi-user mode with remote file sharing, 3 processes, and daemons user definable system state 4 shutdown to ROM 5 shutdown and reboot 6 single-user mode, only root file system mounted s,S System V Run Levels 12

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

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

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

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

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

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

  19. The /etc/inittab file in SunOS ap::sysinit:/sbin/autopush -f /etc/iu.ap ap::sysinit:/sbin/soconfig -f /etc/sock2path fs::sysinit:/sbin/rcS >/dev/console 2<>/dev/console </dev/console is:3:initdefault: p3:s1234:powerfail:/usr/sbin/shutdown -y -i5 -g0 >/dev/console 2<>/dev/console s0:0:wait:/sbin/rc0 >/dev/console 2<>/dev/console </dev/console s1:1:wait:/usr/sbin/shutdown -y -iS -g0 >/dev/console 2<>/dev/console</dev/console s2:23:wait:/sbin/rc2 >/dev/console 2<>/dev/console </dev/console s3:3:wait:/sbin/rc3 >/dev/console 2<>/dev/console </dev/console s5:5:wait:/sbin/rc5 >/dev/console 2<>/dev/console </dev/console s6:6:wait:/sbin/rc6 >/dev/console 2<>/dev/console </dev/console fw:0:wait:/sbin/uadmin 2 0 >/dev/console 2<>/dev/console </dev/console of:5:wait:/sbin/uadmin 2 6 >/dev/console 2<>/dev/console </dev/console sc:234:respawn:/usr/lib/saf/sac -t 300 co:234:respawn:/usr/lib/saf/ttymon -g -h -p "`uname -n` console login: " -T sun  -d /dev/console -l console -m ldterm,ttcompat ml:23456:once:su abaqus57 -c '(umask 022; /usr/local/abapre/bin/flexlm lmgrd)' 19

  20. 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, 20

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

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

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

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

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

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

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

  28. 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, 28

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

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

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

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

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

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

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

  36. 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, 36

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

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

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

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

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

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

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

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

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

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

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

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

  49. BIOS xdm X-login runlevel 5 MBR LinuxKernel LILO init Shell Consolelogin getty First 512-bytesegment of thefirst boot disk runlevel 3 Other OS Boot Up Sequence in x86 Linux 49

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

More Related