|
Backing Up the MBR
Backing Up the MBR October 20, 2005
Posted by ubuntonista in guides, ubuntu. trackback
I found myself in the situation of helping a friend reinstall windows on a system which also has Ubuntu on it. In other words, it was a dual boot system, and we were both afraid that re-installing Windows will overwrite the Master Boot Record (MBR) and make it impossible to boot into Ubuntu in the short term. So we devised a plan, with a little help from google to backup his MBR before reinstalling windows, and then restoring it after reinstalling windows.
Create a backup of your MBR by doing a:
$dd if=/dev/hdx of=MBR-backup bs=512 count=1
That should read “create a disk dump of the input file, which is /dev/hdx (change to hda, or hdb or sda, depending on where the MBR is on your computer), and save it in the output-file MBR-backup in the directory from where the command is issued. Backup the first sector only, while you are at it”.
Now that is the backup of your MBR. Restore it later using:
$dd if=MBR-backup of=/dev/hdx bs=512 count=1
Again, change hdx to hda, or hdb or wherever the MBR needs to be restored to. You may have to use a live cd to restore the backup since you will be unable to login to Linux after you reinstall Windows.
As with all other advice, take this with a pinch of salt, and search on google for a solution to your problem, understand the solution and then embark on your mission!
If you are going to need to use a Live CD to recover the backup MBR then you could have booted into rescue mode from the install CD (of any linux distro you choose) and mounted the linux partition, chrooted to the root partition and typed grub-install /dev/hdx.
mkdir /mnt/temp
mount /dev/hda3 /mnt/temp ## if hda3 was the linux partition
chroot /mnt/temp
grub-install /dev/hda
That would install the grub first stage boot loader to you the MBR of the hard disk and presented you with the same options you had before the Windows reinstall. no need for backup MBR records!
Note that the grub-install method has the added protection of not inadvertantly overwriting your partition table if it had been modified since your last MBR backup.
This is because the 512byte MBR sector is actually two parts:
1) The first 446 bytes is the grub stage1 bootloader (or the windows bootloader after you’ve reinstalled windows and it “helpfully” overwrites grub).
2) The last 64 bytes is where your partition table is stored.
So, if you only want to backup the bootloader in the MBR, remember to change the bs=512 to bs=446.
source:
http://ubuntu.wordpress.com/2005/10/20/backing-up-the-mbr/
|