Linux administrator Manual (5)-boot and Shutdown

Source: Internet
Author: User

This section describes what happens when the Linux system is booted and shut down and should be completed correctly. If the correct process is not followed, the file may be damaged or lost.

Overview of boot and Shutdown

The process of enabling a computer and causing its operating system to be loaded is called boot. The name comes from an image of the Computer pulling itself up from its bootstraps, but the act itself slightly more realistic.
During startup, the computer first loads a short section called bootstrap loaderProgramIt loads and starts the operating system in sequence, and bootstrap loader is usually stored in a fixed location of the hard disk or floppy disk. the reason for this two-step process is that the operating system is large and complex, and the first section of computer LoadingCodeSmall (several hundred bytes) to avoid unnecessary complexity of firmware.

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

After Linux is loaded, it initializes hardware and device drivers, and then runs init. init to start other processes to allow users to log on and do other things. The details of this section are discussed below.

To shut down a Linux system, all processes are first told to end (which causes them to close all files and complete other necessary tasks to end neatly), and then unmount the file system and swap areas, finally, print the information that can turn off the power to the console. if the process is not followed correctly, terrible things may happen. most importantly, the file system buffer cache may not be written back, which means that all data in the cache will be lost, the file system on the disk is incomplete, and may not be available.

Near-view guide process

You can boot Linux from a floppy disk or hard disk. The installation and start guide section ([wel]) tells you how to install Linux and boot as desired.

After PC boot, the BIOS performs some tests to ensure that everything is normal and then start the real boot. it selects a disk (usually the first soft drive, if there is a floppy disk, otherwise it is the first hard disk, if installed; the sequence is configurable ). then read the first sector, which is called the boot fan. For a hard disk, also called the Master Boot Record, because the hard disk can contain multiple partitions, each partition has its own boot fan.

The guiding fan contains a small program (small enough to be stored in one sector). Its responsibility is to read and start the operating system from the disk. when Linux is started from a floppy disk, the pilot fan contains the code to read the first several hundred data blocks (depending on the core size, of course) to the predetermined memory location. on Linux boot floppy disk, there is no file system, and the core is in a continuous sector, because this simplifies the boot process. of course, you can use LILO (Linux Loader) to boot from the file system.

From hard disk boot, the code of the primary Boot Record checks the Partition Table (also in the primary Boot Record sector), confirms the active partition (marked as a bootable partition), and reads the boot sector from the partition, then start the code of the boot sector. the code of the pilot sector of the partition is the same as that of the floppy disk: Read the partition into the core and start it. but the details are different, because it is useless to create a separate partition for the core image, so the code in the partition guide Fan cannot only read the disk in sequence, it must find the sectors in which the file system places them. there are several ways to solve this problem, but the most common method is to use Lilo. (The details about how to do it have nothing to do with the discussion here. For more information, see the Lilo documentation. It is comprehensive)

When lilo is used for boot, it reads and directs the default core. you can also set lilo to guide one of several cores, or even other operating systems. You can also choose which core or operating system to boot. lilo can be set to ask which user to guide if someone presses the ALT, shift, or ctrl key during boot (when lilo is started. lilo can be set to include a timeout option and ask. When timeout occurs, the default core is guided.

Meta: In addition to Lilo, there are other boot loaders, such as loadlin. Their information will be provided in the next version.

Starting from a floppy disk or a hard disk has its own advantages, but it is usually better to start from a hard disk, because this avoids the debate about a floppy disk. and fast. however, the installation of the same boot from the hard disk may be more troublesome, so many people first boot with a floppy disk, and then install lilo to boot from the hard disk after the same work is good.

Linux core is started only after being read into the memory. The following is an overview:

Linux core is compressed and installed, so it first needs to decompress itself. The core image starts with a small program to be decompressed.

If you have a Linux super-vgacard that can be recognized and supports some special text modes (such as 100 columns and 40 rows), Linux will ask you which mode to use. when compiling the core, you may have booked a video mode and won't ask. this can also be done using LILO or rdev.
Then, the core checks what other hardware (hard disk, floppy disk, Nic ...), configure the appropriate device driver and output the search result. for example, when I boot, I get the following information:

Lilo boot:
Loading Linux.
Console: color labels + 80x25, 8 virtual hosts les
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: 7332 K/8192 K available (300 K kernel code, 384 K reserved, 176 k Data)
Floppy Drive (s): fd0 is 1.44 m, fd1 is 1.2 m
Loopback device init
Warning wd8013 Board not found at I/O = 280.
Math coprocessor using irq13 error reporting.
Partition check:
Hda: hda1 hda2 hda3
VFS: mounted root (EXT filesystem ).
Linux version 0.99.pl9-1 (root @ haven) 05/01/93 14:12:20

The exact text varies on different systems and depends on the hardware, Linux version, and configurations.
Then the core tries to mount the root file system. the location can be set during compilation, or rdev or Lilo. automatic detection of file system types. if the root file system fails to mount, for example, because you forget to include the relevant file system driver in the core, the core will fail and the system will stop (nothing can be done at this time ).

The root file system is usually read-only mount (this can be the same as the location method ). this allows the file system to check when it is mounted. It is not a good idea to check a readable and mounted file system.

Then, the core starts the program Init (in/sbin/init) in the background (its process number is 1 ). init does a lot of startup work. the exact thing depends on settings. For more information, see chapter. it must start at least some necessary background programs.

Init then switches to multi-user mode and starts Getty to provide the virtual console and serial line. getty is a program for users to log on to the virtual console and serial terminal. init may also start some other programs based on settings.

Now, the boot is complete, and the system starts and runs properly.

More information about shutdown

It is important to follow the correct process when shutting down the Linux system. Otherwise, the file system may become waste and the file may become messy. This is because Linux uses the disk cache and does not immediately write data to the disk, but intermittent write-back. This greatly improves performance, but it also means that if you just turn off the power, the cache may keep a lot of data, the data on the disk may not be all working file systems (because some data has been written back to the hard disk, but some have not ).

Another reason why the power cannot be turned off directly is: In a multitasking system, many things may run in the background, and power off may cause heavy losses. The correct shutdown sequence ensures that all background processes can save their data.

The command for shutting down a Linux system is shutdown. It usually uses one of two methods.

If the system only has one user, the usual way to use shutdown is to exit all running programs, log out from all the virtual consoles, and log on to the root account (if you are already root, of course you do not have to log off or log on again, but you should switch to the root directory to avoid unmount issues), and then run the command shutdown-H now (although it is generally unnecessary for a single user, but if you need a delay, use a plus sign to add one to represent the number of minutes instead of now)

If the system is a multi-user, use the command shutdown-H + time message. The time is the number of minutes that the system stops. The message is a short message that notifies all users of the cause of system shutdown.

# Shutdown-H + 10' we will install a new disk. System shocould
> Be back on-line in three hours .'
#

The above command warns all users that the system will be shut down in 10 minutes. It is recommended that they save the information; otherwise, the information will be lost. The warning is displayed on all logon terminals, including all xterms:
Broadcast message from root (ttyp0) Wed Aug 2 01:03:25 1995...

We will install a new disk. System shocould
Be back on-line in three hours.
The system is going down for system halt in 10 minutes !!

The warning is automatically repeated several times before the system is shut down. As time passes, the interval is getting shorter and shorter.

When the system is shut down after the delay, all file systems (except the root) are unmounted, all user processes (if someone has not logged out) are terminated, and the WAF process is closed, everything stops. After that, init prints a message to tell you that you can turn off the power. At this time, you can only turn off the power supply at this time.

Sometimes (although very few on any good system), the system may not be properly shut down. For example, in abnormal situations such as core disorder and crash, you may not be able to enter any command. Therefore, it may be difficult to shut down normally, which means you can only shut down the system directly. The problem may not be so serious. For example, if someone mistakenly moves your keyboard, the core and update programs are still running normally. Waiting for some time may be a good suggestion, this gives update the opportunity to store the cached data back to the hard disk, and then shut down the data directly.

Some people like to use sync to shut down the system three times, wait until the disk I/O is stopped, and then power off. If no program is running, shutdown is equivalent. However, it does not mount any file system and may cause problems with the "clean file system" mark of ext2fs. This three-time sync method is not recommended.

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

Restart

Re-start is to completely shut down the system, turn off the power, and then turn on. The simple method is to restart the system with shutdown instead of simply stopping the system. This requires the shutdown-r option, for example, the command shutdown-R now.

Many Linux systems run shutdown-R now when pressing Ctrl-alt-Del. This is configurable. For example, it may be better to set a certain latency in a multi-user system. If anyone can access the system, it is best to press Ctrl-alt-del to do nothing.

Single User Mode

The shutdown command can also be used to switch to the single-user mode. In this mode, no one can log on. Only the root user can use the console. This is useful for system management tasks that cannot be performed during system running. The single-user mode will be discussed in detail in the chapter.

Emergency boot (soft) disk

Not always boot from the hard disk. For example, if lilo is set incorrectly, the system may be unable to boot. In this case, another method that can always be guided is required. A typical PC may be a soft drive.

Many Linux distributions allow an emergency boot disk emergency boot floppy during installation. It should be done. However, some boot disks only contain the core, and assume you will be using the programs on the distribution's installation disks to fix whatever problem you have. Sometimes these programs are not enough: For example, you may need to save your backup, but the backup/storage software does not exist in the Linux installation disk.

Therefore, you may need to generate your own root disk. 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 mounted, you cannot use a floppy disk to do anything else. Therefore, it is not convenient to have only one floppy disk. However, if you have enough memory, you can set the boot disk to load the root disk to the ramdisk (for this reason, the core of the boot disk needs special settings ). Once the root disk is attached to the ramdisk, the soft drive can be used to mount other disks.

Related Article

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.