Linux Administrator Handbook (5) _unix Linux

Source: Internet
Author: User

This section describes what happens when a Linux system boots and shuts down, and should be done correctly. If the correct procedure is not followed, the file may be corrupted or missing.

Boot and Shutdown overview

The process of turning on a computer and causing its operating system to be loaded is called booting. The name comes from a computer pulling itself up to its bootstraps, but the act itself slightly Stic.
During startup, the computer first loads a small piece of program called Bootstrap Loader, which loads and starts the operating system sequentially, bootstrap loader is usually stored in a fixed location on the hard disk or the floppy disk. The reason for this 2-step process is that the operating system is large and complex, and the first piece of code that the computer loads is small (hundreds of bytes) so that the firmware is unnecessarily complicated.

Different computers have different bootstrap. For a PC, the computer (its BIOS) reads a floppy disk or the first sector of the hard disk (called a boot fan). Bootstrap loader is included in this sector. It loads the operating system located elsewhere on the disk (and other).

After Linux is loaded, it initiates hardware and device drivers and then runs Init. Init initiates other processes to allow the user to log in and do other things. The details of this section are discussed below.

In order to shut down a Linux system, first all processes are told to end (this allows them to close all files, complete the other things necessary to make it end neatly), then unmount the file system and swap area, and finally print the information to the console that can turn off the power. Terrible things can happen if you don't follow the right process. Most important, the file system cache cache may not be writeback, which means that all of the data in it will be lost, the file system on the disk is incomplete, and may not be available.

The near-view guidance process

You can boot Linux from a floppy disk or a hard disk. The Install and Start Guide installation section ([Wel]) tells you how to install Linux and boot in the way you want.

When the PC boots, the BIOS does some testing to make sure everything is OK, and then start the real boot. It selects a disk (usually the first floppy drive, and if there is a floppy disk, it is the first hard drive, if installed; the order is configurable). Then read the first sector, which is called the Guide fan; For hard disks, also called Master Boot Records, because the hard disk can contain multiple partitions, each has its own boot fan.

The boot fan consists of a small program (small to be stored in a sector), and its responsibility is to read the actual operating system from disk and start it. When booting Linux from a floppy disk, the boot fan contains code that reads only the first hundreds of blocks of data (of course, depending on the core size) to the predetermined memory location. On a Linux boot floppy, there is no file system and there is a continuous sector in the core because it simplifies the boot process. Of course, using Lilo (LInux LOader) can boot from the file system.

Boot from the hard drive, the code for the master boot record checks the partition table (also in the primary boot record sector), confirms the active partition (marked as a bootable partition), reads the boot sector from the partition, and then launches the code for the boot sector. The code for the boot sector of the partition does the same as the floppy disk: Read the core from the partition and start. But the details are different, because it is useless to make a separate partition for the core image, so the code in the partition boot fan cannot read the disk sequentially, it must find the file system to put it in which sectors. There are several ways to solve this problem, but the most common approach is to use Lilo. (The details about how to do this are irrelevant to the discussion here; see the LILO documentation for more information, it's comprehensive)

When you boot with LILO, it reads in and boots the default core. You can also set up Lilo so that it can boot one of several cores, or even other operating systems, or allow the user to choose which core or operating system to boot at boot time. Lilo can be set to if someone holds down ALT while booting, SHIFT, or CTRL (when Lilo starts), Lilo will not immediately boot the default and ask the user which to boot. Lilo can be set to take a timeout option and ask if the default core is booted when the timeout occurs.

META: In addition to Lilo there are other boot loader programs, such as Loadlin, whose information will be given in the next release.

Booting from floppy disks and hard drives each have advantages, but usually boot better from the hard drive, since this avoids the debate about floppy disks. And fast. However, installing the same boot from the hard drive may have more trouble, so many people first boot with a floppy disk, then when the same work is good, then install Lilo from the hard drive.

The Linux core is actually started when it is read into memory, as outlined below:


The Linux core is compressed and installed, so it has to decompress itself first. The core image begins with an uncompressed applet.

If you have Linux-identifiable SUPER-VGA cards and support for some special text patterns (such as 100 columns and 40 lines), Linux asks which mode you want to use. When compiling the core, you may have ordered a video mode and will not ask. This can also be done with Lilo or Rdev.

Then, core check what other hardware (hard disk, floppy disk, network card ...), and configure the appropriate device driver; Also, the output finds information about the results. For example, when I boot, I get a message similar to the following:

LILO Boot:
Loading Linux.
Console:colour ega+ 80x25, 8 virtual consoles
Serial driver version 3.94 with no serial options enabled
Tty00 at 0x03f8 (IRQ = 4) is a 16450
Tty01 at 0x02f8 (IRQ = 3) is a 16450
LP_INIT:LP1 exists (0), using polling driver
memory:7332k/8192k available (300k kernel code, 384k reserved, 176k data)
Floppy drive (s): Fd0 is 1.44M, FD1 is 1.2M
Loopback Device Init
Warning WD8013 Board not found at I/o = 280.
The Math coprocessor using irq13 Error reporting.
Partition Check:
HDA:HDA1 hda2 Hda3
vfs:mounted Root (ext filesystem).
Linux version 0.99.pl9-1 05/01/93 14:12:20

The exact text is different on different systems, depending on the hardware, the Linux version, and its configuration.
Then the core tries to mount the root file system. The location can be set at compile time, or use Rdev or Lilo at any time. The file system type is automatically detected. If the root file system mount fails, for example because you forgot to include related file system drivers in the core, the core will fail and the system stops (there is nothing left to do at this time).

The root file system is usually read-only mount (this can be used in the same way as the location). This allows the file system to be checked on Mount time; It is not a good idea to check for a read-write file system that has been mount.

The core then launches the program init (located in/sbin/init) in the background (its process number is 1). Init does a lot of startup work. The exact thing depends on the setting; See chapter for more information. It should at least start some of the necessary backstage waiting programs.

Init then switches to multiuser mode and starts Getty, providing virtual consoles and serial lines. Getty is a program that lets users log on through a virtual console and a serial terminal. Init may also start some other programs, based on settings.

At this point, the boot completes, the system starts and runs normally.

For more information about shutting down

It is important to follow the correct process when shutting down a Linux system. Otherwise, the file system may become a waste and the file may become cluttered. This is because Linux uses disk caching and does not immediately write data to disk, but instead writes it back intermittently. This greatly improves performance, but it also means that if you simply turn off the power, the cache may retain a large amount of data, and the data on the disk may not be a full working file system (because some data has been written back to the hard disk and some of it is not).

Another reason not to directly power off is that in a multitasking system, the background may run a lot of things, power off may be costly. Using the correct shutdown sequence ensures that all background processes are able to save their data.

The command to shut down the Linux system normally is shutdown. It usually uses one of 2 methods.

If your system is only one user, the usual way to use shutdown is to quit all running programs, log off from all virtual consoles, and log in with root (if you are already root, of course you don't have to log off or sign in, but you should switch to the root directory to avoid problems due to unmount), Then run the command shutdown-h now (although a single user is generally unnecessary, but if you need a delay, add a plus one to represent the number of minutes instead of now)

If the system is multiuser, use the command shutdown-h +time message, and time is the number of minutes to the system stop, messages are the SMS to inform all users of the system shutdown reason.

# shutdown-h +10 ' We'll install a new disk. System should
> Be back on-line in three hours. '
#

The above command warns all users that the system will be shut down in 10 minutes, and they may want to save the information otherwise they will be lost. Warnings will be displayed on all logged on terminals, including all xterm:
Broadcast message from root (ttyp0) Wed Aug 2 01:03:25 1995 ...

We'll install a new disk. System should
Be the on-line in three hours.
The system is going down for system halt in minutes!!

Warnings are automatically repeated several times before the system shuts down, and as time passes, the interval becomes shorter.

When the system really begins to shut down after the delay, all file systems (except the root) are unmount, all user processes (if anyone has not logged off) are terminated, the daemon is closed, and everything stops. After that, init prints out a message telling you that you can turn off the power. At this point, and only at this time, you can turn off the power.

Sometimes (although very few on any good system), the system may not shut down properly. For example, a core disorder, crash, and so on, may not be able to type any command, so a normal shutdown may be difficult, this is only a direct shutdown. The problem may not be that serious, for example, someone has mistakenly moved your keyboard, the core and update programs are still working, waiting for some time may be a good suggestion, which allows update to buffer cache data back to the hard drive, and then directly shut down.

Someone likes to use sync three times to shut down the system, wait until the disk I/O stops, and then turn off the power. If there are no programs running, this is equivalent to using shutdown. However, it does not unmount any file system and may cause problems with the EXT2FS "Clean file system" flag. This method of 3 times sync is deprecated.

(In case you are ' re wondering:the reason for three syncs are that in the early days of UNIX, when the commands were typed Sepa Rately, that's usually gave sufficient time for most disk I/O to be finished.)

Reboot

Reboot is to completely shut down the system, turn off the power, and then turn it on. The simple approach is to restart the system with shutdown instead of just stopping the system. This will use the Shutdown-r option, such as the command Shutdown-r now.

Many Linux systems run Shutdown-r now when the Ctrl-alt-del key is pressed. This can be set, such as setting a certain delay in a multiuser system may be better. If anyone can access the system, then it is best to set the press Ctrl-alt-del do nothing.


Single user mode

The shutdown command can also be used to switch to Single-user mode, which cannot log on, and only root can use the console. This is useful for system administration tasks that the system does not normally run on. Single-user mode is discussed in detail in the chapter.

Emergency boot (soft) disk

It is not always possible to boot from a hard disk. For example, if Lilo is set incorrectly, the system may not boot. At this point, you need another way to always boot. For a typical PC, it may be a floppy drive.

Many Linux distributions allow an emergency Boot disk emergency boot floppy to be generated during installation. should do. However, some of these boot disks contain only the core, and assume you are using the programs on the distribution ' s installation disks to fix whatever proble M you have. Sometimes these programs are not enough: for example, you may need to back up your backup, while the backup/back up software is not on the Linux installation disk.

Therefore, you may need to generate the root disk yourself. The Bootdisk HOWTO ([Cha]) written by Graham Chapman contains guidance on this. Of course, you must remember to make your emergency boot disk and root disk up to date.

When the root disk is mount, you cannot use the floppy drive to do anything else, so it may not be convenient if you have only one floppy drive. However, if you have enough memory, you can set the boot disk to load the root disk onto the RAM disk (for this reason, the core of the boot disk requires special settings). Once the root disk is loaded into the RAM disk, the floppy drive can be used to mount the other disks.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.