Strange grub problem with Gentoo

I recently did a profile upgrade ( from 17.1 to 23.0) in Gentoo,
after that I built a new kernel 6.15.3

nevj@mary /usr/src $ eselect kernel list
Available kernel symlink targets:
  [1]   linux-5.15.88-gentoo
  [2]   linux-6.6.0-gentoo
  [3]   linux-6.15.3-gentoo *

genkernel all
emerge --ask --noreplace sys-kernel/gentoo-sources:6.15.3

All seemed to go well
Then I attempted to setup grub. My machine has grub controlled by Debian and has Gentoo as a dual boot option.

In Gentoo
grub-mkconfig -o /boot/grub/grub.cfg

Reboot into Debian
update-grub

Reboot and
Gentoo fails to boot.... none of my 3 kernels will boot.... not 6.15.3 ( the new one) nor 6.6.0 nor 5.18.88
The message is 'unable to mount root fs'

So I mount the gentoo filesystem and check /etc/fstab… it is OK… it uses a UUID for /

So I go to the grub menu, select gentoo6.15.3, press ā€˜e’ and I see the last line

initrd /boot/amd-uc.img

What is that???

I mount the gentoo filesystem again and look at /boot

nevj@mary ~ $ ls -l /boot
total 102960
-rw-r--r-- 1 root root   148480 Jun 27 20:42 amd-uc.img
drwxr-xr-x 2 root root     4096 Jun 29 10:46 grub
-rw-r--r-- 1 root root 10909928 Jan 29  2023 initramfs-5.15.88-gentoo-x86_64.img
-rw-r--r-- 1 root root 12663652 Jun 28 22:50 initramfs-6.15.3-gentoo-x86_64.img
-rw-r--r-- 1 root root 12237272 Nov 10  2023 initramfs-6.6.0-gentoo-x86_64.img
-rw-r--r-- 1 root root  4954398 Jan 29  2023 System.map-5.15.88-gentoo-x86_64
-rw-r--r-- 1 root root  4042263 Feb 17  2023 System.map-6.1.12-gentoo-x86_64
-rw-r--r-- 1 root root  7350978 Jun 28 21:55 System.map-6.15.3-gentoo-x86_64
-rw-r--r-- 1 root root  6094604 Apr  8  2023 System.map-6.2.10-gentoo-x86_64
-rw-r--r-- 1 root root  6094595 Mar 20  2023 System.map-6.2.7-gentoo-x86_64
-rw-r--r-- 1 root root  6345540 Nov 10  2023 System.map-6.6.0-gentoo-x86_64
-rw-r--r-- 1 root root  9865664 Jan 29  2023 vmlinuz-5.15.88-gentoo-x86_64
-rw-r--r-- 1 root root 12947968 Jun 28 21:56 vmlinuz-6.15.3-gentoo-x86_64
-rw-r--r-- 1 root root 11742752 Nov 10  2023 vmlinuz-6.6.0-gentoo-x86_64

Yes, it is there

Then I look at /boot/grub/grub.cfg

       linux   /boot/vmlinuz-6.15.3-gentoo-x86_64 root=UUID=5fa0230a-6757-4281-a209-9f116869d70c ro  
        echo    'Loading initial ramdisk ...'
        initrd  /boot/amd-uc.img /boot/initramfs-6.15.3-gentoo-x86_64.img

That initrd line is different to what shows with ā€˜e’ in the grub menu… it only has initrd /boot/amd-uc.img

So I go back to the grub menu , select the Gentoo 6.15.3 line , do ā€˜e’, and edit it to

initrd  /boot/initramfs-6.6.0-gentoo-x86_64.img

Then it boots… SUCCESS
but two questions

  1. How is it that both initrd files are in the grub.cfg file in Gentoo, but they do not make it to the commands that show with ā€˜e’ in the grub menu? … that has to be a grub error?
  2. What is this /boot/amd-uc.img file that makes the boot fail?
mary /boot # ls -l
total 102960
-rw-r--r-- 1 root root   148480 Jun 27 20:42 amd-uc.img
drwxr-xr-x 2 root root     4096 Jun 29 10:46 grub
-rw-r--r-- 1 root root 10909928 Jan 29  2023 initramfs-5.15.88-gentoo-x86_64.img
-rw-r--r-- 1 root root 12663652 Jun 28 22:50 initramfs-6.15.3-gentoo-x86_64.img
-rw-r--r-- 1 root root 12237272 Nov 10  2023 initramfs-6.6.0-gentoo-x86_64.img

It was made on Jun27 , the day before vmlinuz and initramfs were made for 6.15.3
Well the only things I did in Gentoo before genkernel were

The profile upgrade
followed by
config file updating

Therefore the profile update must have made that
amd-uc.img file?
I dont understand?

Is there a grub expert who can help me understand this?

2 Likes

The workaround

In Gentoo
cd /boot
mv amd-uc.img amd-uc.img.hide
grub-mkconfig -o /boot/grub/grub.cfg
Reboot into Debian
update-grub
Reboot into Gentoo
it boots !!

But I would love to know why I had to hide that file?

1 Like

Wiki is your friend. Maybe try also gentoo-kernel-bin?

2 Likes

But, my machine has an Intel CPU…what is my update doing trying to load AMD microcode into the initramfs?

2 Likes

That’s strange.. I don’t know. Just leave AMD off then?

1 Like

Hi Neville, :waving_hand:

sorry to learn that you ran into those problems.
But I think analyzing this case may be of interest to others as well.

I had to do some research on the grub issue myself, as it seemed pretty weired at first.

This is AMD CPU microcode, not a full initramfs. Booting with only that suggests the kernel can’t mount the root filesystem.

(more info: see link posted by @ihasama )

I also found out that it“s a CPU microcode update image for AMD processors. It contains fixes and updates for AMD CPUs, loaded early at boot time.

It’s not supposed to be used alone.

That must be the reason why Gentoo fails to boot: amd-uc.img is not a proper initramfs.

Possible reason: It might be caused by GRUB in Debian not handling multiple initrd files per kernel entry correctly. Just a rough guess. But it seems sensible.

Why does GRUB only show initrd /boot/amd-uc.img at boot, when grub.cfg has both amd-uc.img and initramfs-6.15.3-gentoo-x86_64.img? :thinking:

That“s a tough one.
It might be a Debian GRUB limitation or bug. I“m by no means sure of that.

Gentoo’s grub.cfg contains:

initrd /boot/amd-uc.img /boot/initramfs-6.15.3-gentoo-x86_64.im

O.K. This seems to be a valid entry. :+1:
It tells GRUB to load both files — the microcode and the initramfs.

But when you run update-grub from Debian, Debian’s GRUB scripts might not properly handle multiple initrd entries. ItĀ“s the only logical explanation I can think of.

Might be due to the following:

When Debian’s GRUB runs update-grub, it calls a script called os-prober, which scans other partitions (like Gentoo’s) to create menu entries.

But Debian’s os-prober doesn’t understand that Gentoo is using two initrd files.
It sees amd-uc.img in /boot, thinks it’s the initrd, and mistakenly uses only that.
So it ignores the actual initramfs, e.g., initramfs-6.15.3-gentoo-x86_64.img.

As a result Gentoo boots with only the CPU microcode and not the full initramfs.
Therefore: kernel panic, ā€œunable to mount root fsā€.

By renaming amd-uc.img:

  • Debian’s os-prober can’t see it.
  • So it falls back to the correct initramfs-6.15.3-gentoo-x86_64.img.
  • Gentoo boots successfully because the real initramfs is now used.

Does this make some sense :red_question_mark:

Many greetings from Rosika :slightly_smiling_face:

3 Likes

Yes! I think you got it right and it’s Debian grub update issue.

2 Likes

Hi Rosika,
It makes sense, but there are 2 issues left hanging

  • why did my profile update try to load AMD microcode… it cant possibly work … I have an Intel processor?
  • it may be that grub/osprober looks at grub.cfg and just takes the first thing it finds on the initrd line that is present in /boot, and puts that in the boot commands. I think the initrd boot command may only accept one filename

I shall read the grub manual.

Regards
Neville

2 Likes

Hi Neville, :waving_hand:

I think you“re right there. Very plausible indeed. :+1:

I found out that the new 23.0 profile may enable sys-kernel/linux-firmware
by default, which includes firmware for both AMD and Intel CPUs.

