Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mikaeldui/bf3cd9b6932ff3a2d49b924def778ebb to your computer and use it in GitHub Desktop.

Select an option

Save mikaeldui/bf3cd9b6932ff3a2d49b924def778ebb to your computer and use it in GitHub Desktop.
CachyOS Kernel for Fedora with Secure Boot

image

CachyOS Kernel for Fedora with Secure Boot

Did you just install kernel-cachyos and got hit by bad shim signature when booting? Me too. This is how I fixed it.

First, make sure you have Secure Boot with mokutil --sb-state.

Note, there's a second way of doing this by using sbctl, but I didn't want to wipe my Secure Boot keys.

Need help? Feel free to leave a comment below, contact me (@mikaeldui) on the CachyOS Discord, or send me an email.

Installing the CachyOS Kernel

Full instructions at https://github.com/CachyOS/copr-linux-cachyos

  1. Check your CPU support /lib64/ld-linux-x86-64.so.2 --help | grep "(supported, searched)", my CPU supports v2, v3 and v4.
  2. Enable a suitable repo: sudo dnf copr enable bieszczaders/kernel-cachyos.
  3. Install suitable kernel: sudo dnf install kernel-cachyos kernel-cachyos-devel-matched.
  4. Let the kernel load modules: sudo setsebool -P domain_kernel_load_modules on.
  5. Done!

If you reboot now you'll get the "bad shim signature" error and have to pick an official Fedora kernel to boot. Don't worry, you didn't break anything.

Signing the CachyOS Kernel

We can self-sign the kernel by adding our key as a MOK (Machine Owner Key).

Based on general kernel signing procedures for Fedora and RHEL.

# Install required packages
sudo dnf install pesign openssl kernel-devel mokutil keyutils

# Allow our user to sign kernels
sudo echo "$USER" | sudo tee -a /etc/pesign/users
sudo /usr/libexec/pesign/pesign-authorize

# Generate a certificate to sign the kernel with
openssl req -new -x509 -newkey rsa:2048 -keyout "key.pem" \
        -outform DER -out "cert.der" -nodes -days 36500 \
        -subj "/CN=CachyOS Secure Boot/"
openssl pkcs12 -export -out key.p12 -inkey key.pem -in cert.der
sudo certutil -A -i cert.der -n "CachyOS Secure Boot" -d /etc/pki/pesign/ -t "Pu,Pu,Pu"

# Import the certificate
sudo pk12util -i key.p12 -d /etc/pki/pesign
sudo mokutil --import "cert.der"

# Sign the kernel, replace "vmlinuz-6.14.6-cachyos1.fc42.x86_64" with the current version.
cd /boot
sudo pesign --certificate 'CachyOS Secure Boot' \
         --in vmlinuz-6.14.6-cachyos1.fc42.x86_64 \
         --sign \
         --out vmlinuz-6.14.6-cachyos1.fc42.x86_64.signed
		 
# Manually replace the unsigned kernel with the signed one (pesign can't overwrite files right now).
sudo mv vmlinuz-6.14.6-cachyos1.fc42.x86_64.signed vmlinuz-6.14.6-cachyos1.fc42.x86_64

And reboot and choose enroll the key. The MOK password is only used once so I suggest using "12345678". Replace "CachyOS Secure Boot" and "vmlinuz-6.14.6-cachyos1.fc42.x86_64" with whatever applies in your case.

Automatically signing kernel updates

Whooray! You can now boot the CachyOS Kernel for Fedora with Secure Boot enabled! Let's make sure that it continues to work across updates!

  1. Create and open sudo nano /etc/kernel/postinst.d/00-signing
  2. Enter the following content:
#!/bin/sh

set -e

KERNEL_IMAGE="$2"
MOK_KEY_NICKNAME="CachyOS Secure Boot"

if [ "$#" -ne "2" ] ; then
	echo "Wrong count of command line arguments. This is not meant to be called directly." >&2
	exit 1
fi

if [ ! -x "$(command -v pesign)" ] ; then
	echo "pesign not executable. Bailing." >&2
	exit 1
fi

if [ ! -w "$KERNEL_IMAGE" ] ; then
	echo "Kernel image $KERNEL_IMAGE is not writable." >&2
	exit 1
fi

echo "Signing $KERNEL_IMAGE..."

pesign --certificate "$MOK_KEY_NICKNAME" --in "$KERNEL_IMAGE" --sign --out "$KERNEL_IMAGE.signed"
mv "$KERNEL_IMAGE.signed" "$KERNEL_IMAGE"
  1. Correct the permissions with: sudo chown root:root /etc/kernel/postinst.d/00-signing ; sudo chmod u+rx /etc/kernel/postinst.d/00-signing

Fix default kernel after updates

Whenever you receive an update to the official Fedora kernel it will replace the CachyOS kernel as the default kernel. One solution is to uninstall the official kernel, and another is to reset the default kernel to CachyOS after each update:

  1. Create and open sudo nano /etc/kernel/postinst.d/99-default
  2. Enter the following content:
#!/bin/sh

set -e

grubby --set-default=/boot/$(ls /boot | grep vmlinuz.*cachy | sort -V | tail -1)
  1. Correct the permissions with: sudo chown root:root /etc/kernel/postinst.d/99-default ; sudo chmod u+rx /etc/kernel/postinst.d/99-default
@mikaeldui
Copy link
Copy Markdown
Author

mikaeldui commented May 26, 2025

@msmafra It's a copy paste of some "kernel install hook" script that I found, that I modified for pesign. I'm far from a bash expert. There are more checks to be added, e.g. it shouldn't re-sign the official Fedora kernels. πŸ˜‚ I'll check and test your code tomorrow. Perhaps this should be turned into a general MOK kernel signing tool in a normal Git repo.

If you can't wait for the next update then you can trigger a reinstall with sudo dnf reinstall kernel-cachyos-core apparently. I don't know what happens if you reinstall the running kernel though.

@infirms
Copy link
Copy Markdown

infirms commented Jun 15, 2025

Thanks, looks very promising, will definitely use it.

@msmafra
Copy link
Copy Markdown

msmafra commented Jun 15, 2025

I'm flabbergasted (:smile: ) how it's been working on my machine, but the 99-default has a mistake of my part there.

#!/bin/bash

set -o errexit

set_cachyos_as_default() {

    local MOST_RECENT
    MOST_RECENT="$(find /boot -name "vmlinuz*cachyos*.*" | sort --version-sort | tail --lines=1 | tr --delete "\n")"

    grubby --set-default=/boot/"${MOST_RECENT}"

}

set_cachyos_as_default

The find line does this
Screenshot-2025-06-15-09-58-28
the ls line does
Screenshot-2025-06-15-10-00-39

The variable will receive the value e.g /boot/vmlinuz-6.15.2-cachyos1.fc42.x86_64 instead of vmlinuz-6.15.2-cachyos1.fc42.x86_64 as @mikaeldui 's original, making the grubby line /boot//boot/vmlinuz-6.15.2-cachyos1.fc42.x86_64 (which I still shocked is working on my machine. So the grubby line should actuall have only the "MOST_RECENT" variable to avoid problems. Very sorry.

So this, removing the /boot/ part should be the one used.

#!/bin/bash

set -o errexit

set_cachyos_as_default() {

    local MOST_RECENT
    MOST_RECENT="$(find /boot -name "vmlinuz*cachy*.*" | sort --version-sort | tail --lines=1 | tr --delete "\n")"

    grubby --set-default="${MOST_RECENT}"

}

set_cachyos_as_default

@mikaeldui
Copy link
Copy Markdown
Author

I'm flabbergasted (:smile: ) how it's been working on my machine

It's ridiculously smooth for how simple it is. I can't even tell when I'm getting the kernel updates.
image

"vmlinuz*cachyos*.*"

@msmafra I've updated the Gist to now look for just "cachy" so that it's compatible with all the different CachyOS kernels, that all start with "cachy" in Fedora/COPR, .e.g. "cachyos", "cachylts", "cachyrt" and "cachyserver".

If you want you could create scripts for Fedora Silverblue and derivatives: https://discussion.fedoraproject.org/t/bieszczaders-kernel-cachyos/46112/126

Gnome Boxes/libvirt can properly simulate Secure Boot when UEFI is enabled, so you get "bad shim signature" if the kernel signing fails.

@msmafra
Copy link
Copy Markdown

msmafra commented Jun 15, 2025

I'm flabbergasted (:smile: ) how it's been working on my machine

It's ridiculously smooth for how simple it is. I can't even tell when I'm getting the kernel updates. image

"vmlinuz*cachyos*.*"

@msmafra I've updated the Gist to now look for just "cachy" so that it's compatible with all the different CachyOS kernels, that all start with "cachy" in Fedora/COPR, .e.g. "cachyos", "cachylts", "cachyrt" and "cachyserver".

If you want you could create scripts for Fedora Silverblue and derivatives: https://discussion.fedoraproject.org/t/bieszczaders-kernel-cachyos/46112/126

Gnome Boxes/libvirt can properly simulate Secure Boot when UEFI is enabled, so you get "bad shim signature" if the kernel signing fails.

Oh, thanks. I updated my files to match it.

@FoxyLoon
Copy link
Copy Markdown

In Fedora, the line sudo echo "$USER" >> /etc/pesign/users does not work
But a better way might be: sudo echo "$USER" | sudo tee -a /etc/pesign/users

@FoxyLoon
Copy link
Copy Markdown

FoxyLoon commented Jul 30, 2025

missing a "sudo" on the line that says:
sudo chown root:root /etc/kernel/postinst.d/00-signing ; chmod u+rx /etc/kernel/postinst.d/00-signing

Correct:
sudo chown root:root /etc/kernel/postinst.d/00-signing ; sudo chmod u+rx /etc/kernel/postinst.d/00-signing

@Manah7
Copy link
Copy Markdown

Manah7 commented Sep 18, 2025

Works fine, thanks!

