顯示具有 BOOT 標籤的文章。 顯示所有文章
顯示具有 BOOT 標籤的文章。 顯示所有文章

2010年4月9日 星期五

復原 Windows MBR 的各種方式

玩 Linux 最常見的方式就是切 Partition 做多重開機, 讓 GRUB 寫入 MBR 做開機選單. 但是若不小心把 Linux Partition 刪掉了, 或是哪天不想玩 Linux 了, 想恢復為 Windows 單一作業環境的時候, 就得把 Windows Pre-Boot 程式寫回 MBR 的前 446 Bytes 喔!
方法一:使用 DOS / Win9x / ME 開機片開機
開機後在 MS-DOS 模式下執行 fdisk /mbr
重新啟動電腦即可

方法二:使用 Windows 2000 / XP 光碟片開機 (過程中需要 Administrator 密碼)
在 Welcome to Setup (歡迎使用安裝程式) 畫面中按 R 或 F10 進入「Windows 修復主控台」
進入主控台後, 輸入 fixmbr
重新啟動電腦即可
詳細操作過程請參考微軟官方網頁 - Windows XP 修復主控台的說明

方法三:使用 Linux 光碟片開機, 進入 Rescue 模式; 或用 KNOPPIX 之類的 Linux 作業系統開機 (過程中請啟用網路)
依序輸入以下指令恢復 Windows MBR
wget http://cha.homeip.net/downloads/ms.mbr -O /tmp/ms.mbr
dd if=/tmp/ms.mbr of=/dev/hda
exit (重開機時請移除光碟片)
  • 以上操作結果同 fdisk /mbr
  • 網路上流傳 dd if=/dev/zero of=/dev/hda bs=446 count=1 效果等同 fdisk /mbr 是錯誤的, 這樣只會清掉 MBR 的 Pre-Boot 內容而已.
  • 警告: 請勿於頭腦混沌、神智不清時使用 dd 指令; 使用時請特別注意數字是否正確!

方法四:什麼開機片都沒有, 但開機後還有 GRUB> 提示符號
依序輸入以下指令啟動 Windows
rootnoverify (hd0,0)
makeactive
chainloader +1
boot
  • (hd0,0) 其中 hd0 表示 Primary IDE Master HDD, 0 表示第一個分割區, 請依實際狀況套用.
  • 注意: 這只是解決 Windows 的啟動問題而已, 仍要靠前三種方法的其中一種才能讓 MBR 恢復正常喔! 當然, Windows 開機後您也可以上網尋找其他的解決方案 :)

-------------------------------------------------------------------------------
最後使用方法四,成功進入XP,之後利用 TestDisk 救回XP MBR.

2010年4月8日 星期四

重建 GRUB (linux boot loader)

 方法一:

GRUB (GRand Unified Bootloader 縮寫) 是 linux 系統中常用的系統啟動軟體,另一個同功能的是 LILO (LInux LOader 縮寫),它的作用是接管 BIOS 交付控制權給作業系統時的第一個工作–把作業系統正確地從硬碟載入。通常一般使用者在用光碟裝完 linux 後,例如 ubuntu,系統就會自動裝好 GRUB,就像 Windows 系統一樣。然而如果有某種原因被毀損了,最常見的是在同個硬碟想有 dual system,先裝好 linux 再裝 Windows,Windows 會很不客氣毫不猶豫地直接蓋掉 GRUB,你的 linux 就此無法開機,這時就需要重建 GRUB 了…

如何重建 GRUB 的步驟如下:
  • 使用原來的 linux 安裝光碟開機。現代的系統都是 live-cd,即開機光碟 boot 完就是可操作的系統。
  • 開一個終端機程式,可以輸入命令。
  • 執行 sudo grub,回答密碼。
  • grub> find /boot/grub/stage1,它會找原來裝 GRUB 的硬碟分區,例如 (hd1,0),即第二個硬碟的第一個分區。
  • grub> root (hd1,0),告訴它 linux root 在哪裡。
  • grub> setup (hd0),安裝 GRUB 在第一個硬碟的 MBR (Master Boot Record)。把 Windows 的 bootloader 蓋掉… 之後可以在 GRUB menu 中加入進 Windows 系統的選項,本文不討論這個。
  • grub> quit,結束,這樣就完成 GRUB rebuild,可以 reboot 了。
另一作法是把 GRUB 安裝在硬碟分區裡,例如 grub> setup (hd1,0),安裝 GRUB 在第二個硬碟的第一個分區,而不是 MBR。這種方法可以使用 Windows 的 boot loader 來作 dual system 啟動.

Reference from  http://ying.homedns.org/wp/2007/11/283/

------------------------------------------------------------------------------------------------------------------------------------
 方法二:

用Ubuntu 9.10的Live CD試用Ubuntu啟動後,打開終端
sudo -i
sudo fdisk -l (查看你的分區信息)
# mount /dev/sdaX /mnt
sdaX,此處填寫 / 的位置

         # grub-install --root-directory=/mnt/ /dev/sda

最後
   
       # update-grub2

使用 Windows bootloader 來 load Linux

用 Windows 本身的 bootloader 來建立多系統的電腦


使用 Windows NT/2000/2003/XP 本身的 bootloader 來 dual boot 需要一個叫 bootpart 的程式,在這裡下載。另外要注意安裝 linux 時要把 GRUB 裝在 linux 的分區,而不是裝在 MBR。

bootpart 執行後可以看到類似下面的資料,是所有硬碟的 partition 列表,
C:\>bootpart
Boot Partition 2.60 for WinNT/2K/XP (c)1995-2005 G. Vollant (info@winimage.com)
WEB : http://www.winimage.com and http://www.winimage.com/bootpart.htm
Add partition in the Windows NT/2000/XP Multi-boot loader
Run "bootpart /?" for more information

Physical number of disk 0 : 96e096d
0 : C:* type=7  (HPFS/NTFS), size= 15358108 KB, Lba Pos=63
1 : C:  type=5  (Extended), size= 145476607 KB, Lba Pos=30716280
2 : C:  type=7   (HPFS/NTFS), size= 145476576 KB, Lba Pos=30716343
Physical number of disk 1 : f6568938
3 : D:* type=83  (Linux native), size= 19535008 KB, Lba Pos=63
4 : D:  type=5  (Extended), size= 2000092 KB, Lba Pos=39070080
5 : D:  type=82   (Linux swap), size= 2000061 KB, Lba Pos=39070143
找到裝有 linux 的 partition,如上面的 3,執行下面的命令:
C:\>bootpart 3 bootlnx.sec ubuntu
意思是建立一個叫 bootlnx.sec 檔名的檔案,用第三個 partition boot,並用 “ubuntu” 的名字加入 Windows bootloader 的選單。執行完了之後,產生一個 bootlnx.sec 檔案,並在 boot.ini 中加了最後一行:
[boot loader]
timeout=5
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows XP Media Center Edition" /noexecute=optin /fastdetect
C:\bootlnx.sec="ubuntu"
這樣就 ok 了,重開機會看到上面的兩個選項 “Windows XP Media Center Edition” 及 “ubuntu”。

Reference from http://ying.homedns.org/wp/2007/12/286/

2010年4月4日 星期日

解決ubuntu 9.10 用wubi安裝,upgrade kernel 後GRUB2毀損的問題




insmod ntfs


set root=(hd0,1)

loopback loop0 /ubuntu/disks/root.disk

set root=(loop0)

linux /boot/vmlinuz-2.6.31-20-generic root=/dev/sda3 loop=/ubuntu/disks/root.disk ro

initrd /boot/initrd/initrd.img-2.6.31-20-generic

boot


開機完成後執行 "sudo update-grub2" 即可

How to repair and clone disk with ddrescue

  ddrescue  is a tool that can be used to repair and clone disks on a  Linux system . This includes hard drives, partitions, DVD discs, flas...