When you ran ran genkernel all, it likely found amd-uc.img in
/lib/firmware/amd-ucode.
Please check the the path, Neville, as I don“t have a Gentoo system to verify it.

So it blindly included it in the initrd setup, assuming AMD CPU. :thinking:

Cheers from Rosika :slightly_smiling_face:

1 Like

Hi Rosika,
It did not attempt to load any Intel firmware.?
I think there may be a setting somewhere in /etc/profile which came from the 23.0 upgrade, and which specified AMD.
I will check.

.Regards
Neville

1 Like

Hi Neville, :wave:

Hmm, I just checked on my system:

sudo dmesg | grep microcode
[sudo] password for rosika: 
[    0.000000] microcode: microcode updated early to revision 0x21, date = 2019-02-13
[    1.081590] microcode: sig=0x306a9, pf=0x2, revision=0x21
[    1.082063] microcode: Microcode Update Driver: v2.2.

I think you can check it on Gentoo as well.
This should tell whether Intel microcode is being loaded.

Intel does have a microcode file (intel-uc.img).
But it might not always be used by default in Gentoo or genkernel :red_question_mark: :thinking:

Cheers from Rosika :slightly_smiling_face:

1 Like

No!!! It has to be there for grub to work properly!!!
You really need to catch-up on the changes with the Gentoo book.
For one, genkernel, is being deprecated, while it may work.it will not properly install the initramfs.
While, gentoo-sources, may have been used for kernel config, several years ago, Gentoo strongly suggests using either the gentoo-kernel or gentoo-kernel-bin.
For initramfs, Gentoo is using dracut to install initramfs.
And while Debian may be booting Gentoo, you still do not have a working Gentoo, and until you follow the latest Gentoo book and rebuild your Gentoo.
And why even install grub on Gentoo, if Debian is set for grub?

2 Likes

Hi Daniel, :waving_hand:

My understanding was that it only needs to be there if you have an AMD CPU and want early microcode loading. :thinking:
For Intel systems, you want intel-uc.img instead, not amd-uc.img, I think.

Needing microcode in initrd is true in general, but in this specific case (Intel CPU + wrong microcode), it’s the presence of amd-uc.img that causes failure.

Yes one can still use genkernel, but it requires more manual configuration, and Gentoo no longer recommends it for most users.
That“s what I found out as well.

Cheers from Rosika :slightly_smiling_face:

2 Likes

Well, I didn’t have microcode in my Gentoo. Intel i5-3470.

I installed it and after reboot I have it:

No issues with grub. I did sudo grub-mkconfig -o /boot/grub/grub.cfg and it found the microcode and added it to my config

2 Likes

With Gentoo, that file must be read by grub, whether you have a AMD CPU or not, the Microsoft code is handled differently.

Yes I know, and it needs to be present, whether you have AMD or not!!

2 Likes

I can’t find that file on my HTPC running Gentoo. Today I installed the Intel microcode. It worked well without it and still works without the AMD

2 Likes

My Gentoo would not boot without it, but that may be because I have tried a couple of AMD GPU, and always go back to nouveau and Nvidia!!!

3 Likes

You installed intel microcode… that makes some sense as you have an Intel CPU.
I think it would have failed if you had installed AMD microcode.

3 Likes

It may have to be there, but it should be the correct microcode for your CPU… I think my update got its CPU information wrong and installed the wrong microcode

OK I need to move on from genkernel. I will use the manual kernel build instead.
The weird thing is, genkernel did not put that AMD-uc.img file in /boot… the profile update did it.

I did not install grub from gentoo, I only built a grub.cfg file.
Debian’s grub/osprober needs to find a grub.cfg file in gentoo, so that it can construct the grub commands to boot gentoo. If there is no grub.cfg file in gentoo, it uses a generic boot method which may not work for gentoo.

2 Likes

It is the way you taught me to build a kernel.
I dont see the point of having a downloaded binary kernel… the idea of gentoo is to optimize everything for my machine by compiling locally.

What I have seems to work. What do you mean by not having a working gentoo.?
The only problem was booting. That AMD-uc.img file needed to be removed. It cant possibly need it… I dont have an AMD cpu. It might benefit from intel firmware… what this firmware does is patch the hardware to eliminate security flaws in the hardware design.

3 Likes