Understanding grub/boot

I have a vague concept, but I would fail any test over the boot process. I’ve read a page about the grub2 commands but still am having a hard time understanding exactly how it works, or maybe what choices I need to make on the install.

To demonstrate my lack of understanding and question, after the first OpenSUSE version I installed, I now have created multiple partitions on my hard drive with a home partition separate. I installed 12.1 on an extended partition. Having read that not all computers support booting to extended partitions, I was prepared for it not working. When I restarted the system, it was just a blinking cursor. So I used a gparted disk to flag the original system, added to its menu to chainload to the extended partition and got the system to work.

With 12.3, I managed to get a primary partition available and installed it on that. However, booting still did not work. So now I don’t know if the extended partition might have booted if I understood what I needed to do.
Maybe since it is using grub2, it needed to change the main MBR of the whole hard disk?

Anyway, where I get confused is on the boot loader setting screen. On the 13.1 setup, I see the similar help screens which do not really tell me what I could understand.

There are several checkmarks, and could it be valid to check multiple ones, or only one?
When it says, boot from Master Boot Record, does that mean it will change my whole hard drive boot process and if something was working it may no longer work?
When it says Boot from Root Partition, is that … Well, I don’t know what that could mean… Is root same as boot? For those having a separate boot partition from your main system play a role here? Since there’s a checkmark for extended, does root mean like primary? Is root whichever partition your main system (/) is on so it really means set a flag? But then on the Boot Loader Options Screen there’s something for setting active flag, so I don’t know what this means here. There’s also something about writing code to the MBR. I may have done that back at 11.2 or whenever, but I originally was trying to install windows 98 without luck with new hardware (or maybe something with the booting process?).
When it says Boot from Extended Partition, how does that relate to the options screen about setting a flag?

I don’t want to change my main disk MBR or whatever it’s called. I may want to or have to if grub2 requires it, (and in the future), but I want to know what would impact that. Changing my target extended partition I don’t care about if that’s all it changes. Is there a boot record for the partition that maybe I’m not allowing to be written on install?

What impact does checking or not checking the various options have and when would, why would I check them?

The help screen says “Write Generic Boot Code to MBR in Boot Loader Options to update the master boot record if that is needed”. Do I need it? When do I need it? I’m thinking if I had windows running in a partition I would never write to MBR. I am assuming the MBR is for the whole hard disk and enables booting to whichever partition is flagged for booting.

I just know enough to know I don’t know much. Mainly I want to know which check marks to check and why and when and what it does where.

Usually, the installer will select defaults that work in most cases and do not cause other problems.

The MBR is just the first physical sector of the drive. It contains boot code and the partition table. The boot code is probably from Windows.

If grub is installed in the MBR, then that replaces the Windows boot code with grub2 boot code. But that won’t affect anything else. Windows will still work. You will just see a grub2 boot menu as the first step of booting.

In a normal situation, the grub boot code has to go in either the MBR or one of the primary partitions. You can configure your install to put it in the root partition. But it the root partition is a logical partition, that won’t work. People who have grub installed in a logical partition have to know a bit more about what they are doing and about how to boot from there. If you are unsure, then you probably don’t want that.

I hope that helps a little. Ask more questions if you want more answers. I don’t want to say too much and make it sound too complicated.

For working with Grub 2, have a look at my bash script: GNU Grub2 Command Listing Helper with --help & Input - Blogs - openSUSE Forums

For dealing with MBR and GPT formatted hard disks: Creating Partitions During Install for MBR and GPT Hard Disks - Blogs - openSUSE Forums

You indeed have to start somewhere, perhaps these blogs can help?

Thank You,

I had seen your blog on the grub2cmd scripting, but I’m really wanting to understand how the boot loader options work. The creating partitions one was informative. And the part about GPT disks cleared up some things. I had thought GPT disks were special disks, but sounds like GPT is just a partition table format system, but you need a PC with the firmware to read/use it. So any disk can be made as a GPT disk, but only certain PCs can use them. Is that correct?

What I really want to do is boot from a logical partition as nrickert talked about. But I think I’ll settle for later on that and because I don’t want to change the MBR at this time. So my third primary partition has 12.3 on it and I’d like to boot from that. So from what I read on your blog, I want to load the grub boot loader into partition 3 and set it active. Can I do that now with my running system? What if I was fresh installing it to that partition? How do I “load it into partition 3” based upon the boot install options? Would that be check “boot from root partition”? Is that what “boot loader location” means, to load the grub at that location? If multiple options are checked, does it load it at all locations? I’m guessing that loading it at the MBR has extra stuff it puts there unlike if you load it at a partition.

