LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Moving boot record to mbr (https://www.linuxquestions.org/questions/linux-general-1/moving-boot-record-to-mbr-632527/)

raypen 04-02-2008 02:49 PM

Moving boot record to mbr
 
Experimenting with recovery situations is becoming somewhat important
as of the last time I recompiled the kernel and couldn't boot. Fixed
it easily enough but it got me thinking about the ways I might recover
from boot failures.

Running a dual-boot system with Win2K on the IDE0 primary channel and
Slackware Linux on a second hard drive attached to the IDE1 primary
channel. This a typical Windows/linux setup which uses the ntloader
and boot.ini to boot both systems. LILO is installed on the Linux
partition (hdb2), a copy of which is placed in the root directory of
the C: drive and labeled bootsect.lnx, which is referenced in boot.ini.

Since my bios allows booting from several sources, I thought I might
like to boot directly to Linux in the event of an ntloader problem.
I can set the boot source in the bios to boot from HDD-1 instead of the
normal HDD-0, but this requires a boot entry in the mbr of the second
hard drive.

I'm not sure how to accomplish this. I thought of the following:

1. Simply copy the boot record on hdb2 to the mbr (hdb) using dd
2. Altering lilo.conf to referece /dev/hdb instead of /dev/hdb2 and
rerunning lilo.

I'm not sure what implications are inherent in either of these approaches
but I am partial to the first since I would like to retain the capability
of the original boot sequence using ntloader while ,in a pinch, selecting
the second hard drive in the bios. The first procedure allows lilo.conf
to remain as is. Either way, I figure that any recompile or alteration
in the boot configuration will require copying boot record on hdb2 to
hdb or vice versa.

The only problem I see is that simply copying the partition boot record
to the mbr will screw up the partition table.

Any thoughts?

johnsfine 04-02-2008 03:05 PM

The first sector (512 bytes) of the drive contains both the MBR and the primary partition table. So if you copied 512 bytes from hdb2 to hdb you certainly would destroy the partition table.

I don't know how dd behaves when copying less than 512 bytes to a disk sector. You can't actually write less than 512 bytes to a disk sector. To get the right result you must read the previous contents, overwrite the beginning of that in memory, then write the whole 512 bytes. I don't know whether the linux disk driver does that for you when writing a short sector, or whether dd does it, or whether you need to do it for yourself.

I forget the correct length. According to Wikipedia, it is 440 bytes. (When replacing the boot code and preserving the partition table, replace the first 440 bytes and preserve the next 72 bytes).
http://en.wikipedia.org/wiki/Mbr

When you tell the BIOS to boot HDD-1, I think it prepares a drive table to give the boot routine telling the boot routine that HDD-1 is drive 0. I'm not sure your BIOS does that, but I think so. If it does, I have no idea whether LILO installed on hd1 will be confused when it finds itself booting on what the BIOS calls hd0.

raypen 04-09-2008 08:33 AM

Quote:

I don't know how dd behaves when copying less than 512 bytes to a disk sector. You can't actually write less than 512 bytes to a disk sector. To get the right result you must read the previous contents, overwrite the beginning of that in memory, then write the whole 512 bytes. I don't know whether the linux disk driver does that for you when writing a short sector, or whether dd does it, or whether you need to do it for yourself.
Try this:

Code:

dd if=/dev/hdb2 bs=440 count=1 of=/dev/hdb
Only the boot code is replaced; the disk identifier and partition table are left untouched.
Changed the boot device to HDD-1 and booted straight into LILO, bypassing the usual ntloader
selection. Lovely Linux, the partition did not have to be marked as bootable.

Now I have a nice alternative Linux boot although if I ever recompile ad rerun LILO, I'll
have to remember to change the code in the MBR.

syg00 04-09-2008 09:01 AM

I am *really* surprised that worked. I mean *really* surprised ...
Mind you, I haven't used Lilo in a lot of years.
Lilo is just a poor choice for this - grub is much more flexible, in that it doesn't need to be copied every time it is updated. Same applies to the boot record copied over for boot.ini usage.
I find the whole M$oft boot-loader architecture seriously lame, and never use it.

For boot-loader recovery, any liveCD will generally do - or a simple chroot into your disk install. Several distros do this for you as an option from the install CD/DVD.

raypen 04-10-2008 08:18 AM

I experimented with GRUB some time ago given all its accolades
but I could just never seem to make it work on this machine. I
also have had many problems with other rescue cd's which never
seem to be able to boot correctly. I can use the install cd but
I have never figured out how to cancel the install procedure and
simply use it to perform other tasks.

LILO has always seemed so easy to understand and simple to use.
However I have never used it to try to boot Win 2000; all I've read
suggests that Win2K will not accept any loader except its own.

Maybe one of these days I'll work up the courage to try GRUB again
but being the timid soul I am, I don't look forward to it.

syg00 04-10-2008 08:33 AM

Quote:

Originally Posted by raypen (Post 3116817)
However I have never used it to try to boot Win 2000; all I've read suggests that Win2K will not accept any loader except its own.

Old wives tale. Win2k uses similar (same ???) ntldr code as XP - chainloads fine from both lilo and grub.


All times are GMT -5. The time now is 08:46 PM.