As of late, I have been using the somewhat risky ‘dd’ command to backup my PCs MBR before any installation. I say somewhat risky because once the command is sent, there is no ‘undoing’. So it requires 100% accuracy (and/or lots of backups)
I installed winXP on a PC earlier this weekend, replacing FreeDOS which was on same partition. The PC now has (from “fdisk -l” command run as root):
Device Boot Start End Blocks Id System
/dev/sda1 1 12748 102398278+ 7 HPFS/NTFS
/dev/sda2 12749 16572 30716280 83 Linux
/dev/sda3 * 16573 18484 15358140 83 Linux
/dev/sda4 18485 182402 1316665344 5 Extended
/dev/sda5 18485 19313 6656000 82 Linux swap / Solaris
/dev/sda6 19313 23775 35840000 83 Linux
/dev/sda7 23775 182402 1274166272 83 Linux
sda1 before the winXP install had freeDOS. As you can see the Boot partition is sda3 which has the / (root) of an openSUSE-11.4 install.
Backup Linux MBR. What I did BEFORE installing winXP was download and burn the liveCD PMagic (currently version-6.0). Then once ready to proceed I booted to PMagic and opened a terminal and backed up the MBR by typing:
dd if=/dev/sda of=MBR-backup-corei7-440 bs=440 count=1
which created the file “MBR-backup-corei7-440”. I plugged in a USB stick and I copied that file “MBR-backup-corei7-440” to the USB stick.
Change partition boot flag to where WinXP will be installed. I also ran gparted from that PMagic liveCD session and removed the ‘boot’ partition flag from /sda3 and instead marked /sda1 as the boot partition. This meant that the PC for the time being would ONLY boot /sda1 (and hence NOT boot Linux).
Install winXP. I then restarted the PC and performed the winXP install, being careful to install on the first partition with winXP (which winXP called C: and linux called /sda1). I confirmed the PC would boot to only winXP (there being no boot manager).
Once winXP was installed, I rebooted to the PMagic liveCD.
backup WinXP MBR. This time, to be cautious, I backed up the winXP MBR from a terminal with the command:
dd if=/dev/sda of=MBR-windows-xp-440 bs=440 count=1
and I plugged in a memory stick and I copied the file “MBR-windows-xp-440” to the USB memory stick. That meant I could always restore the MS-Windows MBR any time. (I did not have to use this backup).
**Restore Linux MBR **. Now that memory stick also still had the file “MBR-backup-corei7-440” from before. So I then using that file from the memory stick, copied that backup MBR onto the hard drive with the ‘dd’ command:
dd if=MBR-backup-corei7-440 of=/dev/sda bs=440 count=1
Note the entries for ‘if’ and ‘of’ are different. It is ABSOLUTELY important to get that right. Maybe backup the file “MBR-backup-corei7-440” in a second place to ensure you have an extra copy in case one messes this up in a moment of absent mindedness.
**Restore boot flag to Linux **. After I had the MBR restored (with that command) I then in the PMagic session launched the program gparted and removed the boot flag from sda1 and marked sda3 with the boot flag. So now the PC was the SAME as before, with a boot flag on sda3 and the old MBR back in place.
**Restart and all is well **. I then restarted, and I was back to what I had in the beginning, with a bootable Linux on /sda3 and a bootable WinXP OS on /sda1.