Tuesday, October 20, 2009

Reinstall Win XP on a double boot machine with linux

Without reinstalling linux itself.
  • backup your MBR (I like to stay safe, but this is not needed) with:
$ sudo dd if=/dev/sda of=MBRbackup bs=512 count=1 ***note
  • Download a gparted or any live distro like knoppix or whatever
  • Reinstall win
  • boot from the live distro or in rescue mode from the installation cd
  • mount the linux partition
mkdir /mnt/temp
mount /dev/sda1 /mnt/temp
  • chroot to the root partition and type grub-install /dev/hdX. (when X is the drive letter).
chroot /mnt/temp
grub-install /dev/sda

that's it
not bad as it seemed as a first sight

The process described forward will install GRUB first stage boot loader to the MBR and present you with the same options you had before the Windows reinstall.

Note that this option has an added protection of not overwriting the partition table if it changed since the last MBR backup (this of course should not happen).

This is because the 512byte MBR sector is actually two parts:
- The first 446 bytes of the sector are the grub stage1 bootloader (or the windows bootloader after you’ve reinstalled windows and it overwriten grub).
- The last 64 bytes is where the partition table is stored.
You can, just to be on the safe side, change the bs=512 to bs=446 when using the first option. (you can figure out it should be 448 and not 446, but it really doesn’t matter since this area contains a constant that doesn’t change).

C U to the next problem


No comments:

Post a Comment