日期:2014-05-16  浏览次数:20716 次

Linux: Startup Analysis II -- GRUB analysis

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