Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Microcode initrd, genkernel and Grub2
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
marco.difresco
Tux's lil' helper
Tux's lil' helper


Joined: 29 Jul 2011
Posts: 108

PostPosted: Wed Jun 24, 2015 3:26 pm    Post subject: Microcode initrd, genkernel and Grub2 Reply with quote

Hi all,
as I was re-installing my system, I got to the point of installing the Intel microcode and I found this article.

At the end it mention to load the microcode at boot and specifically:
Quote:
If you're already using another initrd, you can specify several of them in your bootloader or, if your bootloader does not support that, merge them yourself using cat. The early microcode might be ignored if it's not the first initrd, though.


It is something I would like to test, especially since in the past I had issues loading the microcode as a module.

I compile the kernel with genkernel and it creates an initrd; therefore I am wondering if sys-boot/grub-2.02_beta2-r3 support the specification of several initrd.

If so, where do I configure it to pickup the microcode initrd and put it with along the genkernel inside /boot/grub/grub.cfg? I assume it is somewhere /etc/grub.d/ in order to make the integration automatic every time I execute:
Code:
LANG=C grub2-mkconfig -o /boot/grub/grub.cfg


If Grub doesn't support the use of several initrd, the above quote mentions the possibility of merging the microcode initrd and the other (genkernel in my case) initrd. Searching around I found this article that mention how to do it, and in specific:
Code:
# cp /boot/initramfs-genkernel-x86_64-3.17.1-gentoo-r1 /home/fitzcarraldo/initramfs-genkernel-x86_64-3.17.1-gentoo-r1.bak.early # Backup the recently-built initramfs first.
# cat ucode.cpio /boot/initramfs-genkernel-x86_64-3.17.1-gentoo-r1 >/boot/initramfs-genkernel-x86_64-3.17.1-gentoo-r1.ucode
# cp /boot/initramfs-genkernel-x86_64-3.17.1-gentoo-r1.ucode /boot/initramfs-genkernel-x86_64-3.17.1-gentoo-r1
# rm /boot/initramfs-genkernel-x86_64-3.17.1-gentoo-r1.ucode


I tried to do it for practice sake and it is doable, but I am wondering if there is a way to "generalize" it so I can put it in a script that automatically pick up the last kernel I compiled and it merges the micorode initrd in it - for example I am using the following script to compile the kernel:
Code:
#!/bin/bash
export CONCURRENCY_LEVEL=9
cd /usr/src/linux
make silentoldconfig
genkernel --oldconfig --menuconfig --save-config --install --symlink --no-dmraid --no-zfs all
LANG=C grub2-mkconfig -o /boot/grub/grub.cfg
emerge @module-rebuild

and it would be nice to put some line at the end of it to merge the microcode initrd.

Thanks in advance
_________________
Marco Di Fresco
Silicon Gadget
Import MSSQL bak files to MySQL
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2971
Location: Germany

PostPosted: Wed Jun 24, 2015 6:24 pm    Post subject: Reply with quote

isn't it just "initrd a b c d ..." in grub?

I don't know if there is a genkernel --microcode...
Back to top
View user's profile Send private message
Sprchkn
n00b
n00b


Joined: 04 Mar 2016
Posts: 3
Location: Kansas

PostPosted: Fri Apr 29, 2016 2:44 pm    Post subject: Reply with quote

This is old, but if you name the microcode file as "early-ucode.cpio" as given in the Gentoo Wiki, you can just add the text:

Code:
"early-ucode.cpio" \


into the /etc/grub.d/10-linux file.

For instance, mine read:
Code:

initrd=
for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \


and I changed it to:
Code:

initrd=
for i in "early-ucode.cpio" \
         "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \


I'm not sure how bash sorts files, so that may not work if early-ucode.cpio isn't picked up before another ramdisk image, since several sources state that the ucode should be loaded first. That should at least point you in the right direction though.
Back to top
View user's profile Send private message
dweezil-n0xad
Apprentice
Apprentice


Joined: 30 Oct 2006
Posts: 156
Location: Ostend, Belgium

PostPosted: Tue Jun 28, 2016 1:48 pm    Post subject: Reply with quote

Arch Linux has a patch to make grub2-mkconfig detect the microcode and put it first in initrd.
I've edited and put this patch in /etc/portage/patches/sys-boot/grub/grub-intel-microcode.patch and emerged grub.
Code:

--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -65,6 +65,12 @@ case x"$GRUB_FS" in
    ;;
 esac
 
+intel_ucode=
+if test -e "/boot/microcode.cpio" ; then
+    gettext_printf "Found Intel Microcode\n" >&2
+    intel_ucode="$(make_system_path_relative_to_its_root /boot/microcode.cpio)"
+fi
+
 title_correction_code=
 
 linux_entry ()
@@ -136,7 +142,7 @@ EOF
     message="$(gettext_printf "Loading initial ramdisk ...")"
     sed "s/^/$submenu_indentation/" << EOF
    echo   '$(echo "$message" | grub_quote)'
-   initrd   ${rel_dirname}/${initrd}
+   initrd   ${intel_ucode} ${rel_dirname}/${initrd}
 EOF
   fi
   sed "s/^/$submenu_indentation/" << EOF

I use this script to compile new kernels
Code:
#!/bin/sh

zcat /proc/config.gz > /usr/src/linux/.config
cd /usr/src/linux
make oldconfig
make -j8 && make modules_install
mount /boot
make install
genkernel --install --no-ramdisk-modules initramfs
cp /lib/firmware/microcode.cpio /boot
grub2-mkconfig -o /boot/grub/grub.cfg
emerge @module-rebuild

the result in /boot/grub/grub.cfg:
Code:
...
echo   'Loading initial ramdisk ...'
initrd   /microcode.cpio /initramfs-genkernel-x86_64-4.6.3-gentoo
...

_________________
i7-4790K | 16GB DDR3 | GTX 970 | 500GB SSD
ASUS N56VV | i7-3630QM | 12GB DDR3 | GT 750M | 256GB SSD


Last edited by dweezil-n0xad on Tue Jun 28, 2016 3:57 pm; edited 1 time in total
Back to top
View user's profile Send private message
alinefr
Tux's lil' helper
Tux's lil' helper


Joined: 05 Jul 2009
Posts: 112
Location: São Paulo, Brasil

PostPosted: Tue Jun 28, 2016 3:27 pm    Post subject: Reply with quote

As you are already using genkernel, it can do the things in the right way for you.

I use genkernel for luks & zfs and my initramfs is generated in-kernel (no grub), but it should work in a separated initramfs file as well.

So my genkernel.conf has:

INITRAMFS_OVERLAY="/usr/share/microcode"

And my /usr/share/microcode:

Code:

/usr/share/microcode/
/usr/share/microcode/kernel
/usr/share/microcode/kernel/x86
/usr/share/microcode/kernel/x86/microcode
/usr/share/microcode/kernel/x86/microcode/GenuineIntel.bin


It just works, out of the box. Genkernel is clever enough to put this overlay at the start of the initramfs.
Back to top
View user's profile Send private message
candrews
Developer
Developer


Joined: 10 Aug 2005
Posts: 154

PostPosted: Tue Jun 28, 2016 4:23 pm    Post subject: Reply with quote

dweezil-n0xad wrote:
Arch Linux has a patch to make grub2-mkconfig detect the microcode and put it first in initrd.
I've edited and put this patch in /etc/portage/patches/sys-boot/grub/grub-intel-microcode.patch and emerged grub.
Code:

--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -65,6 +65,12 @@ case x"$GRUB_FS" in
    ;;
 esac
 
+intel_ucode=
+if test -e "/boot/microcode.cpio" ; then
+    gettext_printf "Found Intel Microcode\n" >&2
+    intel_ucode="$(make_system_path_relative_to_its_root /boot/microcode.cpio)"
+fi
+
 title_correction_code=
 
 linux_entry ()
@@ -136,7 +142,7 @@ EOF
     message="$(gettext_printf "Loading initial ramdisk ...")"
     sed "s/^/$submenu_indentation/" << EOF
    echo   '$(echo "$message" | grub_quote)'
-   initrd   ${rel_dirname}/${initrd}
+   initrd   ${intel_ucode} ${rel_dirname}/${initrd}
 EOF
   fi
   sed "s/^/$submenu_indentation/" << EOF

I use this script to compile new kernels
Code:
#!/bin/sh

zcat /proc/config.gz > /usr/src/linux/.config
cd /usr/src/linux
make oldconfig
make -j8 && make modules_install
mount /boot
make install
genkernel --install --no-ramdisk-modules initramfs
cp /lib/firmware/microcode.cpio /boot
grub2-mkconfig -o /boot/grub/grub.cfg
emerge @module-rebuild

the result in /boot/grub/grub.cfg:
Code:
...
echo   'Loading initial ramdisk ...'
initrd   /microcode.cpio /initramfs-genkernel-x86_64-4.6.3-gentoo
...


I reported an issue with Gentoo at https://bugs.gentoo.org/show_bug.cgi?id=587422 including a pull request. Hopefully at some point this all just works :)
Back to top
View user's profile Send private message
dweezil-n0xad
Apprentice
Apprentice


Joined: 30 Oct 2006
Posts: 156
Location: Ostend, Belgium

PostPosted: Tue Jun 28, 2016 5:48 pm    Post subject: Reply with quote

alinefr wrote:
As you are already using genkernel, it can do the things in the right way for you.

I use genkernel for luks & zfs and my initramfs is generated in-kernel (no grub), but it should work in a separated initramfs file as well.

So my genkernel.conf has:

INITRAMFS_OVERLAY="/usr/share/microcode"

And my /usr/share/microcode:

Code:

/usr/share/microcode/
/usr/share/microcode/kernel
/usr/share/microcode/kernel/x86
/usr/share/microcode/kernel/x86/microcode
/usr/share/microcode/kernel/x86/microcode/GenuineIntel.bin


It just works, out of the box. Genkernel is clever enough to put this overlay at the start of the initramfs.
This only works on my system when the generated seperate initramfs is not compressed (COMPRESS_INITRD="no").
I tried with lzop, xz and gzip. No microcode update.
With no initramfs compression:
Code:
[    0.000000] microcode: microcode updated early to revision 0x20, date = 2016-03-16


edit: a little research confirms that the ucode has to be in uncompressed initramfs
_________________
i7-4790K | 16GB DDR3 | GTX 970 | 500GB SSD
ASUS N56VV | i7-3630QM | 12GB DDR3 | GT 750M | 256GB SSD
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware 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