LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-02-2008, 02:49 PM   #1
raypen
Member
 
Registered: Jun 2002
Location: Midwest
Distribution: Slackware
Posts: 365

Rep: Reputation: 30
Post 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?
 
Old 04-02-2008, 03:05 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
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.

Last edited by johnsfine; 04-02-2008 at 04:05 PM.
 
Old 04-09-2008, 08:33 AM   #3
raypen
Member
 
Registered: Jun 2002
Location: Midwest
Distribution: Slackware
Posts: 365

Original Poster
Rep: Reputation: 30
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.
 
Old 04-09-2008, 09:01 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
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.
 
Old 04-10-2008, 08:18 AM   #5
raypen
Member
 
Registered: Jun 2002
Location: Midwest
Distribution: Slackware
Posts: 365

Original Poster
Rep: Reputation: 30
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.
 
Old 04-10-2008, 08:33 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by raypen View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving lilo to the MBR davidsrsb Slackware 2 09-19-2005 08:31 AM
Moving MBR hig Linux - Software 7 03-14-2005 01:50 PM
How to Clear the Master Boot Record(MBR) hazarcon Linux - Newbie 2 09-15-2004 03:12 AM
Moving Grub to the MBR cucolin@ Linux - Laptop and Netbook 2 12-30-2003 07:22 AM
boot record (MBR) emperor13 Linux - General 1 12-01-2001 11:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration