still confused... multiple grub's on multiple drives

Questions about Grub, UEFI,the liveCD and the installer
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
spamhog
Level 3
Level 3
Posts: 146
Joined: Thu Dec 17, 2009 6:21 pm
Contact:

still confused... multiple grub's on multiple drives

Post by spamhog »

Mint is installed on /dev/sda2.

Grub is installed from Mint onto /dev/sda automtically but also manually on /dev/sdb and /dev/sdc .

Other OSs boot well:

- one other full install to hard disk on /dev/sda1,
automatically recognized in update-grub and added to the grub boot menu

- some live .iso's on /dev/sdc1 after adding files to to /etc/grub.d/,
none appears in grub-update, so seem added on the fly at boot time,
and I can't tell if it's by reading the extra files in /etc/grub.d/
or by pointers hidden into the grub's on the hard disks

Now choosing to boot from sdb and sdc works well and all OS's boot regularly.

ALL are called by UUID or by partition label or by filesystem label,
so none depends on the order of the whole drives.

However,
does booting using say the grub installed on /dev/sdc
still depend on the grub files in /boot/grub/ on /dev/sda2?

In other words,
if the computer lost ANY out of
- the whole drive /dev/sda
- the grub on /dev/sda
- the partition /dev/sda1
- or the files in /boot/grub/ on /dev/sda1
can the comp still boot the remaining OS's from the grub's /dev/sdc? :?: :?: :?:

I suspect the whole chain is needed no matter which grub is called.

The implication would be that for resilience each grub installation should at be made by a running, functioning, fully installed OS on the same drive, containing any extra files pointing to the other OS's in its owninstalled /etc/grub.d/.

What's the smilie for "opening a can of worms"? :mrgreen:
Last edited by LockBot on Sun May 28, 2023 10:00 pm, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: still confused... multiple grub's on multiple drives

Post by Termy »

Interesting as this topic is, I think ultimately, you shouldn't need to worry about any of this. For the most part, GRUB will continue to do its thing, updating your GRUB configuration, probing the system for other OS installations, launching your favorite installation of Linux, etc.

One thing you should know. Let's say you have Linux installed on '/dev/sda' and '/dev/sdb'. You might load up '/dev/sda', install a new kernel which I believe ultimately leads to the execution of grub-mkconfig(8), via update-grub(8). That will update for anything you might have changed on '/dev/sdb'. If you had recently changed the OS on '/dev/sdb' to something else, GRUB would now pick that up. The same applies vice versa. In another words, updating GRUB on one drive/installation does not automatically update GRUB on them all — it's individual.

It's kind of cool that you have me thinking about this. I've used Linux for over a decade and would by many be considered an advanced Linux user, but I've never asked myself how GRUB actually works or how it detects operating systems on other drives/partitions. Thanks for prompting me to think about it. I hope more people chime in, potentially sharing interesting information about GRUB.
spamhog wrote: Mon Nov 28, 2022 7:37 am However, does booting using say the grub installed on /dev/sdc still depend on the grub files in /boot/grub/ on /dev/sda2?
I don't think so, but I'm having a hard time finding specific information online about how GRUB works under the hood. I would guess it checks the MBR for relevant information and perhaps SYSFS ('/sys'). I can't imagine it mounts the filesystems to search through '/boot', and indeed I couldn't find any evidence of that.

The update-grub(8) executable is actually a wrapper (or 'stub') for grub-mkconfig(8), the latter of which is the actual tool that seems to detect other operating systems. There's also '/usr/bin/os-prober', at least on my system, but it seems unrelated.
spamhog wrote: Mon Nov 28, 2022 7:37 am can the comp still boot the remaining OS's from the grub's /dev/sdc?
Lost any what? Data? If so, then I'd say the answer is no, because some data loss could certainly result in GRUB being unable to detect the OS properly, but it really depends on exactly how grub-mkconfig(8) finds a valid OS.

I had a quick peek at '/usr/bin/os-prober', which seems to make heavy use of SYSFS, but I didn't look thoroughly nor did I look through the sourced script(s). Perhaps grub-mkconfig(8) also refers to SYSFS for low-level information shared by the kernel, but that now leads me down the rabbit hole of how that information is gathered; is it like magic numbers or file signatures?
I'm also Terminalforlife on GitHub.
User avatar
AndyMH
Level 21
Level 21
Posts: 13716
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: still confused... multiple grub's on multiple drives

Post by AndyMH »

If you are having to select the drive to boot the OS it sounds like you are booting in legacy mode. You can check with efibootmgr:

Code: Select all

andy@T432 ~ $ efibootmgr
EFI variables are not supported on this system.
If you get this you are booting legacy, anything else is UEFI.

