1 / 47

Booting and Shutting Down

Booting and Shutting Down. Chapter 2. Introduction. UNIX is a complex operating system, and turning UNIX systems on and off is more complicated than just flipping the power switch. Both operations must be performed correctly if the system is to stay healthy. 1. Bootstrapping.

Download Presentation

Booting and Shutting Down

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. Booting and Shutting Down Chapter 2

  2. Introduction • UNIX is a complex operating system, and turning UNIX systems on and off is more complicated than just flipping the power switch. • Both operations must be performed correctly if the system is to stay healthy. Chapter 2 - Booting and Shutting Down

  3. 1. Bootstrapping • Introduction: • Bootstrapping is the nerd word for “starting up a computer” • During this process, the kernel is loaded into memory and begins to execute. A variety of initialization tasks are performed, and the system is made available to users. Chapter 2 - Booting and Shutting Down

  4. 1. Bootstrapping • Boot time is a period of special vulnerability. All of the following can prevent a computer from coming up • Errors in configuration files • Missing or unreliable equipment • Damaged filesystems • Dealing with Boot configuration is often one of the first tasks an administer must perform on a new system. • Unfortunately it is also one of the most difficult Chapter 2 - Booting and Shutting Down

  5. 1. Bootstrapping • The Boot Process • Power on – • prom code is executed, then how do I load and start the kernel? • Kernel loaded – • Hardware probed, then init is spawned (PID 1) • Init (all controlled by rc files) • File systems checked and mounted • System demons started Chapter 2 - Booting and Shutting Down

  6. 1. Bootstrapping • Automatic and manual booting • Most UNIX systems can boot in either automatic mode or manual mode. • In automatic, the system performs the complete boot procedure on its own. • In manual mode, the system follows the automatic procedure up to a point and then turns control over to the operator before most init scripts have run. At this point the machine is in single-user mode. Chapter 2 - Booting and Shutting Down

  7. 1. Bootstrapping • You usually have to boot manually when some problems break automatic booting • corrupt file system, • improperly configured network device • Therefore it is important to understand the process of how to perform a manual boot. Chapter 2 - Booting and Shutting Down

  8. 1. Bootstrapping • Steps in the boot process • Loading and initialization of the kernel • Device detection and configuration • Creation of spontaneous system processes • Operator intervention (manual boot) • Execution of system startup scripts • Multi-user operation • We effect most bootstrap configuration by editing the system startup scripts Chapter 2 - Booting and Shutting Down

  9. 1. Bootstrapping • Kernel initialization • The first bootstrapping task is to get this program into memory so that it can be executed • Most systems have a two stage process • The PROM loads a small boot program into memory from disk. • This program arranges for the kernel to be loaded • The kernel then find out how much memory is available • Many of the kernel’s internal data structures are statically sized, so the kernel sets aside some memory for itself. Chapter 2 - Booting and Shutting Down

  10. 1. Bootstrapping • Hardware configuration • One of the first chores is to check out the environment to see what hardware is present. • When you construct a kernel for your system, you tell it what hardware devices it should expect to find • When the kernel begins to execute, it tries to locate and initialize each device that you have told it about. Chapter 2 - Booting and Shutting Down

  11. 1. Bootstrapping • System processes • Once basic initialization is complete, the kernel creates several “spontaneous” processes in user space. • They are spontaneous because they are not created by the normal UNIX fork mechanism. • On a System V-ish machine they are: • sched – process 0 • init – process 1 • Then various memory and kernel process handlers Chapter 2 - Booting and Shutting Down

  12. 1. Bootstrapping • Of all these processes, only init is really a full-fledged user process. • The others are actually portions of the kernel that have been dressed up to look like processes for scheduling or architectural reasons. • Now init has to create the daemons and the processes to handle basic operations (like accepting logins) Chapter 2 - Booting and Shutting Down

  13. 1. Bootstrapping • Operator intervention (manual boot only) • Single-User Mode • Usually prompted for the root password • Then given a shell • One many systems /root is mounted read-only • if /tmp is part of /root then some programs will not work properly (vi, …) • Most other filesystems are not mounted. • This is good if you have a sick filesystem. Chapter 2 - Booting and Shutting Down

  14. 1. Bootstrapping • Execution of startup scripts • At this point there are no more magic steps in the boot process. • The startup scripts are just normal shell scripts and they are selected and run by init according to an algorithm that, though sometimes tortuous, is eminently comprehensible. • The care, feeding, and taxonomy of startup scripts merits a major section of its own and is taken up in Section 4. Chapter 2 - Booting and Shutting Down

  15. 1. Bootstrapping • Multi-user operation • After the initialization scripts have run, the system is fully operational • except no one can log in. • For logins to occur a getty process must be listening to a particular terminal • init spawns several getty processes • init is also responsible for spawning graphical login systems such as xdm, gdm, or dtlogin. Chapter 2 - Booting and Shutting Down

  16. 2. Booting PCs • At this point we have seen the general outline of the boot process. We are now going to go back and fill in some of the details. • We will start with the initial power-on sequence and the loading of the kernel. • On traditional hardware this is a straightforward process • PC booting, on the other hand, is a lengthy ordeal that requires a bit of background information to understand. Chapter 2 - Booting and Shutting Down

  17. 2. Booting PCs • How a PC is different from proprietary hardware • When a machine boots, it begins by executing code stored in ROMs. • On a machine designed explicitly for UNIX, the code typically knows how to use devices connected to the machine, how to talk to the network on a basic level, and how to understand disk-based filesystems. • This is convenient because you can just type the name of a new kernel and the firmware will know how to locate and read that file. Chapter 2 - Booting and Shutting Down

  18. 2. Booting PCs • On PC’s the initial boot code is called a BIOS • It is extremely simplistic compared to the firmware of a UNIX machine. • Actually a PC has several level of BIOS • one for the machine itself, • One for the VIDEO card • one for the SCSI card (if present) • … • Working out the conflicts and interactions among the various BIOSes can be a real nightmare. Chapter 2 - Booting and Shutting Down

  19. 2. Booting PCs • The PC boot process • The BIOS will normally let you select which devices you want to boot from. • Once your machine has figured out what device to boot from, it will try to load the first 512 bytes of the disk (the Master Boot Record - MBR) • The MBR tells the computer from which partition to load a secondary program (the boot loader) • More info is given in Chapter 8 • The default MBR just loads from the first partition • more sophisticated ones now allow multiple OS’s (and kernels) • The boot loader is responsible for loading the kernel Chapter 2 - Booting and Shutting Down

  20. 2. Booting PCs • Examples of boot loaders include • LILO: the Linux boot loader • The FreeBSD boot loader • … • Your text covers how to use and configure these in detail. Chapter 2 - Booting and Shutting Down

  21. 2. Booting PCs • Multibooting on PCs • Since many operating systems run on PCs, it is fairly common to set up a machine to be able to boot several different systems. • To make this work you need to configure a boot loader to recognize all of the different operating systems on your disk. Chapter 2 - Booting and Shutting Down

  22. 3. Booting in Single-User Mode • This section gives the nitty-gritty details of single-user booting on each of our example operating systems. • Sloaris single-user • HP-UX single-user • Linux single-user • FreeBSD single-user Chapter 2 - Booting and Shutting Down

  23. 3. Booting in Single-User Mode • Notice that the options given in LILO a Linux Boot Loader are similar to the options given in the Sun Boot Prom. • Except that you can do certain hardware things from the SUM firmware that you can’t in a boot loader • like probe the SCSI devices Chapter 2 - Booting and Shutting Down

  24. 4. Startup Scripts • Introduction • After you exit single-user mode, init executes the system startup scripts • System scripts can be organized in two principal ways, each deeply rooted in ancient history. • On systems descended from BSD, the scripts are kept in /etc and have names starting with the letters rc. • On System-V derived systems, the scripts are kept in /etc/init.d and links to them are made in the directories /etc/rc0.d, /etc/rc1.d,... Chapter 2 - Booting and Shutting Down

  25. 4. Startup Scripts • Some tasks that are often performed by the startup scripts • Setting the name of the computer • Setting the time zone • Checking the disks with fsck (in automatic mode) • Mounting the systems disks • Removing the old files from /tmp • Configuring the network interfaces • Starting up daemons and network services Chapter 2 - Booting and Shutting Down

  26. 4. Startup Scripts • Most startup scripts are quite verbose and print out a description of everything they are doing. • On systems of yore, it was common practice to modify startup scripts to make them do the right thing for a particular environment. • These days, you put the details in a separate configuration file that the scripts consult. • They generally set the values of certain shell variables. Chapter 2 - Booting and Shutting Down

  27. 4. Startup Scripts • System V-style startup scripts • These are the most common today. • The System V init defines 7 “run levels” • Level 0 - the system is completely shut down. • Level 1 - single user mode • Level 2 - 5 are multi-user levels • Level 6 is a “reboot” level Chapter 2 - Booting and Shutting Down

  28. 4. Startup Scripts • Level 0 and 6 are special • The system can’t actually remain in them; it shuts down or reboots a s a side effect of entering them. • On most systems, the normal multi-user run level is 2 or 3 (4 and 5 are rarely used) • There seem to be more run levels than are necessary or useful • The usual explanation is that a phone switch had 7 run levels, so a UNIX system should have at least that many • Red Hat actually supports 10 (7 through 9 are undefined) Chapter 2 - Booting and Shutting Down

  29. 4. Startup Scripts • /etc/inittab tells init what to do at each of its run levels • The format varies from system to system, but the basic idea is that inittab defines commands that are to be run (or kept running) when the system enters each level. • It is usually not necessary for system administrators to deal directly with /etc/inittab because the script-based interface is adequate for almost any application Chapter 2 - Booting and Shutting Down

  30. 4. Startup Scripts • The master copies of the startup scripts live in a directory called init.d (usually in /etc) • Each script is responsible for one daemon or one particular aspect of the system. • The scripts understand the arguments start and stop. • Most also understand restart. • When moving from one level to another it looks in rclevel.d (rc0.d, rc1.d,…) Chapter 2 - Booting and Shutting Down

  31. 4. Startup Scripts • This directory (rclevel.d) typically contains symbolic links that point back to init.d • The names start with S or K followed by a number and name for example: S34named • The S and K tell init.d what to start or kill (on the way up or down) • and what order to do it in • ascending on the way up, • descending on the way down Chapter 2 - Booting and Shutting Down

  32. 4. Startup Scripts • Solaris startup scripts • Solaris, HP-UX, and Red Hat all use System V-style startup scripts that are kept in an init.d directory. • Under Solaris, both the init.d and rclevel.d directories are in /etc. Chapter 2 - Booting and Shutting Down

  33. 4. Startup Scripts • HP-UX startup scripts • Under HP-UX, the actual startup scripts are kept in /sbin/init.d • The run-level directories are also in /sbin • Config files that change the behavior of the startup scripts generally live in /etc/rc.config.d • Their names correspond to the names of the startup scripts in /sbin/init.d • Output is put n /etc/rc.log Chapter 2 - Booting and Shutting Down

  34. 4. Startup Scripts • Red Hat startup scripts • Startup scripts are the one thing that distinguish Linux distributions from each other. • Debian uses startup scripts similar to Solaris • Slackware uses scripts that are similar to FreeBSD’s • Red Hat uses a hybrid of the System V and BSD systems, with a few twists thrown in just to make life difficult for everyone. Chapter 2 - Booting and Shutting Down

  35. 4. Startup Scripts • FreeBSD startup scripts • FreeBSD’s init runs only a single startup script /etc/rc • This master script then runs the system’s other rc scripts • all of which live in /etc and are called rc.something Chapter 2 - Booting and Shutting Down

  36. 5. Rebooting and shutting down • UNIX file systems buffer changes in memory and write them back to disk only sporadically. • This scheme makes disk I/O faster, but it also makes the file systems susceptible to data loss when the system is rudely halted • It is always a god idea to shut down a machine nicely when possible. • Improper shutdowns can result in anything from subtle, insidious problems to major catastrophe. Chapter 2 - Booting and Shutting Down

  37. 5. Rebooting and shutting down • On non-UNIX operating systems, rebooting the operating system is an appropriate first course of treatment for almost any problem. • On a UNIX system, it is better to think first and reboot second. • You usually need to reboot when you add a new piece of hardware or when existing hardware becomes so confused that it cannot be reset. Chapter 2 - Booting and Shutting Down

  38. 5. Rebooting and shutting down • Unlike bootstrapping, which can be done in essentially only one way, there are a number of ways to shut down or reboot. They are: • Turning off the power. • Using the shutdown command • Using the halt and reboot commands • Sending init a TERM signal • Using telinit to change init’s run level • Killing init. Chapter 2 - Booting and Shutting Down

  39. 5. Rebooting and shutting down • Turning off the power • Even on small UNIX systems, turning off the power is not a good way to shut down • You can potentially loose data and leave the system’s files in an inconsistent state. • Some machines have a “soft power switch” • when you press the button, the machine actually runs some commands to perform a proper shutdown sequence. Chapter 2 - Booting and Shutting Down

  40. 5. Rebooting and shutting down • shutdown: the genteel way to halt the system • shutdown is the safest, most considerate, and most thorough way to initiate and halt or reboot or return to single-user mode. • Unfortunately, almost every vendor has decided to tamper with its arguments. Chapter 2 - Booting and Shutting Down

  41. 5. Rebooting and shutting down • You can ask shutdown to wait a while before bringing down the system. • During that waiting period, shutdown sends messages to logged-in users at progressively shorter intervals, warning them of the impending downtime. • You can also supply a short message of your own • Your message should tell why the system is being brought down and should estimate how long it will be before users can log in again. Chapter 2 - Booting and Shutting Down

  42. 5. Rebooting and shutting down • halt: a simpler way to shut down • The halt command performs the essential duties required to bring the system down. • It is called by shutdown -h • halt • logs the shutdown, • kills the nonessential processes, • executes the sync system call, • waits for the filesystem writes to complete, • and then halts the kernel Chapter 2 - Booting and Shutting Down

  43. 5. Rebooting and shutting down • reboot: quick and dirty restart • reboot is almost identical to halt, but it causes the machine to reboot from scratch rather than halting. • reboot is called by shutdown -r • Like halt it supports the -n and -q flags Chapter 2 - Booting and Shutting Down

  44. 5. Rebooting and shutting down • Sending init a TERM signal • The results of killing init are unpredictable and often nasty. • When the BSD version of init receives a TERM signal, it usually kills all user processes, daemons, and gettys and returns the system to single user mode. • This facility is used by shutdown • More information about signals is given in Chapter 4. Chapter 2 - Booting and Shutting Down

  45. 5. Rebooting and shutting down • telinit: change init’s run level • On systems with the beefy multilevel init, you can use the telinit command to direct init to go to a specific run level • telinit is most useful for testing changes to the inittab file Chapter 2 - Booting and Shutting Down

  46. 5. Rebooting and shutting down • Killing init • init is so important to the operation of the system that if it is killed with kill -KILL or kill -9, most computers will reboot automatically (some kernels just panic) • This is a rough way to reboot • Use shutdown or reboot instead Chapter 2 - Booting and Shutting Down

  47. Chapter 2 - Booting and Shutting Down

More Related