1

Say, I have 2 linux systems. They both of them have /boot/grub/grub.cfg, but the one that's used on boot is from one of them. There's no /boot partition. How is it determined which /boot/grub/grub.cfg should be used and how change that?

I have 1 physical disk, 2 partitions and UEFI/GPT.

Oskar K.
  • 295

2 Answers2

2

It's not quite clear from your question but I believe:

  • Assuming we have two physical disks, it'll depend on where BIOS/UEFI is looking. Otherwise known as the boot order. This is slightly different with UEFI because the installer talks directly to the system to install its shim, but you could have two systems with two separate UEFI shims installed. The order is decided by the system at boot.

  • Assuming two partitions on one physical disk with BIOS, it'll depend on who wrote to the MBR (master boot record, beginning portion of the disk) last (at install, or since you ran install-grub). They can overwrite each other if you reinstall grub. update-grub should only update the local configuration.

  • Assuming two partitions, one physical disk, UEFI, both should be able to co-exist peacefully. You'll get a pick of order at boot at the system level, and each bootloader might know about the other one but they aren't competing for one MBR.

Oli
  • 293,335
  • 2
    update-grub does not touch the MBR (it just regenerates grub.cfg), grub-install does. – fkraiem Apr 01 '16 at 10:16
  • @fkraiem Interesting point, thank you. Updated. – Oli Apr 01 '16 at 10:20
  • . You'll get a pick of order at boot at the system level, -- where? what determines which grud is used? – Oskar K. Apr 01 '16 at 10:58
  • @OskarK. Every BIOS I've ever used has had some sort of boot order selection, either in the setup screen or as an optional PRESS F12 TO SELECT BOOT DEVICE screen. Or, commonly both. – Oli Apr 01 '16 at 12:06
  • you didn't understand my question. how does bios know what OS are there installed? When I boot, I see the boot menu from Ubunut which contains "Ubuntu, Windows, Arch" items for booting. Why is the grub from exactly Ubuntu and not from Arch used? – Oskar K. Apr 01 '16 at 12:48
  • BIOS or UEFI is linking to that copy of grub because that's either the priority disk in BIOS/UEFI, or it's installed in the MBR (BIOS) and the other isn't —they can't coexist— or it's the top entry in the UEFI partition. As I've said in my answer what is actually happening this is highly dependent on the hardware being used. – Oli Apr 01 '16 at 13:49
  • see my update. also "or it's the top entry in the UEFI partition." -- how to change that? – Oskar K. Apr 02 '16 at 01:50
  • In the setup screens you see at boot – Oli Apr 02 '16 at 10:00
  • My BIOS setup screen only shows one Ubuntu to boot even though there are three partitions on the same SSD with grub.cfg to choose from. I found that the last partition installed is the one which grub.cfg file is read. I would like to create a menu to pick which of the three grub uses. Like OP I have UEFI/GPT setup. I have a hunch OP would also benefit from a menu to select which grub.cfg grub uses. – WinEunuuchs2Unix Aug 25 '18 at 22:04
  • @fkraiem for the win! This solves the issue when dual-booting with OSes on different drives. – Adam Erickson Jun 24 '22 at 11:49
0

I have three distributions on one SSD. The setup is UEFI/GPT. Whenever a new distribution is installed it takes control of grub.

To get the desired /boot/grub/grub.cfg to be in control, boot with that distribution and use:

$ sudo cat /boot/efi/EFI/ubuntu/grub.cfg
search.fs_uuid 8337e8c8-6461-44f2-b5fe-dfd5b6b05883 root 
set prefix=($root)'/boot/grub'
configfile $prefix/grub.cfg

$ sudo grub-install
Installing for x86_64-efi platform.
Installation finished. No error reported.

$ sudo cat /boot/efi/EFI/ubuntu/grub.cfg
search.fs_uuid b40b3925-70ef-447f-923e-1b05467c00e7 root 
set prefix=($root)'/boot/grub'
configfile $prefix/grub.cfg
  • The first cat reveals Ubuntu 19.04 grub is used on 8337e8c8-6461-44f2-b5fe-dfd5b6b05883
  • The grub-install command will override that with the booted distributions UUID
  • The last cat reveals Ubuntu 16.04 grub is now used on b40b3925-70ef-447f-923e-1b05467c00e7.
  • From now on only Ubuntu 16.04 update-grub command will change the grub boot menu. Running update-grub in Ubuntu 19.04 will changes it's local copy of /boot/grub/grub.cfg but not effect the boot menu.

I've created a script to give more meaningful names to grub menu options:

sed -i "s|Windows Boot Manager (on /dev/nvme0n1p2)|Windows 10|g" /boot/grub/grub.cfg
sed -i "s|Windows Boot Manager (on /dev/sda1)|Windows 10 original|g" /boot/grub/grub.cfg
sed -i "s|Ubuntu 16.04.5 LTS (16.04) (on /dev/nvme0n1p7)|Broken Ubuntu 16.04|g" /boot/grub/grub.cfg
sed -i "s|Ubuntu 19.04 (19.04) (on /dev/nvme0n1p10)|Ubuntu 19.04|g" /boot/grub/grub.cfg

Now a grub menu options change from:

2. Ubuntu 19.04 (19.04) (on /dev/nvme0n1p10)
3. Advanced options for Ubuntu 19.04 (19.04) (on /dev/nvme0n1p10)

to:

2. Ubuntu 19.04
3. Advanced options for Ubuntu 19.04