grub 安裝 GRUB 開機管理程式。
### 維護模式的進入:
linux –s
linux single
硬碟搜尋順序
在 Grub 當中的代號
第一顆
(hd0)
(hd0,0)
(hd0,1)
(hd0,4)
....
第二顆
(hd1)
(hd1,0)
(hd1,1)
(hd1,4)
....
第三顆
(hd2)
(hd2,0)
(hd2,1)
(hd2,4)
....
[root@www ~]# grub-install [--root-directory=DIR] INSTALL_DEVICE
選項與參數:
--root-directory=DIR 預設 /,grub-install 將檔案複製到 /boot/grub/,
若要複製到其他目錄與裝置去,就要用這個參數。
INSTALL_DEVICE 安裝的裝置代號。
#範例一:將 grub 安裝在目前系統的 MBR 底下,系統為 /dev/hda:
[root@www ~]# grub-install /dev/hda
# 因為原本 /dev/hda 就是使用 grub ,所以似乎不會出現什麼特別的訊息。
# 如果去查閱一下 /boot/grub 的內容,會發現所有的檔案都更新了,因為重裝了!
#範例二:我的 /home 為獨立的 /dev/hda3 ,如何安裝 grub 到 /dev/hda3 (boot sector)
[root@www ~]# grub-install --root-directory=/home /dev/hda3
Probing devices to guess BIOS drives. This may take a long time.
Installation finished. No error reported.
This is the contents of the device map /home/boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.
(fd0) /dev/fd0
(hd0) /dev/hda %*<==會給予裝置代號的對應表!*)
[root@www ~]# ll /home/boot/grub/
-rw-r--r-- 1 root root 30 Apr 30 11:12 device.map
-rw-r--r-- 1 root root 7584 Apr 30 11:12 e2fs_stage1_5
....(底下省略)....
# 檔案都安裝了,但並沒有設定檔,那要自己建立。
[root @test root]# vi /boot/grub/menu.lst
timeout 100 %*<==延遲時間,單位0.1秒 *)
Color black/cyan yellow/cyan %*<==設定顏色的參數 *)
i18n (hd0,0)/boot/grub/messages %*<==設定 i18n 多國語系的訊息提示 *)
keytable (hd0,0)/boot/us.klt %*<==設定鍵盤形式,通常使用美規的鍵盤即可 *)
Default 0 %*<==預設的開機選項,依照底下的排序,第一個為 0 *)
title linux %*<==第一個開機設定檔,亦即排序為 0 號 *)
kernel (hd0,0)/boot/vmlinuz root=/dev/hda1 devfs=mount
initrd (hd0,0)/boot/initrd.img
%*<==上面兩個則是開機設定檔的基本內容,分別是 *)
核心檔案所在地與 Ramdisk 的設定內容
title failsafe %*<==第二個開機設定檔,亦即排序為 1 號 *)
kernel (hd0,0)/boot/vmlinuz root=/dev/hda1 devfs=nomount failsafe
initrd (hd0,0)/boot/initrd.img
title windows
rootnoverify (hd0,0)
chainloader +1
## 設定 Windows OS 的方式跟 Linux 不同。
## rootnoverify 指示 GRUB 不需掛載 hda1 的分割區,只需知道是要啟動此分割區上的作業系統即可。
## chainloader 指定 hda1 的第一個磁區做啟動磁區 (boot sector)。
## 兩行亦可合併成 chainloader (hd0,0) +1。
[root @test root]# vi /boot/grub/menu.lst
timeout 100 %*<==延遲時間,單位0.1秒 *)
Color black/cyan yellow/cyan %*<==設定顏色的參數 *)
i18n (hd0,0)/boot/grub/messages %*<==設定 i18n 多國語系的訊息提示 *)
keytable (hd0,0)/boot/us.klt %*<==設定鍵盤形式,通常使用美規的鍵盤即可 *)
Default 0 %*<==預設的開機選項,依照底下的排序,第一個為 0 *)
title linux %*<==第一個開機設定檔,亦即排序為 0 號 *)
kernel (hd0,0)/boot/vmlinuz root=/dev/hda1 devfs=mount
initrd (hd0,0)/boot/initrd.img
%*<==上面兩個則是開機設定檔的基本內容,分別是 *)
核心檔案所在地與 Ramdisk 的設定內容
title failsafe %*<==第二個開機設定檔,亦即排序為 1 號 *)
kernel (hd0,0)/boot/vmlinuz root=/dev/hda1 devfs=nomount failsafe
initrd (hd0,0)/boot/initrd.img
title windows
rootnoverify (hd0,0)
chainloader +1
## 設定 Windows OS 的方式跟 Linux 不同。
## rootnoverify 指示 GRUB 不需掛載 hda1 的分割區,只需知道是要啟動此分割區上的作業系統即可。
## chainloader 指定 hda1 的第一個磁區做啟動磁區 (boot sector)。
## 兩行亦可合併成 chainloader (hd0,0) +1。
[root @test root]# grub
# 安裝在 Super Block :
grub> root (hd0,0) %*<==這裡輸入我要的 root 硬碟磁區! *)
Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0,0) %*<==實際安裝上來!使用 setup 指令! *)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0,0)"... failed (this is not fatal)
Running "embed /boot/grub/e2fs_stage1_5 (hd0,0)"... failed (this is not fatal)
Running "install /boot/grub/stage1 (hd0,0) /boot/grub/stage2 p /boot/grub/menu
.lst "... succeeded
Done.
# 安裝在 MBR :
grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 17 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd0) (hd0)1+17 p (hd0,0)/boot/grub/stage2
/boot/grub/menu.lst"... succeeded
Done.
grub> quit %*<==離開 grub*)
練習題