Linux boot up

Source: Internet
Author: User
Tags crypt

Explanation: http://blog.chinaunix.net/uid-23036581-id-2230525.html

I. Brief introduction of the sequence of Rhel boot
bios-> mbr-> kernel-> Init
1, when the computer when the power is turned on the computer will enter the BIOS (BIOS work is mainly to detect some hardware equipment);
2, after the detection will enter the MBR is the boot loader (MBR is located in the hard disk of the first sector of a total of 512bytes, wherein the first 446bytes of the code is in the selection of the boot partition is determined by which partition to boot);
3, loading the system kernel (core), in the kernel is mainly loaded in the computer device driver, so that you can control the device on the computer, and read-only to mount the root directory, that is, at the beginning can only read the root directory corresponding to the partition, so/etc,/bin,/sbin,/ Dev,/lib These five directories must be in the same root directory in a partition;
4, the last init this program, so init this program process number 1, Linux is the first implementation of the program;
The INIT program performs the following programs according to the run level:
/etc/rc.d/rc.sysinit;
/ETC/RC.D/RC and ETC/RC.D/RC? d/
/etc/rc.d/rc.local
• If you have the appropriate graphical interface management program

Second, the BIOS initialization of the main three tasks
BIOS
(BASIC Input/Output System)
1, the computer peripheral equipment detection, power self-Test post (Power on auto test);
2, the BIOS will choose which device to boot, for example: floppy disk boot, CD-ROM boot, network boot, the most common from the hard disk boot;
3, choose a good device from which to boot, began to read the device's MBR boot sector;

Three, the main work in boot loader
1, boot loader can be installed in two places:
• Installed in the MBR of the hard disk;
• When sometimes the MBR is occupied by other boot management programs can be Boot Loader is installed on the boot sector of one of the partitions on the hard disk, the
2, boot Loader code is divided into two stages:
   (1) boot Loader The first stage of the program code is very small, only 446bytes, Can be stored in the MBR or a section of the boot sector,
   (2) boot Loader The first stage of the code is loaded from the boot partition, that is, boot Loader the second stage of the program code is stored in the/boot partition;  
3, the following example of the boot process for three boot Loader, such as installing two systems on a single drive: Windows 2003 and Red Hat Linux
When the computer is powered on, The MBR is loaded into the first stage code to load the second stage of the program code, into the Grub boot menu here to choose which system will be loaded into the corresponding core;
 

Iv. Introduction to Grub and grub.conf the contents of this configuration file
is actually loaded into kernel from the MBR loading boot loader, Loading init These programs are the responsibility of grub, the multi-boot hypervisor.
1, GRUB ( GR and  U nified  B Ootloader) has the following features:
· Grub Boot Manager can enter instructions at the interface of the boot prompt, for example, in the Grub interface, you can press the C key to enter the instruction according to the prompt starting with grub>;
· Grub's boot manager can support the following file systems: Ext2/ext3, ReiserFS, JFS, FAT, Minix, FFS, and so on;
• Support MD5 password to protect grub configuration file;
2,/boot/grub/ grub.conf    This profile is a grub configuration file, it is recommended to do a backup before making changes
   below to describe the contents of this configuration file and the syntax inside:
· Actions that begin with # are not used when the annotation is executed;
• You can have a line beginning with title , which is divided into two parts:
(1) Basic settings:

default=0 refers to a system record that uses the first set of title presets to boot, if there are multiple title indicates multiple start, if the preset to use the second set of systems to power on the value set to 1
timeout=5 refers to the interface to the grub, there will be 5 seconds for the user to select the system to start, if not selected automatically use the above default setting value;
splashimage= (hd0,0)/grub/splash.xpm.gz The background pattern used when booting up, here (hd0,0) means ( hard drive number, partition number )
Hiddenmenu hiding the boot menu

(2) used to distinguish the settings of multiple systems, if the host also installed other systems and set a multi-boot, here can also see other system settings;

title Red Hat Enterprise Linux as (2.6.9-11.el) The system name that is displayed in the Grub boot menu
Root (hd0,0) Specifies the directory in which the following file is located, and this hd0,0 also refers to the directory used to refer to the boot, usually referred to the/boot directory
kernel/vmlinuz-2.6.9-11.el ro root=label=/rhgb quiet sets the location of the kernel image relative to the position specified by the root line above , RO root=label=/is set/in the root directory location, RO is read-only meaning, that is, to mount the root directory read-only, you can also use root=/dev/hda2 similar to this form to mount the root directory, RHGB means to display the boot process with a graphical interface, The quiet means that the error message is not displayed when the boot process is removed;
initrd/initrd-2.6.9-11.el.img The specified file into memory, the file is stored in a number of drivers;

3, if we modify the grub.conf this configuration file, set to take effect immediately;
4. In addition, if the MBR on the hard disk is cleared, use the following instructions to reinstall Boot loader into the MBR:
/sbin/grub-install/dev/hda
5, introduce the boot manager to enter the grub can do what action (kernel parameters before the boot)
(1) After booting into the Grub interface, select the system you want to use (choose Linux here)
(2) Press the A key, you can change the kernel parameters in the boot, that is, you can pass a parameter to kernel; You can see the following interface

(3) In root=label=/This part can not be moved, will be removed after the back, first enter a space and then enter a 1, such as:

This 1 is an additional parameter, indicating that to enter the single-user mode, you do not need to enter the root password to log in as root;
(4) When entering the # prompt character, you can set the root password.

You'll find a problem. It is not safe for anyone to change the root password in this way before the host.
6. Set password and encryption method for grub to enter single user mode:
Set the password in the Grub profile to prevent the illegal person from entering in single-user mode.
(1) Edit the grub.conf configuration file, in the Basic Settings section, insert a linePassword 123456To set the password, here is the password set to 123456.

(2) After rebooting, in the Grub menu, you need to enter P, and then enter the password to proceed to the next step, select another mode.

(3) It can be found that the password set above is clear text, in grub, this password can be encrypted, such as:

Note:Grub-md5-crypt This command in the setting of an encrypted password, even if each input password is the same after encryption is different, so the above groups of passwords are not the same,grub-md5-crypt >>/boot/grub/grub.confThis line of instructions in the implementation of the above will not be prompted to enter two password, although no hint but still can be entered, each input password once press ENTER, and so on, after setting a good password, Then open the grub.conf file, you will find an encrypted password appended to the grub.conf file, will append the first two lines of the file is removed, the third line is to use the password, and then as in the set, and so on the above settings, be sure to delete the last three lines of content, otherwise it will be wrong.
PASSWORD–-MD5 This MD5 means that the password used later is MD5 encrypted.
7, before entering the system, press the E key to enter the command edit mode, to modify the boot configuration file
In the Grub menu selection, press "E" key, you can see the corresponding system of three rows grub.conf configuration parameters, select the wrong line, and then press "E" key, you can modify this line:

Such as: Select the second line, press the E key, you can modify this line of content, here is only the unfinished example, the normal start of the line to use a single user mode to start, after the completion of the modification press ENTER, return to the previous interface, and then press "B" key, using the settings after editing the boot.

V. Introduction to the work done during the initialization of the kernel
Kernel has the following four tasks when booting up:
1, testing the hardware equipment on the computer;
2, the detected hardware driver loaded into the kernel;
3. Kernel the root directory in read-only mode if the necessary driver is loaded;
4, kernel loaded into the first program init this program;

Vi. Introduction to what the INIT program did at the time of initialization
The INIT program reads/etc/inittab This configuration file to decide what to do
1. Decide which run level you want to use below to introduce several common (run level will be described in detail in the next section)
The Run level can be divided into 7 types from 0 to 6

· Run Level 1: Single user mode, mainly used to maintain the system, which has been used before;
· Run Level 3: The full service is enabled but enters text mode after login;
· Run Level 5: Enable full service login and enter graphical interface mode;
Note:In Inittab's configuration fileId:5:initdefault:The previous setting of this Initdefault to 5 indicates that the preset will use Run Level 5, which is the default to enable full service and enter graphical interface mode.
2, Init will execute the initial operating system program

3, Init will be executed according to the run level to execute the program in the corresponding directory of the run level, if the Inittab configuration file preset run level is 5, then the 5 parameter will be passed to/ETC/RC.D/RC this program execution, in/ETC/RC.D directory, you can see the directory for the run level of the RC0.D to rc6.d seven directory, so the INIT program executes the program in the run level directory according to the run level that is executed to determine which services to enable.

4, set a key combination, such as: Define shortcut keys, press the three key combinations 3 seconds to restart the system

6, in defining the UPS system, when the power supply problems, as well as the power to perform what procedures to recover.

6. Six Virtual consoles (dummy console) (TTY1~TTY6)

7, if the start is run Level 5, initialization work will start X11 (graphical interface)


vii. iniit initialization Flowchart

The following subsections will be introduced according to the flowchart above

Viii. introduction of Run level (first step of init initialization process)
In the Run level, in addition to the 0~6 of the seven species, there are S and emergency these two

Run level Function
0 Used for shutdown (not in Initdefault)
1,s,emergency Single user mode (only allow root account login, mainly used to do maintenance system work)
2 You can allow all users to log on, but do not enable network functionality
3 Allow all users to log in with full functionality, but enter the system in text mode
4 User definable, the default is the same as run Level 3
5 Same as the Run Level 3 feature, allows all users to log in and has full functionality to enter the system in graphical interface mode
6 For restarting the host (cannot be located in Initdefault)

The main difference between the three executions of the

Run level 1,s,emergency is how much the program executes:
• 1: After executing the INIT program, the/ETC/RC.SYSINIT program is then executed to initialize the system and then execute the/etc/rc1.d/ All programs under the directory;
· S: After executing the INIT program, only the/etc/rc.sysinit program is executed to initialize the system;
Emergency: After executing the INIT program, only some necessary programs in the/etc/rc.sysinit  program will be executed and will not be fully executed;
1. Describe some of the features of the run level
The run level uses the INIT directive to define which run level to use.
2, there are three ways to choose which run level
(1) to use at power-on, the preset run level is set in the/etc/inittab file, for example: Initdefault the previous value;
(2) can be from the boot Loader pass a parameter to kernel (for example: in the Grub boot Menu Press "A" key, before the boot can give kernel a parameter in single-user mode login System)
(3) after booting into the Linux system, you can use the init command, and then enter which run level; (For example: Init 5 enters run levels 5)
3, after executing using the runlevel instruction, you can display below the current rank under;
     /sbin/ RunLevel

ix. Introduction/etc/rc.d/rc.sysinit What this program does primarily (the second step of the init initialization process)
rc.sysinit This file is a script file, mainly a few judgment programs, There are also programs that set variables;
Rc.sysinit This file works as follows:
1, Boot Udev, which is a hot-swappable device, such as USB, and also initiates SELinux;
2, the kernel parameter is set to/etc/ sysctl.conf configuration file, this configuration file under the detailed description of the unit,
3, set the system time,
4, load keymaps settings, keymap settings is defined in the keyboard, so that the computer can find the corresponding keyboard settings;
5. Enable swap this virtual memory partition,
6, set the host name, the host name is set in the/etc/sysconfig/network configuration file under the Hostname= key,
7, check the root directory is not a problem, and re-mount a readable writable state;
8, enable RAID array, and the device of LVM,
9, the function of enabling disk quota is to limit how much hard disk space the user can use,
10, check other file system and attach them;
11, Finally will clear the modified locks and PID files, in fact, is to clear some of the boot cache files, as well as some useless information and files;

10, describes the role of the/ETC/RC.D/RC program
1, this step is based on the loaded run level to execute the run level corresponding to the program to determine which services to enable, for example, if the run The level value is 5 and will execute all programs in the/etc/rc.d/rc5.d/* directory to deactivate or start services that should be available at this runlevel, such as
 
with rc5.d This directory to explain, you can see that this directory is a number of linked files, all the linked files are linked to the   . /init.d/*   An executable file in this directory, in fact Init.d and rc5.d after D is the representative   Daemon ( "UNIX" new process; port supervision [Control] program )   meaning.

11. Introduction of Daemon Processes (process )
1, Daemon processes is executed in the background of the program, the main function is to provide some system services, so in the INIT.D directory of all the programs are in the background to provide system services program, And these procedures in the background to provide system services are waiting for others to provide services, such as: httpd This program is to provide Web services, mainly open 80 port, so that others can connect through 80 ports.
2, Daemon mainly divided into two types, the main difference is the way to provide services, described as follows:
(1) Standalone (Chinese Translation: independent): In the standalone program, when the user requests the service, the Service group users will be provided by themselves;
(2) Transient (Chinese Translation: Temporary program, staging area): When the user asks the demand, will first with xinetd (called: Supper Daemon) This Daemon program requires service, and then xinetd program to call the Transient type of program, and finally Transient type of program is able to provide services to users;
3. There are two kinds of Daemon in Standalone :
(1) When the boot, the init of this program directly started;
For example: Virtual Console;
(2) System V Daemon Program
Example: HTTPd program (Web service provided);

12. Introduce the characteristics of System V program
1, in fact, the Run level is defined when the computer starts, what services to provide:
·In each runlevel there is his corresponding directory, as mentioned in the RC5.D directory;
·The program used to initialize System V is stored in the/etc/rc.d/init.d/directory;
2. Describe how RunLevel defines which services to provide.
Because in the runlevel corresponding directory, there are some connections, and these links are used to callINIT.DDirectory of the program, and the folder to start or stop the service parameters, so according to the runlevel corresponding directory link, you can set the system after the start to provide what services.
3. The following is the format of the link file name mentioned earlier:

The name of this linked file is divided into three main areas:
(1) toKOrSBeginning:K(Kill abbreviation) begins with the service that you want to deactivate the link to;S(start abbreviation), which indicates the service to enable the link;
(2) The number is two digits: Indicates the order of execution, the smaller the number of the first execution, but in the order of K and S execution is the K to deactivate the linked service, and then perform the S-enabled service, this is because all services are retired like zeroing meaning, and then enable the service, so the program to execute these links, The service on the system is initialized;
(3) The name of the linked system V program:
4, in addition, the System V program has a feature, that is, start and stop all with the same program, just add different parameters:
Example:/ETC/INIT.D/HTTPD start enable Web service
/ETC/INIT.D/HTTPD Stop deactivating Web services
Here's start, stop is the parameter used

13. Introduce the function of the/etc/rc.d/rc.local program (the third step of init initialization process)
1. After executing the link in the directory corresponding to the run level, the Rc.local program will be executed, such as: Run Level2 to 5.
Where S is enabled, 99 means execution is executed in the final order, and the executing program is rc.local;

2, therefore, you can modify rc.local this file, the runlevel2-5 to execute the instructions or programs are set in the Rc.local file.

14, introduce the characteristics of Virtual consoles (init initialization process Fourth Step)
Virtual Consoles,virtual Consoles has the following features:
1, defined in the/etc/inittab file, the use of/sbin/mingetty to generate tty1 to Tty6 of the six virtual consoles;

2. If you want to switch Virtual consoles, press Ctrl-alt-f (1~6) at the same time
3, Virtual consoles file is in/dev/this directory, the corresponding files are tty1, Tty2, Tty3, Tty4, Tty5, tty6; But there are many files in this directory that start with TTY
4./dev/tty0 is a virtual consoles that represents the current use
5. The following three preset virtual consoles settings are available in Rhel:
· Rhel defines 12 virtual consoles;
· In these 12 virtual consoles, only 1~6 can log in.
· If you log in using the graphical interface, you will first use virtual Consoles 7 login (i.e. Tty7)
Note: You can use CTRL-ALT-F7 to switch back to the graphical interface when the graphical interface is started.

How to control the stop and start of service on the system
In the service stop and start of the control system, there are two main types of tools.
1, the control system preset is automatically start the service;
There are three tools available to control the Linux operating system and preset services that will start automatically:
(1)Ntsysv: This tool can also be used under virtual consoles, this command executes after the interface, such as: You can start the service interface to set the system preset to start which services, if no parameters after Ntsysv, will only set the current run level, If you want to set another run level, you need to add the following parameters:
For example:Ntsysv–levelSpecifies the services to be started to modify RunLevel 3 and 5 presets
Note: This command is also available in text mode.

(2)Chkconfig: This tool can be set up quickly and is suitable for various Linux command line mode tools
For example: To view preset auto-start settings Note: The following GPM service is a service that can use the mouse under Virtual consoles, you can see the GPM service in Runlevel2~5 under the beginning of S, is also a preset will automatically start the meaning;

Execute the following instructions, you can let the runlevel1~3 preset does not automatically start the GPM service, as you can see the original 2 and 3 originally started with S has now become the beginning of K, indicating that the preset is a stop.

You can use Chkconfig–list to see if a service preset will start automatically, such as: off means not enabled, on means enabled, and if you want to see all the services you can remove the GPM, you will see a list of many services.

(3)system-config-services
This tool is a graphical interface tool, can only be executed under the graphical interface, the left window can be checked to select the preset to start the service, click Edit Runlevel can choose which level of the preset service to modify, but can only be set to a few, such as:

2, after the system boot, you can manually control the service stop and start, immediately control the start-up status of the service;
The following three tools allow you to manually control the start and stop of a service:
(1)Service: This tool can immediately start or deactivate the standalone type of service;

In the text mode if the mouse function is enabled, using the mouse to select the text point, press the middle mouse button to paste the selected text to the cursor location, so it is convenient to select some text, now to deactivate the GPM service, the instructions are as follows:
· Service gpm Stop disables GPM services (this method does not necessarily support all Linux versions)
· /ETC/INIT.D/GPM stop immediately deactivates the GPM service (it is recommended to use the absolute path method to execute this directive: This method supports all Linux versions)
· /ETC/INIT.D/GPM start immediately open the GPM service
· /ETC/INIT.D/GPM Reload Restart Service immediately
· /ETC/INIT.D/GPM Restart Restart Service immediately
· /ETC/INIT.D/GPM Status Display service enabled state
(2)Chkconfig: This tool can immediately start or deactivate services managed by the XINETD program
For example: Chkconfig telnet off to deactivate the Telnet service;
Chkconfig telnet on to enable the Telnet service;
(3)system-config-services
Graphical interface tool, select the service, then click Start (Enable) or stop (stop) or restart (restart).

16, the introduction of the use of command shutdown
There are four instructions that can be used to shut down the machine
1, Shutdown–h now H is the halt (meaning of termination) , then is the parameter is immediately, can also enter the time, for example:13:22 means 1:22 P.M. shutdown
2, halt
3. Power off
4, the init 0 enters the runlevel 0 level to do the shutdown action;
Note: These four instructions will perform the sync command before shutting down, synchronizing the data to the hard drive to avoid loss of data in memory.

17, introduce the use of instructions to restart the computer
1, Shutdown–r now-r is the meaning of reboot (restart), here now can also be replaced by time
2, reboot
3. Init 6
6. Ctrl-alt-del (used in Virtual Console environment)

Linux boot up

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.