[CentOS] How to move my MBR

Fri May 23 05:59:53 UTC 2008
Theo Band [GreenPeak] <theo.band at greenpeak.com>

Scott Moseman wrote:
> I removed an ATA drive (/home) for a new SATA and my system would not
> boot.  I'm guessing that it put the MBR on that drive instead of the
> drive that holds the / partition.  What's the best way confirm where
> the MBR resides and, after I verify that's my problem, how I can move
> (or make a copy) onto a different drive?
>   
The BIOS determines which disk (the first) will be chosen to boot from. 
Sometimes hitting F12 or some other key gives you a menu to choose from. 
I have seen occasions were the bios was confused on what the "default" 
first disk was. Removing the last disk, booting, adding the disk would 
than help.

To make a plain bootsector copy:
dd if=/dev/sda of=/dev/sdb bs=512 count=1

But that the fist step of the boot loader. Next it will try to load the 
grub menu etc. from some disk (need not be the same disk, but mostly 
this disk contains a small (100MB) partition that holds these files and 
the kernel and ramdisk images. After boot this partition is normally 
mounted under /boot (for easy maintenance). So just copying the boot 
sector gives you only a grub prompt and then it stops.

So try boot with a rescues disk (or LiveCD) so that you can study your 
disks.

To install grub after booting from a resuce CD, you can use:

grub
root (hd0,1)   # press tab for command completion
setup (hd0)


With all these examples you need to verify of course which 
disks/partition (sda/sdb etc) you need to choose.
One way to search is to enter grub and use the find command with command 
completion:

Probing devices to guess BIOS drives. This may take a long time.
    GNU GRUB  version 0.95  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]

grub> find (hd<TAB>
 Possible disks are:  hd0 hd1 hd2 hd3

grub> find (hd0,(TAB>
 Possible partitions are:
   Partition num: 0,  Filesystem type is ext2fs, partition type 0x83
   Partition num: 1,  Filesystem type unknown, partition type 0xfd

grub> find (hd0,0)/<TAB>
 Possible files are: lost+found vmlinuz-2.6.21-1.3194.fc7 grub 
System.map-2.6.21-1.3194.fc7 config-2.6.21-1
.3194.fc7 initrd-2.6.21-1.3194.fc7.img config-2.6.9-55.0.6.ELsmp 
initrd-2.6.9-55.0.6.ELsmp.img System.map-2
.6.9-55.0.6.ELsmp vmlinuz-2.6.9-55.0.6.ELsmp 
initrd-2.6.9-55.0.6.ELsmp.img_vg_new initrd-2.6.9-55.0.6.ELsmp
.img_noraid

grub> find (hd0,0)/


Theo