LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Is MBR in the boot block/sector or is MBR the boot block/sector? (https://www.linuxquestions.org/questions/linux-newbie-8/is-mbr-in-the-boot-block-sector-or-is-mbr-the-boot-block-sector-4175648188/)

ultra_reader 02-12-2019 08:29 PM

Is MBR in the boot block/sector or is MBR the boot block/sector?
 
Hello there.

I know what MBR is and what it contains but I found several references across linux books talk about boot sector/block which exists before block group 0 (ext2/3 layout) and holds data to start the system ----> bootstrap loader.

So now Im having second thoughts about if those references actually mean MBR?

Any clarification will be appreciated!

Thank you!!!

frankbell 02-12-2019 08:43 PM

With Linux distros, the boot loader need not necessarily be installed to the MBR, though it often is.

For an example, see this page illustrating a Slackware install and look for the picture labeled "Lilo destination is preferable on Master boot record MBR."

ultra_reader 02-12-2019 08:52 PM

Quote:

Originally Posted by frankbell (Post 5961264)
With Linux distros, the boot loader need not necessarily be installed to the MBR, though it often is.

For an example, see this page illustrating a Slackware install and look for the picture labeled "Lilo destination is preferable on Master boot record MBR."

I don't get it. It says option1 and 2 are safest but the guide proceeded with MBR? Ok.

Although It doesn't answer original question, thank you!

michaelk 02-12-2019 09:24 PM

Not sure I fully understand the question and it would be nice if you could post a reference but the boot sector code is the first 446 bytes of the MBR which isn't enough space for the entire boot loader code so it is typically split into several stages. Depending on boot loader and version the next stage is sometimes written in the empty space between the end of the MBR and the start of the first partition.

https://en.wikipedia.org/wiki/GNU_GRUB

syg00 02-13-2019 12:19 AM

Quote:

Originally Posted by ultra_reader (Post 5961257)
I know what MBR is and what it contains

Be careful what you think you know ...
Quote:

but I found several references across linux books talk about boot sector/block which exists before block group 0 (ext2/3 layout) and holds data to start the system ----> bootstrap loader.

So now Im having second thoughts about if those references actually mean MBR?
Possibly not - partitions can have a boot sector record that can be chainloaded. References to ext? makes this the likely source of confusion. As above, refences will engender more appropriate responses.

ultra_reader 02-13-2019 12:35 AM

Quote:

Originally Posted by michaelk (Post 5961276)
Not sure I fully understand the question and it would be nice if you could post a reference but the boot sector code is the first 446 bytes of the MBR which isn't enough space for the entire boot loader code so it is typically split into several stages. Depending on boot loader and version the next stage is sometimes written in the empty space between the end of the MBR and the start of the first partition.

https://en.wikipedia.org/wiki/GNU_GRUB

This!!!

Sorry if I wasn't enough clear the 1st time.
My doubt came from this two extracts from oreilly "how linux kernel works"

Quote:

Ext2 Disk Data Structure

The first block in each Ext2 partition is never managed by the Ext2 filesystem, because it is reserved for the partition boot sector (see Appendix A).
Appendix A:

Quote:

The BIOS bootstrap procedure essentially performs the following four operations:

1,
2,
3: Searches for an operating system to boot. Actually, depending on the BIOS setting, the procedure may try to access (in a predefined, customizable order) the first sector (boot sector) of every floppy disk, hard disk, and CD-ROM in the system.
But later says:

Quote:

Ancient Age: the Boot Loader

The boot loader is the program invoked by the BIOS to load the image of an operating system kernel into RAM. Booting from a hard disk is done differently. The first sector of the hard disk, named the Master Boot Record(MBR), includes the partition table[*] and a small program, which loads the first sector of the partition containing the operating system to be started
Wasn't bootstrap responsible for that last task? Try to access the first sector?

And at the same time the MBR tries to load the first sector as well?

It's confusing!

Here's the book (you can sign up for free trial, I think it's one week or so)

https://learning.oreilly.com/library...52/apas02.html

GazL 02-13-2019 03:35 PM

