Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How does an 'emerge @world' update lead to updating grub.cfg
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 522

PostPosted: Sat Sep 14, 2024 3:05 pm    Post subject: How does an 'emerge @world' update lead to updating grub.cfg Reply with quote

H folks

I'm trying to understand the sequence of events that leads to grub.cfg being updated, when I do a regular update using `emerge ... @world`. When there is a new kernel in the update, the new bits get installed in /boot, and I note that grub.cfg is automatically updated to reflect the changes. I have a customized grub.cfg on one of my machines, because it reads the kernel from one disk and the kernel's root filesystem from another.

Are the changes to grub.cfg made just by something running 'grub-mkconfig', or is there more to it than that? If' it's just `grub-mkconfig`, I can just write a script to update the auto-generated grub.cfg -- `grub-mkconfig` already has provision for that. If it's something more complicated, perhaps I need a different approach?

BR, Lars
Back to top
View user's profile Send private message
sMueggli
Guru
Guru


Joined: 03 Sep 2022
Posts: 497

PostPosted: Sat Sep 14, 2024 3:21 pm    Post subject: Reply with quote

It is probably done by installkernel.

And customising /boot/grub/grub.cfg is a bad idea as the header of the file clearly shows:
Code:
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22694

PostPosted: Sat Sep 14, 2024 3:48 pm    Post subject: Reply with quote

emerge @world does not, on its own, touch boot at all. Some packages might touch that, and your emerge might pull in such a package. Other users may be using a kernel package that does not touch boot. Therefore, it would help if you told us exactly what "a new kernel in the update" means for you. For me, it means a new sys-kernel/gentoo-sources, which I then need to build and install outside Portage, so that package does not touch my boot. I could switch to one of the more automated mechanisms, but the benefit is not worth the time I would spend making it work like I want.
Back to top
View user's profile Send private message
pietinger
Moderator
Moderator


Joined: 17 Oct 2006
Posts: 5121
Location: Bavaria

PostPosted: Sat Sep 14, 2024 5:25 pm    Post subject: Reply with quote

sMueggli wrote:
It is probably done by installkernel.

Yes ... "installkernel" is able to do this ... and will do start grub-mkconfig IF you have enabled the use-flag "grub" for this package. If you disable this use-flag for "installkernel" then it will NOT start "grub-mkconfig" and you have to do it yourself.

See: https://wiki.gentoo.org/wiki/Installkernel#Descriptions_of_plugin_scripts_2

=> /usr/lib/kernel/postinst.d/91-grub-mkconfig.install
_________________
https://wiki.gentoo.org/wiki/User:Pietinger
Back to top
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 522

PostPosted: Sat Sep 14, 2024 6:26 pm    Post subject: Reply with quote

pietinger wrote:

Yes ... "installkernel" is able to do this ... and will do start grub-mkconfig IF you have enabled the use-flag "grub" for this package.


Thank you. Yes I do have this use-flag, because the installation instructions say to add it. I didn't know what it did until today :)

Quote:

And customising /boot/grub/grub.cfg is a bad idea as the header of the file clearly shows:


Maybe so. I make my changes using a script in /etc/grub.d, which I believe is the documented way to do it -- if you're running 'grub-mkconfig'. That's why I needed confirmation that this utility was invoked. Not making the changes is not an option in my set-up.

BR, Lars.
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20485

PostPosted: Sun Sep 15, 2024 4:51 am    Post subject: Reply with quote

sMueggli wrote:
And customising /boot/grub/grub.cfg is a bad idea as the header of the file clearly shows:
Code:
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
That's only true if you use grub-mkconfig. I don't and have no trouble managing it as prior to grub2.
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
sMueggli
Guru
Guru


Joined: 03 Sep 2022
Posts: 497

PostPosted: Sun Sep 15, 2024 8:40 am    Post subject: Reply with quote

lars_the_bear wrote:
Quote:

And customising /boot/grub/grub.cfg is a bad idea as the header of the file clearly shows:


Maybe so. I make my changes using a script in /etc/grub.d, which I believe is the documented way to do it -- if you're running 'grub-mkconfig'. That's why I needed confirmation that this utility was invoked. Not making the changes is not an option in my set-up.


Yes, changing the Grub configuration via /etc/default/grub and scripts in /etc/grub.d is the recommended way. Running grub-mkconfig will produce the desired output, regardless how many times it is invoked and which tool or user is executing it.
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1709
Location: South America

PostPosted: Sun Sep 15, 2024 10:29 pm    Post subject: Reply with quote

pjp wrote:
sMueggli wrote:
And customising /boot/grub/grub.cfg is a bad idea as the header of the file clearly shows:
Code:
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
That's only true if you use grub-mkconfig. I don't and have no trouble managing it as prior to grub2.

And I have no trouble managing it manually before and after GRUB 2 :) I only use grub-mkconfig (and don't overwrite grub.cfg with its output when I do) on occasion to compare with what I have. Or as a starting point on new installations that don't have any grub.cfg yet.

The syntax and commands are very well documented in the Texinfo manual (info grub).
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20485

PostPosted: Mon Sep 16, 2024 3:56 am    Post subject: Reply with quote

I was simply clarifying that grub-mkconfig isn't required.
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
lars_the_bear
Guru
Guru


Joined: 05 Jun 2024
Posts: 522

PostPosted: Mon Sep 16, 2024 7:18 am    Post subject: Reply with quote

pjp wrote:
I was simply clarifying that grub-mkconfig isn't required.


Sure. But I'm finding that it gets run every time 'emerge ... @world' delivers a new kernel. Now I know how to stop it doing that but, of course, I have to remember to update grub.cfg myself every time the kernel updates.

BR, Lars.
Back to top
View user's profile Send private message
mi_unixbird
Tux's lil' helper
Tux's lil' helper


Joined: 24 Jul 2015
Posts: 130

PostPosted: Mon Sep 16, 2024 6:14 pm    Post subject: Reply with quote

sMueggli wrote:
It is probably done by installkernel.

And customising /boot/grub/grub.cfg is a bad idea as the header of the file clearly shows:
Code:
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#


No, the file says that if it be generated by grub-mkconfig, and grub-itself says on the matter:

Quote:
grub-mkconfig does have some limitations. While adding extra custom menu entries to the end of the list can be done by editing /etc/grub.d/40_custom or creating /boot/grub/custom.cfg, changing the order of menu entries or changing their titles may require making complex changes to shell scripts stored in /etc/grub.d/. This may be improved in the future. In the meantime, those who feel that it would be easier to write grub.cfg directly are encouraged to do so


It would be an absolute disaster if grub2-mkconfig were somehow required. As Grub itself says, customizing very simple things with it is arcane science and it basically guesses based on heuristics what the menu should look like and it generally becomes overcomplicated, unreadable soup. My grub.cofg is simply:

Code:

   timeout=2
   default=0

   insmod all_video
   set root=(hd1,gpt2)

   menuentry 'desktop login'  {
     linux /boot/vmlinuz root=/dev/nvme0n1p2 init=/sbin/runit-init ro quiet net.ifnames=0 acpi_enforce_resources=lax autologin=user
   }

   menuentry 'agetty'  {
     linux /boot/vmlinuz root=/dev/nvme0n1p2 init=/sbin/runit-init ro quiet text net.ifnames=0 acpi_enforce_resources=lax
   }

   menuentry 'single'  {
     linux /boot/vmlinuz root=/dev/nvme0n1p2 init=/sbin/runit-init ro quiet text single
   }

   menuentry 'init=/bin/bash'  {
     linux /boot/vmlinuz root=/dev/nvme0n1p2 ro init=/bin/bash
   }


The bottom two entries are honestly useless. If I ever need to use them for recovery I might as well use sysrescueCD or something but havng them doesn't hurt.

There is a longstanding myth that Grub2 configuration is impossibly complicated and impossible to understand for mere mortal men due to the things generated by grub2-mkconfig. I think anyone who looks at this configuation can see what it does without a lot of schooling on the matter. It's clean, simple and understandable. I just looked at the output of grub2-mkconfig on my system. It finds some kind of initial ramdisk somewhere which I don't use. But something resembling one in my /boot apparently exists. I don't even know how it got there and it loads all sorts of modules and filesystems and by the looks of it will attempt to start with /sbin/init as my init while I use /sbin/runit-init. It generates a 500 line file opposed to this simple 20 line file.

sMueggli wrote:
lars_the_bear wrote:
Quote:

And customising /boot/grub/grub.cfg is a bad idea as the header of the file clearly shows:


Maybe so. I make my changes using a script in /etc/grub.d, which I believe is the documented way to do it -- if you're running 'grub-mkconfig'. That's why I needed confirmation that this utility was invoked. Not making the changes is not an option in my set-up.


Yes, changing the Grub configuration via /etc/default/grub and scripts in /etc/grub.d is the recommended way. Running grub-mkconfig will produce the desired output, regardless how many times it is invoked and which tool or user is executing it.


Recomended by whom? As I quoted the GRUB documentation. It acknowledges the limitations of this approaches and encourages whoever finds it easier to edit it directly to do so.
_________________
execctl --path exec filectl --current-directory list
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20485

PostPosted: Tue Sep 17, 2024 3:14 am    Post subject: Reply with quote

lars_the_bear wrote:
pjp wrote:
I was simply clarifying that grub-mkconfig isn't required.


Sure. But I'm finding that it gets run every time 'emerge ... @world' delivers a new kernel. Now I know how to stop it doing that but, of course, I have to remember to update grub.cfg myself every time the kernel updates.

BR, Lars.
So far I've only installed sys-kernel/gentoo-kernel-bin one time, so I don't really know how all that works. I typically build and update my own explicitly and not by using @world (I'm no expert). The "new" grub-mkconfig method was excruciatingly obtuse and I never took the time to learn how it works. A long time ago a helpful forum poster commented how the old way still worked in grub2 (I think it's very slightly different), so I've continued to use that because it isn't broke, and I don't know how to fix the new "and improved" way :).

I don't recall how I installed that gentoo-kernel-bin, but the grub.cfg file very much resembles how I do it manually, so I presume that's how I did it. :).
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum