You are not logged in.

#1 2023-11-13 00:02:54

D3vil0p3r
Member
Registered: 2022-11-05
Posts: 186

[SOLVED] EFI - BIOS/LEGACY - Update GRUB hooks at kernel upgrade

I'm using Arch Linux in a Virtual Machine (VMware Workstation) and when I installed it, I tested two installations:
* set UEFI boot on VM settings
* set BIOS/Legacy on VM Settings

In the first case, the boot directory is /boot/efi while in the second case is /boot.

I created a hook file in "/etc/pacman.d/hooks/kernel-linux.hook":

[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = linux
Target = linux-lts*
Target = linux-zen*

[Action]
Description = Pacman hook to update-grub automatically
When = PostTransaction
Exec = /bin/sh -c "grub-mkconfig -o /boot/grub/grub.cfg"

so, each time that the kernel is upgraded, this hook is triggered and run:

/bin/sh -c "grub-mkconfig -o /boot/grub/grub.cfg"

I guess that this approach is right for BIOS/Legacy scenario. For EFI boot scenario, this command is different? Should I execute a different command?

Not sure if related to this, but when I use the EFI boot approach in baremetal with Dual Boot with Windows, and I use the hook file above, when I upgrade the system (and the kernel), sometimes all the entries of the bootloader are removed except for the Arch Linux one, so when I access to it and I run "update-grub", it restores the other removed entries (like Windows one), but I'm not sure if this mentioned issue is related to the usage of this hook above in EFI boot scenario.

Last edited by D3vil0p3r (2023-11-13 12:06:49)

Offline

#2 2023-11-13 00:31:34

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,591

Re: [SOLVED] EFI - BIOS/LEGACY - Update GRUB hooks at kernel upgrade

...and what's the point of doing that on every update?

Offline

#3 2023-11-13 01:12:36

D3vil0p3r
Member
Registered: 2022-11-05
Posts: 186

Re: [SOLVED] EFI - BIOS/LEGACY - Update GRUB hooks at kernel upgrade

Scimmia wrote:

...and what's the point of doing that on every update?

Is it not a good practice to do that at each kernel upgrade? Is this hook useless? If so, in which cases the grub config should be updated?

Offline

#4 2023-11-13 01:14:36

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,591

Re: [SOLVED] EFI - BIOS/LEGACY - Update GRUB hooks at kernel upgrade

The grub config should be updated when you add or remove a kernel, or when you change command line parameters. Also when you reinstall grub to disk, to make sure the config is compatible with the grub that's actually running.

Regenerating the config on every update is useless on Arch. Arch doesn't change the kernel image name on every update.

Last edited by Scimmia (2023-11-13 01:15:22)

Offline

#5 2023-11-13 01:49:46

D3vil0p3r
Member
Registered: 2022-11-05
Posts: 186

Re: [SOLVED] EFI - BIOS/LEGACY - Update GRUB hooks at kernel upgrade

Ok. So let's guess I use that hook only for Install and Removal (I can delete the Upgrade line), how can I face the questions I posted on the first post?

Offline

#6 2023-11-13 04:34:14

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,591

Re: [SOLVED] EFI - BIOS/LEGACY - Update GRUB hooks at kernel upgrade

The only question I see is if you should use that command or a different one, so the answer is that you shouldn't use that command, or any command, at all. The rest of the post is hard to decipher, as statements like "In the first case, the boot directory is /boot/efi while in the second case is /boot" make no sense at all.

Offline

#7 2023-11-13 10:27:22

D3vil0p3r
Member
Registered: 2022-11-05
Posts: 186

Re: [SOLVED] EFI - BIOS/LEGACY - Update GRUB hooks at kernel upgrade

Scimmia wrote:

The only question I see is if you should use that command or a different one, so the answer is that you shouldn't use that command, or any command, at all.

But I should use that command if I add a new kernel or remove one.

Scimmia wrote:

The rest of the post is hard to decipher, as statements like "In the first case, the boot directory is /boot/efi while in the second case is /boot" make no sense at all.

I try to make the question better: if I'm using EFI boot, the update of GRUB can be performed by "grub-mkconfig -o /boot/grub/grub.cfg" or a different command?

Offline

#8 2023-11-13 11:40:47

-thc
Member
Registered: 2017-03-15
Posts: 502

Re: [SOLVED] EFI - BIOS/LEGACY - Update GRUB hooks at kernel upgrade

D3vil0p3r wrote:

I try to make the question better: if I'm using EFI boot, the update of GRUB can be performed by "grub-mkconfig -o /boot/grub/grub.cfg" or a different command?

Not quite.

An installed GRUB consists of the configuration (basic: /etc/default/grub, /etc/grub.d/*, active: /boot/grub/grub.cfg) and the runtime files (basic: /usr/bin/grub*, /usr/lib/grub/*, /usr/share/grub/*, active: boot sector or EFI binary, /boot/grub/*).

Each time you change a part of the basic GRUB configuration, grub.cfg needs to be updated.

Each time an updated kernel and/or initrd is installed replacing the current one, GRUB needs no action.

Each time a new kernel is installed, GRUB needs an update for grub.cfg adding those kernels - regardless of the boot method.

Each time GRUB itself is updated, it's good practice to update the configuration (grub.cfg) and the active loader (grub-install ...) with the latter being different for the boot method.

Last edited by -thc (2023-11-15 07:33:08)

Offline

#9 2023-11-13 12:02:34

D3vil0p3r
Member
Registered: 2022-11-05
Posts: 186

Re: [SOLVED] EFI - BIOS/LEGACY - Update GRUB hooks at kernel upgrade

-thc wrote:

Each time a new kernel is installed, GRUB needs an update for grub.cfg adding those kernels - regardless of the boot method.

Each time GRUB itself is updated, it's good practice to update the configuration (grub.cfg) and the active loader (grub-install ...) with the latter being different for the boot method.

Thank you for the detailed answer. Sorry for the stupid question: In EFI boot method, the output of "grub-mkconfig" can be "/boot/grub/grub.cfg" right?

Offline

#10 2023-11-13 12:05:30

-thc
Member
Registered: 2017-03-15
Posts: 502

Re: [SOLVED] EFI - BIOS/LEGACY - Update GRUB hooks at kernel upgrade

Yes.

Offline

Board footer

Powered by FluxBB