13 July 2010

Update Master Boot Record (MBR) replacing the System disk

Some times ago, I've written an article explaining how to restore MBR with grub. It works only if there is no disk change.

Almost the same procedure can be used if the System disk change.

For instance you have your GNU/Linux on your first disk, and you add another disk (with better efficiencies ?) as System disk (getting the first index), but you want to restore this MBR instead of other (for instance if you install a Windows operating system on your new disk).

The variables of this example are:
- /dev/sda the new disk,
- /dev/sdb the old system disk
- /dev/sdbM the ext2/ext3/ext4 boot partition (corresponds to hd1,M-1 for bootloader)
- grub as bootloader

- boot with a GNU/Linux Rescue or Live CD of your choice
- remove/rename the /boot folder of the launched GNU/Linux Rescue or Live CD instance
- mount your boot partition
mkdir /boot
mount -t ext3 /dev/sdaM /boot
- update the grub configuration file (/boot/grub/grub.conf), replacing all hdN occurrence corresponding to partition of the old disk, by hdP (with P=N+1)
- prefer using LABEL=XXX or UUID=YYY to indicate the root partition on the "kernel" line instead of hdX information
- update the grub device map (very important for old and new disk to be seen)
grub-install --recheck /dev/sdb
- update grub MBR information (the disk/partition information correspond to your /boot partition)
root (hd1,M-1)
setup (hd1,M-1)
- update the MBR (the disk information corresponds to where the MBR must be installed - usually the first disk (your new one))
grub-install /dev/sda

No comments:

Post a Comment

Thank you for your visit, let's share your point of view: