Linux boot process detailed
configuration files that affect startup
Common Start-Up troubleshooting
Use of rescue mode
Use of Live CDs
The Linux boot process is detailed:
1: Load BIOS hardware information, follow the settings to get the first bootable boot setting
2: Read the bootloader<grub.....> of the MBR in the hard disk
MBR detailed
Name: Primary boot sector, primary boot sector
Location: 0 Cylinders of the hard drive, 0 heads, 1 sectors
Size: Disk default One sector size is 512 bytes, and MBR is also 1 sectors, naturally 512 bytes
The three parts are composed of:
1: Master boot Program (bootloader) is 446 bytes
The master boot program, which is responsible for loading from the active partition and running the system boot program
2:partition table area (partition table), DPT, 64 bytes
The number of partitions in the hard disk and the size of each partition are recorded in it.
Each partition table entry is 16 bytes long, a total of 64 bytes is a partition item 1, a partition entry 2, a partition item 3, a partition item 4
The 3:MBR valid identity bit, which accounts for 2 bytes and is fixed at 55AA. If this flag is 0xaa55, it is considered MBR.
Grub (GRand Unified bootloader "Grub") is a multi-OS launcher from the GNU project.
3: According to boot loader settings, to boot partition loading Kernel,kernel will start to detect the hardware and load the driver
4: After the hardware driver succeeds, Kernel will take the initiative to execute the INIT program, and INIT will get run-level information;
5:init execute/etc/rc.d/rc.sysinit file to prepare the working environment (such as network, time zone, etc.) for software execution;
6:init execute the services under Run-level and start (script mode);
7:init execute the script/etc/rc.d/rc.local file after boot;
8:init executes the virtual Terminal control program Mingetty to start the login process, and finally waits for the user to log in;
——————————————————————————————————————————————————————————————————————————————————————————————————————
Post (BIOS) ———— >mbr boot ———— >grub menu ———— > Load kernel (kernel) ———— > Run init process
———— > Read/etc/inittab configuration file
---> Execute/etc/rc.d/rc.sysinit scripts
---> Execute/ETC/RC.D/RC scripts
--->/etc/rc0.d/*
--->/etc/rc1.d/*
--->/etc/rc2.d/*
--->/etc/rc3.d/*
--->/etc/rc4.d/*
--->/etc/rc5.d/*
--->/etc/rc6.d/*
---> Start mingetty process
——————————————————————————————————————————————————————————————————————————————————————————————————————————
Linux boot-related configuration files
To enable the graphical interface at the INIT3 level: StartX
From Init3-->init5 into the GUI requires restart service, user re-login
RHEL6 system boot-related configuration file
Bios
/boot/grub/grub.conf-->bootloader Loading kernel
[Email protected] ~]# vim/boot/grub/grub.conf
/etc/inittab--> Judging the start level
Systemctl-f Enable Multi-user.target RHEL7:
[Email protected] ~]# Vim/etc/inittab
# Default RunLevel. The runlevels used is:
# 0-halt (do not set Initdefault to this)
# 1-single User mode
# 2-multiuser, without NFS (the same as 3, if you don't have networking)
# 3-full Multiuser mode
# 4-unused
# 5-x11
# 6-reboot (do not set Initdefault to this)
#
Id:5:initdefault: #这个代表我当前启动级别是5, can be changed to 3
/etc/rc.d/rc.sysinit--> System initialization: Image: Hostname and/etc/fstab are specified here.
Execution Rc.sysinit completes the important work including mount partition activation swap loading modules.
/ETC/RC.D/RC[1-6].D--(Here the program/service s start all boot execution; k Start-up does not execute)
RC[1-6].D: The different services that correspond to different runlevel. These directories are
Are some of the symbolic connections that are connected to some files under the/ETC/RC.D/INIT.D. Start with S, with K
The start does not start. The number following the first letter is a priority.
Try to see the start level of the next network
[Email protected] ~]# vim/etc/init.d/network
#! /bin/bash
#
# Network bring Up/down Networking
#
# chkconfig:2345 10 90
Look at the line that has chkconfig, 2345 means to be started in RunLevel 2 3 4 5, 10 is for
The order in which this service is started, 90 is the order in which this service is closed when shutting down.
[[email protected] rc3.d]# ls *network*
S10network
[[email protected] rc3.d]# ls *network*
S10network
[Email protected] rc3.d]# chkconfig--list Network
Network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[Email protected] rc3.d]# Chkconfig network off
[Email protected] rc3.d]# chkconfig--list Network
Network 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[[email protected] rc3.d]# ls *network*
K90network
#说明, if the boot starts at this level, the shutdown sequence is no longer displayed.
If the system startup boot level is maliciously changed to 0 or 6, enter single-user mode to modify the default boot level.
/etc/rc.local--> set power on automatically execute a command
For example: Set up auto-mount CD, automatically open a service
[Email protected] rc.d]# vim/etc/rc.local
[Email protected] rc.d]# ll/etc/rc.local
lrwxrwxrwx. 1 root root 07:06/etc/rc.local-rc.d/rc.local
#为链接文件
Run Mingetty, open tty1-6
[Email protected] ~]# Ps-aux |grep mingetty
Warning:bad syntax, perhaps a bogus '-'? See/usr/share/doc/procps-3.2.8/faq
Root 2156 0.0 0.0 4064 536 tty2 ss+ 09:22 0:00/sbin/mingetty/dev/tty2
Root 2158 0.0 0.0 4064 532 tty3 ss+ 09:22 0:00/sbin/mingetty/dev/tty3
Root 2160 0.0 0.0 4064 532 tty4 ss+ 09:22 0:00/sbin/mingetty/dev/tty4
Root 2163 0.0 0.0 4064 536 tty5 ss+ 09:22 0:00/sbin/mingetty/dev/tty5
Root 2165 0.0 0.0 4064 536 tty6 ss+ 09:22 0:00/sbin/mingetty/dev/tty6
Root 4278 0.0 0.0 103256 840 pts/1 s+ 15:35 0:00 grep mingetty
————————————————————————————————————————————————————————————————————————————————————————
prevent passwords from being cracked
We all know that entering single user mode can break the root password and how to prevent it from being cracked?
That can only encrypt grub.
How do I encrypt grub? We'll know when we practice.
First, you want to set the password using MD5 encryption redact
[Email protected] ~]# Grub-md5-crypt
Password:
Retype Password:
$1$wqfpc$a5wf2zghdyldz.wkh6kxg0 #这个就是加密后的密文
Then we add the password to the grub configuration file.
[Email protected] ~]# vim/boot/grub/grub.conf
#boot =/DEV/SDA
Default=0
Timeout=5
Splashimage= (hd0,0)/grub/splash.xpm.gz
Hiddenmenu
Lock
Password--md5 $1$wqfpc$a5wf2zghdyldz.wkh6kxg0
Title Red Hat Enterprise Linux (2.6.32-431.el6.x86_64)
Root (hd0,0)
....
Lock
Lock locking system, cannot start
Final restart test (reboot)
You can enter the Grub edit mode by pressing the P key in the Grub boot menu when restarting
____________________________________________________
Enter Rescue mode
When the system is broken, it can't get in. Enter rescue mode copy data
Mount the installation system CD
Restart
F2 Enter the virtual machine BIOS settings, set the boot from CD, F10 save
Enter the disc boot interface and select the rescue Install system
Load Ramfs: Memory file system
Chroot/mnt/sysimage # Toggle File system root
Mount other storage devices, copy data
————————————————————————————————————————————————————————
Common system Troubleshooting solutions:
1: Forget the root user's password
Workaround: Reboot the system into single-user mode and reset the password
The GRUB interface presses any key to intervene in the startup process.
E key, edit the option that the kernel receives at startup, add "1".
Enter and the B button to start the operating system according to the modified option.
Remove the x in the reboot, and then use the root to enter the password again, you do not need to enter the password
You can change root by entering the system passwd.
2:: Disk resource exhaustion failure
1: Unable to write new file, Prompt "...: No space on Device"
2,: Some programs can not run, even the system can not start
Cause of failure
1: Disk space has been filled with large amounts of data and is running out of space
2: Although there is still free space, the number of files I node is exhausted
Solution:
1. Clean up disk space and delete useless, redundant files
2. Transfer or delete trivial files that occupy a large number of I nodes
3. Go to Single user mode, rescue mode to repair or delete files
3: Dual system Startup Repair
Installing the Windows,linux dual system is recommended to install Windows first, then Linux
Fault:
When we install a dual system environment, install Linux before installing Windows or
Windows is damaged by installing a dual-system environment, and after reinstalling Windows,
Storage of the Grub MBR (Master boot record, master boot record) is saved by the Windows system
The bootstrap program NTLDR, which causes the Linux system to fail to boot.
Solve:
1, if you want to restore dual system boot, first use the above method to enter the rescue mode, execute the chroot command as follows:
sh-4.1# Chroot/mnt/sysimage
2. Switch the root directory to the root of the hard disk system, and then execute the grub-install command to reinstall GRUB:
sh-4.1# GRUB-INSTALL/DEV/SDA
3. Then execute exit command sequentially, exit Chroot mode and Rescue mode (execute two exit command):
sh-4.1# exit
sh-4.1# reboot
After the system restarts, the grub-guided dual-system boot is restored.
You can also borrow LIVECD to handle faults such as: Recycled Dragon
MBR Backup and Recovery
Backup Mbr:dd if=/dev/sda of=/tmp/mbr bs=512 count=1
Destruction Mbr:dd If=/dev/zero of=/dev/sdb bs=512 count=1
Recovery Mbr:dd if=/tmp/mbr of=/dev/sdb bs=512 count=1
Linux system startup principle and troubleshooting