欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Linux: Startup Analysis II -- GRUB analysis

程序员文章站 2022-06-30 21:58:04
...

Question Summary:

1> What is GRUB?

2> What's its position when Linux start up?

GRUB is BootLoader in Linux, its main focus is load Kernel.

 

1. GRUB configuration

1) The GRUB config file stores in "/boot/grub/grub.conf"

     Also it has a soft link "/etc/grub.conf"

2) "/boot" directory stores the file needed for system start up.

ls /boot
config-2.6.18-194.el5
lost+found
System.map-2.6.18.el5
grub
message
vmlinuz-2.6.18-194.el5
initrd-2.6.18-194.el5.img
symvers-2.6.18-194.el5-gz

 3) What stores in "/boot/grub/grub.conf"?

#grub.conf generated by anaconda
#...
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5)
            root(hd0,0)
            kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/ rhgb quiet
            initrd /initrd-2.6.18-194.el5.img

1) default: the default start up os, in real server env, we will not install multiple os.

2) timeout: the default waiting time(second)

3) splashimage: GRUB GUI image. (hd0,0) --> hd(Hard Disk). hd0 the first hard disk. hd(0, 0) the first segment on the first hard disk.

    Here, (hd0,0) represents the hardware position of folder "/boot".

    So we can find splash.xpm.gz in /boot/grub directory.

4) hiddenmenu: If we comment this, then we can get the information of GRUB procession.

5) kernel: point out the position of kernel. ro means readonly.

6) initrd: load image file

 

2. Single user mode

1) Why should we use single user mode?

    We may forget the password for root.

    There may be file system chaos after a sudden power off.

    Single user mode enable us login system as root and don't have to input password.

    Single user mode disabled X-Window

2) How can we shift to single user mode?

e: edit current start menu
c: enter GRUB command line
b: start current selected start menu item
d: delete current line
Esc: return to GRUB start up GUI and cancel all the modification for current menu item.

1. Step into GRUB GUI when start up.

2. Press e into edit line mode

3. Move highlight to kernel row, and press e again into edit mode.

4. Add 1 or s to the end of this line like this: kernel /vmlinuz-2.6.18-194.el ro root=LABEL=/ rhgb quiet 1

5. Press b to boot the system with single user mode as root.

 

3. Setup password for GRUB

1) Why should we set password for GRUB?

    To prevent other people change the password or damage system when entering single user mode by using GRUB.

2) How should we set password for GRUB?

    Just have to add line before title.

#grub.conf generated by anaconda
#...
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
password --md5 **********************
title CentOS (2.6.18-194.el5)
            root(hd0,0)
            kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/ rhgb quiet
            initrd /initrd-2.6.18-194.el5.img

 

4. Recover GRUB

1) After startup and get into GRUB GUI, there is no menu displayed, only grub> prompt:

    That may results from a damaged row in grub.conf file.

     As convention, we should backup /boot directory for emergency use.

press c to enter grub command line.

grub> cat /boot/grub/grub.conf (look up the params)

grub> root (hd0,0) --> set root path as the /boot directory

grub> kernel (hd0,0)/vmlinuz-2.4.18-14 ro root=LABEL=/  --> set kernel file as ...

grub> initrd (hd0,0)/initrd-2.4.18-14.img  --> set initrd 

grub> boot

2) What if we cannot even get into GRUB GUI?

We have to use linux installation cd to recover the system.

相关标签: Linux GRUB