BIOS reads sector 0 of the disk -the Master Boot Record - and loads and runs the Master Bootloader contained within.

Master Bootloader looks in the partition table of the MBR for the first partition that is flagged as active, loads the Partition Boot Record (the first sector of that partition) from that, and runs the Partition Bootloader, which loads the OS.

Now, where it gets interesting is that when you install the linux bootloader you have the choice of overwriting either the Master Bootloader or the Partition Bootloader with either the lilo or grub stage1 bootloader:
  • If you overwrite the Partition Bootloader, then the Master bootloader will still work as before and start whichever partition bootloader is marked active.
  • If you overwrite the Partition Bootloader but have never installed the standard Master bootloader -- perhaps a completely new disk with no other OS on it -- then nothing will boot.
  • If you overwrite the Master bootloader then depending on how they are configured lilo/grub bootloaders can either chain the Partition bootloader, or just load the kernel directly, bypassing the Partition bootloader entirely.

So, in short, if your disk only contains linux, then you might as well install the bootloader to the MBR. If you will be dual booting with something else and your MBR already contains a Master Bootloader, then it might be best to install the linux bootloader to the Partition and mark it as active, but you don't have to.


Now, because the first sector of a partition may contain a bootloader, many, but not all filesystems will ignore the first few sectors of the partition just to be sure that they're not going to clobber it. If I remember rightly XFS isn't one of them and as such is not a suitable choice for a partition holding a bootloader. ext2/3/4 are safe.

Then of course there's EFI which is a whole other can of worms. ;)

Hope that helps.

ultra_reader 02-13-2019 05:48 PM

Quote:

Originally Posted by GazL (Post 5961670)
BIOS reads sector 0 of the disk -the Master Boot Record - and loads and runs the Master Bootloader contained within.

Master Bootloader looks in the partition table of the MBR for the first partition that is flagged as active, loads the Partition Boot Record (the first sector of that partition) from that, and runs the Partition Bootloader, which loads the OS.

Now, where it gets interesting is that when you install the linux bootloader you have the choice of overwriting either the Master Bootloader or the Partition Bootloader with either the lilo or grub stage1 bootloader:
  • If you overwrite the Partition Bootloader, then the Master bootloader will still work as before and start whichever partition bootloader is marked active.
  • If you overwrite the Partition Bootloader but have never installed the standard Master bootloader -- perhaps a completely new disk with no other OS on it -- then nothing will boot.
  • If you overwrite the Master bootloader then depending on how they are configured lilo/grub bootloaders can either chain the Partition bootloader, or just load the kernel directly, bypassing the Partition bootloader entirely.

So, in short, if your disk only contains linux, then you might as well install the bootloader to the MBR. If you will be dual booting with something else and your MBR already contains a Master Bootloader, then it might be best to install the linux bootloader to the Partition and mark it as active, but you don't have to.


Now, because the first sector of a partition may contain a bootloader, many, but not all filesystems will ignore the first few sectors of the partition just to be sure that they're not going to clobber it. If I remember rightly XFS isn't one of them and as such is not a suitable choice for a partition holding a bootloader. ext2/3/4 are safe.

Then of course there's EFI which is a whole other can of worms. ;)

Hope that helps.


Thanks!!!! This clarified my original doubt!!!!

edit: sorry but what happens in the case of EFI/UEFI? thx!

GazL 02-14-2019 03:57 AM

In EFI the bootloaders are files within the EFI "SYSTEM" partition (which is fat32 formatted). EFI chooses which one to boot from a list it keeps in non-volatile memory.

ultra_reader 02-14-2019 02:40 PM

Quote:

Originally Posted by GazL (Post 5961851)
In EFI the bootloaders are files within the EFI "SYSTEM" partition (which is fat32 formatted). EFI chooses which one to boot from a list it keeps in non-volatile memory.

Thanks a lot @Gazl!!! Your replies helped understand better that part of the boot process which it didn't stuck on my head!!!!


SOLVED!!!!!!!

GazL 02-14-2019 03:45 PM

You're welcome. Happy booting! :)


All times are GMT -5. The time now is 01:13 PM.