If I had wanted to boot from a logical partition, would I check boot from master boot record AND boot from extended partition, making sure not to check write generic boot code to MBR? That is, when grub replaces the generic code, it adds “smarts” so that it is able to boot to a logical partition whereas the generic boot code does not know how to do that?

So, it is my opinion that unless your boot drive is larger than 2.2 TB, I would stick with an MBR formatted boot disk and flee from GPT hard disks and UEFI boot setups. Next, I have an article on booting from an external hard drive, but what is shown can be any hard drive and the blog shows what you must do:

https://forums.opensuse.org/blogs/jdmcdaniel3/installing-opensuse-13-1-onto-external-hard-drive-150/

I am not a big fan of loading the grub bootloader into a Logical Partition because Windows has been known to blow that up. In my blog, I loaded grub into the root / partition, not located on the logical partition. Pay attention to that suggestion.

Thank You,

Thanks for the link and after reading, I thought I understood it. I’m doing a chainloading from an old bootable partition to the extended partition which was where I had available space. I can’t remember which order I tried what, but I checked one, boot from root partition?, and when that gave me a “Invalid or unsupported executable format” I managed to manually enter grub commands of root, kernel, and initrd and 13.1 loaded. I then used 13.1’s Yast -> boot loader screen to check both, boot from the root and from the extended partition, but got the same error.

I had set my menulist from the old system boot partition to include:

title Chainloader 12.1
    rootnoverify (hd0,7)
    chainloader +1

title Chainloader 13.1
    rootnoverify (hd0,6)
    chainloader +1

The 12.1 worked in the extended partitions. So I don’t know why the same doesn’t work for 12.3. Which means I don’t understand something. I came across something and tried “makeactive” before the chainloader, but still same error.

I still don’t really understand what the checkmarks mean. I really don’t want to lose my working boot partition from the old system. It’s in the first primary partition. I don’t know which check marks mean to write magic unseen boot loader code and which ones mean overwrite the boot menu.

They actually mean what they say - “install bootloader in this location”. Script that performs final step loops over all checked locations and calls utility to install bootloader in each one.

Unfortunately, it does not work that well in case of grub2. Having more than one location checked will with high probability result in unbootable system, similar to what you observed. So for now I would strongly recommend not to use multiple boot locations in case of grub2.

Some of the discussion has become confusing,

In order to boot, the BIOS loads a sector into memory and jumps to it (executes it as code).

In the normal scheme of things, the BIOS loads the MBR into memory and jumps to it. The MBR code then loads the partition boot record (first sector of the partition) for the active partition, and jumps to that.

When the installer ask about “boot from MBR” or “boot from /” or “boot from external partition”, it is asking where to write that boot record (that single sector).

The general rules: You can put the boot record in the MBR, though Windows may later overwrite that.
You can put the boot record in any ext2/ext3/ext4 partition, because the first sector is reserved for that purpose.
You can put the boot record in the external partition (the primary partition that carves out space for logical drives), though at the risk that some other software might overwrite it.

The standard BIOS code can only boot from a primary partition. If you put the boot record on a logical drive, then you have to make other arrangements to boot.

As for alternate arrangements:

Some folk put the boot record on a logical partition, then copy that boot record to a file, and use the Windows boot loader to boot using the boot record in that data file.

Other folk have more than one linux installed. So they have the BIOS boot one of those, and have a grub2 entry to chainload the boot sector for the other linux, and that chain-loaded boot sector can be on a logical drive.

What is not completely clear to me, is what you are trying to accomplish. If you were to list your partitions, what’s on them, and what you want to be able to boot, we could probably come up with decent suggestions.

I may have overlooked the message for the installation. Once a system is running, the Boot Loader screen just says “Boot Loader Location”. Which gave me the idea that I need to tell it where the boot loader is rather than where I want to create it.

I manually loaded 13.1 and ran the boot loader screen once with just the check mark on the root partition and once with it on the extended partition. When I ran the old grub menu with the chainloader screen, I got the same error, Invalid or unsupported executable format. Could there be something about the old grub not being able to chainload to the grub2 partition?

Which may be because I don’t understand it. :slight_smile:

