This is my first ever question, I have put this question in front of Red Hat Instructors but didn't find any satisfying answers.

I'm using RHEL/CENTOS6, GRUB Legacy 0.97, and have consulted heaps of documentation explaining linux boot process.

Almost all of the blogs, documentation etc. successfully explain the steps involved and the whole process but fail unanimously at as what actually takes place when loading grub stage2.

Here is my understanding of the process and have done a bit of testing as well;

  1. BIOS(not using EFI) reads MBR, finds partition table, and loads GRUB stage1 (first 446 bytes) into memory
  2. I have /boot partition under 1024 cylinders, and the idea I have extracted from a bunch of documentation is that GRUB stage1 can directly load stage2 if it is located at some place under 1024 cylinders. Some documentation I have consulted mentions that stage1.5 is located right after MBR before sector 63, while others suggest that it can be anywhere in first 1MB of disk and yet another group claimed that stage1.5 is just a GRUB v2 thing and does not apply on GRUB legacy.
  3. GRUB stage2 has all the necessary drivers/modules to read file systems and thus loads kernel and ramdisk and handover control to kernel.
  4. Kernel kicks off init on RHEL/CENTOS 6 and systemd on RHEL/CENTOS 7.

I have dumped all the data from the 1st MB of the disk and can confirm that there is nothing except MBR. I get confused as to how 446 byte GRUB stage1 can load stage2 from a file system? According to some images on wikipedia and a few documents, when GRUB is installed, stage1 contains a LBA48 pointed to stage2.

Playing on the fact, I tried to test if systems boots when stage2 in removed or renamed from /boot/grub/ directory. The systems was still bootable even when there was no stage2 in the filesystem.

1st MB from /dev/sda

[root@chief zul.kifal]# dd if=/dev/sda bs=1024k count=1 | hexdump -C
00000000  eb 48 90 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |.H..............|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 03 02  |.........|...t..|
00000040  80 00 00 80 fc 49 08 00  00 08 fa 90 90 f6 c2 80  |.....I..........|
00000050  75 02 b2 80 ea 59 7c 00  00 31 c0 8e d8 8e d0 bc  |u....Y|..1......|
00000060  00 20 fb a0 40 7c 3c ff  74 02 88 c2 52 f6 c2 80  |. ..@|<.t...R...|
00000070  74 54 b4 41 bb aa 55 cd  13 5a 52 72 49 81 fb 55  |tT.A..U..ZRrI..U|
00000080  aa 75 43 a0 41 7c 84 c0  75 05 83 e1 01 74 37 66  |.uC.A|..u....t7f|
00000090  8b 4c 10 be 05 7c c6 44  ff 01 66 8b 1e 44 7c c7  |.L...|.D..f..D|.|
000000a0  04 10 00 c7 44 02 01 00  66 89 5c 08 c7 44 06 00  |....D...f.\..D..|
000000b0  70 66 31 c0 89 44 04 66  89 44 0c b4 42 cd 13 72  |pf1..D.f.D..B..r|
000000c0  05 bb 00 70 eb 7d b4 08  cd 13 73 0a f6 c2 80 0f  |...p.}....s.....|
000000d0  84 f0 00 e9 8d 00 be 05  7c c6 44 ff 00 66 31 c0  |........|.D..f1.|
000000e0  88 f0 40 66 89 44 04 31  d2 88 ca c1 e2 02 88 e8  |..@f.D.1........|
000000f0  88 f4 40 89 44 08 31 c0  88 d0 c0 e8 02 66 89 04  |..@.D.1......f..|
00000100  66 a1 44 7c 66 31 d2 66  f7 34 88 54 0a 66 31 d2  |f.D|f1.f.4.T.f1.|
00000110  66 f7 74 04 88 54 0b 89  44 0c 3b 44 08 7d 3c 8a  |f.t..T..D.;D.}<.|
00000120  54 0d c0 e2 06 8a 4c 0a  fe c1 08 d1 8a 6c 0c 5a  |T.....L......l.Z|
00000130  8a 74 0b bb 00 70 8e c3  31 db b8 01 02 cd 13 72  |.t...p..1......r|
00000140  2a 8c c3 8e 06 48 7c 60  1e b9 00 01 8e db 31 f6  |*....H|.......1.|
00000150  31 ff fc f3 a5 1f 61 ff  26 42 7c be 7f 7d e8 40  |1.....a.&B|..}.@|
00000160  00 eb 0e be 84 7d e8 38  00 eb 06 be 8e 7d e8 30  |.....}.8.....}.0|
00000170  00 be 93 7d e8 2a 00 eb  fe 47 52 55 42 20 00 47  |...}.*...GRUB .G|
00000180  65 6f 6d 00 48 61 72 64  20 44 69 73 6b 00 52 65  |eom.Hard Disk.Re|
00000190  61 64 00 20 45 72 72 6f  72 00 bb 01 00 b4 0e cd  |ad. Error.......|
000001a0  10 ac 3c 00 75 f4 c3 00  00 00 00 00 00 00 00 00  |..<.u...........|
000001b0  00 00 00 00 00 00 00 00  19 aa 09 00 00 00 80 20  |............... |
000001c0  21 00 83 dd 1e 3f 00 08  00 00 00 a0 0f 00 00 dd  |!....?..........|
000001d0  1f 3f 8e fe ff ff 00 a8  0f 00 00 58 f0 04 00 00  |.?.........X....|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.0184614 s, 56.8 MB/s

Magic word 0044-0047h = 0x000849fc

00000040  80 00 00 80 **fc 49 08 00**  00 08 fa 90 90 f6 c2 80  |.....I..........|

[root@chief zul.kifal]# dd if=/dev/sda skip=$((0x849fc)) bs=512 count=1 | hexdump -C
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.00260914 s, 196 kB/s
00000000  52 56 5e bf f8 81 66 8b  2d 83 7d 04 00 0f 84 c4  |RV^...f.-.}.....|
00000010  00 80 7c ff 00 74 3e 66  8b 1d 66 31 c0 b0 7f 39  |..|..t>f..f1...9|
00000020  45 04 7f 03 8b 45 04 29  45 04 66 01 05 c7 04 10  |E....E.)E.f.....|
00000030  00 89 44 02 66 89 5c 08  c7 44 06 00 70 50 66 31  |..D.f.\..D..pPf1|
00000040  c0 89 44 04 66 89 44 0c  b4 42 cd 13 0f 82 93 00  |..D.f.D..B......|
00000050  bb 00 70 eb 56 66 8b 05  66 31 d2 66 f7 34 88 54  |..p.Vf..f1.f.4.T|
00000060  0a 66 31 d2 66 f7 74 04  88 54 0b 89 44 0c 3b 44  |.f1.f.t..T..D.;D|
00000070  08 7d 68 8b 04 2a 44 0a  39 45 04 7f 03 8b 45 04  |.}h..*D.9E....E.|
00000080  29 45 04 66 01 05 8a 54  0d c0 e2 06 8a 4c 0a fe  |)E.f...T.....L..|
00000090  c1 08 d1 8a 6c 0c 5a 52  8a 74 0b 50 bb 00 70 8e  |....l.ZR.t.P..p.|
000000a0  c3 31 db b4 02 cd 13 72  3a 8c c3 8e 45 06 58 c1  |.1.....r:...E.X.|
000000b0  e0 05 01 45 06 60 1e c1  e0 04 89 c1 31 ff 31 f6  |...E........1.1.|
000000c0  8e db fc f3 a4 1f 61 83  7d 04 00 0f 85 42 ff 83  |......a.}....B..|
000000d0  ef 08 e9 34 ff 5a ea 00  82 00 00 be 05 81 e8 3d  |...4.Z.........=|
000000e0  00 eb 06 be 0a 81 e8 35  00 be 0f 81 e8 2f 00 eb  |.......5...../..|
000000f0  fe 4c 6f 61 64 69 6e 67  20 73 74 61 67 65 32 00  |.Loading stage2.|
00000100  2e 00 0d 0a 00 47 65 6f  6d 00 52 65 61 64 00 20  |.....Geom.Read. |
00000110  45 72 72 6f 72 00 bb 01  00 b4 0e cd 10 46 8a 04  |Error........F..|
00000120  3c 00 75 f2 c3 00 00 00  00 00 00 00 00 00 00 00  |<.u.............|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  fd 49 08 00 f6 00 20 08  |.........I.... .|

(/boot) starts at 2048.

# fdisk -lu /dev/sda

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0009aa19

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux Par...
/dev/sda2         1026048    83886079    41430016   8e  Linux LVM

Will really appreciate if anyone can explain it.

  • 2
    Have you zeroed out the existing file? Because deleting it is unlikely to remove the actual data that grub is referring to from the disc.
    – Anthon
    Jan 31, 2016 at 13:03
  • Took the system back to original state. dd if=/dev/zero of=/boot/grub/stage2 bs=124k count=1. Verified that whole file had been zeroed. Rebooted. System still boots successfully. Jan 31, 2016 at 13:14
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – terdon
    Feb 2, 2016 at 10:58

5 Answers 5


From https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/3/html/Reference_Guide/s1-grub-whatis.html


GRUB loads itself into memory in the following stages:

The Stage 1 or primary boot loader is read into memory by the BIOS from the MBR[1]. The primary boot loader exists on less than 512 bytes of disk space within the MBR and is capable of loading either the Stage 1.5 or Stage 2 boot loader.

The Stage 1.5 boot loader is read into memory by the Stage 1 boot loader, if necessary. Some hardware requires an intermediate step to get to the Stage 2 boot loader. This is sometimes true when the /boot/ partition is above the 1024 cylinder head of the hard drive or when using LBA mode. The Stage 1.5 boot loader is found either on the /boot/ partition or on a small part of the MBR and the /boot/ partition.

The Stage 2 or secondary boot loader is read into memory. The secondary boot loader displays the GRUB menu and command environment. This interface allows selection of the kernel or operating system to boot, pass arguments to the kernel, or look at system parameters.

It seems rather obvious stage 2 is the actual grub binary. In fact, the documentation states grub 2 is loaded by name.

I would try to do:

dd if=/dev/zero of=/boot/stage2

Additional data:

Inspecting /boot/grub:

copy of stage1 bootloader:


Files for stage1_5:


File for stage2:


Link to grub image:


  • 1
    I have already zeroed the stage2 file, dd if=/dev/zero of=/boot/grub/stage2 bs=124k count=1. It didn't effect the system at all. Jan 31, 2016 at 13:54
  • please do a sudo grub-install /dev/sda and reboot Jan 31, 2016 at 13:56
  • according to this, it should work en.wikipedia.org/wiki/GNU_GRUB Jan 31, 2016 at 13:59
  • grub-install /dev/sda has regenerated /boot/grub/stage2 binary and system is still bootable. Jan 31, 2016 at 14:02
  • maybe dd is creating a new file actually instead of overwriting the old one. Jan 31, 2016 at 14:02

In computers that conform to the IBM PC boot BIOS sequence:

  • The MBR (absolute sector 0) from disk is loaded by BIOS at memory 0000:7C00.
  • That code is executed.

Form IBM to W7

The code used by IBM PC to boot could be seen here:
First version of MBR from IBM® Personal Computer™ DOS 2.00

That code has many versions that are also presented in the starman's pages.
An start point about those many versions could be this page:
from MS-DOS 3.30 through MS-Windows™ 95 (A)

One of the most common MBR codes is this:
MBR for: MS-Windows™ 95B, 98, 98SE and ME

Most of that code versions used to just load the next VBR (Volume Boot Record). The VBR of the partition marked as boot-able in the partition table and then transfer execution to it.
(Please Understand that the VBR is not the absolute disk sector 0 or W7 MBR)

Search for this assembler note at the W7 MBR page:

; The following code uses INT 13, Function 42h ("Extended Read") to read the
; first sector (VBR) of the bootable partition into Memory at location 0x7c00.

Windows™ 7 (and Vista) VBR ( Volume Boot Record )

It is interesting to read this from the W7VBR page:

; The following code uses INT 13, Function 42h ("Extended Disk Read") to read ; 1 sector at a time of the remaining 15 sectors of the Boot Record Area into ; Memory; starting at location 7E00.

As you can confirm, the boot code started at the MBR (disk sector 0), loaded the VBR (Volume Boot record) and many (15 in W7) following sectors.


But we are talking about GRUB here, so, go to the GRUB page:

And search for this code:

[7C44] -> Note: A very important location for anyone using GRUB!
          This (4-byte) Quad-Word contains the location of GRUB's
          stage2 file in sectors! It's called "stage2_sector" in
          the stage1.S code. If GRUB is installed in the MBR by a
          distro that always includes a number of sectors from
          stage2 immediately following the GRUB MBR, you will see
          the bytes 01 00 00 00 in this location; otherwise, it
          will point to stage2 in the "/boot/grub" directory.

That is almost always 01 00 00 00 (or just: the next sector).

What that means is that BIOS load absolute sector 0 (MBR), GRUB code installed in the MBR keeps reading following sectors. Up to the size of core.img (GRUB2) in recent distros (about 60 sectors, or ~30 kB). Present day drives leave a full Mega-byte free after the MBR, so there is no problem. EFI disks have a separate partition for all this code and there is even less problem (for size, that is).


Legacy GRUB write stage2, or optionally stage 1.5 in some corner cases, to the MBR and several/many of the following 62 sectors.

And that is also explained in images in the Wikipedia Grub page.

From GNU site 10 GRUB image files:

   This is an essential image used for booting up GRUB. Usually, this is
   embedded in an MBR or the boot sector of a partition. Because a PC boot
   sector is 512 bytes, the size of this image is exactly 512 bytes.

   All stage1 must do is to load Stage 2 or Stage 1.5 from a local disk.
   Because of the size restriction, stage1 encodes the location of Stage 2
   (or Stage 1.5) in a block list format, so it never understand any
   filesystem structure. 

NOTE: The stage2 might be written to other Physical disk. From the GRUB page:

[7C40] -> 80 ("Boot Drive") NOTE: For those of you with multi-OS
          booting systems, if your Linux installation with GRUB's
 See:     remaining software (stage2, menu file, etc.) is located
 7C5A     somewhere other than on the Primary Master drive, this
          value will be 81, 82, etc. depending upon which drive
          that Linux OS's /boot/grub directory is located. In the
          stage1.S file, it's called the GRUB_INVALID_DRIVE byte
          and commented as: "the disk to load stage2 from." (The
          word INVALID has something to do with the code logic.)
  • 1
    Thanks for your answer, it is by far the closest response I have yet received. I had a look at the GRUB page already yesterday and did a bit of reverse engineering. 4-byte (Quad) Word located at offsets 0044h-0047h got me to the location of stage2 on disk. It was something like 256MB from the start of disk (/boot on a standard partition), I looked up /boot/grub/stage2's inode using debugfs, both of them were different locations. I zeroed stage2 in the file-system, but Quad word still took me to a valid stage2. My question now becomes, can I look at this valid file from file-system? Feb 1, 2016 at 22:44
  • I have had a look at the whole first MB of disk, there is nothing but 512bytes of MBR. By looking at the magic Quad word, I did conclude that it is looking at a different location rather than /boot/grub/stage2, what bothers me is that why that location (pointed by Quad Word) is 256MB deep into the disk. Feb 1, 2016 at 23:01
  • The disk started at sector 2048 ~ 1MB. Have updated the question with more details. Feb 2, 2016 at 0:00
  • @BinaryZebra. Your statement "By far, the usual way to install stage2 to the MBR" is absolute rubbish. An MBR cannot hold GRUB Legacy stage2
    – fpmurphy
    Feb 2, 2016 at 1:28
  • You said you tested deleting stage2 from the filesystem. If your first such test did not involve actually overwriting the file, it is likely that the filesystem found a different location for the stage2 file when you replaced it after the test. But since the blocks were not overwritten, the content of the stage2 is still present in those original blocks, although they may now be marked as free space in the filesystem metadata. If you don't reinstall stage1, your GRUB will likely stop working if/when something causes those "free" blocks to be reused and overwritten.
    – telcoM
    May 19, 2018 at 9:13

GRUB Legacy can be installed in several ways: with or without Stage 1.5.

When installed with Stage 1.5, the pointer in the MBR points to the beginning of Stage 1.5. The MBR code loads the first block of Stage 1.5; the code in that block includes a list of further blocks to load, and a BIOS partition number and a filename specifying where to find Stage 2.

But in the OP's case, GRUB Legacy has been installed without Stage 1.5, as indicated by the text Loading stage2 in the second hex dump. In this case, MBR loads the first block of Stage 2 directly, and like in the case of Stage 1.5, the first block will have a list of further blocks to load embedded in it.

The separation between stage 1.5 and stage2 existed to allow embedding stage 1.5 between the MBR and the beginning of the first partition even on disks that used the old DOS-compatible convention of starting the first partition at the beginning of track #1, head #0, rather than from block #2048 (i.e. exactly 1 MiB from the start of the disk) as modern operating systems do. Stage 2 might not fit into the area between the MBR and the beginning of the partition, but stage 1.5 is smaller, since it only needs to be able to read one filesystem type.

When installed with Stage 1.5, the Stage 2 of GRUB Legacy can be treated like a regular file, since it is loaded by filename, not by absolute block numbers. But when installed without Stage 1.5, Stage 2 may not be moved on disk from whatever block location it was placed by the installer. Filesystem-type-specific actions should be performed to make sure that the file won't be accidentally moved: for example, on a VFAT filesystem, the Stage 2 file should be marked with the "system" and "read-only" attributes.

Of course, the installer can embed Stage 2 between the MBR and the beginning of the first partition if it fits in the available space, in which case protection from in-filesystem manipulations will not be an issue.

Here's the tail end of the OP's second hex dump:

000001f0  00 00 00 00 00 00 00 00  fd 49 08 00 f6 00 20 08

It contains the specification of further blocks to load, as a number of 8-byte block list structures. In this case there is just one of them: "load 0x00f6 blocks starting from block# 0x000849fd to 16-bit segment address 0x0820". Note that the block number is only 32-bit, not a full LBA48 block number: this restricts GRUB Legacy from accessing the full capacity of large disks.

  1. BIOS(not using EFI) reads MBR, finds partition table, and loads GRUB stage1 (first 446 bytes) into memory

This is entirely correct.

  1. I have /boot partition under 1024 cylinders, and the idea I have extracted from a bunch of documentation is that GRUB stage1 can directly load stage2 if it is located at some place under 1024 cylinders.

Technically, "at any location that is addressable by a 32-bit LBA block number", but otherwise correct. The "under 1024 cylinders" would come into play if the BIOS had no support for LBA access, and GRUB had to fall back to old C/H/S style BIOS calls... but in any post-Y2K hardware, this should not be an issue.

Some documentation I have consulted mentions that stage1.5 is located right after MBR before sector 63,

If stage1.5 is used, this is where it usually ends up. It does not have to be there, though. The "before sector 63" comes from the old DOS convention for the location of the beginning of the first partition, as I stated above.

while others suggest that it can be anywhere in first 1MB of disk

It actually can be anywhere that is addressable by a 32-bit block number, but again, the first 1 MB is where it usually is, when Stage 1.5 is used at all. The "first 1 MB" comes from the modern SSD/SAN-friendly convention of setting the beginning of the partition at exactly 1 MiB from the beginning of the disk, which is a nice big even power-of-2 so it will be aligned nicely with larger block sizes, RAID stripe sizes and/or whatever other alignment preferences the storage hardware might have.

and yet another group claimed that stage1.5 is just a GRUB v2 thing and does not apply on GRUB legacy.

This documentation gets it exactly backwards: stage1.5 is specifically GRUB Legacy thing only.

  1. GRUB stage2 has all the necessary drivers/modules to read file systems and thus loads kernel and ramdisk and handover control to kernel.


  1. Kernel kicks off init on RHEL/CENTOS 6 and systemd on RHEL/CENTOS 7.

A bit of simplification, but essentially correct.

In RHEL/CentOS 6, the very first userspace process initially runs /init within the initial ramdisk file, which is actually a script, whose last action is to run exec switch_root <mountpoint_of_real_root_filesystem> /sbin/init <arguments> or similar.

In RHEL/CentOS 7, the /init is actually a link to /usr/lib/systemd/systemd within the initramfs, which will start a special version of systemd that recognizes some systemd-specific parameters with a rd. prefix. Like the /init script in older versions, it sets up whatever is needed to access the root filesystem, then exec()s the "full" version of systemd on the real root filesystem.

  • Thanks for taking the time to provide a detailed answer. Will you be kind enough to also share some knowledge around exec switch_root step as well? What bothers me is that when /init is running from ramdisk or initramfs udev/dev and proc filesystems are mounted at /dev & /proc respectively. How do udev/dev and proc get remounted/remapped to dev and proc directories on real / filesystem? Should switch_root system call not complain that / is busy? Nov 15, 2019 at 6:45
  • See the man pages of the switch_root tool and its source code - it encapsulates all the critical actions of the switch in a single tool, and the initramfs is constructed to minimize the number of userspace processes active at the time of the switch. After switching, the tool deletes the initramfs contents, and as soon as there are no processes holding onto them, the kernel initramfs driver cleans them up, until nothing is left of the initramfs.
    – telcoM
    Nov 15, 2019 at 8:01

What I did is configure and install Hiren's boot cd to load on a usb flash drive with the automated grub loader from hiren.info once I had the bootable Hiren's usb drive I resized the primary partition on the hdd reducing one gb form the back end of the flash drive. Then I created an ext4 partition in the unallocated space. Next all I did is run grub2config command in xterm on RIPLinuX and the installation was relatively automated. The wizard allows you to select the partition and directory that grub2 is installed in. I set the loader to the mbr on the primary partition of the flash drive and the ext4 /boot/grub as the installation directory for the grub2 files. grub2config installation help

What happens is the grub2 grldr replaces the previous grldr in the root directory of the primary partition on the flash drive. The previous menu.lst file will likely be backed up before replacement with the new menu.lst file with the boot options you selected in the automated wizard. Once you complete the 4 or 5 step process (depending on your configuration preference) simply reboot the system selecting the usb disk as your boot device and when the grub2 menu.lst loads with your boot options just type the letter "c" to enter the grub2 command interface. Now you can fully load and boot to portable grub2 environment. grub2 command list1 grub2 command list2 grub2 command list3

additional screenshots posted here: https://www.minds.com/groups/profile/924192575922864128

  • 1
    You obviously put some effort into this, and we appreciate that.  But I believe that you may have misunderstood the question.  As far as I can make out, the OP is asking “How does this thing work?” (i.e., “How is it implemented?”), while you seem to be answering a “How do I do X?” question.  Also, please capitalize the first word of each sentence and the word “I”. Dec 25, 2018 at 7:55
  • The question is about GRUB Legacy and not about GRUB2.
    – fpmurphy
    Dec 25, 2018 at 17:57

There are many ways in which grub could boot a system. It depends on:

  • Whether there are multiple partition (read about lvm) tables or not (a partition space may get partitioned into several separate partitions). I'll be considering only disks with only one partition table (and matching sub-partitions) of that type on this post.
  • The type of partition table that the disk is using (atari, aix, amiga, bsd, dvh, gpt, mac, msdos (usual default in PCs), pc98, sun, loop and GPT at least). You have given an example of a msdos partition table MBR (I'll further limit this post to that partition type).
  • The filesystem type for each of the partitions. Well, mainly the filesystem of the partition where GRUB needs to load more code (usually /boot).
  • The size of several structures ( (1) Are the sectors to be loaded next beyond one of the (many) limits (from 528 MByte to 137 GByte), that defines which values could be used and which not. (2) What spaces and relative sizes of "free" space (like the 62 sectors after the MBR in msdos partitions or the sectors in the VBR (in windows parlance) )
  • The disk sector size (usually 512 bytes in older systems, usually 2k nowadays).

Limiting the discussion to an MBR boot sector (msdos partition) and an ext{2,3,4} filesystem on /dev/sda1 (you have no separate /boot partition or, if you have, you have not given the detail of the LVM structure for such partition).

Even in this limited scenario there are still (at least) some ways in which grub could be installed:

  • The stage1 (446 bytes) is written to the MBR (the first sector).
  • A stage2 may be written to the 62 sectors after the MBR. The pointer (what you call: Magic word 0044-0047h = 0x000849fc (a 32 bit word)) becomes 01 00 00 00 (the next sector)).
  • Either, stage1 may be written also to the VBR - booting 100+ linux systems from one disk, which is known as chain loading.
  • There could be many boot managers which could chainload in different ways, there are just too many to mention.
  • Then, either a filesystem driver, specific to each filesystem type needs to be loaded, and then, using it, search for the file /boot/stage2 and load it.

But this are just possibilities, in your case, the Magic word points to the middle of partition /dev/sda1 (at absolute sector (dec) 543.228 echo $((0x000849fc))). You have given the first sector at that position. What you are missing is to detect which file is using that sector:

# tune2fs -l /dev/sdc1 | grep Block\ size       # find FS block size.
Block size:               4096

# echo $(( (0x000849fc - 2048) * 512 / 4096 ))

# debugfs
debugfs 1.41.3 (12-Oct-2008)
debugfs:  open /dev/sda1
testb 676647
debugfs:  testb 676647
Block 676647 marked in use
debugfs:  icheck 676647
Block           Inode number
676647          5869525
debugfs:  ncheck 5869525
Inode           Pathname
5869525         /path/to/FileLoadedByGrub
  • Note that the question was specifically about GRUB Legacy, not about the current GNU GRUB.
    – telcoM
    Nov 14, 2019 at 7:15
  • @telcoM The answer was written with grub0.97 in mind, Where am I misleading you?
    – IsaaC
    Nov 17, 2019 at 22:38
  • I see you edited the names of the stages. But unlike the modern GNU GRUB, the grub0.97 was for BIOS PCs only (although there were some patches to make it compatible with UEFI, but they never went into official releases). No point in talking about aix, amiga, dvh or Macs: GRUB 0.97 was not compatible with the firmwares of systems using those partition table formats. For Sun systems, older SPARC-based ones had a different firmware and partition table format, necessitating a different bootloader. Newer x86-based Sun/Oracle hardware uses UEFI and GPT partitioning.
    – telcoM
    Nov 17, 2019 at 23:30
  • Also, you're talking about a filesystem driver specific to each filesystem type being used to load stage2; in GRUB 0.97, the name of that optional component is stage1.5. A completely filesystem-agnostic stage1 loads either a stage1.5 that understands a single filesystem type, or stage2, using a blocklist I described in my answer. If stage1.5 is used, it will read stage2 as a file in a filesystem. In any case, stage2 is monolithic: the filesystem drivers it contains can be only selected at compile time.
    – telcoM
    Nov 17, 2019 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.