Compile and Install a Linux Kernel in Asahi Linux

TL;DR: Install build tools, download the kernel source, copy .config, make, install everything, fix DTB path, run update-m1n1, do not reboot without verifying DTB fix!

1. Preparation

  1. Install Asahi Linux (if not already installed):

    If Asahi Linux is not already installed, run the following command on macOS and follow the instructions to set it up.

    curl https://alx.sh | sh
    
  2. Download the kernel source:

    Download the appropriate version from the Fedora Asahi Repo, then extract and enter the directory:

    tar -xf kernel-asahi-kernel-6.12.1-404.asahi.tar.gz
    cd kernel-asahi-kernel-6.12.1-404.asahi/
    
  3. Install the building essentials:

    To compile the kernel, you’ll first need to install the required build tools:

    sudo dnf install make automake gcc gcc-c++ openssl-devel ncurses-devel flex bison
    

2. Config and Compile

  1. Copy the current kernel configuration:

    Copy your existing kernel configuration as a starting point and then open it in menuconfig to adjust settings if needed.

    sudo cp /boot/config-$(uname -r) .config
    make menuconfig
    
  2. Compile the kernel:

    Use the -j flag (adjust the number according to your CPU cores) for faster compilation:

    make -j 24
    
  3. Install the modules, device trees, VDSO and kernel:

    Run the following command to install modules, device trees, VDSO, and the kernel itself:

    sudo make modules_install dtbs_install vdso_install install
    

But the installation is not finished yet. If you reboot now, you’ll end up unbootable. Because after running dtbs_install, the device tree blob (dtb) files are installed in the wrong location.


3. Deal with DTB Problems

The default Makefile creates a symlink from /boot/dtb to /boot/dtb-$(kernel-version), but actually installs the files in /boot/dtbs/$(kernel-version). This mismatch makes the symlink invalid, causing the system to fail to locate DTB files at boot. Rebooting without fixing this will result in missing peripheral drivers and potentially an unbootable system.

To fix this, move the directory to match the expected name (replace 6.12.1 with your kernel version):

sudo mv /boot/dtbs/6.12.1/ /boot/dtb-6.12.1

4. Update m1n1

After every kernel upgrade, you need to update m1n1 to ensure the boot firmware is correctly aligned with your new kernel:

sudo update-m1n1

Refer to the Asahi Linux Docs for more details on why this step is necessary.


5. Done and Reboot

Before rebooting, double-check that you have completed every step. Skipping any part could result in an unbootable system or boot loops. A critical note: due to issues like the absence of USB keyboard support in GRUB (see this issue), recovering from such a scenario can be very challenging.

When you’re certain that everything is in place, you can safely reboot:

sudo reboot