You are not logged in.

#1 2008-11-16 02:57:38

B-Con
Member
From: USA
Registered: 2007-12-17
Posts: 554
Website

How does Grub find stage2?

I'm trying to get a clear mental image of this in my head: Grub has two stages, stage1 and stage2. stage1 gets written to the MBR. stage2 gets written to... anywhere special, other than simply the file /boot/grub? Since it appears to me that stage1 is the same for all Grub installs, how does it know which partition to look on for stage2?

This question arises because I have two installs of Grub on two different partitions, and reinstalling Grub under the distro on each partition makes its own Grub the default one on boot. But since their stage1's are identical, I'm wondering what is changing between installing Grub to one partition and installing it to the other partition that tells the MBR to point to the different GRUBs.

(Part of the reason I ask is to see if there's an easier/lazier way to switch between the GRUB installs without re-installing GRUB. My initial thought was to back-up and restor the MBR, but that doesn't look like it will work.)

Offline

#2 2008-11-16 08:05:32

klixon
Member
From: Nederland
Registered: 2007-01-17
Posts: 525

Re: How does Grub find stage2?

You tell it where to look with

root (hd0,0) <== this one
setup (hd0)

It seeks in that partition under / and /grub

Last edited by klixon (2008-11-16 08:06:19)


Stand back, intruder, or i'll blast you out of space! I am Klixon and I don't want any dealings with you human lifeforms. I'm a cyborg!

Offline

#3 2008-11-16 12:58:02

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: How does Grub find stage2?

klixon wrote:

It seeks in that partition under / and /grub

Do you mean, it seeks in that partitition for /grub or /boot/grub?

Offline

#4 2008-11-16 14:12:41

klixon
Member
From: Nederland
Registered: 2007-01-17
Posts: 525

Re: How does Grub find stage2?

section 13.3.34 in the grub manual wrote:

The option --prefix specifies the directory under which GRUB images are put. If it is not specified, GRUB automatically searches them in /boot/grub and /grub.

indeed.. good catch smile


Stand back, intruder, or i'll blast you out of space! I am Klixon and I don't want any dealings with you human lifeforms. I'm a cyborg!

Offline

#5 2008-11-16 17:04:01

grep
Member
From: Finland
Registered: 2008-10-25
Posts: 13

Re: How does Grub find stage2?

B-Con wrote:

...reason I ask is to see if there's an easier/lazier way to switch between the GRUB installs without re-installing GRUB.

Also I prefer to be lazy and let the kernel package's install scripts update all /boot/grub/menu.lst's... I have 3 Linux installations and just 1 hdd in one box. Every installation has it's own /boot partition with it's own grub binaries.

sda1 = 1st installations /boot partition, 100 MB ( grub installed to /dev/sda's main MBR )

sda2 = 2nd installations /boot partition, 100 MB ( grub installed to /dev/sda2 )

sda3 = 3rd installations /boot partition, 100 MB ( grub installed to /dev/sda3 )

Everything I had to manually was

1) for chain booting other grubs I added

title 2nd Linux
        rootnoverify (hd0,1)
        chainloader +1
title 3rd Linux
        rootnoverify (hd0,2)
        chainloader +1

in the the very first /boot/grub/menu.lst  (at /dev/sda1)

2) be awake when configuring 2nd & 3rd installations so that their grubs are installed on sda2 and sda3, not sda's MBR.

With newer hardware it may be possible to skip separate /boot partitions, but actually they can be practical. My SCSI card's firmware says at boot up (c) 1994, so it couldn't boot over 2 GB...

Last edited by grep (2008-11-16 18:34:48)

Offline

#6 2008-11-22 07:39:17

B-Con
Member
From: USA
Registered: 2007-12-17
Posts: 554
Website

Re: How does Grub find stage2?

klixon wrote:

You tell it where to look with

root (hd0,0) <== this one
setup (hd0)

It seeks in that partition under / and /grub

But when Grub is loading, how does it know what was specified? Once Grub has loaded stage1 from the disk's MBR that's all it has to work with, it has no access to any other configuration data until stage2 is loaded, which is why I wonder how stage2 is loaded. So I can only presume that this information is written into stage1 in the MBR.

Last edited by B-Con (2008-11-22 07:41:15)

Offline

#7 2008-11-22 08:33:26

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: How does Grub find stage2?

I think stage one includes some basic information so that it can read whatever filesystem stage 2 is located on, and from stage two it can load all the info it needs to read it's config, kernels, etc.

I might be wrong.

Offline

#8 2008-11-22 08:50:06

B-Con
Member
From: USA
Registered: 2007-12-17
Posts: 554
Website

Re: How does Grub find stage2?

iphitus wrote:

I think stage one includes some basic information so that it can read whatever filesystem stage 2 is located on, and from stage two it can load all the info it needs to read it's config, kernels, etc.

I might be wrong.

stage1 is only 448 bytes, though, and while I suppose it's possible that it could read the basics of a filesystem with just that much code, I find it hard to believe that it could read every possible supported filesystem. stage1 would then have to be customized to the specific FS of the target destination.

Offline

#9 2008-11-22 09:06:26

stojic
Member
From: Zagreb, Croatia
Registered: 2008-02-24
Posts: 51

Re: How does Grub find stage2?

You are missing stage 1.5 which is started by stage1 and which knows how to read the filesystem. See http://www.pixelbeat.org/docs/disk/ for example.

Offline

#10 2008-11-23 13:57:44

sssslang
Member
Registered: 2006-03-18
Posts: 9

Re: How does Grub find stage2?

B-Con wrote:

I'm trying to get a clear mental image of this in my head: Grub has two stages, stage1 and stage2. stage1 gets written to the MBR. stage2 gets written to... anywhere special, other than simply the file /boot/grub? Since it appears to me that stage1 is the same for all Grub installs, how does it know which partition to look on for stage2?

hi, i have the same question, and a quick google search give me some info: http://ubuntuforums.org/showthread.php?t=825734

hope it's useful for you.

Offline

#11 2008-11-24 00:12:01

B-Con
Member
From: USA
Registered: 2007-12-17
Posts: 554
Website

Re: How does Grub find stage2?

stojic wrote:

You are missing stage 1.5 which is started by stage1 and which knows how to read the filesystem. See http://www.pixelbeat.org/docs/disk/ for example.

sssslang wrote:
B-Con wrote:

I'm trying to get a clear mental image of this in my head: Grub has two stages, stage1 and stage2. stage1 gets written to the MBR. stage2 gets written to... anywhere special, other than simply the file /boot/grub? Since it appears to me that stage1 is the same for all Grub installs, how does it know which partition to look on for stage2?

hi, i have the same question, and a quick google search give me some info: http://ubuntuforums.org/showthread.php?t=825734

hope it's useful for you.

Nice, thanks for the links, very helpful.

grep wrote:

Also I prefer to be lazy and let the kernel package's install scripts update all /boot/grub/menu.lst's... I have 3 Linux installations and just 1 hdd in one box. Every installation has it's own /boot partition with it's own grub binaries.

Thanks for the tip, that'll be helpful.

Offline

Board footer

Powered by FluxBB