Repair broken linux-kernel installation

Sometimes, update via pacman failed and the linux kernel may not be installed properly. This can end in grub trying to boot, but without a Kernel grub shows the error-message to load the kernel first. Here is how to fix this.

While updating via pacman, the computer shut down unexpected, so the update did not finish properly. After this, grub could not boot to the kernel and showed the error:

error: file 'vmlinuz-linux' not found. Loading initial ramdisk ... error: you need to load the kernel first.

Press any key to continue

The solution is to boot arch from an external media (thumbdrive etc.), mount the volumes, change the root and reinstall linux via pacman.

1. Download and make livedisk

The image for archlinux can be downloaded here: https://archlinux.org/download/ (scroll down to country-mirrors for direct download).

To create the bootable drive, check this: https://wiki.archlinux.org/title/USB_flash_installation_medium

1.1 Use mac for livedisk

If using macOS, the linux commands do not work. Important are the following ones:

su $adminUsername to switch to root user in terminal, found here: https://support.apple.com/guide/terminal/enter-administrator-commands-apd5b0b6259-a7d4-4435-947d-0dff528912ba/mac

diskutil list to list all mounted Volumes, found here: https://osxdaily.com/2009/12/01/list-all-mounted-drives-and-their-partitions-from-the-terminal/

diskutil unmountDisk force /dev/disk<#> to force unmount of Volume if it is busy, found here: https://superuser.com/questions/906513/get-rid-of-resource-busy-message-on-mac-os-x

2. Check and mount volumes

Boot arch from livedisk and show all devices via lsblk. Check used partition scheme, e.g.:

/sda1 = 100MB Windows Boot

/sda2 = 250GB Windows

/sda3 = 1.51GB boot

/sda4 = 630GB cryptlvm

/sda6 = 52 GB /

Open cryptvolume with cryptsetup open /dev/sda4 cryptlvm and unlock it with the password.

Mount / and /boot:

mount /dev/mapper/cryptvol-root /mnt

mount /dev/sda3 /mnt/boot

3. Change root and reinstall kernel

Change root to new mount, see https://wiki.archlinux.org/title/Chroot for more info:

arch-chroot /mnt/boot

Reinstall linux-kernel with pacman -Syu linux linux-headers

Maybe first we need to rm /var/lib/pacman/db.lck since pacman did not close correctly, for more info see https://wiki.archlinux.org/title/Pacman#%22Failed_to_init_transaction_(unable_to_lock_database)%22_error

4. Finish update

After this it could also be useful to

mkinitcpio -p linux

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

And maye restart the pacman update.

This should fix the error and linux should boot without problems anymore. Yay!