Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 537618 - sys-boot/grub:2 10_linux initramfs version guessing is buggy
Summary: sys-boot/grub:2 10_linux initramfs version guessing is buggy
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Mike Gilbert
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-25 03:49 UTC by taozhijiang
Modified: 2019-07-08 18:19 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description taozhijiang 2015-01-25 03:49:22 UTC
grub2 can not find suitable initrid for other versions kernel image, which will
cause the system failed to startup with these boot options.


Reproducible: Always

Steps to Reproduce:
1. ➜  /boot  ls
gentoo                                              kernel-genkernel-x86_64-3.16.5-gentoo
grub                                                lost+found
initramfs-devel-3.17.7-stage1-x86_64-3.17.7-gentoo  make.conf
initramfs-devel-3.17.7-stage2-x86_64-3.17.7-gentoo  stage
initramfs-devel-stage1-x86_64-3.16.5-gentoo         System.map-devel-3.17.7-stage1-x86_64-3.17.7-gentoo
initramfs-genkernel-x86_64-3.16.5-gentoo            System.map-devel-3.17.7-stage2-x86_64-3.17.7-gentoo
kernel-devel-3.17.7-stage1-x86_64-3.17.7-gentoo     System.map-devel-stage1-x86_64-3.16.5-gentoo
kernel-devel-3.17.7-stage2-x86_64-3.17.7-gentoo     System.map-genkernel-x86_64-3.16.5-gentoo
kernel-devel-stage1-x86_64-3.16.5-gentoo

2.➜  /boot  sudo grub2-mkconfig -o /boot/grub/grub.cfg_to_report
Generating grub configuration file ...
Found linux image: /boot/kernel-genkernel-x86_64-3.16.5-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-3.16.5-gentoo
Found linux image: /boot/kernel-devel-stage1-x86_64-3.16.5-gentoo
Found linux image: /boot/kernel-devel-3.17.7-stage2-x86_64-3.17.7-gentoo
Found linux image: /boot/kernel-devel-3.17.7-stage1-x86_64-3.17.7-gentoo
done
➜  /boot  sudo cat /boot/grub/grub.cfg


Actual Results:  
missing 
initrd  /initramfs-genkernel-x86_64-ZZZZZZZ

manual fix grub.cfg can fix this problem.

Expected Results:  
        echo    '载入 Linux x86_64-3.16.5-gentoo ...'
        linux   /kernel-genkernel-x86_64-3.16.5-gentoo root=ZFS=rpool/ROOT/gentoo ro init=/usr/lib/systemd/systemd quiet ipv6.disable=1 elevator=bfq
        echo    '载入初始化内存盘...'
        initrd  /initramfs-genkernel-x86_64-3.16.5-gentoo
}


system version:
➜  /boot  uname -a
Linux localhost 3.17.7-gentoo #3 SMP PREEMPT Thu Jan 8 23:02:44 HKT 2015 x86_64 Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz GenuineIntel GNU/Linux
➜  /boot  

software versions:
[ebuild   R   ~] sys-boot/grub-2.02_beta2-r6:2  USE="libzfs multislot nls sdl truetype -debug -device-mapper -doc -efiemu -mount -static {-test}" GRUB_PLATFORMS="-coreboot -efi-32 -efi-64 -emu -ieee1275 -loongson -multiboot -pc -qemu -qemu-mips -xen" 0 KiB
Comment 1 Mike Gilbert gentoo-dev 2015-01-25 03:57:36 UTC
Your initramfs does not meet the naming convention expected by /etc/grub.d/10_linux. Use something more sane.
Comment 2 taozhijiang 2015-01-25 04:29:47 UTC
ina(In reply to Mike Gilbert from comment #1)
> Your initramfs does not meet the naming convention expected by
> /etc/grub.d/10_linux. Use something more sane.

I am using
genkernel all --no-clean --no-mountboot --zfs --bootloader=grub2 --splash --callback="emerge @module-rebuild" --menuconfig --kernname="devel-3.17.7-stage2"

to generate kernel, but in /etc/grub.d/10_linux, it use

version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`

to generate version string.

It is my personal fault. But I think the 10_linux should get improved, because this means my kernel name can not contain any digits.
Comment 3 Mike Gilbert gentoo-dev 2015-01-25 04:47:22 UTC
(In reply to taozhijiang from comment #2)

I'm not going to try and code for arbitrary strings passed to genkernel. If you can create a patch that actually works for this, you are welcome to send it upstream.
Comment 4 taozhijiang 2015-01-25 06:05:27 UTC
(In reply to Mike Gilbert from comment #3)
> (In reply to taozhijiang from comment #2)
> 
> I'm not going to try and code for arbitrary strings passed to genkernel. If
> you can create a patch that actually works for this, you are welcome to send
> it upstream.

➜  grub.d  diff -a 10_linux.bak 10_linux -U 3 
--- 10_linux.bak        2015-01-25 12:10:06.556397497 +0800
+++ 10_linux    2015-01-25 13:59:03.789003465 +0800
@@ -184,7 +184,7 @@
   basename=`basename $linux`
   dirname=`dirname $linux`
   rel_dirname=`make_system_path_relative_to_its_root $dirname`
-  version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
+  version=`echo $basename | sed -e "s,^[^0-9\-]*-,,g"`
   alt_version=`echo $version | sed -e "s,\.old$,,g"`
   linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
 
@@ -193,6 +193,7 @@
           "initrd-${version}" "initramfs-${version}.img" \
           "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
           "initrd-${alt_version}" "initramfs-${alt_version}.img" \
+          "initramfs-${version}" \
           "initramfs-genkernel-${version}" \
           "initramfs-genkernel-${alt_version}" \
           "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
➜  grub.d
Comment 5 Mike Gilbert gentoo-dev 2015-01-25 19:04:38 UTC
I'll reopen this, but note that any changes need to be reviewed and accepted upstream.
Comment 6 Ladislav Zitka 2016-09-07 15:10:36 UTC
Additionally I discovered another failing behavior discussed at:
https://forums.gentoo.org/viewtopic-t-1051118.html

With sys-boot/grub-2.02_beta2-r9 I am experiencing following situation:
1. ~# ls /boot
zeus boot # ls -la 
total 22560 
drwxr-xr-x  5 root root    4096 Sep  7 15:57 . 
drwxr-xr-x 23 root root    4096 Jul 14 06:09 .. 
drwxr-xr-x  2 root root    4096 Aug 23 11:12 backup 
drwxr-xr-x  6 root root    4096 Sep  7 15:47 grub 
-rw-r--r--  1 root root 2644340 Sep  7 15:57 initramfs-genkernel-x86_64-4.4.6-gentoo 
-rw-r--r--  1 root root 2645712 Sep  7 15:42 initramfs-zeuskernel-x86_64-4.4.6-gentoo 
-rw-r--r--  1 root root       0 Aug 13 21:22 .keep 
-rw-r--r--  1 root root 5339808 Sep  7 15:57 kernel-genkernel-x86_64-4.4.6-gentoo 
-rw-r--r--  1 root root 5339808 Sep  7 15:42 kernel-zeuskernel-x86_64-4.4.6-gentoo 
drwx------  2 root root   16384 Dec 20  2013 lost+found 
-rw-r--r--  1 root root 3525519 Sep  7 15:57 System.map-genkernel-x86_64-4.4.6-gentoo 
-rw-r--r--  1 root root 3525519 Sep  7 15:42 System.map-zeuskernel-x86_64-4.4.6-gentoo 

So there is file set with supported naming and other with unsupported in the moment. Originally the behavior reported by taozhijiang didn't discover this. In my case wrong ram disk is detected for specific kernel(providing just snippet):
Found linux image: /boot/kernel-zeuskernel-x86_64-4.4.6-gentoo 
Found initrd image: /boot/initramfs-genkernel-x86_64-4.4.6-gentoo

So this should be also kept in mind when changing the string matching patterns, that they don't overlap.
Comment 7 Jack 2019-07-01 22:00:55 UTC
Is there any point to add to the genkernel docs this limitation if you use --kernname?  It seems odd to not be able to use any digits, but at least warning folks someplace would be helpful.