Linux: Startup Analysis II -- GRUB analysis

本文介绍了GRUB作为Linux启动加载器的基本概念及其配置方法。详细解释了GRUB配置文件的结构和参数含义,并提供了进入单用户模式及设置GRUB密码的方法。此外还介绍了如何在GRUB出现问题时进行恢复。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值