Linux administrator Manual (5) -- boot and Shutdown
Source: Internet
Author: User
Article Title: Linux administrator Manual (5)-boot and shutdown. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Machine
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 the startup process, the computer first loads a short piece of program called bootstrap loader, which loads and starts the operating system in sequence. bootstrap loader is usually stored in a fixed location of the hard disk or floppy disk. the reason for these two steps is that the operating system is large and complex, and the first piece of code loaded by the computer is small (several hundred bytes), so as to avoid unnecessary complexity of the 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 sufficien
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.