[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Booting with Grub, was Re: Stupid question



On Mon 14 Feb 2022 at 10:41:52 (-0500), Chuck Zmudzinski wrote:
> On 2/13/2022 11:23 AM, Andrei POPESCU wrote:
> > On Du, 13 feb 22, 02:40:27, Chuck Zmudzinski wrote:
> > > This is my understanding of how grub works.
> > > 
> > > It looks you are using the old MBR partitioning scheme. The logical
> > > partition indicates that.
> > > So I also assume you are using the legacy booting (not UEFI). So the first
> > > thing that
> > > happens is that you will have an active partition set that your BIOS will
> > > boot (if you have
> > > standard bootcode installed in the first sector of the disk).
> > Legacy BIOS doesn't have an understanding of partitions, it will just
> > look for a bootloader in the MBR of the mass storage device chosen to
> > boot from.
> > 
> > The active / bootable flag was (still is?) a Microsoft thing[1], Linux
> > bootloaders never cared about it and can load operating systems
> > regardless if the corresponding partition is marked active or not.
> > 
> > [1] as far as I recall it was used in DOS times to let the bootloader
> > know which is the system partition, but it could be (ab)used for
> > multi-booting ;)
> 
> That's a good clarification that the active partition is a Microsoft thing
> implemented by the bootcode Microsoft installs in the MBR of the device
> chosen to boot from. Now for an unanswered question: What
> does bootcode installed by Debian Linux in the MBR do? How does it
> decide which partition to boot from? I think this is what the OP
> is asking.

By reading the grub.cfg that Grub is directed to use by the
grub-install command. In my post, I tried to keep it simple
for the OP by instructing them to run grub-install from the
installation whose /boot/grub/grub.cfg was to be read.
Of course, Grub, being Grub, and grandly universal, you don't
have to do it like that, as David ably showed. You can install
Grub by running grub-install from anywhere, and directing it
to use files from anywhere else.   man 8 grub-install.

The point is that when you install Grub into the MBR (plus the
BIOS Boot partition on GPT disks), you build a program that
can read devices and filesystems: hence it can find a
/boot/grub/grub.cfg wherever it is placed.

Both the Grub MBR and the Windows one are relatively "thick",
but not stupid. After all, there aren't many bytes in one
sector. The distinction is that Windows-MBR will jump to the
partition marked by the boot flag, whereas Grub-MBR jumps to
a fixed location (built in when you install it) where its
core-image (actually its core-iamge-loader) is located. That
image is necessarily outside any filesystem so that it can't
get moved by fs operations. (As GPT disks don't necessarily
contain any such areas, that's why you need a BIOS Boot
partition, as a playground for Grub.) It's the core image
that's really clever.

Disclaimers: Everything above assumes BIOS booting.

Windows-MBR is an oversimplification, but the distinction
between the two is what's important here. There has been
some evolution in capabilities (not much), and not all
originate from Microsoft either.

Cheers,
David.


Reply to: