Linux system boot process and grub configuration

Source: Internet
Author: User

Linux Start-Up flowchart: (in the operating part of the picture see upload attachment)


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/EB/wKiom1Xv51SDO1tYAARUl7ILl2w709.jpg "title=" Kaiji.png "alt=" Wkiom1xv51sdo1tyaarul7ill2w709.jpg "/>



To manually start the system on the GRUB command line:

Prerequisite: The system does not enter the interface normally when booting, but according to the prompt error to determine the boot program is not damaged, you can manually enter the GRUB command line to start the system.

Enter the GRUB command line interface at Grub Boot (that is, press the C key to enter the GRUB command line interface when the system starts reading seconds)

The first step: set the root path where grub is located on which device. Then see if the directory under/boot/on the current system is complete, use the Find command to find

Step Two: Specify the location of the kernel and its parameters and the location of the INITRD and restart using the boot command.

Three ways to fix grub

First: The system was not restarted after grub was damaged. You can use the Grub command to fix it (this method must ensure that the Boot/grub directory and its extreme files are present in the current system and cannot be corrupted)

grub> Root (hd0,0)

Root (hd0,0)

Filesystem type is EXT2FS, partition type 0x83

grub> Setup (hd0)

Setup (hd0)

Checking if "/boot/grub/stage1" exists ... no

Checking if "/grub/stage1" exists ... yes

Checking if "/grub/stage2" exists ... yes

Checking if "/grub/e2fs_stage1_5" exists ... yes

Running "Embed/grub/e2fs_stage1_5 (hd0)" ... Sectors is embedded.

Succeeded

Running "Install/grub/stage1 (hd0) (hd0) 1+27 P (hd0,0)/grub/stage2/grub/grub.conf" ... succeeded

Done.

Grub>

Repair completed, exit can be

The second type: Reinstall GRUB (This method checks the Boot/grub directory and its stages files, if not, automatically created between them)

[Email protected] grub]# Grub-install--root-directory=/DEV/SDA

--root-directory: Used to specify the root directory of grub, which is the directory where boot is located

/DEV/SDA: Indicates that GRUB is created on the current disk

Third method: Enter emergency rescue mode repair

When grub is damaged, we can go into rescue mode to repair the Geub or remove the hard drive to another host to fix grub.

First, we simulate a corrupted grub scenario. Execution

DD If=/dev/zero OF=/DEV/SDA bs=200 conut

This means that we destroy the first 200 bytes of the SDA disk with a special device/dev/zero, which destroys the first 200 bytes in the MBR

To begin the repair process:

Step one: Since the hard drive grub is corrupted, booting from the hard drive is not possible at this time. So I need to boot this system from other devices that have the Grub boot Manager installed, which can be CD-ROM, U-disk and other boot disks. So we need to go into the Biso interface and choose to start with disc mirroring.

Step two: Choose when grub is booting

Select by step

Selecting a device with full grub (that is, repairing the image to be used)

Next network selection, because we do not need to use the network to boot, so we can not set up the network

Next, it is important to prompt us to repair the environment will look for the disk to install the program and mount it to the/mnt/sysimage directory, if you are not particularly familiar with this process, you can automatically mount the words to choose Continue

The next step prompts us to find the first installable bootstrapper on the disk

Prompt to mount system system, then enter rescue mode

Next Change the system path

Repair with the Grub-install command and develop a disk device for the repaired grub, everything will be automatically generated

Then restart the system, enter the Biso to modify the boot entry for the hard drive, the system will start normally

Manually install make grub.

Prerequisites: Sometimes replace the bootloader as needed, or replace Lilo with GRUB. Or add a new bootloader. For example, to backup an operating system replicated to another partition, the data in the MBR is not backed up, and you need to create a new bootloader on the side of the backup.

First step: Determine if the system installs the GRUB software. Using the Grub 0.x version on CENTOS5 or 6 is called grub, and the Grub 1.x version, called GRUB2, is used on centos7. Use RPM to see if it is installed. My experimental environment is CENTOS6. The simulation scenario is to manually create the grub on a new hard disk

[Email protected] grub]# Rpm-q Grub

Grub-0.97-93.el6.x86_64

Step Two: Add a new hard disk to the system, which is displayed as/DEV/SDB (the add process is not written). It is then partitioned. And the kernel reread the partition table (note that if it is a newly added blank disk, the PARTX command causes the kernel to reread the partition table can be seen immediately in the/proc/partitions file, if the disk has previously been partitioned, you may need to restart the system in order to/proc/ partitions file to see the new partition condition)

[Email protected] ~]# cat/proc/partitions

Major Minor #blocks name

8 0 104857600 SDA

8 1 204800 sda1

8 2 62914560 Sda2

8 10485760 SDB

8 6425968 SDB1

8 4056412 SDB2

253 0 20971520 dm-0

253 1 2097152 dm-1

253 2 10485760 Dm-2

253 3 20971520 dm-3

Then the format file system type is EXT4 type

[Email protected] ~]# mke2fs-t EXT4/DEV/SDB1

[Email protected] ~]# BLKID/DEV/SDB1

/dev/sdb1:uuid= "eed16606-c4ed-4f00-b8fb-925898b6e102" type= "Ext4"

[Email protected] ~]# mke2fs-t EXT4/DEV/SDB2

[Email protected] ~]# BLKID/DEV/SDB2

/dev/sdb2:uuid= "6c2c0c61-a7ea-46be-8f74-82ab73396970" type= "Ext4"

Because grub must be created to find the boot directory, and the current boot directory is in use, all of us create the boot directory under/MNT and then mount the/DEV/SDB1 to the/mnt/boot directory

[[email protected] mnt]# mkdir boot

[Email protected] mnt]# Mount/dev/sdb1/mnt/boot

[[email protected] mnt]# DF

Filesystem 1k-blocks used Available use% mounted on

/dev/mapper/vg0-root 20511356 3196124 16266656 17%/

Tmpfs 506144 0 506144 0%/dev/shm

/DEV/SDA1 194241 27923 156078 16%/boot

/DEV/MAPPER/VG0-USR 10190136 1957908 7707940 21%/usr

/dev/mapper/vg0-var 20511356 331624 19131156 2%/var

/DEV/SDB1 5039592 10268 4766664 1%/mnt/boot

You can then use the Grub-install command to install grub on the/DEV/SDB1.

[Email protected] grub]# Grub-install--root-directory=/mnt/dev/sdb

You must specify the GRUB technician root directory using--root-directory, because grub must look for the GRUB directory and its associated files from the boot directory, and if not, Grub-install creates the Grub directory and its child-related files in the boot directory. However, the grub.conf file is not created by default, so it needs to be edited manually. /DEV/SDB1 is the disk that the specified grub will be installed on,

However, to make the boot disk must have kernel files Vmlinus and initrd files, so copy these two files to this boot directory

[Email protected] ~]# cp/boot/vmlinuz-2.6.32-504.el6.x86_64/mnt/boot/

[Email protected] ~]# Cp/boot/initramfs-2.6.32-504.el6.x86_64.img/mnt/boot

Then edit the grub.conf configuration file

Since we are going to use/DEV/SDB3 as a root file system, we need to create some files and directories on it.

Create an AA directory under/mnt/

[[email protected] mnt]# mkdir AA

Mount/dev/sdb3 to/mnt/aa

[Email protected] mnt]# MOUNT/DEV/SDB3/MNT/AA

Enter this directory on which the root file system needs to create the base directory

[[email protected] aa]# MKDIR-PV etc bin sbin lib lib64 tmp usr Dev proc sys var home root

Copy binary/bin/bash and its dependent library files into the bin directory created

[Email protected] aa]# Cp/bin/bash./bin

[Email protected] aa]# Ldd/bin/bash

Linux-vdso.so.1 = (0x00007fff3a9fd000)

libtinfo.so.5 =/lib64/libtinfo.so.5 (0x00000036f7c00000)

libdl.so.2 =/lib64/libdl.so.2 (0x00000036ecc00000)

libc.so.6 =/lib64/libc.so.6 (0x00000036ed000000)

/lib64/ld-linux-x86-64.so.2 (0x00000036ec800000)

[Email protected] aa]# cp/lib64/libtinfo.so.5./lib64

[Email protected] aa]# cp/lib64/libdl.so.2./lib64

[Email protected] aa]# cp/lib64/libc.so.6./lib64

[Email protected] aa]# cp/lib64/ld-linux-x86-64.so.2./lib64

Switch root directory

[Email protected] aa]# CHROOT/MNT/AA

bash-4.1#

This means that bash is ready to run, but it also needs to replicate the/sbin/init program and its associated libraries as a startup program. But you can also set the kernel boot program is not/sbin/init, but set to/bin/bash

Modify the kernel parameters in the grub.conf configuration file Init=/bin/bash

[email protected] grub]# cat grub.conf

Default=0

Timeout=5

Hiddenmenu

Title Redhat (My Linux)

Root (hd0,0)

kernel/vmlinuz-2.6.32-504.el6.x86_64 ro Root=/dev/sda3 selinux=0 init=/bin/bash

Initrd/initramfs-2.6.32-504.el6.x86_64.img

Then create a new virtual machine, select the newly installed disk as the first disk, and launch successfully enough to go directly to the Bash interface


This article is from the "Seven Stars" blog, please be sure to keep this source http://qikexing.blog.51cto.com/7948843/1693166

Linux system boot process and grub configuration

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.