LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 10-04-2009, 02:07 PM   #1
zoombee
LQ Newbie
 
Registered: Nov 2008
Posts: 17

Rep: Reputation: 0
Where on the disk is the boot loader?


I would like to know a bit about boot loaders, where they save their data, and where partitions begin

http://en.wikipedia.org/wiki/GNU_GRUB
"GRUB Stage 1.5 is located in the first 30 kilobytes of hard disk immediately following the MBR."

Does that mean that the first partition starts after the first 30.5 kilobytes of the hard disk data? (MBR has 0.5 KB)

Is this a standard for most of the operating system partitioning tools? I mean, when you create the first partition on a hard disk, in Windows or Linux, the partition will start always exactly after the first 30.5 kilobytes of the hard disk?

thanks
 
Old 10-04-2009, 05:19 PM   #2
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
Yes - the first partition is considered to start on cylinder 1 (not zero). This is simply an old convention that is changing, but is true for the majority of cases.
 
Old 10-04-2009, 06:09 PM   #3
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 113Reputation: 113
I think the exact wording is

"stage 1.5. GRUB Stage 1.5 is located in the first 30 kilobytes of hard disk immediately following the MBR"

This could mean stage1.5 is in the first sector but not in the first partition.

Since each head has 63 sector the first sector of the first head is also reserved in which the only first 512 bytes are read by the Bios and is commonly called the MBR.

The first partition actually starts at 63x512 = 32256 bytes. 52256 - 512 (the MBR) = 31744 bytes which can accommodate the stage1.5

As a proof here is a partition table with 5 partitions all 10 cylinder each.
Code:
root@saikee-desktop-1:/home/saikee# fdisk -l /dev/sdb

Disk /dev/sdb: 61.4 GB, 61491756544 bytes
255 heads, 63 sectors/track, 7475 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xc7d8763d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          10       80293+  83  Linux
/dev/sdb2              11          20       80325   83  Linux
/dev/sdb3              21          30       80325   83  Linux
/dev/sdb4              31          40       80325    5  Extended
/dev/sdb5              31          40       80293+  83  Linux
By definition 10 cylinders = 10x255x63x512 = 82252800 bytes. When this is divided by 1024 (unit of 1 block in LBA) to give 80325 blocks which match exactly with the size of sdb2, sdb3 and sdb4.

The sdb1 is the first partition and loses exactly 32256 bytes or 31.5 blocks therefore it has 80325-31.5 = 80293.5 blocks. In fdisk this is shown as 80293+ blocks.

It is interesting to see the logical partition sdb5 is the same size as sdb1. This is because every logical partition must have it own partition table and its first sector has been used for that purpose. The partition table of sdb1 to sdb4 are contained in the MBR.

Stage1.5 isn't used much nowadays. I never use it myself. The stage1 is normally hard-coded the hard disk address of the stage2. This enable Grub to boot an operating system virtually from any partition in a hard disk.

Each partition has a boot sector at the beginning of the partition and this is where the boot loader resides unless the user opts for installing it in the MBR.

Last edited by saikee; 10-04-2009 at 06:12 PM.
 
Old 10-07-2009, 02:10 PM   #4
zoombee
LQ Newbie
 
Registered: Nov 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Great answer saikee, thanks a lot !!
I would like to ask a few more questions:
- where exactly I can find the stage2 on the linux partition?
- how is Windows using the 30 KB before the first partition, does it install the NT loader there?
- if I install the boot loader (grub) on a partition, and not on the MBR, then where does it install the stage 1.5? Do partitions have also 30 KB at the beginning for the boot loaders?

thanks
 
Old 10-07-2009, 05:34 PM   #5
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 113Reputation: 113
zoombee,

Due to the size of stage2, of more than 120k, I believe Grub does not place stage2 in the boot sector of a partition but rather the stage1 and stage1.5. It is likely both stage1 and stage1.5 have hard coded the disk address of stage2 which is always inside either /grub (for distro having /boot partition like Red Hat or some Open Suse) and /boot/grub (for all distros that has /boot as subdirectory to /). Stage1 is also inside the boot sector when a Linux places its boot loader inside its root partition. A proof of this is when a Xp or Vista boots a Linux the pre-requisite is to copy the first 512 bytes of the Linux partition and store it in the "c" drive" of the XP or Vista. This allows Xp or Vista to hand over the PC control to Linux without leaving the NTFS partition or has the ability to read a Ext2/3 partition.

When Grub is set up to boot from the MBR it is possible for stage1 to load the stage2 directly using the hard disk location because stage1.5 can be missing will not cause a failure. This is reported every time if you use the "setup" command of Grub. Whichever Linux you use all the system files of Grub are always inside /boot/grub or /grub.

The M$ system traditionally has a common MBR that is interchangeable between Dos up to Xp. Only Vista and Win7 use a different one but still its function is the same. M$ MBR is best imaged like a blind person searching the first 4 primary partitions and boots whichever one that has the bootable flag set "on" position. In other word the M$ MBR does not know which system it is booting and I have successfully ued Xp's MBR to boot up Grub installed in a data-only Fat partition without any OS inside. Every partitioning tool exists in PC will switch off the existing bootable flag if the owner switches another primary partition as bootable. In M$ term the partition is called "active". Linux calls it bootable but Linux never uses the bootable flag.

For the above reason every M$ system even up to now must be booted from a bootable primary partition, at least in first instance as Win2k, Xp, Vista or Win7 can be installed in a logical partition as long as there is a Fat or NTFS primary partition to house its boot loader.

The above suggests a M$ system always places its boot loader inside the boot sector of the partition it resides. M$ systems have a big issue with it as the boot loader occupying the boot sector is backward compatible only. Therefore a W2k installed after Xp will not be able to boot Xp and Xp installed after Vista can't boot Vista etc.

Last edited by saikee; 10-07-2009 at 05:43 PM.
 
Old 10-10-2009, 10:07 PM   #6
zoombee
LQ Newbie
 
Registered: Nov 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks again. I just want to make a minor observation:
Quote:
Originally Posted by saikee View Post
It is interesting to see the logical partition sdb5 is the same size as sdb1. This is because every logical partition must have it own partition table and its first sector has been used for that purpose. The partition table of sdb1 to sdb4 are contained in the MBR.
According to this:
http://en.wikipedia.org/wiki/Extende...1_.28unreal.29

Every logical partition has reserved 20 sectors (1 for MBR and 19 are kept unused)

So it's 20, not 30.5

I don't know why its 30.5 in your example
 
Old 10-10-2009, 10:38 PM   #7
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
Perhaps you should read the link you posted
Quote:
Remark: Neither a tiny extended partition with only 3 MB nor a hard drive with 20 sectors per track are realistic but these values have been chosen to make this example more readable.
 
Old 10-11-2009, 12:50 PM   #8
zoombee
LQ Newbie
 
Registered: Nov 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by syg00 View Post
Perhaps you should read the link you posted
I see, the empty space(in sectors) is equal with the number of sectors per track minus 1. Usually it's 63 sectors per track, that makes 31.5 KB

In this case, the information about GRUB on Wikipedia is not totally accurate: the space for Stage 1.5 is 31 KB, not 30 KB
 
  


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
Boot Loader issue : Installed to USB Hard disk :( chittu Linux - Newbie 5 05-15-2007 09:34 AM
boot loader on floppy disk problem cuto19 Ubuntu 2 03-07-2006 06:07 PM
Boot Loader floppy Disk nathanv117 SUSE / openSUSE 2 11-13-2004 08:24 PM
Restoring boot loader (with boot disk?) Kylotan Linux - General 0 07-08-2004 06:29 AM
Kernel Compile Boot Loader? boot disk? SPMcRuube Linux - Newbie 3 12-03-2002 07:02 PM

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

All times are GMT -5. The time now is 07:57 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