Application Guide: quickly understand the Linux Startup Mode Mechanism

Source: Internet
Author: User

Linux boot mode can boot Linux from a floppy disk or hard disk. When Linux is started from a floppy disk, the Code contained in the boot sector is read-only to the first several hundred data blocks (depending on the kernel size, of course) to the specified memory location. On a Linux boot floppy disk, there is no system and the kernel is in a continuous sector, because this simplifies the boot process.

Boot Linux from a floppy disk

After Linux is loaded, it initializes hardware and device drivers, and then runs init. Init can start other processes to allow users to log on and do other things. The details 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), then unmount the file system and swap partitions, finally, print the information that can turn off the power to the console. If the process is not followed correctly, terrible things may happen. The most important file system buffer Cache may not be written back, which means that all data in the Cache will be lost, the disk file system is incomplete, and may not be available.

Hard Disk boot

When booting from a hard disk, the code of the primary Boot Record checks the Partition Table (also in the primary Boot Record area), 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 for the pilot sector of the partition is the same as that of the floppy disk: Read the partition into the kernel and start it. But the details are different. Because it is useless to create a separate partition for the kernel image, the code in the partition pilot sector cannot only read the disk in sequence, it must find the file system and put them in which sectors. There are several ways to solve this problem, but the most common method is to use GRUB.

When GRUB is used for boot, it reads and directs the default kernel. You can also set GRUB to boot one of several kernels or even other operating systems. You can also choose which kernel or operating system to boot during boot.

Comparison

Starting from a floppy disk has its own advantages, but it is usually better to start from a hard disk because it avoids conflicts with a floppy disk and is 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 GRUB to boot from the hard disk after the system works well.

After the Linux kernel is read into the memory, Linux is started. The following is an overview:

The Linux kernel is compressed and installed, so it must first decompress itself. The kernel image starts with an unzipped applet.

Then, the kernel checks what other hardware (hard disk, floppy disk, Nic...) is available ......), And configure the appropriate device driver. At the same time, output the information of the search results. For example, I got the following information during guidance.

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 2.4.18-12 Thiz (root @ haven) 05/01/2002 14:12:20

Accurate text output varies with systems, depending on the hardware, Linux version, and configurations. Then the kernel tries to load the root file system. If the root system fails to load, for example, if you forget to include the relevant system driver in the kernel, the kernel will fail and the system will stop. The root file system is usually loaded in read-only mode (this can be the same as the location method ). This allows the file system to be checked during loading. Then, the kernel starts the program init (in/sbin/init) in the background, and its Process number is 1. Init can do a lot of startup work. It must start at least some necessary background daemon.

Switch init to multi-user mode and start getty to provide virtual console and linked list lines. Getty is a program for users to log on to the virtual console and linked list terminal. Init may also start some other programs. Now the boot is complete, and the system starts and runs properly.

It is important to follow the correct process when shutting down the Linux system. Otherwise, the file system may be damaged 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 the performance, but it also means that if you just turn off the power, the Cache may retain a lot of information, 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. Correct shutdown sequence can ensure 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 problems due to uninstallation), 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 has multiple users, run the shutdown-h + time message command. Time is the number of minutes to the system stop, and message is a short message that tells all users why the system is shut down.

# 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 shut down in 10 minutes. They 'd better save the data, otherwise the data 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 2002...

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, all file systems (except the root) are uninstalled, all user processes (if not logged out) are terminated, the waken process is closed, and everything is stopped. After that, init displays a message indicating that you can turn off the power supply. Sometimes (although rarely appears on any good system), the system may not be properly shut down. For example, in abnormal situations such as kernel disorder and crash, you may not be able to enter any command. Therefore, it may be difficult to shut down normally. In this case, you can only shut down the system directly. The problem may not be so serious. For example, if someone mistakenly moves your keyboard, the kernel and the update program are still running normally, waiting for some time may give update the opportunity to store the cached data back to the hard disk, and then shut down the data directly.

Restart 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 set it to Ctrl + Alt + Del.

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.