In order to boot, the BIOS loads a sector into memory and jumps to it (executes it as code).In the normal scheme of things, the BIOS loads the MBR into memory and jumps to it. The MBR code then loads the partition boot record (first sector of the partition) for the active partition, and jumps to that.

When the installer ask about “boot from MBR” or “boot from /” or “boot from external partition”, it is asking where to write that boot record (that single sector).

Which is part of what I hadn’t understood. The help screen doesn’t seem to fully explain that.

The general rules: You can put the boot record in the MBR, though Windows may later overwrite that.

Which I’m still vague on. The MBR enables things to boot, but the boot record is an additional thing or is that what MBR means - that is, just and only just the boot record which Linux writes or windows writes? Which may include things like a partition table but is not in addition to what windows writes, but could be different.

Other folk have more than one linux installed. So they have the BIOS boot one of those, and have a grub2 entry to chainload the boot sector for the other linux, and that chain-loaded boot sector can be on a logical drive.

What is not completely clear to me, is what you are trying to accomplish. If you were to list your partitions, what’s on them, and what you want to be able to boot, we could probably come up with decent suggestions.

And this is the choice I’m wanting to make at this time. For some reason, I couldn’t get partition 3 to boot 12.3 and had to use chainloader. It may because of not checking the Write to root partition. Once I get 13.1 booting, I will go back and try that.

What I’m trying to accomplish is to understand it. From the beginning I never understood the checkmarks and just kind of guessed or let it default. Last time, I may have been to scared to overwrite something I didn’t check anything, which may be why 12.3 isn’t booting, but I don’t remember for sure. I thought it is about time to understand it so when I have something different than normal/standard I will be able to fix it and know what I’m doing.

What I have currently:

sda1 - Ext3 - boot (or actually menu) partition from probably 11.2
sda2 - swap
sda3 - Ext4 - 12.3 which I'm using now by chainloading from the sda1 menu.  
sda4 - Extended
sda5 - Ext3 - Data - but separate from the "home" partition included with the (/) partition.
sda6 - Ext4 - 11.3
sda7 - Ext4 - 13.1
sda8 - Ext4 - 12.1

What I want currently is to boot to sda1, like I’ve been doing, choose from the menu, 13.1, and have it chainload to sda7.
The menu of sda1 has:
title Chainloader 13.1
rootnoverify (hd0,6)
chainloader +1

The thing to understand there is more then one way to setup booting on a computer. For a MBR formatted disk you must have some code in the first sector of the disk which is called the MBR. This is called by the BIOS what happens next depends on what code you put in the MBR so called generic code uses the boot flag to determine which partition is to be started. If you but Grub in the MBR then it is preset to know which partition to boot from and can go straight to the real boot stuff. In the case of generic. it really knows nothing about the OS so you put some code in the first sector of the partition to continue the boot sequence. The details are up to the OS but some code has to be at the start of the partition that the the generic MBR code hand over the boot process to. In MS world it used to be that 2 hidden files had to be first in the files system in order to boot the OS. With Grub you can put grub code in the fisrt sector of a partition and since it knows whats happening it can then continue the boot at the location imbedded into its code. Thus it can boot to Logical partitions which at least the the past MS stuff could not.

With EFI bios the boot code lives in a special FAT formatted partition and each OS has its own section of the files structure (ie directory) where it’s boot stuff lives.

For this to work you need to install bootloader (if we speak about 13.1, it is most likely grub2) boot code in boot sector of partition 7. During installation you can check “Boot from root partition” assuming /dev/sda7 is the only partition in 13.1. Or you can check custom location and manually select /dev/sda7. But do not check more than one location. Select exactly one.

But you need select one or another to install boot code in partition boot sector.

I’m trying to remember it that is the exact wording of the error message that I had on one box with 13.1RC2.

The install itself went mostly well, except that the booting was not properly setup. This is bug 848655, if you want the gory details.

I managed to half-way fix the booting, and generate a grub.cfg. Then I invoked that via the “configfile” command from another installation on the same computer. That got me booted into the system.

I then tried to complete the fix, by running Yast → System → Bootloader
which I thought would reinstall grub2. It did most of what I wanted, but I got an error message when booting.

It turned out that the boot sector was never written, though I do not know why. If I dumped the boot sector to disk


# dd if=/dev/sda1 of=bootsect count=1

then running “od -x” on that “bootsect” file showed it to be entirely binary zeros. In particular, it did not have the FFAA in the last two bytes, which is what was being complained about.

I fixed it with


# /usr/sbin/grub2-install --force /dev/sda1

I had thought that Yast always used “–force” when installing the bootloader in other than the MBR, but it appears that it doesn’t.

I am using:


### Entry to boot grub from "/dev/sda6"
menuentry "Alternate grub/linux on /dev/sda6"  {
        set root=(hd0,6)
        chainloader +1
}
menuentry "configfile for grub/linux on /dev/sda6" {
       configfile (hd0,6)/boot/grub2/grub.cfg
}

If the “chainloader” entry fails because the bootsector on that partition is bad, then I can fall back to the “configfile” entry.

If you wanted to boot sda7, you should have used “rootnoverify (hd0,7)”.

Grub2 counts disks starting at zero, but counts partitions starting at 1. This is a change from grub1 (or “legacy grub”).

If you told it to install grub2 on the extended partition, you would instead need “rootnoverify (hd0,4)”.

I recommend that you use a “configfile” fallback command, as suggested in my previous reply. By the way, I add those lines to “/etc/grub.d/40_custom”.

This requires that you are using grub2 as primary bootloader. OP was using grub legacy.

Thanks. I didn’t notice that. So my next reply was also wrong (about partition counting) for legacy grub.

I tried the “configfile”, but as acknowledged, it did not work. However, “rootnoverify (hd0,4)” did work!

Which brings more questions/confusion on my part. I checked the extended partition, and it wrote “it” there, but what if I had wanted my 11.3 or 12.1 to boot instead? It was on the menu of 13.1 for the (hd0,4), but the color/format/style was all different and I assume to be part of 13.1. Something I’m not understanding here. Is it that hd0,4 boot sector is pointing to which extended partition you want to boot and it can only be one? That is, I can set it to be 5, 6, 7, or 8? I think this must be true. (and which would be 4,5,6, or 7 in the old grub if I were to go back and set 11.3 bootloader to be the extended partition?) Is the bootloader code different depending where it’s written? I noticed my sda3 12.3 “bootsect” extract is different from the sda4 extended.

When I do the dd command on sda7, I get:
od -x bootsect
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0001000

But when I do it for sda4, I get all kinds of stuff. Also for sda6.
I might try and go back and set the checkmark for the root again in bootloader? Maybe doing one and then the other removes the previous one?

If you want another Linux to control the boot you need to install grub from that Linux or point the grub code to the root partition you want to control the process…

Only one OS controls the booting you can chain or otherwise boot other OS’s from the one that is in control.

If you put grub in an extended partition it has code that points to the root it is associated with and thus the system that controls the boot process. Any further choice is made from the grub menu.

I read about grub, but for some reason I’m having some problems in understanding it. It’s almost like any documentation is written with the idea you already understand the concept. I think it’s starting to dawn on me, but there’s still major portions missing.

I made a copy of my partition to an external USB drive. Then I thought it’d be nice to boot from there. For multiple reasons/conditions. I have the /boot/grub2/grub.cfg file already there as part of the copied partition made using gparted. I don’t want to change that. I now realize booting to UUID, drive names, etc. can cause conflicts so without addressing any of those issues, when I try to boot, it just says something to the effect there’s no operating system.

According to documentation, I could do something like grub-install /dev/sda with --root-directory=
But I can’t figure out if that is going to change my grub.cfg file or just write magic stuff onto hidden areas of the hard disk.

MBR, boot record, boot partition, root partition, all these seem to be cloudy and unclear to me. I think my root/boot partition is the same, but YaST seems vague to me relating about these things and what it actually does. I believe the MBR is associated with the whole hard disk and can be generic or Linux for booting. Then, if generic, (maybe Linux), it transfers control to one of the 4 primary partitions. Then, somehow, it boots. I don’t know about this boot record/sector/whatever, because if it is written on the first record/sector, what about what was written there, – is that my data? Can the extended primary partition have this magic booting stuff which reads the grub.cfg in the actual extended partition?

I think in making a clone of a windows drive or maybe it came that way on the drive, there is an MBR on the disk. Is that enough to boot a Linux partition or is there additional hidden magic stuff which needs to be in the partition, maybe something like this stage2 I read about? Is there a way to only put the magic hidden stuff on an existing drive/partition so it can boot to it’s already created menu?