MBR, GRUB and GPT

Linux OS Topics
Post Reply
Ageek
Sergeant
Sergeant
Posts: 22
Joined: Sat Aug 01, 2009 10:54 am

MBR, GRUB and GPT

Post by Ageek » Sun Jul 03, 2011 7:34 pm

What is MBR

MBR is stand for Master Boot Record, which is the first 512 Bytes of the hard disk. As everybody knows MBR is used to store the bootloader, partition table and so on. This was introduced by the IBM for their hardwares.

If we consider the structure of the MBR;

0 - 445 Bytes - mainly used to store the Boot Loader
446 - 509 Bytes - (64 Bytes) used to store the partition table
510 - 512 Bytes - Store the ending identifier "AA55" magic number


Boot Loader

Boot Loader is the area to use to initialize the booting process. Windows uses their own proprietary boot loader (eg; NTLDR), Linux system uses GRUB at this moment earlier used LILO and
so on.

GRUB (GRand Unified Bootloader) is a universal boot loader which can be used to boot any operating system, however NTLDR support only Windows :(

How does GRUB store all theses info

GRUB divides the boot loader into 2 parts; GRUB stage 1 (stored in the MBR) and GRUB stage 2 (as example stored in Linux /boot partition)

That is why GRUB can give a nice GUI with customized background images so on.

Partition Table

In MBR 64 Bytes are allocated to store the partition table. User is restricted to create only 4 primary partitions, each given 16 Bytes to store a primary partition. This is the reason only we can create a maximum 4 booting partition.

However, now u can create unlimited primary partition for any kind of operating systems using GPT (GUID Partition Table).
In computer hardware, GUID Partition Table (GPT) is a standard for the layout of the partition table on a physical hard disk. Although it forms a part of the Extensible Firmware Interface (EFI) standard (Intel's proposed replacement for the PC BIOS), it is also used on some BIOS systems because of the limitations of MBR partition tables, which restrict a disk partition's size to a maximum of 2.19 TB (2.19 × 1012 bytes) or 2 TiB?512 bytes (2,199,023,255,040 bytes or 4,294,967,295 (232?1) sectors × 512 (29) bytes per sector).GPT allows for a maximum disk and partition size of 9.4 ZB (9.4 × 1021 bytes) or 8 ZiB?512 bytes (9,444,732,965,739,290,426,880 bytes or 18,446,744,073,709,551,615 (264?1) sectors × 512 (29) bytes per sector).

As of 2010, most current OSs support GPT, although some (including Mac OS X and Windows) only support booting to GPT partitions on systems with EFI firmware.

-Wikipedia


Sometimes when u r booting a computer, as an example a Windows machine u can see an error message saying "NTLDR is missing!" and Linux systems u r taken to the GRUB prompt, this is because MBR is crashed.

What you can do to troubleshoot,


If it is a Windows machine u can fix the MBR, using a windows boot cd repair mode or in Linux u can install the GRUB again. NOTE: This will not gurantee to restore ur all partitions

Best way is back up your MBR, this is what a rescue disk does.

In Linux u can do it using a single line command

Code: Select all

# dd if=/dev/hdX of=/tmp/mbr.bin bs=512 count=1
This will create a dump of the MBR of the disk drive hdX (X need to replace with appropriate no) and out to a file 'mbr.bin' in /temp directory counting 512 Bytes
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Re: MBR, GRUB and GPT

Post by Nipuna » Sun Jul 03, 2011 8:47 pm

Thank You Very Much Uditha Sir. I learned So many from This.

And I Found another way of Reinstalling GRUB when we have installed Ubuntu and Windows together without Backing Up GRUB by using Ubuntu Live CD.
I found that from Ubuntu Forums by Searching on Google Using "Recover Ubuntu after Windows Installation".

I told this to show you that I had those GRUB problems and not to show Big Picture and I know obliviously Uditha Sir Know those if i tell or Not
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: MBR, GRUB and GPT

Post by Neo » Sun Jul 03, 2011 9:49 pm

Very useful article UdithaM. Thanks for sharing!!!
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: MBR, GRUB and GPT

Post by SemiconductorCat » Fri Oct 07, 2011 1:42 pm

however NTLDR support only Windows :(

But anyway, I have load linux/freedos/reactos/GNU Hurd/or other bootloaders using the NTLDR.
sounds like you have not read even the wiki page about NTLDR. Non of my business
anyway so leave me alone. Oky just limit to the facts !

but NTLDR supports more OSes than just windows. It just also have a configuration
file called boot.ini like Grub's /boot/grub/menu.lst.

There is no worth duplicating the information here,read up this link. If link
is confusing , you know what to do [google with tags]
http://jaeger.morpheus.net/linux/ntldr.php

and NTLDR is not the boot sector , When you format a file as fat32 or as a windows partition
it will implicitly write the boot code to it's [particular partition's] boot sector.And that
code will search for NTDLR file and load it to memory. Then that will read the boot.ini
file and print the menu of operating systems and other options. the message NTDLR
missing is printed from the code resided in that boot sector. If you copy a bootsector
of a windows partition using dd tool and open it using a hex editor [KHexEdit like]
then you can view that string message there.

so if you install windows after linux, no matter it still oky. You have two options.
1. Find your /boot/grub/stage1 file [it's the grub boot sector] , and
copy that to windows fat partition [ this is necessary because NTDLR does not
have information to read ext3/ext4 file system] and configure boot.ini to
execute that stage1 file.
2. Use a easy tool like Supergrub/grub installer disk, to load grub, and using the grub prompt
it's damm easy to load the kernel and load linux. [windows 7 like OSes does not support
grub installer if you don't give it permissions]. but still possible.
3. The method ^ above discussed. Just compile the bootsect.S and replace with with
dd command.



and also when installing grub, or boot loader it's not necessary to install it just to the MBR.
In my case I have put shifted linux into a extended partition. [because of that limit of 4] and
I put my GRUB stage1 into the file windows partitions and load extended partition's grub
using NTDLR.
Boot Loader is the area to use to initialize the booting process. Windows uses their own proprietary boot loader (eg; NTLDR), Linux system uses GRUB at this moment earlier used LILO and
so on.
Linux , we probably referring to the kernel.what we have to do when we want to boot linux is just unpack
it and it's ramfile system to memory and just jump there. Reallocation and allocation of memory will be
handled by the kernel code itself after you transfer the control to it.

And linux also supports a bootloader , if you don't need lilo or grub and you don't have any idea of dual
booting, then linux bootsector method will works fine there. But older days I have load linux using
floppy even, I need more clarification about this , is it still supporting to load kernel directly from a
boot sector code?
^- need clarification.
Post Reply

Return to “Linux”