root@me:~# uname -a
Linux halobaena 6.16.7-cachyos1.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC [...] x86_64 GNU/Linux
root@me:~# mokutil --sb-state
SecureBoot enabled

@mikaeldui
Copy link
Copy Markdown
Author

Works fine, thanks!

root@me:~# uname -a
Linux halobaena 6.16.7-cachyos1.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC [...] x86_64 GNU/Linux
root@me:~# mokutil --sb-state
SecureBoot enabled

You're welcome, @Manah7!

@ken-kuro
Copy link
Copy Markdown

Thanks for the information, helped me a lot. Might I ask do you use any of the https://github.com/CachyOS/copr-linux-cachyos?tab=readme-ov-file#-addons ?

@polycatenane
Copy link
Copy Markdown

This works on atomic Fedora, but it seems like there's no nice way to set up an auto-sign hook currently. Hopefully, bootc will have some kind of way to automate signing.

@mikaeldui
Copy link
Copy Markdown
Author

This works on atomic Fedora, but it seems like there's no nice way to set up an auto-sign hook currently. Hopefully, bootc will have some kind of way to automate signing.

@polycatenane did you have to do anything special on atomic Fedora? After a file system corruption I switched to Bluefin-DX.

@polycatenane
Copy link
Copy Markdown

The instructions you wrote work well so nothing special for that. The main issue is that I couldn't figure out an easy way to do signing automatically, besides building a new image using the modified kernel.

@MaxiTornado
Copy link
Copy Markdown

I just updated my UEFI, redid secure boot, went through the key-making, signing, and replacing process again, and it didn't work. CachyOS kernel results in black screen after grub. No bad shim message, that wasn't present before I redid the signing, either.

@mikaeldui
Copy link
Copy Markdown
Author

@MaxiTornado do you have an Nvidia GPU?

@MaxiTornado
Copy link
Copy Markdown

Nope, RX 6800. I also sent you a friend request on Discord, btw, if you don't wanna bloat the discussion log here.

@mikaeldui
Copy link
Copy Markdown
Author

@MaxiTornado maybe the current kernel might be incompatible with your system. Could you try selecting an older kernel or the official Femora kernel?

@MaxiTornado
Copy link
Copy Markdown

Official kernel works just fine, I'm on it right now. I tried both 6.19.9 and 6.19.8, and neither of them booted, but the official 6.19.11 does. I had the exact same hardware and UEFI settings a few hours ago, and the kernel was working, the only change has been the UEFI update, and consequent re-importing of keys for it. I also had to redo the signing for openrazer, and that worked.

@MaxiTornado
Copy link
Copy Markdown

Okay, I figured it out with AI. (Don't worry, I didn't execute any code from it, except checking my mok list.)

I did not know that secure boot keys enrolled for a previous UEFI version do not get deleted when you update your UEFI. So all re-signing the kernel did was add the new key to it as well, and one wrong plus one right key don't allow you to boot. I just wasn't seeing the bad shim message because I had rhgb quiet in my grub. I cleaned it up, and it works again.

@mikaeldui
Copy link
Copy Markdown
Author

@MaxiTornado good. It sounded weird that the keys would've been cleared, but I thought maybe you claared them manually. πŸ˜ƒ They're stored in permanent memory, similar to the Windows license key. Some UEFIs let you delete all keys, incl. Microsoft's keys. I wonder how many companies use that to only allow OS's signed by their own IT department πŸ˜ƒ

@NathanielH-snek
Copy link
Copy Markdown

Okay, I figured it out with AI. (Don't worry, I didn't execute any code from it, except checking my mok list.)

I did not know that secure boot keys enrolled for a previous UEFI version do not get deleted when you update your UEFI. So all re-signing the kernel did was add the new key to it as well, and one wrong plus one right key don't allow you to boot. I just wasn't seeing the bad shim message because I had rhgb quiet in my grub. I cleaned it up, and it works again.

What did you end up having to do? I upgrading my mobo, cpu, ram and I haven't been able to get this to work. I nuked everything listed in mok and readded a new cert but no dice.

@mikaeldui
Copy link
Copy Markdown
Author

@NathanielH-snek the easiest way would be to just wait for the next CachyOS kernel update, that will be signed correctly by your MOK. Until then just use the official Fedora kernel.

I bricked my laptop once by uninstalling a kernel so I don't recommend trying to do that (reinstalling the CachyOS kernel).

@MaxiTornado
Copy link
Copy Markdown

What did you end up having to do? I upgrading my mobo, cpu, ram and I haven't been able to get this to work. I nuked everything listed in mok and readded a new cert but no dice.

Use certutil to delete CachyOS keys until you have none. Go to /lib/modules and find the latest CachyOS folder. Copy the vmlinuz file from it, rename it to include its full version, and replace the one in /boot with it. Redo key-making and signing process. That's it. Automation file should work still, no need to redo that.

@c0mpile
Copy link
Copy Markdown

c0mpile commented May 5, 2026

The easiest way to do all of it is to use sbctl and sign the kernel with your own keys. It takes less than 2 minutes and then you never have to touch it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment