Grub 之常用命令和Windows引導修復(一)


剛剛午睡起來,神清氣爽。腰不疼了,腿不算了,打字也有精神了——於是寫篇博文--也算是寫篇經驗總結--剛剛一位群里的哥們裝CentOS沒成功。引導全壞掉了。
恩,首先老樣子--講下Grub是干嘛的--


GNU GRUB(簡稱“GRUB”)是一個來自GNU項目的多操作系統啟動程序。GRUB是多啟動規范的實現,它允許用戶可以在計算機內同時擁有多個操作系統,並在計算機啟動時選擇希望運行的操作系統。GRUB可用於選擇操作系統分區上的不同內核,也可用於向這些內核傳遞啟動參數
先普及下Grub是怎么識別硬盤的

IDE硬盤用hd開始,SCSI硬盤用sd開頭。軟盤用fd開頭。命名和linux不大一樣。是從0算起。
(hd0,0)。表示C盤。
(hd0,4)。表示D盤。當然這里指的是(第一個邏輯分區,如果D盤也是主分區,應該寫成hd0,1)

由於主分區只能有四個,所以第一硬盤的四個主分區分別用(hd0,0)~(hd0,3)來表示;邏輯分區則從(hd0,4)開始算,即第一邏輯分區用(hd0,4),第二邏輯分區用(hd0,5)來表示,依次類推。
一般機子的硬盤都是一個主分區,其余是邏輯分區。因此C盤用(hd0,0),D盤用(hd0,4)來表示。 光盤用(cd)表示,第一軟驅用(fd0)表示。
文件的表示:( , ) /path/to/file

--然后說下常用命令和參數,學會命令后可以做成menu.lst,相當於一個腳本--就不用每次開機的時候自己輸入了

boot - 引導先前已經被指定並載入的操作系統或鏈式裝載程序。
chainloader - 將指定的文件作為一個鏈式裝載程序載入。為了獲取在一個指定分區第一 扇區內的文件,使用+1作為文件名。
displaymem - 顯示當前內存的使用情況,這個信息是基於BIOS的。這個命令有助於確定系統在引導前有多少內存。
initrd - 使用戶能夠指定一個在引導時可用的初始RAM盤。當內核為了完全引導而需要某些模塊時,這是必需的。
install p - 安裝GRUB到系統的主引導記錄。這個命令允許系統重啟時出現GRUB接口。
//(警告:install命令將覆蓋主引導扇區中的其他信息。如果命令被執行,那么除了GRUB信息之外的其他用於引導其他操作系統的信息都將丟失。在執行這條命令前,確定你對它有正確的了解。)
kernel - 當使用直接載入方式引導操作系統時,kernel命令指定內核從GRUB的根文件系統中載入 。
//比如 kernel /vmlinuz root=/dev/hda5
Vmlinuz是內核。。它從GRUB的根文件系統載入的,如(hd0,0)。同時,后面一個選項被傳給內核。它指出當Linux內核載入時,內核的根文件系統應該是位於hda5,第一個IDE硬盤的第五個分區。
color - 設定在菜單中使用的顏色,一種是作為前景色,一種作為背景色。可以簡單地使用顏色名稱,如red/black。比如:
color red/black green/blue
default - 默認項目的標題名稱。如果菜單接口超時,那它將被載入。
fallback - 當這個命令被使用時,如果第一次嘗試失敗,那么這個項目的標題名稱將被使用。
hiddenmenu - 這個命令被使用時,它不顯示GRUB菜單接口,在超時時間過期后載入默認項。用戶通過按[Esc]鍵,可以看到標准的GRUB菜單。
timeout - 這個命令設定了在GRUB載入由default命令指定的項目的時間間隔,以秒為單位。
splashimage - 它指定在GRUB引導時所使用的屏幕圖像的位置。
  grub[1]
title - 設定用來裝載一個操作系統的一組特定命令的標題。
//字符#用來在菜單配置文件放置注釋。

我們詳細說下Window加載

title WindowsXP //標簽題目
root (hd0,0) //綁定根目錄到第一主分區,也可以用rootnoverify (hd0,0) rootnoverify就是指定根,但是不要掛載。
makeactive //激活分區--因為是Windows,所以必須激活。
chainloader +1//鏈式引導
至於Linux

title Linux
root (hd0,1)
kernel (hd0,1)/linux/vmlinuz //指明內核位置
initrd (hd0,1)/linux/initrd.img //指明安裝文件位置--這是個鏡像文件。
title 行是在在開機時所看到的菜單,顯示的就是 fc4install ,它要加在 title 的后面。title是必須保留的,它是grub的語法的標簽,可以在title 后面寫入想要添加的東西,這是可以自己定義的,比如 title fc4setup也是可以的。
root (hd0,1) 行使用 root開頭,然后加一個空格,至於用戶把vmlinuz和initrd.img 放在哪個分區了,可以打開 wingrub,單擊tools菜單選擇partioinlist (分區列表),在打開的對話框中查到。
kernel 命令行以kernel 開頭,然后加一個空格,並在其后給定vmlinuz文件存放路徑,這個命令行的作用是告訴計算機將使用(hd0,1)分區下的linux目錄中的kernel 內核來啟動;
initrd 行和 kernel 行類似;主要用於指明安裝的文件放在哪個分區和哪個目錄中,即在該命令后指定文件的安裝目錄。

下面說說常見的錯誤:

1 : Filename must be either an absolute filename or blocklist 
解釋 :1號錯誤表示文件名格式錯誤。在 GRUB 中要么是以絕對路徑給出文件 
例子 : 
grub> kernel vmlinuz root=label=/ 
Error 1: Filename must be either an absolute pathname or blocklist 
grub> 
  
  
  
 
2 : Bad file or directory type 
解釋 :2號錯誤表示命令期望的是一個普通文件,但相應文件名的對象是一個符號鏈接、目錄、FIFO 
例子 : 
grub> kernel /testdir root=LABEL=/ 
Error 2: Bad file or directory type 
grub> 
  
  
  
 
3 : Bad or corrupt data while decompressing file 
  
解釋 :3號錯誤表示解壓文件時發生錯誤。可能是因為這個文件被損壞了 
  
  
  
 
4 : Bad or incompatible header in compressed file 
解釋 :4號錯誤表示壓縮文件的頭部格式不被兼容或者錯誤 
  
  
  
 
5 : Partition table invalid or corrupt 
解釋 :5 號錯誤表示分區表無效或者被破壞。這是一個不好的預兆 
  
  
  
 
6 : Mismatched or corrupt version of stage1/stage2 
解釋 :6號錯誤表示 install 命令發現 stage1 和 stage2 的頒布號不被兼容 
  
  
  
 
7 : Loading below 1MB is not supported 
解釋 :This error is returned if the lowest address in a kernel is below 
the 1MB boundary. The Linux zImage format is a special case and 
can be handled since it has a fixed loading address and maximum size 
  
  
  
 
8 : Kernel must be loaded before booting 
解釋 :8號錯誤表示執行 boot 命令之前沒有先執行 kernel 命令 
  
  
  
 
9 : Unknown boot failure 
解釋 :9 號錯誤表示未知的引導錯誤 
  
  
  
 
10 : Unsupported Multiboot features requested 
解釋 :10 號錯誤表示請求 Multiboot header 所要求功能不被 GRUB 所支持。 
  
  
  
 
11 : Unrecognized device string 
解釋 :11 號錯誤表示無法識別的設備字符串。 
例子 : 
grub> root hd0 
Error 11: Unrecognized device string 
grub> 
  
  
  
 
12 : Invalid device requested 
解釋 :12 號錯誤表示請求的設備無效 
例子 : 
grub> root (hd2) 
Error 21: Selected disk does not exist 
grub> kernel /grub/grub.conf root=LABEL=/ 
Error 12: Invalid device requested 
grub> 
  
  
  
 
13 : Invalid or unsupported executable format 
解釋 :13 號錯誤表示無效或者無法識別的可執行格式 
例子 : 
grub> kernel /grub/grub.conf root=LABEL=/ 
Error 13: Invalid or unsupported executable format 
grub> 
  
  
  
 
14 : Filesystem compatibility error, cannot read whole file 
解釋 :14 號錯誤表示文件系統兼容性錯誤,無法讀取整個文件 
  
  
  
 
15 : File not found 
解釋 :請求的文件無法找到 
例子 : 
grub> find /grub-noexist/grub.conf 
Error 15: File not found 
grub> 
  
  
  
 
16 : Inconsistent filesystem structure 
解釋 :16 號錯誤表示不一致的文件系統結構。可能是文件系統結構被破壞了。 
  
  
  
 
17 : Cannot mount selected partition 
解釋 :17號錯誤表示無法掛載指定分區。例如 swap 分區 
例子 : 
grub> root (hd0,2) 這是一個 swap 分區 
Filesystem type unknown, partition type 0x82 
grub> kernel /vmlinuz 
Error 17: Cannot mount selected partition 
grub> 
  
  
  
 
18 : Selected cylinder exceeds maximum supported by BIOS 
解釋 :18 號錯誤表示選擇的柱面超過了 BIOS 支持的最大能力。這通常發生在不支持 LBA 模式 
的硬盤上。 
  
  
  
 
19 : Linux kernel must be loaded before initrd 
解釋 :19 號錯誤表示執行 initrd 命令前必須先執行 kernel 命令 
  
  
  
 
20 : Multiboot kernel must be loaded before modules 
解釋 :20 號錯誤表示執行 module 或者 moduleunzip 命令前必須先執行 kernel 命令 
  
  
  
 
21 : Selected disk does not exist 
解釋 :21 號錯誤表示選擇的磁盤不存在 
例子 : 
grub> root (hd2) 
Error 21: Selected disk does not exist 
grub> 
  
  
  
 
22 : No such partition 
解釋 :22 號錯誤表示分區不存在 
例子 : 
grub> root (hd0,10) 
Error 22: No such partition 
grub> 
  
  
  
 
23 : Error while parsing number 
解釋 :23 號錯誤表示參數解釋錯誤,希望是一個數值,但參數卻是其他類型 
例子 : 
grub> root (hda,0) 
Error 23: Error while parsing number 
grub> 
  
  
  
 
24 : Attempt to access block outside partition 
解釋 :24 號錯誤表示嘗試訪問的 block 超出了分區 
  
  
  
 
25 : Disk read error 
解釋 :25 號錯誤表示磁盤讀錯誤 
  
  
  
 
26 : Too many symbolic links 
解釋 :26 號錯誤表示太多的符號連接(默認最多允許5個) 
  
  
  
 
27 : Unrecognized command 
解釋 :無法識別的命令 
  
  
  
 
28 : Selected item cannot fit into memory 
解釋 :選擇的對象無法被加載到內存中。 
例子 : 
[root@monitor boot]# dd if=/dev/zero of=vmlinuz-2.4.20-31.9 bs=1024 count=1 seek=1 
讀入了 1+0 個塊 
輸出了 1+0 個塊 
  
[root@monitor boot]#grub 
grub> kernel /vmlinuz-2.4.20-31.9 root=label=/ 
[Linux-bzImage, setup=0x1400, size=0xfffff200] 
  
Error 28: Selected item cannot fit into memory 
  
grub> 
  
  
  
 
29 : Disk write error 
解釋 :磁盤寫錯誤 
  
  
  
 
30 : Invalid argument 
解釋 :無效參數 
例子 : 
grub> serial --noarg=0 
Error 30: Invalid argument 
grub> 
  
  
  
 
31 : File is not sector aligned 
解釋 :This error may occur only when you access a ReiserFS partition by 
block-lists (e.g. the command `install'). In this case, you should 
mount the partition with the `-o notail' option. 
  
  
  
 
32 : Must be authenticated 
解釋 :要求輸入口令才能繼續進行下面的操作。例如配置文件中有 password 或者 lock 命令 
例子 : 
password root1234 
title DOS 
lock 
rootnoverify (hd0,0) 
chainloader +1 



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM