---
title: "Fix \"Bad Shim Signature\" for Custom Kernels on Ubuntu"
description: "Fix the \"bad shim signature\" error when booting a custom kernel on Ubuntu 22.04, 24.04 or 26.04: sign it with your own key, or turn Secure Boot off."
url: https://devicetests.com/fix-bad-shim-signature-error-booting-custom-kernels-ubuntu
language: en
---

# How To Fix "Bad Shim Signature" Error When Booting Custom Kernels in Ubuntu 22.04

By Carlos Bradley · Updated November 4, 2026 · First published July 19, 2023

Short answer

“Bad shim signature” means **Secure Boot** is on and the kernel isn’t signed with a key your computer trusts. Most self-built and mainline kernels aren’t. Sign the kernel with your own key (a Machine Owner Key, MOK) and keep Secure Boot on, or turn Secure Boot off.

The steps work the same on Ubuntu 22.04, 24.04 and 26.04. Ubuntu’s own kernels are already signed: picking one in the GRUB menu (under **Advanced options for Ubuntu**) starts the computer again.

## Why it happens

_The Secure Boot chain: the firmware chip, shim, the GRUB menu and the kernel, joined by arrows. Below, your own key signs the kernel and is enrolled into shim._

1. The firmware checks shim, which Microsoft has signed.
2. Shim checks GRUB and the kernel against the keys it trusts, including your enrolled MOK.
3. GRUB asks shim to check the kernel. A failed check gives "bad shim signature".
4. Your custom kernel.
5. Your own key: it signs the kernel and is enrolled into shim.

Each step checks the signature of the next one. Your own key fixes the last link.

## Option 1: Sign the kernel with your own key

This keeps Secure Boot on. Check that it is on with `mokutil --sb-state`.

1. Install the tools:

   ```
   sudo apt install sbsigntool mokutil openssl
   ```

2. Create a key pair:

   ```
   openssl req -new -x509 -newkey rsa:2048 -nodes -days 3650 -subj "/CN=My kernel signing key/" -keyout MOK.priv -outform DER -out MOK.der
   ```

3. Make a PEM copy of the certificate for `sbsign`:

   ```
   openssl x509 -in MOK.der -inform DER -outform PEM -out MOK.pem
   ```

4. Queue the key for enrollment. You choose a one-time password:

   ```
   sudo mokutil --import MOK.der
   ```

5. Restart. In the blue **MOK management** screen, choose **Enroll MOK**, **Continue**, **Yes**, type the password, then **Reboot**.

6. Sign your kernel. Replace `<version>` with yours:

   ```
   sudo sbsign --key MOK.priv --cert MOK.pem --output /boot/vmlinuz-<version>.signed /boot/vmlinuz-<version>
   ```

7. Replace the unsigned kernel with the signed one, then update GRUB:

   ```
   sudo mv /boot/vmlinuz-<version>.signed /boot/vmlinuz-<version>
   sudo update-grub
   ```

Check the result with `sbverify --cert MOK.pem /boot/vmlinuz-<version>`. Sign again after every kernel rebuild. Modules you build yourself need signing too, with the DER certificate:

```
kmodsign sha512 MOK.priv MOK.der module.ko
```

> Make a new key; don't reuse Ubuntu's
>
> Don’t use the DKMS key in `/var/lib/shim-signed/mok/`. Ubuntu marks it for modules only, and shim ignores it when checking kernels. And keep `MOK.priv` safe: anyone who has it can sign code your computer will trust.

## Option 2: Turn off checking in shim

This needs no firmware menu, but your computer then starts any kernel.

1. Run `sudo mokutil --disable-validation` and choose a password.
2. Restart and confirm the change in the blue MOK management screen.

To undo it, run `sudo mokutil --enable-validation` and confirm it the same way.

## Option 3: Turn off Secure Boot

1. Restart and open the BIOS/UEFI settings. The key depends on the computer, often F2, Delete, F10 or Esc. See the [BIOS keys by brand](https://devicetests.com/how-to-enter-bios-on-hp-laptop#bios-and-boot-menu-keys-by-brand).
2. Find **Secure Boot**, usually under **Boot**, **Security** or **Authentication**.
3. Set it to **Disabled**.
4. Save and exit, often with F10, then start your custom kernel.

> Have your BitLocker key ready
>
> Without Secure Boot, any boot code can run, including malware. If Windows is on the same computer, it may ask for its BitLocker recovery key afterwards. Only start kernels you built or trust.

## Sources

- [Ubuntu: Secure Boot (security documentation, MOK keys, disable validation)](https://documentation.ubuntu.com/security/security-features/platform-protections/secure-boot/)
- [Ubuntu: How to sign things for Secure Boot](https://ubuntu.com/blog/how-to-sign-things-for-secure-boot)
- [Ubuntu manpage: mokutil (24.04)](https://manpages.ubuntu.com/manpages/noble/man1/mokutil.1.html)
- [Ubuntu manpage: sbsign (24.04)](https://manpages.ubuntu.com/manpages/noble/man1/sbsign.1.html)
- [Ubuntu packages: sbsigntool (24.04 and 26.04)](https://packages.ubuntu.com/noble/sbsigntool)

## Test it yourself

Check your own device with a free test. It runs in your web browser.

- [My device](https://devicetests.com/my-device): See your system, browser, screen, graphics and memory in plain words, and copy them as one report.
- [Printer test page](https://devicetests.com/printer-test-page): Print a colour, black and white, grey or alignment page, or save it as a PDF, and read what it shows.
- [GPU test](https://devicetests.com/gpu-test): See which graphics chip your browser uses, what it supports, and how fast it draws.
