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, 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.
Any suggestions?
Thanks.
Mark Hull-Richter, Linux Kernel Engineer DATAllegro (www.datallegro.com) 85 Enterprise, Second Floor, Aliso Viejo, CA 92656 949-680-3082 - Office 949-330-7691 - fax
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. 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.
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.
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:
- change boot=/dev/hda to boot=/dev/sda (in /etc/lilo.conf)
- make sure disk=/dev/sda exists and is correct (also in /etc/lilo.conf)
- lilo -v
b) grub:
- make sure /boot/grub/device.map has the correct value for sda
- change (hd0) to the sda device in /boot/grub/menu.lst
- 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@centos.org http://lists.centos.org/mailman/listinfo/centos
John Summerfield wrote:
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 MBR includes the primary partition table in addition to the stage 1 boot code.
John R Pierce wrote:
John Summerfield wrote:
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 MBR includes the primary partition table in addition to the stage 1 boot code.
except when the drive's not partitioned. New drives are not, and I don't know a reason you must: I'm sure this will work fine:
mke2fs /dev/hda
On Thu, 2007-04-12 at 23:01 +0800, John Summerfield wrote:
John R Pierce wrote:
John Summerfield wrote:
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?
<snip>
except when the drive's not partitioned. New drives are not, and I don't know a reason you must: I'm sure this will work fine:
mke2fs /dev/hda
<snip>
It does. I've been using unpartitioned HD's for *years* as desired. Further... (YMMV for this?) you can install and use unpartitioned disks in older HW that has a BIOS that won't "see" a disk too large for its BIOS. It won't boot, but Linux will find it and you can use it. And partition it if you want.
As to the OP's original Q, the (B?)LFS project's hints had a "Make any OS boot-able from any drive" hint at one time. May still be there, haven't looked for years. It was with LILO. It worked.
HTH -- Bill