2012年7月9日 星期一

重建Ubuntu MBR

Ubuntu的MBR不見了,只剩下windows的MBR
1. 準備Ubuntu LiveCD
2. 利用Ubuntu LiveCD開機
3. 進入terminal
    # cd /
    # sudo -s -H
    # mount -t ext4 /dev/sda6 /mnt      ->sda6為Ubuntu所在的磁區
    # mount -t proc proc /mnt/proc
    # mount -t sysfs /sys /mnt/sys
    # mount -o bind /dev /mnt/dev
    # chroot /mnt /bin/bash         ->切換 root到硬碟上的Ubuntu

如果不知道Ubuntu在那一個磁區,查詢硬碟上的partition資訊    
    # ls -l /dev/disk/by-label
    # fdisk -l

安裝grub2
    # aptitude install grub2 grub-pc

如果已經安裝了grub,先移除
    # apt-get pruge grub

更新grub
   # update-grub
   # grub-install /dev/sda
   # reboot
恢復原先Ubuntu的grub

如果開機後,沒有任何開機選單,只出現
  grub >  -> 這代表沒有grub menu
  grub > find /boot/grub/core.img
  grub > root (hd0, 5)    -> root (hdx, y) previous command will tell you the x, y in this case is (hd0, 5)
  grub > kernel /boot/grub/core.img
  grub > boot
  現在可以進入Ubuntu 系統

如果開機會直接進入Ubuntu,沒有menu可以選擇要那個OS
   # update-grub
  讓 grub自動建立menu.list, 檔案位置在/boot/grub/menu.list
  grub2沒有menu.list,是grub.cfg, 檔案位置在/boot/grub/grub/cfg