First look at the format of the configuration file:
[[email protected] ~]# uname -r2.6.32-642.el6.x86_64[[email protected] ~]# cat /boot/grub/grub.conf # note that you do not have to Rerun grub after making changes to this file# notice: you have a /boot partition. This means that# all kernel and initrd paths are relative to /boot/, eg.# root (hd0,0) # kernel /vmlinuz-version ro root=/ Dev/sda2# initrd /initrd-[generic-]version.img #boot =/dev/sdadefault=0 timeout=5 splashimage= (hd0,0)/grub/splash.xpm.gzhiddenmenutitle CentOS 6 (2.6.32-642.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=uuid= A60b5a4a-0be1-44b6-bce3-363d117f52b7 rd_no_luks rd_no_lvm lang=en_us. utf-8 rd_no_md sysfont=latarcyrheb-sun16 crashkernel=auto keyboardtype=pc Keytable=us rd_no_dm rhgb quietinitrd /initramfs-2.6.32-642.el6.x86_64.img
The most important thing about grub is identifying disk information:(hd0,0)
1, the hard drive code is enclosed in parentheses ().
2, hard drive in HD, followed by a set of numbers, the numbers separated by commas
3, is in the order of search as the number of the disk, rather than according to the number of the disk line (multi-drive case, the order of the search is based on the boot sequence set in the BIOS, not the slot number)
4, the first search disk number is 0, the second is 1, and so on
5, the first partition number on each fast disk is 0, the second partition is 1, and so on
Therefore,(hd0,0) represents the first partition on the first disk
default=0 Default boot entry, if multiple operating systems are installed at the same time, 0 represents the first title system defined, 1 represents the second title system defined, and so on
Timeout=5 indicates the waiting time to choose, if more than 5 seconds, the default startup entry is used to define the
Splashimage= (hd0,0)/grub/splash.xpm.gz define background picture information at startup
Hiddenmenu If you want to declare a menu at startup, the menu information is not displayed by default, and if you want to display the menu, you can annotate the configuration information (# at the beginning of the line); the so-called display menu is the following information:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/87/33/wKiom1fXZzriT_CGAAAUf-xygSc369.png "title=" Qq20160913103935.png "alt=" Wkiom1fxzzrit_cgaaauf-xygsc369.png "/>
Title defines the name of each operating system
Root indicates where the kernel file is stored, which refers to the location of the partition, not/directory
The name of the kernel kernel and some core parameters at startup. Because the root directory needs to be mounted during startup, you need to specify the partition where the root is located. RHGB indicates color display, quiet indicates silent mode load kernel
INITRD Virtual File system
How to configure the Grub.conf file:
Default: Set the kernel or operating system to start
Timeout: The time of the timeout;
Splashimage:grub background image of the menu (optional)
Image: XPM format, compressed to Zip,14bits color, 640x480
Need to install GIMP Picture Editing Tool
Hiddenmenu: Hide Selection menu (optional)
Title defines an operating system or kernel
Root: Indicates the partition where the current operating system or kernel file is being booted
kernel: Kernel file path, device where the root file system resides, and parameters passed to the kernel
initrd: Indicates that the RAMDisk file path for the secondary kernel to complete the system boot is again in the memory cache
Experiment:
One, set password protection edit function (before title )
Add password--md5 "encrypted password" above the title in the grub.conf config file.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/87/36/wKiom1fXqKiBy7IQAAAXcZ3KrjY929.png "style=" float: none; "title=" Qq20160913145517.png "alt=" Wkiom1fxqkiby7iqaaaxcz3krjy929.png "/>
How to generate the password: in Vim last line mode, enter the command, when the cursor automatically jumps to the beginning of the start, enter the password and press ENTER, and then enter the password once and press ENTER, that is, generate a password
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/87/34/wKioL1fXrT7CbjDLAAABzMX7Ygw208.png "title=" Qq20160913150734.png "alt=" Wkiol1fxrt7cbjdlaaabzmx7ygw208.png "/>
You will need to enter a password each time you boot to the menu for editing:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/87/36/wKiom1fXq9PhNOp-AAAU6zcLMvk155.png "title=" Qq20160913151442.png "alt=" Wkiom1fxq9phnop-aaau6zclmvk155.png "/>
Second, set the password protection kernel ( within title )
Add password--md5 "encrypted password" within the title of the grub.conf config file.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/87/34/wKioL1fXrQegARvMAAAYPSJABOI325.png "title=" Qq20160913153746.png "alt=" Wkiol1fxrqegarvmaaaypsjaboi325.png "/>
How to generate the password: in Vim last line mode, enter the command, when the cursor automatically jumps to the beginning of the start, enter the password and press ENTER, and then enter the password once and press ENTER, that is, generate a password
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/87/34/wKioL1fXrVryRHhdAAABzMX7Ygw950.png "title=" Qq20160913150734.png "alt=" Wkiol1fxrvryrhhdaaabzmx7ygw950.png "/>
Each time you boot into the system, you need to enter the password:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/87/37/wKiom1fXrxrS_KOyAAAHHlGAff8423.png "title=" Qq20160913154724.png "alt=" Wkiom1fxrxrs_koyaaahhlgaff8423.png "/>
Third, recover after damage to grub.conf file
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/87/AC/wKioL1ffqtzw_3MMAAAhVKEe5Qw079.png "title=" Qq20160919170155.png "alt=" Wkiol1ffqtzw_3mmaaahvkee5qw079.png "/>
Four, in the case of partitioning, delete and restore/boot and/etc/fstab (friendly tip: Do a snapshot backup first)
1, first check the local partition and related configuration file/etc/fstab,/boot/grub/grub.conf
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/87/6A/wKioL1ffip_grNOPAAAeF2zy9zI288.png "title=" Qq20160919144905.png "alt=" Wkiol1ffip_grnopaaaef2zy9zi288.png "/>
2. Delete/boot and/etc/fstab and restart the system
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/87/62/wKioL1ffS_GAVk12AAAKMLhHkqA723.png "title=" Qq20160919092826.png "alt=" Wkiol1ffs_gavk12aaakmlhhkqa723.png "style=" float:none; "/>
3, due to the deletion of/boot and/etc/fstab, the system can not find the boot partition and kernel, it is necessary to enter the rescue mode, indicating that the system did not
Partition, you must first create a partition
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/87/66/wKiom1ffTPHyO_RoAAAKLT8PSqQ081.png "title=" Qq20160919093218.png "alt=" Wkiom1fftphyo_roaaaklt8psqq081.png "/>
4. Create/Boot and/etc/fstab
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/87/70/wKiom1ffk3SQ8tIIAAAgLWRg19U902.png "title=" Qq20160919152736.png "alt=" Wkiom1ffk3sq8tiiaaaglwrg19u902.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/87/70/wKiom1fflovjUG07AAAD3aHqrZo942.png "title=" Qq20160919154042.png "alt=" Wkiom1fflovjug07aaad3ahqrzo942.png "/>
5. Create the GRUB configuration file
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/87/70/wKiom1fflk_TVAeYAAAWhPOC-2o786.png "title=" Qq20160919153912.png "alt=" Wkiom1fflk_tvaeyaaawhpoc-2o786.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/87/6D/wKioL1fflp-QbrA5AAALc2iYFZA295.png "title=" Qq20160919144606.png "alt=" Wkiol1fflp-qbra5aaalc2iyfza295.png "/>
6, restart the system, and return to the familiar interface
Five, in the case of logical volume, delete and restore/boot and/etc/fstab (friendly tip: Take a snapshot backup first)
1, first check the local partition and related configuration file/etc/fstab,/boot/grub/grub.conf
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/87/66/wKiom1ffS_GQ9g8XAAA0siE9LVs281.png "style=" float: none; "title=" Qq20160919092609.png "alt=" Wkiom1ffs_gq9g8xaaa0sie9lvs281.png "/>
2. Delete/boot and/etc/fstab and restart the system
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/87/62/wKioL1ffS_GAVk12AAAKMLhHkqA723.png "style=" float: none; "title=" Qq20160919092826.png "alt=" Wkiol1ffs_gavk12aaakmlhhkqa723.png "/>
3, due to the deletion of/boot and/etc/fstab, the system can not find the boot partition and kernel, it is necessary to enter the rescue mode, indicating that the system did not
Partition, you must first create a partition
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/87/66/wKiom1ffTPHyO_RoAAAKLT8PSqQ081.png "title=" Qq20160919093218.png "alt=" Wkiom1fftphyo_roaaaklt8psqq081.png "/>
4. Create/Boot and/etc/fstab
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/87/6B/wKiom1ffgLDTdwG0AAA0-I_9x-c844.png "title=" Qq20160919140613.png "alt=" Wkiom1ffgldtdwg0aaa0-i_9x-c844.png "/>
5. Create the GRUB configuration file
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/87/6C/wKiom1ffgo-icUylAABhJVCNvPQ394.png "title=" Qq20160919141521.png "alt=" Wkiom1ffgo-icuylaabhjvcnvpq394.png "/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/87/66/wKioL1ffaiiBskuYAAAKDdkNHKo967.png "title=" Qq20160919102124.png "alt=" Wkiol1ffaiibskuyaaakddknhko967.png "/>
6, restart the system, and return to the familiar interface
Six, homemade Linux on a USB stick
1. Partition the USB drive and create a file system
# FDISK/DEV/SDB
/DEV/SDB1 corresponding to/BOOT/DEV/SDB2/
# MKFS.EXT4/DEV/SDB1
# MKFS.EXT4/DEV/SDB2
2. Mount/boot of USB flash drive and/
# Mkdir/mnt/boot
# Mkdir/mnt/sysroot
# Mount/sdb1/mnt/boot
# Mount/sdb2/mnt/sysroot
3. Install Grub to u disk
# Grub-install--root-directory=/mnt/dev/sdb
4. Copy kernel and INITRD files to USB drive
# Cp/boot/vmlinuz-version/mnt/boot/vmlinuz
# cp/boot/initramfs-version.img/mnt/boot/iniyramfs.img
5. Create the root system file of the target file to the USB drive
# Mkdir-pv/mnt/sysroot/{etc/rc.d,usr,var,proc,sys,dev,lib,lib64,bin,sbin,boot,src,mnt,media,home,root}
6, porting bash, etc. to the root file system of U disk
# bash copy.sh
The script reads as follows:
#!/bin/bash
ch_root= "/mnt/sysroot/"
[!-d $ch _root] && mkdir $ch _root
Bincopy () {
If which $ &>/dev/null;then
Local cmd_path= ' which--skip-alias $ '
Local bin_dir= ' dirname $cmd _path '
[-D ${ch_root}${bin_dir}] | | Mkdir-p ${ch_root}${bin_dir}
[-F ${ch_root}${cmd_path}] | | CP $cmd _path ${ch_root}${bin_dir}
return 0
Else
echo "Command not Found"
Return
Fi
}
Libcopy () {
Local lib_list=$ (LDD ' which--skip-alias $ ' | grep-eo '/[^[:space:]]+ ')
For loop in $lib _list;do
Local lib_dir= ' dirname $loop '
[-D ${ch_root}${lib_dir}] | | Mkdir-p ${ch_root}${lib_dir}
[-F ${ch_root}${loop}] | | CP $loop ${ch_root}${lib_dir}
Done
}
Read-p "Please input a command:" command
While ["$command"! = "Quit"];d o
If Bincopy $command; then
Libcopy $command
Fi
Read-p "Please input a command or quit:" command
Done
7. Create a file system profile for u disk
# Vim/mnt/sysroot/etc/fstab
/dev/sda1/boot EXT4 Defaults 1 1
/DEV/SDA2/EXT4 Defaults 1 2
8. Provide configuration file for the grub of U disk
# vim/mnt/boot/grub/grub.conf
Default=0
Timeout=5
Title
Root (hd0,0)
Kernel/vmlinuz ro root=/dev/sda2 selinux=0 init=/bin/bash
Initrd/initramfs.img
The solution that the system does not start properly