偶然間發現ubuntu自9.10來就把grub2當作預設引導程式,而grub2的确功能強大。
一直以來,人們都為安裝linux和windows之後怎樣修複啟動而頭疼。
而grub2的出現,或許可以減少很多麻煩,因為比起grub,grub for dos,grub2的确智能很多。
grub2目前中文文檔很少,下面是一些英文幫助頁面。
ubuntu wiki頁面:
https://help.ubuntu.com/community/grub2
grub2 wiki
http://grub.enbug.org/frontpage
grub2 指令
http://grub.enbug.org/commandlist
grub2的配置檔案主要在下面三個位置
the configuration resides (generally) in three places:
in /etc/default/grub - where a set of general configuration options reside, created by grub-set-default, that you may not want to change much.
in /etc/grub.d - where a set of sh scripts are sequentially used to do useful things that generate the actual bootloader's config file, much like init scripts.
in /boot/grub - where the bootloader itself looks for configuration ( /boot/grub/grub.conf ). this file is written from the /etc/grub.d files, so changes here will be overwritten by some commands.
!!! boot/grub/gurb.conf 可能有誤,在ubuntu下是boot/grub/grub.cfg
/etc/default/grub :預設配置
/etc/grub.d :類似shell腳本一樣的配置
/boot/grub/grub.cfg :所/etc/grub.d檔案夾下的檔案生成的配置檔案,最重要的配置
下面主要說介紹怎樣在ubuntu下修複windows啟動
1.使用grub-mkconfig 指令智能生成grub.cfg
把生成的cfg檔案覆寫到 /boot/grub/grub.cfg 就行了。
隻能說grub-mkconfig指令真是神器,一直很希望能有這樣的智能指令。
# grub-mkconfig -o /root/grubtrial/grub.conf_2
generating grub.cfg ...
found linux image: /boot/vmlinuz-2.6.31-20-generic-pae
found initrd image: /boot/initrd.img-2.6.31-20-generic-pae
found linux image: /boot/vmlinuz-2.6.31-17-generic-pae
found linux image: /boot/vmlinuz-2.6.31-14-generic-pae
found initrd image: /boot/initrd.img-2.6.31-14-generic-pae
found memtest86+ image: /boot/memtest86+.bin
found windows vista (loader) on /dev/sda3
found debian gnu/linux (5.0.3) on /dev/sda8
done
2.能過編寫grub2腳本來修複啟動
首先檢視分區的uuid
> sudo blkid
可能是以下的結果
>/dev/sda2: uuid="10ac99d8ac99b8a4" type="ntfs"
參照下面編寫腳本,使用者的腳本檔案是 /etc/grub.d/40_custom
編輯 /etc/grub.d/40_custom 檔案如下
如果熟悉grub 或者 grub for dos,很容易明白。
grub2的一大特點就是用uuid來代替了以前的(hd0,0)的寫法。
因為硬碟可能增加,移動分區等,但是uuid通常不會改變,這避免了頻繁修改配置檔案
#!/bin/sh
exec tail -n +3 $0
# this file provides an easy way to add custom menu entries. simply type the
# menu entries you want to add after this comment. be careful not to change
# the 'exec tail' line above.
menuentry "windows xp" {
insmod chain
insmod ntfs
search --fs-uuid --set 10ac99d8ac99b8a4
chainloader +1
}
執行
>sudo update-grub
可以檢視到配置檔案更新了。
>cat /boot/grub/grub.cfg