用實驗快速掌握grub和lilo
用實驗快速掌握grub和lilo
[實驗目的]
1.靈活應用grub和lilo引導系統。
2.當系統出現無法引導時,會快速修復。
[實驗要求]
1.RH8.0系統。
2.能夠熟練應用rescue模式,應急實驗中無法預料的錯誤。
[實驗步驟]
1.安裝grub。
情景:假設你現在用grub引導系統,今天grub.conf這個文件突然丟失啦,開機出現的grub如下:grub>,而且你又不能確定系統裝在哪個分區。
1) 創建情景,手動刪除/boot/grub/grub.conf
# mv /boot/grub/grub.conf /boot/grub/grub.conf.BAK
2) 重啟,出現假設的情景。
# reboot
3) 首先,學會在不用光盤rescue模式進入系統。
① 用root (hdx,x)定位到每個分區。
grub> root (hd0,0)
注意:a.(hdx,x)是給BIOS看的,hd0表示第1個硬盤,hd1表示第2個硬盤,逗號后面的數字0表示第1個分區,1表示第2個分區以此類推。
b.作這一步的目的是找到含vmlinuz和initrd*.img文件的那個分區,及根目錄分區/。
c.尋找的方法如下:
grub> root (hd0,0)
顯示:什么文件系統,什么分區系統
grub> kernel /<tab鍵>
顯示:有什么目錄和文件。由此找出包含/boot/vmlinuz和initrd*.img文件的分區,及根目錄/分區。也有可能,/boot和/在同一個分區。這里姑且,/boot和/獨立分區。在同一分區的情況會另有說明。
d.root后,括弧前有個空格。
②根據上述方法,假設找到/boot分區在(hd0,0),/分區在(hd0,10)。
③現在打如下列命令,進入系統:
grub> root (hd0,0)<回車鍵>
grub> kernel /vmlinuz-<tab鍵>補全<空格鍵>ro<空格鍵>root=/dev/hda11<回車鍵>
grub> boot<回車鍵>
注意:a./dev/hdax是給linux內核看的,對于同一個分區,hdax里的x要比(hd0,x)里的x大1。
b.如果,你找出的/和/boot分區不在(hd0,)上,而在(hd1,x)上,那么可能在root=/dev/hda11這而變為:root=/dev/hdbx啦,x根據(hd1,x)里的x而定,比它大1,這個上面說過。
4) 創建一個/boot/grub/grub.conf,方法為拷貝文檔里的樣本。
# cp /usr/share/doc/grub-<tab鍵>補全/menu.lst /boot/grub/grub.conf
原文如下(等于號中間的部分):
=======================================
#
# Sample boot menu configuration file
#
# Boot automatically after 30 secs.
timeout 30
# By default, boot the first entry.
default 0
# Fallback to the second entry.
fallback 1
# For booting GNU/Hurd
title GNU/Hurd
root (hd0,0)
kernel /boot/gnumach.gz root=hd0s1
module /boot/serverboot.gz
# For booting GNU/Linux
title GNU/Linux
root (hd1,0)
kernel /vmlinuz root=/dev/hdb1
# For booting Mach (getting kernel from floppy)
title Utah Mach4 multiboot
root (hd0,2)
pause Insert the diskette now!!
kernel (fd0)/boot/kernel root=hd0s3
module (fd0)/boot/bootstrap
# For booting FreeBSD
title FreeBSD 3.4
root (hd0,2,a)
kernel /boot/loader
# For booting OS/2
title OS/2
root (hd0,1)
makeactive
# chainload OS/2 bootloader from the first sector
chainloader +1
# This is similar to "chainload", but loads a specific file
#chainloader /boot/chain.os2
# For booting Windows NT or Windows95
title Windows NT / Windows 95 boot menu
rootnoverify (hd0,0)
makeactive
chainloader +1
# For loading DOS if Windows NT is installed
# chainload /bootsect.dos
# For installing GRUB into the hard disk
title Install GRUB into the hard disk
root (hd0,0)
setup (hd0)
# Change the colors.
title Change the colors
color light-green/brown blink-red/blue
===================================================
現在假設,你只想引導linux和windows系統,那么只保留下面部分就行,其他的要么注釋掉,要么刪除。保留部分如下(等于號中間的部分):
==============================================
# For booting GNU/Linux
title GNU/Linux
root (hd1,0)
kernel /vmlinuz root=/dev/hdb1
# For booting Windows NT or Windows95
title Windows NT / Windows 95 boot menu
rootnoverify (hd0,0)
makeactive
chainloader +1
# For loading DOS if Windows NT is installed
# chainload /bootsect.dos
==============================================
根據測試,(hd0,0)為/boot分區,(hd0,10)為/分區,而且,用fdisk -l 找到C:\ ,這里假設為:/dev/hda2,那么給BIOS看的東西就是(hd0,1),所以,現在做相應修改如下(等于號中間的部分):
==============================================
# For booting GNU/Linux
title GNU/Linux
root (hd0,0)
kernel /vmlinuz ro root=/dev/hda11
# For booting Windows NT or Windows95
title Windows NT / Windows 95 boot menu
rootnoverify (hd0,1)
makeactive
chainloader +1
# For loading DOS if Windows NT is installed
# chainload /bootsect.dos
==============================================
如果你有其他系統,請做相應修改。另外,如果你覺的title太土的話,也可以修改一下。
5) 重新安裝grub,檢查一下上述文件有無錯誤。
# grub-install /dev/hda
6) 重啟后,應該能看到grub的選擇菜單,雖然土了一點,但絕對能用。
7) 其次,如果你有安裝光盤,可以利用rescue模式,進入系統。
① 安裝光盤放入光驅,寫linux rescue | 選擇English | 選擇 us 鍵盤 | 點擊Continu| OK| 進入虛擬系統。
② 進入硬盤linux環境。
# chroot /mnt/sys<tab鍵>補全
③接著以上 4) 直到 6)。
8) 上面提到,如果/和/boot在同一個分區,這樣的話,在grub>提示下進入系統,具體操作如下修改,假設/和/boot在(hd0,10),那么進入系統的命令如下:
grub> root (hd0,10)
grub> kernel /boot/vmlinuz ro root=/dev/hda11
grub> boot
進入系統后,/boot/grub/grub.conf也做如下修改:
==============================================
# For booting GNU/Linux
title GNU/Linux
root (hd0,10)
kernel /boot/vmlinuz ro root=/dev/hda11
# For booting Windows NT or Windows95
title Windows NT / Windows 95 boot menu
rootnoverify (hd0,1)
makeactive
chainloader +1
# For loading DOS if Windows NT is installed
# chainload /bootsect.dos
==============================================
不知大家注意沒有,grub>提示,手動進入的命令和/boot/grub/grub.conf的菜單幾乎一樣,只是少了titile。
2.安裝lilo。
情景:你起初是用lilo引導,現在lilo壞了,無法引導,出現LI 或LIL等字樣,無法進入系統。或者你起初是用grub引導,現在想用lilo引導。所以你現在必須安裝lilo。
1) 因為lilo要求/boot下的文件要在前512柱面內,所以,如果條件不符合,無法用lilo引導,放棄此實驗。
2)創造實驗條件,破壞掉MBR內的LILO或grub。
# dd if=/dev/sero of=/dev/hda bs=446 count=1
# reboot
注意:上面的bs=446,千萬不能大于446,否則可能損壞硬盤分區表。
3)重啟后,出現系統無法引導。
4) 根據1的7)步,進入rescue模式,在進入硬盤linux環境。
5) 打開lilo.conf的manpage,拷貝里面的部分代碼。
# man lilo.conf
6)拷貝其中的下列代碼,制作新的文件/etc/lilo.conf
==================================
boot = /dev/hda
delay = 40
compact
vga = normal
root = /dev/hda1
read-only
image = /zImage-2.5.99
label = try
image = /zImage-
label =
image = /tamu/vmlinuz
label = tamu
root = /dev/hdb2
vga = ask
other = /dev/hda3
label = dos
table = /dev/hda
=======================================
6) 編輯此/etc/lilo.conf 只保留下面部分(等于號中間的部分):
=======================================
boot = /dev/hda
image = /tamu/vmlinuz
label = tamu
root = /dev/hdb2
other = /dev/hda3
label = dos
=======================================
假設,/boot 分區在(hd0,0),/ 分區在(hd0,10) C:\在:(hd0,1)
現在做如下修改:
=======================================
prompt
boot = /dev/hda
image = /boot/vmlinuz
label = linux
root = /dev/hda11
other = /dev/hda2
label = windows
=======================================
注意:添加了prompt,其實不加也行,在開機時注意按<shift鍵>,這樣,你才有機會選擇系統,否則默認進入第一個操作系統。
7) 安裝lilo,這是必須的。
#lilo
注意,如果無錯,你會看到菜單。如果有錯,它會提示你做相應修改。
8) 重啟,后提示輸入lilo的菜單選項,如果你不知道 的話,可以按<tab鍵>,它會顯示所有菜單,這樣,你就容易寫如要進入的系統菜單名。
3.原來的lilo引導改為grub。
1) 采用1的7) 步,進入rescue模式,在利用chroot進入硬盤linux環境。
2)編輯/boot/grub/grub.conf文件。
3)安裝grub。
# grub-install /dev/hda
4) 重啟應該就是grub引導啦。
[實驗總結]
通過此實驗,大家可以對lilo和grub的菜單比較熟悉。如果菜單出錯,你可以把配置文件修改為最簡單,最必要的條目。另外,請大家一定要留意一下,最終的lilo.conf和grub.conf文件,這兩個文件已經是精簡的不能在精簡啦。另外,比照最初的安裝配置的lilo.conf或grub.conf,你會發現,最起碼少了 initrd*.img這一項目,它的作用是為進行引導而初始化RAM。即便少了也不會影響正常引導。
posted on 2005-09-26 09:08 MingIsMe 閱讀(244) 評論(0) 編輯 收藏 所屬分類: 09 Linux