With legacy boot, the boot code is stored in the first sector (512B) on the drive alongside the partition table. Not a lot of space so the second stage bootloader hides in the gap between the end of the partition table and start of the first partition. I believe the boot code looks for the UUID of your /boot (or / partition) and transfers control to that. With UEFI boot, grub lives in the EFI partition (and it is very easy to install grub to the wrong drive).

Normally you would install grub to the same drive you are installing mint to, but if this has not happened you may have grub installed to another drive (and with legacy boot, it will have overwritten the copy of grub already there).
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
spamhog
Level 3
Level 3
Posts: 146
Joined: Thu Dec 17, 2009 6:21 pm
Contact:

Re: still confused... multiple grub's on multiple drives

Post by spamhog »

Thank you, AndyMH! Entirely correct, it's legacy, and on this old workhorse PC the firmware IS legacy only.

My understanding is that an EFI BIOS will, by rook or crook, identify all EFI capable systems and put them on its own boot menu, maybe in some odd order, sometimes with names that require a bit of trial and guesswork, like
01 ubuntu
02 ubuntu
03 ubuntu
....
And WITHIN each corresponding file system all the info needed to boot it should be present.
On an EFI comp I can select boots from within the BIOS menu or from the grub menu(s)...

with a proviso... (thank you Termy) that grub menu updates are separate.

Update-grub will point grub to the new kernels only in the system that made it.

Often not a problem because exactly for this reason the default boot is configured to point to vmlinuz, which always symlinks to the latest kernel, and only the entry with named kernels point directly to them.

:) :) :) it never ends... atm I assume that grub-install <UUID> tells the configuration that from then on, grub updates must point to that <UUID>
.
So to play safe, if I'm workng from /dev/sda and added something to /etc/grub.d and test it, after all grub-install <whatever other drive> I always end with grub-install /dev/sda. May be unnecessarly but doesn't hurt.
Last edited by spamhog on Mon Nov 28, 2022 11:09 am, edited 1 time in total.
t42
Level 11
Level 11
Posts: 3732
Joined: Mon Jan 20, 2014 6:48 pm

Re: still confused... multiple grub's on multiple drives

Post by t42 »

Termy wrote: Mon Nov 28, 2022 8:37 am I had a quick peek at '/usr/bin/os-prober', which seems to make heavy use of SYSFS, but I didn't look thoroughly nor did I look through the sourced script(s). Perhaps grub-mkconfig(8) also refers to SYSFS for low-level information shared by the kernel, but that now leads me down the rabbit hole of how that information is gathered; is it like magic numbers or file signatures?
nope, each partition is mounted in a row then tests (total not less than a dozen) are called by op, passing to it parameters fs, mount point and partition. For Linux oses it's

Code: Select all

#!/bin/sh
# Test for linux distributions.
set -e

. /usr/share/os-prober/common.sh

partition="$1"
dir="$2"
type="$3"

if (ls "$dir"/lib*/ld*.so* && [ -d "$dir/boot" ] || ls "$dir"/usr/lib*/ld*.so*) >/dev/null 2>/dev/null; then
	if [ -e "$dir/etc/os-release" ]; then
		short="$(grep ^NAME= "$dir/etc/os-release" | sed 's/^[^=]*=//; s/^['\''"]\(.*\)['\''"]$/\1/; s/\\\(.\)/\1/g; s/[[:space:]].*//')"
		long="$(grep ^PRETTY_NAME= "$dir/etc/os-release" | sed 's/^[^=]*=//; s/^['\''"]\(.*\)['\''"]$/\1/; s/\\\(.\)/\1/g')"
	elif [ -e "$dir/usr/lib/os-release" ]; then
		short="$(grep ^NAME= "$dir/usr/lib/os-release" | sed 's/^[^=]*=//; s/^['\''"]\(.*\)['\''"]$/\1/; s/\\\(.\)/\1/g; s/[[:space:]].*//')"
		long="$(grep ^PRETTY_NAME= "$dir/usr/lib/os-release" | sed 's/^[^=]*=//; s/^['\''"]\(.*\)['\''"]$/\1/; s/\\\(.\)/\1/g')"
	elif [ -e "$dir/etc/debian_version" ]; then
		short="Debian"
		long="$(printf "Debian GNU/Linux (%s)\n" "$(cat "$dir/etc/debian_version")")"
	# RPM derived distributions may also have a redhat-release or
	# mandrake-release, so check their files first.
	elif [ -e "$dir/etc/altlinux-release" ]; then
		short="ALTLinux"
		long="$(cat "$dir/etc/altlinux-release")"
	elif [ -e "$dir/etc/magic-release" ]; then
		short="Magic"
		long="$(cat "$dir/etc/magic-release")"
	elif [ -e "$dir/etc/blackPanther-release" ]; then
		short="blackPanther"
		long="$(cat "$dir/etc/blackPanther-release")"
	elif [ -e "$dir/etc/ark-release" ]; then
		short="Ark"
		long="$(cat "$dir/etc/ark-release")"
	elif [ -e "$dir/etc/arch-release" ]; then
		short="Arch"
		long="$(cat "$dir/etc/arch-release")"
	elif [ -e "$dir/etc/asplinux-release" ]; then
		short="ASPLinux"
		long="$(cat "$dir/etc/asplinux-release")"
	elif [ -e "$dir/etc/lvr-release" ]; then
		short="LvR"
		long="$(cat "$dir/etc/lvr-release")"
	elif [ -e "$dir/etc/caos-release" ]; then
		short="cAos"
		long="$(cat "$dir/etc/caos-release")"
	elif [ -e "$dir/etc/aurox-release" ]; then
		short="Aurox"
		long="$(cat "$dir/etc/aurox-release")"
	elif [ -e "$dir/etc/engarde-release" ]; then
		short="EnGarde"
		long="$(cat "$dir/etc/engarde-release")"
	elif [ -e "$dir/etc/vine-release" ]; then
		short="Vine"
		long="$(cat "$dir/etc/vine-release")"
	elif [ -e "$dir/etc/whitebox-release" ]; then
		short="WhiteBox"
		long="$(cat "$dir/etc/whitebox-release")"
	elif [ -e "$dir/etc/pld-release" ]; then
		short="PLD"
		long="$(cat "$dir/etc/pld-release")"
	elif [ -e "$dir/etc/startcom-release" ]; then
		short="StartCom"
		long="$(cat "$dir/etc/startcom-release")"
	elif [ -e "$dir/etc/trustix-release" ]; then
		short="Trustix"
		long="$(cat "$dir/etc/trustix-release")"
	elif [ -e "$dir/etc/openna-release" ]; then
		short="OpenNA"
		long="$(cat "$dir/etc/openna-release")"
	elif [ -e "$dir/etc/mageia-release" ]; then
		short="Mageia"
		long="$(cat "$dir/etc/mageia-release")"
	elif [ -e "$dir/etc/conectiva-release" ]; then
		short="Conectiva"
		long="$(cat "$dir/etc/conectiva-release")"
	elif [ -e "$dir/etc/mandrake-release" ]; then
		short="Mandrake"
		long="$(cat "$dir/etc/mandrake-release")"
	elif [ -e "$dir/etc/fedora-release" ]; then
		short="Fedora"
		long="$(cat "$dir/etc/fedora-release")"
	elif [ -e "$dir/etc/redhat-release" ]; then
		short="RedHat"
		long="$(cat "$dir/etc/redhat-release")"
	elif [ -e "$dir/etc/SuSE-release" ]; then
		short="SuSE"
		long="$(head -n 1 "$dir/etc/SuSE-release")"
	elif [ -e "$dir/etc/gentoo-release" ]; then
		short="Gentoo"
		long="$(cat "$dir/etc/gentoo-release")"
	elif [ -e "$dir/etc/cobalt-release" ]; then
		short="Cobalt"
		long="$(cat "$dir/etc/cobalt-release")"
	elif [ -e "$dir/etc/yellowdog-release" ]; then
		short="YellowDog"
		long="$(cat "$dir/etc/yellowdog-release")"
	elif [ -e "$dir/etc/turbolinux-release" ]; then
		short="Turbolinux"
		long="$(cat "$dir/etc/turbolinux-release")"
	elif [ -e "$dir/etc/pardus-release" ]; then
		short="Pardus"
		long="$(cat "$dir/etc/pardus-release")"
	elif [ -e "$dir/etc/kanotix-version" ]; then
		short="Kanotix"
		long="$(cat "$dir/etc/kanotix-version")"
	elif [ -e "$dir/etc/slackware-version" ]; then
		short="Slackware"
		long="$(printf "Slackware Linux (%s)\n" "$(cat "$dir/etc/slackware-version")")"
	elif [ -e "$dir/sbin/pkgtool" ]; then
		short="Slackware"
		long="Slackware Linux"
	elif grep -qs OpenLinux "$dir/etc/issue"; then
		short="Caldera"
		long="Caldera OpenLinux"
	elif [ -e "$dir/etc/frugalware-release" ]; then
		short="Frugalware Linux"
		long="$(cat "$dir/etc/frugalware-release")"
	elif [ -e "$dir/etc/kdemar-release" ]; then
		short="K-DEMar"
		long="$(printf "K-DEMar GNU/Linux (%s)\n" "$(cat "$dir/etc/kdemar-release")")"
	elif [ -e "$dir/etc/lfs-release" ]; then
		short="LFS"
		long="$(printf "Linux From Scratch (%s)\n" "$(cat "$dir/etc/lfs-release")")"
	elif [ -e "$dir/etc/meego-release" ]; then
		short="MeeGo"
		long="$(head -1 "$dir/etc/meego-release")"
	elif [ -e "$dir/etc/4MLinux-version" ]; then
		short="4MLinux"
		long="4MLinux $(head -1 "$dir/etc/4MLinux-version")"
	elif [ -e "$dir/etc/devuan_version" ]; then
		short="Devuan"
		long="$(printf "Devuan GNU/Linux (%s)\n" "$(cat "$dir/etc/devuan_version")")"
	elif [ -e "$dir/etc/exherbo-release" ]; then
		short="Exherbo"
		long="Exherbo Linux"
	else
		short="Linux"
		long="unknown Linux distribution"
	fi
	
        label="$(count_next_label "$short")"
	result "$partition:$long:$label:linux"
	exit 0
else
	exit 1
fi
-=t42=-
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: still confused... multiple grub's on multiple drives

Post by Termy »

t42 wrote: Mon Nov 28, 2022 11:03 am [...]
Oooh! Wow, I didn't think it would actually mount everything. :lol: I should've looked for the word 'mount' or something. :roll: That's kinda bizarre, but at least it's thorough. Thanks for clarifying. Is that just '/usr/bin/os-prober'? I suppose grub-mkconfig(8) works the same way, or at least does that along with a bunch of other tests.
Last edited by Termy on Mon Nov 28, 2022 11:28 am, edited 2 times in total.
I'm also Terminalforlife on GitHub.
t42
Level 11
Level 11
Posts: 3732
Joined: Mon Jan 20, 2014 6:48 pm

Re: still confused... multiple grub's on multiple drives

Post by t42 »

Termy wrote: Mon Nov 28, 2022 11:14 am I would guess it just trawls through the filesystem to look for something identifying.
Specific identifies are in the code I posted, just look it up. Other testers are in the /usr/lib/os-probes/mounted, but not in /usr/lib/os-prober now
-=t42=-
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: still confused... multiple grub's on multiple drives

Post by Termy »

t42 wrote: Mon Nov 28, 2022 11:20 am [...]
Yeah, sorry, I posted just as I paid more attention to the '/usr/bin/os-prober' code. I did initially suspect grub-mkconfig(8) used '/usr/bin/os-prober' for the probing, but it seems not, because '/usr/bin/os-prober' is from the 'os-prober' package, which isn't marked as a dependency for 'grub2', unless I missed it. We could assume GRUB takes a similar approach, but '/usr/bin/grub-mkconfig' is a binary executable, so we'd have to find some magical documentation or look up the source code.
I'm also Terminalforlife on GitHub.
User avatar
AndyMH
Level 21
Level 21
Posts: 13716
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: still confused... multiple grub's on multiple drives

Post by AndyMH »

spamhog wrote: Mon Nov 28, 2022 10:57 am So to play safe, if I'm workng from /dev/sda and added something to /etc/grub.d and test it, after all grub-install <whatever other drive> I always end with grub-install /dev/sda. May be unnecessarly but doesn't hurt.
If you want to check you have installed grub to the right drives, boot from, say, sda, and run df, it will tell you what is mounted where. If you find say that sdb1 is mounted at /, it is straightforward to reinstall grub on the correct drive. As for UEFI, others know more than me, but the firmware reads all the EFI partitions it finds on boot and adds any bootloaders found to the BIOS boot list.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: still confused... multiple grub's on multiple drives

Post by Termy »

AndyMH wrote: Mon Nov 28, 2022 1:36 pm [...]
I don't personally use EFI, but an exception to that was a Gentoo install I did a while back. I've also had to ask some people I know a bunch of questions related to EFI, in the past, because honestly, EFI confuses me and I don't like it! Give it the old way, any day. That being said, from what I can remember, and from looking at the man page, installing GRUB to an EFI drive can be as simple as:

Code: Select all

grub-install --efi-directory=/boot/efi DEVICE
Where 'DEVICE' is the block device name (IE: '/dev/sda'). Of course, if you're chroot(8)ed in, you'll want to change the path accordingly. I do see some people adding --target=x86_64-efi (or the 32-bit version), to the command, but I don't believe I ever used that. It may default to 64-bit, these days.

Granted, you'll still need to have created that EFI partition, and it's there I'm a bit fuzzy.
I'm also Terminalforlife on GitHub.
Locked

Return to “Installation & Boot”