天天看點

Ubuntu14.04引導菜單修複

        獨立分區下的Ubuntu引導菜單修複有點麻煩,執行挂載等指令時要小心檢查,修複此類引導,首先需要確定目前系統和資料安全(包括Windows和Ubuntu),不可因為分區盤符輸入錯誤導緻資料丢失或誤删除。

一、使用Ubuntu LiveCD

(親測,可行.....)

使用Ubuntu LiveCDCD光牒啟動系統,然後在Terminal終端中查找Ubuntu安裝根分區(fdisk -l),并修複啟動,步驟如下(依次執行):

1、提升root權限      
sudo -i      

2.檢視磁盤清單

fdisk -l      

(該指令會顯示目前磁盤清單,找到Ubuntu根分區,假設為sda2)

3、挂載根分區

mkdir /mnt/temp
mount /dev/sda2 /mnt      

(根分區/dev/sda2需據實際情況确定)

4、挂載boot分區

mount /dev/sda3 /mnt/boot      

(如果有/boot分區,假設為sda3,如果無/boot獨立分區則跳過本步驟)

5、挂載系統目錄

for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done

6、進入原系統
chroot /mnt 

7、重裝grub到MBR
grub-install /dev/sda
update-grub

8、退出原系統
exit

9、重新開機電腦      

備注:swap分區似乎不用挂載?

以上指令執行後,有可能WIN7的菜單又沒有了,不過沒關系,隻用進入Ubuntu然後,再次執行sudo update-grub,會自動添加WIN7引導菜單,重新開機即可。

tst@tst-laptop:~$ sudo update-grub
[sudo] password for tst:
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.32-38-generic
Found initrd image: /boot/initrd.img-2.6.32-38-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Windows 7 (loader) on /dev/sda1
done
tst@tst-laptop:~$      

二、使用傳統Grub menu.lst

如沒有UbuntuCD光牒,也可以修複引導,但需要通過Windows或WinPE等方式先安裝一個Grub引導程式,比如Grub4dos,(安裝方法可參考​​Windows下如何硬碟安裝CentOS​​ 和​​Windows 7下硬碟安裝Ubuntu方法​

​)。然後再啟動進入Grub菜單後使用指令行形式修改menu.lst。

注意:Ubuntu的Grub2引導啟動菜單放在/boot/grub/grub.cfg,早期則用/boot/grub/menu.lst和/boot/grub/stage1。

如果想windows引導Ubuntu(即Grub1引導Grub2),示例如下(該方法已驗證,參考來源下文論壇位址):

/boot非單獨分區

title Ubuntu
root (hd0,x)
kernel /boot/grub/core.img
boot      

/boot單獨分區

title Ubuntu
root (hd0,x)
kernel /grub/core.img
boot      

請注意,不同版本的Ubuntu,core.img可能在不同的目錄下,比如:

  • Ubuntu 10.04 /boot/grub/core.img
  • Ubuntu 12.04 /boot/grub/core.img
  • Ubuntu 12.10 /boot/grub/i386-pc/core.img
  • Ubuntu 14.04 /boot/grub/i386-pc/core.img

這樣修改後的menu.lst就可以引導Ubuntu,即windows引導Ubuntu。

如果想使用Ubuntu預設的引導器來引導Windows,可以在進入Ubuntu之後執行如下兩句即可:

  • sudo grub-install /dev/sda
  • sudo update-grub

這樣系統引導菜單就又交給Ubuntu,把前面的Windows引導菜單就多餘了,在Windows下删除即可。

繼續閱讀