2

I have a simple question. Where is MBR (GRUB) located, it's inside a partition? And does it get removed when you format & delete the partitions of Ubuntu?

3 Answers 3

5

This question isn't quite as simple as you may think.

First off, MBR and GRUB aren't the same thing. MBR is:

the information in the first sector of any hard disk or diskette that identifies how and where an operating system is located so that it can be boot (loaded) into the computer's main storage or random access memory. The Master Boot Record is also sometimes called the "partition sector" or the "master partition table" because it includes a table that locates each partition that the hard disk has been formatted into. In addition to this table, the MBR also includes a program that reads the boot sector record of the partition containing the operating system to be booted into RAM. In turn, that record contains a program that loads the rest of the operating system into RAM.

GRUB, however, is:

a boot loader package from the GNU Project. GRUB is the reference implementation of the Free Software Foundation's Multiboot Specification, which provides a user the choice to boot one of multiple operating systems installed on a computer or select a specific kernel configuration available on a particular operating system's partitions.

A shorter version: MBR is the info on a hard drive that tells the BIOS of the computer what to boot. GRUB is a bootloader, which scans for installed operating systems and presents them in a list to choose among. (Not the best summary, but it should do for now)


Where is MBR (GRUB) located, it's inside a partition?

Well, it depends. You see, there are actually at least two different ways a hard drive might be set up:

  • MBR

    This was explained above, so I think I can leave it at that.

  • GPT

    This is a newer standard than MBR, although it essentially does the same thing. GPT has more features and is generally more useful than MBR. However, for normal purposes, the two aren't vastly different.

(For a more in-depth explanation of the differences: http://www.howtogeek.com/193669/whats-the-difference-between-gpt-and-mbr-when-partitioning-a-drive/)

There is one difference that is very important to your question, though, and that is (U)EFI. Hard drives using GPT are compatible with EFI. MBR is not, at least not normally.

UEFI presents itself in the form of a small FAT32 partition at the very beginning of the hard drive. Inside this, operating systems that support GPT/EFI place their boot files. If the system the hard drive is on is compatible with EFI, it will first look into that EFI partition and find a boot file to load an OS. There's some sort of priority system that decides what file to boot from if there are multiple options, but I don't really know how that works.

MBR does not make use of this EFI partition. Instead, OS boot files are stored in their respective partitions, and the MBR tells the BIOS what to look for. In the case of GRUB, the normal MBR code gets replaced by the stage 1 portion of GRUB. This then passes off to the stage 1.5 part, which then passes off to stage 2. Stage 2 is the only part of the process on the partition.

This configuration is very different on Windows, but we're not here to talk about Windows.

So, finally, the answer. With both MBR and GPT, deleting just the Ubuntu partition is a bad idea. In both cases, important configurations for GRUB are stored in the respective OS partitions, while most (MBR) or all (GPT) of the actual bootloader is at the very beginning of the hard drive.

Deleting the Ubuntu partition won't delete GRUB, and will instead cause grub rescue to come up instead. This is why there are so many questions about removing Ubuntu and keeping Windows or removing Ubuntu and installing Windows: GRUB doesn't like to let go of the drive.


This leads me to the second part of your question:

And does it get removed when you format & delete the partitions of Ubuntu?

Through the power of editing and lack of memory, I seem to have answered this above.


You seem to have a bit of a misunderstanding about what MBR is and what GRUB is. Hopefully, I've fixed that and answered your question as well.

18
  • Thanks very much for this answer. It clarified a lot for me. The reason I asked is because I want to leave my old HDD in a clean state (ie. remove Ubuntu and all MBR/partition table related info). How do I achieve that, considering that it's a MBR scheme? Just formatting and deleting the partitions will get rid of everything (system and partition table)?
    – Victor
    Oct 1, 2016 at 21:06
  • @victorbrt Just deleting all partitions will remove boot stuff. As for wiping the partition table itself, I'm not sure. You'd have to look that up. Oct 1, 2016 at 21:07
  • On MBR-partitioned drive with Grub installed in MBR Grub will not be deleted when you delete Ubuntu-partition, you only delete the configuration-files which reside in most cases in the Ubuntu-partition.
    – mook765
    Oct 1, 2016 at 21:13
  • @mook765, from what I read, just going to diskpark in Windows and selecting my disk, I could do a clean" command (sevenforums.com/tutorials/…) and then the MBR will be overwritten. This theoretically would remove all previous info of grub/mbr, right? My plan is just restore the MBR to "default" on this HDD because I plan to buy another SSD to leave Windows in one and Ubuntu in another, and the HDD just for general storage.
    – Victor
    Oct 2, 2016 at 1:38
  • @victorbrt if you're reusing the drive yourself, there's no reason to do such an extensive wipe. Erasing the existing partitions and creating a new one should be enough. Oct 2, 2016 at 2:20
4

Where is MBR (GRUB) located, it's inside a partition?

No, it's not located inside a partition. MBR (Master Boot Record) is the first sector of a disk, so it is 512 bytes on a 512 bytes-sectored disk.

Just to note, the first sector of a partition is actually called Partition Boot Record or Volume Boot Record.

does it get removed when you format & delete the partitions of Ubuntu?

No, MBR is not removed when you delete partitions as it is located outside the partition range, the partition table would be updated accordingly though in such operation(s).

2
  • Partition-table will be updated accordingly when you delete a partition, so the partition-table is not going to be obsolete...
    – mook765
    Oct 1, 2016 at 21:20
  • @mook765 Edited.
    – heemayl
    Oct 2, 2016 at 21:18
1

With my understanding of MBR & Grub this is sort of a multipart answer. If I'm wrong, please correct me.

The MBR itself exists in 512 bytes of the 1st sector (Sector 0) of a hard drive, outside a partition space. The MBR is loaded with the boot.img file, and the boot.img file's only function is to load core.img.

The core.img exists in the next 32k of disk space (between sector's 1-63). This also exists outside a partitioned area. The core.img is made up of the diskboot.img (depending on the boot method), kernel.img, and the video & file system modules required to display messages & mount the /boot partition. The core.img mounts the /boot partition & read's the grub.cfg & starts the GRUB menu system.

So with my understanding you wouldn't delete Grub itself by removing the /boot partition but the *.cfg file core.img use's to start it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .