[CentOS] Moving/copying the MBR

John Summerfield debian at herakles.homelinux.org
Wed Apr 11 23:09:36 UTC 2007


Luciano Miguel Ferreira Rocha wrote:
> On Wed, Apr 11, 2007 at 10:48:36AM -0700, Mark Hull-Richter wrote:
>> Are there any tools for working with and moving or copying the MBR?
>>
>> My machine has 2 PATA drives (hda & hdb) and 2 SATA drives (sda & sdb).  The
>> MBR is on hda,
> 
> Actually, its on every drive.

Not exactly, there is space for it, it's the first sector, but 512 bytes 
of zeroes doesn't really qualify.

 >  The BIOS just boots the first it cans (by
> a configurable order).
> 
>> but I would like (eventually or sooner) to boot from sda
>> because it is two years newer, faster and, hopefully, more reliable.  Even
>> if I don't change that, I'd like a backup MBR on sda in case hda fails (hdb
>> has gone sour a few times due to something in the power setup, although no
>> data lost and it always comes back).
>>
>> In order to copy the MBR, I'd also need to edit it because the drive
>> configuration would be different, as well as the location of my /boot
>> partition.
> 
> So you don't want to backup hda's MBR to sda, you just want to also be
> able to boot from sda.

In principle, you can just copy the entire hda to sda, provided that sda 
is no smaller than hda. The result is a clone of the source drive, and 
"it's the same size." One can then use fdisk (or similar) and resize2fs 
(or equivalent) to resize the last partition. Probably.

Better, simply partition sda, copy files if you wish (tar does nicely, 
google is your friend), install grub or lilo or similar. _Those_ install 
a useful boot sector.

A problem with copying the first sector is that it anchors the partition 
table, the first four partitions are described in it.

A problem with copying just the boot code is that it expects more 
somewhere else: grub and lilo expect something within a filesystem, the 
standard DOS boot sector looks for a bootable partition (and that in 
turn must contain executable code in its first sector).


> 
> So, you'll need to create the extra boot partition on sda, format it,
> copy /boot data to the new one, umount /boot; mount newboot /boot; and
> then, depending on your boot loader:
> 
> a) lilo:
>   1. change boot=/dev/hda to boot=/dev/sda (in /etc/lilo.conf)
>   2. make sure disk=/dev/sda exists and is correct (also in /etc/lilo.conf)
>   3. lilo -v
> 
> b) grub:
>   1. make sure /boot/grub/device.map has the correct value for sda
>   2. change (hd0) to the sda device in /boot/grub/menu.lst
>   3. execute grub-install /dev/sda
> 
> Note that disk= and device.map specifies the device name on boot. If you
> change the BIOS boot order to boot sda first, then sda will still be
> bios=0x80 (lilo) and (hd0) (grub).
> 
> Anyway, I just recomend the creation of a boot cd with /boot and fix
> /boot when the need arrives.
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> http://lists.centos.org/mailman/listinfo/centos


-- 

Cheers
John

-- spambait
1aaaaaaa at coco.merseine.nu  Z1aaaaaaa at coco.merseine.nu

Please do not reply off-list



More information about the CentOS mailing list