閱讀923 返回首頁    go 阿裏雲 go 技術社區[雲棲]


Grub2 強大的引導程序,智能修複啟動

偶然間發現ubuntu自9.10來就把grub2當作默認引導程序,而grub2的確功能強大。

一直以來,人們都為安裝linux和windows之後怎樣修複啟動而頭疼。

而grub2的出現,或許可以減少很多麻煩,因為比起grub,grub for dos,grub2的確智能很多。

 

grub2目前中文文檔很少,下麵是一些英文幫助頁麵。

ubuntu wiki頁麵:

https://help.ubuntu.com/community/Grub2

grub2 wiki

https://grub.enbug.org/FrontPage

grub2 命令

https://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  

 

 

 

 

最後更新:2017-04-02 06:51:32

  上一篇:go magento -- 1.4.2.0穩定版發布了
  下一篇:go typedef用法