Understanding grub/boot

That is probably coming from your BIOS.

When you boot your computer, it reads the first sector of the disk (called the MBR or Main Boot Record) into memory. Then it checks the last two bytes of that sector to see if they contain the boot signature (as I recall, FFAA). If all is well, it jumps to the beginning of the sector which it presumes to contain boot code.

If that boot signature is missing, it tells you that there is no operating system.

The long and short of it, is that you will need to reinstall grub. That will put the necessary code in the MBR. Check the opensuse Wiki.

Well MBR is easy it is simply a small program that is put on the first sector of the first track the BIOS know to go there and run that code (what ever is there) on boot

The code there is of two possible types. First generic code generic code (ie Windows) looks for a flag setting on each partition known as the boot flag. The first one it finds is assumed to be the boot partition and that is where the boot will continue. Note that there must be some code in the first sector of the boot partition to pick up the chain and eventually start a kernel. The second has a partition assigned in the code (ie grub) and the boot flag is ignored

Things are changed now with EFI BIOSes They act a bit different and there is now introduces a EFI boot partition. In Linux it is normally mounted as /boot/efi. It is FAT formatted and holds the startup code for one or more OS’s each OS having it’s own directory The start up code determines which partition is booted for each OS and thus where the boot continues and eventually loads a kernel and starts things up

Now Linux has a special directory called /boot. That is where the boot code that is called by MBR or /boot/efi code will eventually go to continue the boot. In linux you can mount partitions at any point in the file system so you can have a separate partition that has the boot code on it which is mounted as /boot in the root file sytem. And the earlier boot code (ie MBR/EFI) will then point to that partition to continue the boot.

Remember that essentially booting is a chain of processes where one program calls another until the kernel is actually started then the system gets initiated. The actually details depends…

Yes, probably the BIOS. But reinstalling grub, will that do things other than the MBR? I don’t want to change any files that are visible in the copied partition? I want to be able to copy it back onto my main hard drive if there’s a crash or something.

It will also recreate the “core.img” file (in “/boot/grub2/i386-pc”), and probably the “grub.cfg” file in “/boot/grub2”. And it will probably rebuild the “initrd” (which is needed to boot on an external drive).

If you copy back, you may have to reinstall grub again anyway.

I gathered EFI is different, but I want to understand without it first. And I don’t think my bios supports it.

Is the first sector of the first track different than the first sector of the boot partition (which is really one of the primary 4 for generic code)?

That is, the first sector of the disk transfers control to the first sector of the partition? What if the first partition is active? Does it jump from the first of the disk to the first of the partition which may not be that far away?

Is the first sector of the partition reserved? I recall the one of the hard disk is, I think.

So how do I get code into the first sector of the partition and that is the only thing that is done? I just feel I need to understand this so when things go wrong, I don’t mess up the menu or other things. When I have both the external drive and my hard disk at the same time, if I use YaST boot loader, it will create a menu of everything. I want the menu left alone (and not meaning to uncheck the probe foreign os). I may not remember exactly what I did. But there’s an option for Boot loader location to be “Custom Boot Partition”. I expect if I say my external disk, that will overwrite the menu contained on it.

Maybe I haven’t seen OpenSUSE’s wiki. I found one about grub and 11.1, but it doesn’t seem to answer my questions.

Yes, although they are treated in about the same way.

What if the first partition is active? Does it jump from the first of the disk to the first of the partition which may not be that far away?

Yes.

Is the first sector of the partition reserved?

Yes, for some meanings of “reserved”. It is reserved for the operating system to us for booting, so it cannot be part of an ordinary data file.

So how do I get code into the first sector of the partition and that is the only thing that is done?

Normally, by installing a boot loader. The command “grub2-install” does that.

I just feel I need to understand this so when things go wrong, I don’t mess up the menu or other things.

That’s going to depend on which boot loader you use. With “grub2”, installing it will rebuild the menu.

When I have both the external drive and my hard disk at the same time, if I use YaST boot loader, it will create a menu of everything. I want the menu left alone (and not meaning to uncheck the probe foreign os).

When you boot the external drive, it will use a different menu (if you set it up properly). You want it to use the menu on the external drive, rather that the menu on the internal hard drive.

I may not remember exactly what I did. But there’s an option for Boot loader location to be “Custom Boot Partition”. I expect if I say my external disk, that will overwrite the menu contained on it.

Unless you have multiple operating systems on the external drive, it is best to install grub2 to the MBR of the external drive.

To do that, you need to set the disk order to be assumed by grub2, so that the external drive comes first.

Maybe I haven’t seen OpenSUSE’s wiki. I found one about grub and 11.1, but it doesn’t seem to answer my questions.

If you want full directions, we can give them. But it isn’t clear what you want at this stage, so it’s hard to give directions until you are clearer.

I may be slowly understanding a portion of it. I had not understood that there were multiple first sectors. I’m not sure why I have a hard time with this, but having only one partition on one drive for years didn’t help.

And it only installs code into the first sector of the partition without changing or rebuilding the menu?

Unless you have multiple operating systems on the external drive, it is best to install grub2 to the MBR of the external drive.

If you want full directions, we can give them. But it isn’t clear what you want at this stage, so it’s hard to give directions until you are clearer.

That’s because I’m trying to understand so I don’t know what I want. I guess for now, on my external drive, I have a Windows partition copied, and then I have Linux copied on either the second or inside the extended. (I had the 128GB BIOS USB limitation issue)

So even if it’s best, and I may end up doing it, for practice and understanding, I want to boot directly to the Linux partition. Maybe if there’s nothing in the MBR, I cannot do that. In which case, for now, I want to write generic code to the MBR. Then flag the extended partition for booting (?) and have it install and load grub there. If that’s not possible, then in another primary partition. And to leave the menu alone without rebuilding it.

I could see that some times I may have other drives attached or not attached and wanting to update / repair either a usb drive or an internal drive to make it bootable. Therefore I would not want to change/rebuild the menu because it would be for a different system and so need to leave it alone. I could see the case where my hard drive is going bad or got a new one, want to copy my current partition over, and make it bootable on the new drive. However, I might have added other Linux partitions since I last updated the menu and would not want those menu entries added on the new drive.

I’m not sure if that rebuilds the menu. It does regenerate “core.img” and it possibly regenerates the “initrd” for each kernel.

That’s because I’m trying to understand so I don’t know what I want. I guess for now, on my external drive, I have a Windows partition copied, and then I have Linux copied on either the second or inside the extended. (I had the 128GB BIOS USB limitation issue)

So even if it’s best, and I may end up doing it, for practice and understanding, I want to boot directly to the Linux partition. Maybe if there’s nothing in the MBR, I cannot do that. In which case, for now, I want to write generic code to the MBR. Then flag the extended partition for booting (?) and have it install and load grub there. If that’s not possible, then in another primary partition. And to leave the menu alone without rebuilding it.

All of those may be possible.

Here’s the problem that you have to be careful about:

Booting (or the initial stages) is done via BIOS calls. A BIOS call specifies which disk to read.

When you tell the BIOS to boot from an external drive, the BIOS logically rearranges the order of the disks, so that the external drive (the one from which you are booting) is seen as the first hard drive to BIOS calls. So the grub boot code needs to be compatible with the order of disks that the BIOS will assume during boot. This is what goes in the file “/boot/grub2/device.map” – the order of lines is the assumed order of the disks. If you are using Yast bootloader, then the “Boot Loader Installation Details” button allows you to set the order. If you directly use “grub2-install”, you probably have to edit that file yourself.

I could see that some times I may have other drives attached or not attached and wanting to update / repair either a usb drive or an internal drive to make it bootable. Therefore I would not want to change/rebuild the menu because it would be for a different system and so need to leave it alone.

Let me illustrate.

Suppose I am reinstalling grub on an external drive. I’ll need to have that drive plugged in, and I’ll need to be booted to linux of the same architecture (32-bit or 64-bit). I mount the root partition of the external drive to “/mnt”. I mount other partitions on top of that (including “/proc” and “/sys” and “/dev”. I then “chroot” to “/mnt” to install grub. The menu it may update or install, will be the menu on the external drive. It won’t touch anything on the system that I originally booted. It will only make changes on that external drive (if I did it correctly).

It does not.

and it possibly regenerates the “initrd” for each kernel.

No, it does not. Until 13.1 it was the opposite - mkinitrd called update-bootloader which called grub2-install. In 13.1 update-bootloader now only calls grub2-mkconfig when invoked by mkinitrd.

So the grub boot code needs to be compatible with the order of disks that the BIOS will assume during boot. This is what goes in the file “/boot/grub2/device.map” – the order of lines is the assumed order of the disks.

GRUB2 does not need this file. As long as you are using distributed utilities (grub2-install and grub2-mkconfig) to install and generate configuration, it will search for required filesystem during boot using either filesystem UUID or (in case filesystem does not support them) by creating file with unique name in this filesystem and searching for this file.

Device.map is absolutely redundant (and actually may cause installation to fail). This was needed in openSUSE in the past because YaST used legacy “(hdX,Y)” notation when calling grub2-install, but today it is using OS device names as it should.

This was about the “device.map” file (the forum “quote” omitted that).

Yes, grub2 uses UUID from the configuration. But it first has to use BIOS calls to read the configuration. It is in reading the configuration, that the BIOS disk order for the boot is significant.

I’ll grant that it is possibly only needed by the Yast bootloader installer.

grub2 usues UUID to find configuration.

But it first has to use BIOS calls to read the configuration. It is in reading the configuration, that the BIOS disk order for the boot is significant.

grub2 scans all disks - it does not need to know BIOS disk order. Actually, you can replace biosdisk driver with other (e.g. ahci) at run time and grub2 will still find needed disk, even though they now may be in totally different order.

I gave up on the external drive for awhile. But without understanding this grub, I keep coming up with problems. Here’s two more questions.

  1. This may not necessarily be grub but an .ISO issue, I don’t know. After downloading the 13.2 .ISO file, I wanted to boot it from the menu without having to burn a DVD. Here is what I had searched and found to put in the menu.
menuentry "opensuse 13.2" {
  set isofile="/(user download directory)/openSUSE-13.2-DVD-x86_64.iso"
  set root=(hd0,5)
  loopback loop $isofile
#  search --set -f /live/vmlinuz
  set gfxpayload=keep
  linux (loop)/boot/x86_64/loader/linux boot=live username=user config quiet noswap edd=on nomodeset noeject locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch=no vga=791 ip=  nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=no
  initrd (loop)/boot/x86_64/loader/initrd
}
menuentry "opensuse 13.2 install" {
  set isofile="/(user download directory)/openSUSE-13.2-DVD-x86_64.iso"
  set root=(hd0,5)
  install=hd:/?device=sda6
  loopback loop $isofile
#  search --set -f /live/vmlinuz
  set gfxpayload=keep
  linux (loop)/boot/x86_64/loader/linux boot=live username=user config quiet noswap edd=on nomodeset noeject locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch=no vga=791 ip=  nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=no
  initrd (loop)/boot/x86_64/loader/initrd
}

Either one ends up the same. It loads for awhile but then says, “Please make sure your installation medium is available”.

  1. I then made a DVD which took 30 minutes to make and then took a long time to upgrade. The checksum checked out. When booting and choosing it from the menu, I see a message which says, “Failed to start load kernel modules”. But it seems to run, but I just am scared of it. I had made a partition copy to sda6, and then chose the upgrade option. I had changed the menu to have the right disk ids, but maybe there’s something else which is pointing to the original partition? Anyway, I’m ready to to a clean install, which brings me to questions about the boot loader options I still don’t really understand.

There is “Boot loader location”. I would like to know what is installed where and/or what is changed, if I should choose each option.
_ Boot from Master Boot Record
_ Boot from Root Partition
_ Boot from Extended Partition
_ Custom Boot Partition (assuming I would choose /dev/sda6)

What if I check more than one?

Linux kernel cannot access grub loop device and does not know anytihng about it. You need to place ISO image in location that installation kernel+initrd can access and pass install=xxx parameter.

There is “Boot loader location”. I would like to know what is installed where and/or what is changed

Device in “Boot loader location” is passed directly to “grub-install”. Installer will call “grub-install /dev/XXX” for each /dev/XXX you defined.

I guess I don’t understand how to do that. The image is on sda5, I’m was trying to install onto sda6.

Device in “Boot loader location” is passed directly to “grub-install”. Installer will call “grub-install /dev/XXX” for each /dev/XXX you defined.
I thought I had understood what that means. I went and did an install to sda6 from the DVD, set the options for extended and root. When it rebooted, it had the blinking cursor. I went and used gparted to mark my original boot partition which then transfers to the extended partition. Now things are even more confusing. When I was booting on sda7 for 13.1, I would manually edit the file (just to see how it worked) in the /boot which is part of the /root partition. It would change it on the menu. But when I booted back to 13.1, it showed the new menu of 13.2 that was installed. Once I got back into the 13.1 system, I looked in /boot and the menu was just like it was left. So somehow, 13.2 changed a menu somewhere without changing the 13.1 system menu and without changing my small original boot partition which transfers over to the extended menu.

I don’t know if that’s clear. But my system boots to the original sda1 parition which has the old grub, I choose an extended option I put in it which transfers over using: rootnoverify (hd0,3) chainloader +1
Which I guess is in the extended 4 partition. I just don’t understand how it works. It must have somehow only transferred over to sda7 and it’s grub menu in the past, but now it’s actually in sda4 now?

ok first things first only one OS controls the boot. so if you have 2 OS’s installed only one controls the boot. In this case 13.2 is now in control. So no change is made to the 13.1 files becaue 13.2 is now in charge. See???

I’m confused about your partition usage so could you give us the output of

fdisk -l
that is a lower case L not a one

posted in code blocks (# option in editor window)

Yes, unfortunately due to the way grub2 is installed in openSUSE this is very likely result in this case. This configuration option was carried over from grub legacy. What is the reason to select two boot devices? Just stick to one, it should work.

# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000325f8

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *       16065      160649       72292+  83  Linux
/dev/sda2          160650    16884314     8361832+  82  Linux swap / Solaris
/dev/sda3        16885760   100761599    41937920   83  Linux
/dev/sda4       100761600   976773119   438005760    f  W95 Ext'd (LBA)
/dev/sda5       314665218   976768064   331051423+  83  Linux
/dev/sda6       100763648   186738687    42987520   83  Linux
/dev/sda7       186740736   274823167    44041216   83  Linux
/dev/sda8       274825216   314664959    19919872   83  Linux

Partition table entries are not in disk order

The sda1 is from 11.2 or something. It does the chainloader to sda4. Which now, I think, has the grub2 for 13.2 (sda6) and the grub2 for 13.1, while still in sda7, has been removed from sda4 and replaced with the one installed with 13.2. I don’t know, just still struggling to understand.

I would love to! That was what I was hoping to accomplish by asking what those options did. I’ve been wanting to do that since about 12.1 and is one of the main goals of starting this thread. At this time, I want it to boot directly to sda6 in the extended partition and present the menu. How can I do that? I read some disks can’t. Is that my case? But at the same time, when I had a primary partition available, that didn’t seem to work either.

I want to leave the menu from 11.2 on sda1 alone, because what’s working I don’t want to mess up. I suppose there’s not much left there, but at the first, I could boot into my old systems when the new setup failed. I’m more and more shy of messing things up. With 13.2, if I had done an upgrade on my live system, it would have disabled it leaving me with nothing working due to dropping support for modems. So I really don’t want to change what is working on sda1, but I’m fine with getting it to boot directly into sda6 if possible.

No there is only one grub in any location. grub from 13.2 has replaced any other grub on sda4 . How it worked in grub legacy was to chain load the kernel. You only really needed to go to the grub boot code on the first OS then other OS’s were chain loaded. Only the primary controlling OS needs the grub boot code.

If you pretty much used the defaults for legacy disk partitioning (MBR) then 13.2 is now in charge of booting all other would be chain loaded from the 13.2 grub.

You cannot boot directly to logical partition (it is probably possible in theory but I’m not aware of any MBR code that implements it). It has to be primary partition (including extended partition).

If you want to do multi-booting with many different operating systems I would recommend setting up “primary bootloader” in one standalone partition that is outside of all other installed systems and manually creating primary bootloader configuration to “chainload” bootloaders from installed systems. I would chose grub2 for this but in principle that can be anything you are comfortable with (including Windows :slight_smile: ) This way you manage boot menu of each installed system inside of this installed system and need to update primary bootloader menu only when installing something new.