2010/05/01

搬動ubuntu 9.10 的 root partition

一直以來,搬動root partition 對我來說都是一個大工程,原因是經常搞不定 grub 照成無法開機,但不知為何每次在用linux 時,都會有移動root partition的需求,不是因為換硬碟,就是root partition 給的太小,應該是我一開始沒有規畫好.....

在之前 grub 時期,網上有各種的解決方法可以參考,花點時間找找也就解了,但Ubuntu 9.10 後將grub 改為 grub 2.0 ,事情對我來說就沒那麼單純了.....

先來個環境說明吧,我的"fstable -l"如下:

所用裝置 Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        6376    51215188+   7  HPFS/NTFS
/dev/sda2            6377       19457   105073132+   f  W95 Ext'd (LBA)
/dev/sda5            6377       17191    86871456    7  HPFS/NTFS
/dev/sda6           18403       19405     8056566   83  Linux
/dev/sda7           19406       19457      417658+  82  Linux swap / Solaris
/dev/sda8           17192       18402     9727326   83  Linux

而我原本的 / 是放在 sda6 中,然後在sda8中再安裝了ubuntu netbook remix,結果 netbook remix 版是用grub2 所以取代了 sda6 中原本的grub,我也偷懶一直沒有動它...直到最近 sda6 的空間不夠了沒辨法才對它開刀,結果花了我好多時間...@@..待我慢慢道來..

我的目的是希望將 root 從 sda6 移到 sda8 如下图:

首先用 再生龍clonezilla(謎:開發者國家高速網路的clonezilla專屬網頁反而進不去.....) 將 sda6 直接整塊 clone 到 sda8,接下來我就很衝動對 sda6 作了 "sudo rm -rf *" ya~ 然後開機時它就抱怨找不到 grub ,所以要重裝grub ,這個動作很常見,像之前我們在 linux 安裝完後,再安裝 win xp 就會遇到 .....

接著我就按照論壇上的方法用光碟安裝,

sudo mount /dev/sda8 /mnt
sudo mount --bind /dev/ /mnt/dev
sudo chroot /mnt
sudo grub-install /dev/sda
reboot

結果是....失敗...只看到boot menu 點選進去,永遠都是ERR 15
依這邊的說法是:
File Not Found (Error 15) 此錯誤為 GRUB 2 安裝至 /boot 但主開機磁區(MBR)依然為傳統 Grub。此狀況發生在當您執行 sudo update-from-grub-legacy 時未選擇您的磁碟。
但是我沒有執行過 sudo update-from-grub-legacy ,而且用它教的方法 從開機光碟重新安裝 還是一樣的error出現,這可讓我傷腦筋了,還好後在英文版 grub2 wiki中看到 對從live 重新安裝Grub2 之METHOD 3 - CHROOT如下照作,就可以開機進去了..^^..我認為關鍵是在第7點,確定安裝時是使用live cd上的grub2,可能我原本usr下的grub2問題,所以之前重裝才會無法解決問題。
-------------------------------------------------------------------

METHOD 3 - CHROOT

This method of installation uses the chroot command to gain access to the broken system's files. Once the chroot command is issued, the LiveCD treats the broken system's / as its own. Commands run in a chroot environment will affect the broken systems filesystems and not those of the LiveCD.

  1. Boot to the LiveCD Desktop (Ubuntu 9.10 or later).
  2. Open a terminal - Applications, Accessories, Terminal.

  3. Determine your normal system partition - (the switch is a lowercase "L")

    sudo fdisk -l

    • If you aren't sure, run

      df -Th. Look for the correct disk size and ext3 or ext4 format.

  4. Mount your normal system partition:
    • Substitute the correct partition: sda1, sdb5, etc.

    sudo mount /dev/sdXX /mnt # Example: sudo mount /dev/sda1 /mnt

  5. Only if you have a separate boot partition:

    • sdYY is the /boot partition designation (for example sdb3)
    • sudo mount /dev/sdYY /mnt/boot

  6. Mount the critical virtual filesystems:

    sudo mount --bind /dev  /mnt/dev
    sudo mount --bind /proc /mnt/proc
    sudo mount --bind /sys  /mnt/sys

  7. To ensure that only the grub utilities from the LiveCD get executed, mount /usr

    sudo mount --bind /usr/ /mnt/usr

  8. Chroot into your normal system device:

    sudo chroot /mnt

  9. If there is no /boot/grub/grub.cfg or it's not correct, create one using

    update-grub

  10. Reinstall GRUB 2:
    • Substitute the correct device - sda, sdb, etc. Do not specify a partition number.

    grub-install /dev/sdX

  11. Verify the install (use the correct device, for example sda. Do not specify a partition): sudo grub-install --recheck /dev/sdX

  12. Exit chroot: CTRL-D on keyboard

  13. Unmount virtual filesystems:

    sudo umount /mnt/dev
    sudo umount /mnt/proc
    sudo umount /mnt/sys

    • If you mounted a separate /boot partition:

      sudo umount /mnt/boot

  14. Unmount the LiveCD's /usr directory:

    sudo umount /mnt/usr

  15. Unmount last device:

    sudo umount /mnt

  16. Reboot.

    sudo reboot

沒有留言: