banner
三文字

方寸之间

居善地,心善渊,与善仁,言善信,正善治,事善能,动善时。
github
email
misskey

Fixing the kernel missing issue in Arch Linux

Background#

In the morning, I turned on my computer and decided to update the system in Terminal since it had been a while. There were many packages to update, so I opened the browser to do other things while the update was in progress. However, after only two minutes, the computer suddenly went black... There was no response, but I could hear the computer still running. Without thinking much, I decided to force shutdown. But when I tried to restart the computer and entered the grub interface, it just froze (usually it automatically selects after 5 seconds). I manually selected and received the following prompt:

Loading kernel linux-zen
error: file '/boot/vmlinuz-linux-zen' not found
Loading initial ramdisk
error: you need to load the kernel first
Press any key to continue...

I guessed that the problem was caused by the forced shutdown during the kernel update. I found some solutions on the Arch Linux BBS, and I will record them here.

Note

I am using the linux-zen kernel, so the following content has the -zen suffix. You can change it according to your own configuration. Generally, the installed kernel is linux, so you can remove the -zen suffix.

Solutions#

Using Arch Linux installation media#

  1. After entering the live environment, connect to the network. I am using iwd.
[root@archiso]# iwctl
[iwd]# station wlan0 connect wifi-ssid # Connect to the specified Wi-Fi
[iwd]# station wlan0 show # Confirm if the connection is successful
[iwd]# exit
  1. Mount the / and boot partitions.
mount /dev/sdaX /mnt
mount /dev/sdaY /mnt/boot
  1. Chroot into the system and reinstall the kernel.
arch-chroot /mnt
pacman -S linux-zen
  1. Regenerate the grub bootloader.
grub-mkconfig -o /boot/grub/grug.cfg
  1. Unmount the partitions and reboot.
exit
umount -R /mnt
reboot

After the restart, you should be able to enter the system normally.

grub command line#

This method is similar to the previous one, but it does not require the use of installation media.

Confirm the / partition location#

  1. Use ls to list all the disks on the computer. The output will be similar to:
grub>ls
(hd0) (hd0, gpt1) ...... (hd1, gpt4)
  1. Confirm the / partition by using the cat/ls command + Tab to test. For example:
grub>ls (hd0,gpt3)/ TAB
boot usr ....

The above output indicates that (hd0,gpt3) is the / partition.

Manually load the kernel#

  1. Set the root partition and grub prefix path. Assuming (hd0,gpt3) is the root partition:
grub>set root=(hd0,gpt3)
grub>set prefix=(hd0,gpt3)/boot/grub
  1. Load the kernel and system image.
grub>cat (hd0,gpt3)/boot/grub/grub.cfg # Confirm the device name of the `/` partition, assuming it is `/dev/sda3`
grub>linux /boot/vmlinuz-linux-zen root=/dev/sda3
grub>initrd /boot/initrd-linux-zen.img
  1. Start the system.
grub>boot
  1. Reconfigure grub.
    After booting, follow steps 2, 4, and 5 of the first method to regenerate the grub.cfg file in the command line.

https://bbs.archlinux.org/viewtopic.php?id=274616

https://wiki.archlinux.org/title/GRUB#Using_the_command_shell

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.