util/grub.d/10_linux.in: Ignore kernel if initrd required but
PATCH 1/1 util/grub.d/10_linux.in: Ignore kernel if initrd required but
I have recently seen several bugs on Debian and Ubuntu whereby when a new kernel package is installed the host uses DKMS to build a module and that build fails (often the case with nvidia, but can also affect others, e.g. jool).The kernel install scripts stop before the initrd.img has been created but after the kernel image has been installed.
When non-technical owners/operators then follow 'random' suggestions from web searches or support chat and do update-grub or grub-mkconfig GRUB creates a new menuentry without an "initrd" statement and that results, on booting, with a kernel panic with unobvious messages.
This has been a problem for at least a decade but until now no effort has been made to deal with the root cause.
If this patch (or modifications of it) is accepted it allows distros to add logic to their kernel package install scripts similar to this, that I've used in a Debian proof-of-concept:
(quoted diff) +0 -0
b/debian/templates/image.postinst.in
index 25e7dd6546..7041d10a4d 100755
debian/templates/image.postinst.in +1 -0
@@ -11,6 +11,7 @@ depmod $version if [ -f /lib/modules/$version/.fresh-install ]; then change=install + touch "${image_path%/*}/initrd.img-${version}.required" else change=upgrade fi
When in use grub reports e.g:
Found linux image: /boot/vmlinuz-6.1.0-18-amd64
Missing required 'initrd.img-6.1.0-18-amd64'; ignoring kernel version 6.1.0-18-amd64
Found linux image: /boot/vmlinuz-6.1.0-18-amd64
Missing required 'initrd.img-6.1.0-18-amd64'; ignoring kernel version 6.1.0-18-amd64
---
On some distros if the kernel package installation fails for some reason an initialramfs file may not be created although it is required for a successful boot.
Until now grub will still create the menuentry causing a kernel panic when used (as will happen if it is the default entry after a kernel package upgrade).
Allow other tools to indicate that the file must exist for a menuentry for that kernel version to be created.
Created by kernel package installation script, or manually, if
/boot/${initrd_file}.required
exists when
/boot/${initrd_file}
does not GRUB will skip creating the menuentry for this kernel.
--- util/grub.d/10_linux.in | 7 +++++++ 1 file changed, 7 insertions(+)
util/grub.d/10_linux.in +7 -0
@@ -236,8 +236,15 @@ for linux in ${reverse_sorted_list}; do if test -e "${dirname}/${i}" ; then initrd_real="${i}" break + elif test -e "${dirname}/${i}.required" ; then + gettext_printf "Missing required '%s'; ignoring kernel version %s\n" "$(echo $i)" "$(echo $version)" >&2 + linux="" + break fi done + if test -z "$linux"; then + continue + fi initrd= if test -n "${initrd_early}" || test -n "${initrd_real}"; then
Signature · 8 lines
2.39.2 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Le 2/13/24 à 10:42, TJ a écrit :
Quoted 33 lines
I have recently seen several bugs on Debian and Ubuntu whereby when a new kernel package is installed the host uses DKMS to build a module and that build fails (often the case with nvidia, but can also affect others, e.g. jool).The kernel install scripts stop before the initrd.img has been created but after the kernel image has been installed.
When non-technical owners/operators then follow 'random' suggestions from web searches or support chat and do
update-gruborgrub-mkconfigGRUB creates a new menuentry without an "initrd" statement and that results, on booting, with a kernel panic with unobvious messages.This has been a problem for at least a decade but until now no effort has been made to deal with the root cause.
If this patch (or modifications of it) is accepted it allows distros to add logic to their kernel package install scripts similar to this, that I've used in a Debian proof-of-concept:
debian/templates/image.postinst.in +1
-0@@ -11,6 +11,7 @@ depmod $version if [ -f /lib/modules/$version/.fresh-install ]; then change=install + touch "${image_path%/*}/initrd.img-${version}.required" else change=upgrade fi
Quoted 8 lines
When in use grub reports e.g:
Found linux image:
/boot/vmlinuz-6.1.0-18-amd64
Missing required 'initrd.img-6.1.0-18-amd64'; ignoring kernel version 6.1.0-18-amd64
Found linux image:/boot/vmlinuz-6.1.0-18-amd64
Missing required 'initrd.img-6.1.0-18-amd64'; ignoring kernel version 6.1.0-18-amd64
So if the issue occurs and this patch is applied a message like:
Missing required 'initrd.img-6.1.0-18-amd64'; ignoring kernel version 6.1.0-18-amd64
will be displayed.
But (speaking as a distribution maintainer) I am not sure that a non-technical user will understand the consequences, not will know what to do next.
If the distribution's install kernel script keeps at least the kernel in use when running grub-mkconfig or update-grub (which is a good thing IMO), the machine will still be able to boot, whether or not the not_working boot entry is included in the boot menu, but the kernel upgrade will still not be applied.
Shouldn't this issue be solved at the distribution level, e.g. modifying the kernel install scripts appropriately, at least warning the user that the kernel upgrade failed and giving some hints how to solve the issue, rather than applying an upgrade deemed to fail?
Cheers, Didier
Quoted 38 lines
---
On some distros if the kernel package installation fails for some reason an initialramfs file may not be created although it is required for a successful boot.
Until now grub will still create the menuentry causing a kernel panic when used (as will happen if it is the default entry after a kernel package upgrade).
Allow other tools to indicate that the file must exist for a menuentry for that kernel version to be created.
Created by kernel package installation script, or manually, if
/boot/${initrd_file}.requiredexists when
/boot/${initrd_file}does not GRUB will skip creating the menuentry for this kernel.
Signed-off-by Tj <[email protected]>--- util/grub.d/10_linux.in | 7 +++++++ 1 file changed, 7 insertions(+)util/grub.d/10_linux.in +2
-0@@ -236,8 +236,15 @@ for linux in ${reverse_sorted_list}; do if test -e "${dirname}/${i}" ; then initrd_real="${i}" break + elif test -e "${dirname}/${i}.required" ; then + gettext_printf "Missing required '%s'; ignoring kernel version %s\n" "$(echo $i)" "$(echo $version)" >&2
util/grub.d/10_linux.in for linux in ${reverse_sorted_list}; do · line 250
Quoted 10 lines
util/grub.d/10_linux.in +5
-0+ linux="" + break fi done + if test -z "$linux"; then + continue + fi initrd= if test -n "${initrd_early}" || test -n "${initrd_real}"; then
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel