I recently broke the Arch Linux installation of my laptop by running a system update on low battery. A recipe for disaster, I know. The laptop ran out of battery while updating the kernel, so I got propped with this threatening message from the bootloader after trying to boot it up again:
1error: file '/boot/vmlinuz-linux' not found.
2
3Entering rescue mode...
4
5grub rescue>
This happens because the system crashed while updating the kernel, causing the vmlinuz image in the boot partition to be missing or corrupted. Here are the steps I followed to repair the boot sequence using my Arch recovery USB. I will probably need them in the future. These steps have also been useful when repairing a /boot partition that has run out of space.
Recovery Cheat Sheet
Step 1: Wifi Connection
This will be needed for pacman to locate the mirrors and correctly update the system. I recommend using iwd.
Launch the control utility:
1iwctl
Then, inside the utility, check device name:
1[iwd]# device list
Then, start scanning on your station. I will use wlan0 as an example station name:
1[iwd]# station wlan0 scan
And list the networks found:
1[iwd]# station wlan0 get-networks
Finally connect to your network:
1[iwd]# station wlan0 connect <your_network>
You should now be able to ping a website:
1ping www.google.com
Step 2: Chroot into your Filesystem
Start by discovering the name of your partition. We will use /dev/nvme0n1p2 as an example:
1lsblk
2
3NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
4nvme0n1 259:0 0 476.9G 0 disk
5├─nvme0n1p1 259:1 0 512M 0 part /boot
6└─nvme0n1p2 259:2 0 476.4G 0 part /
We then need to mount both the filesystem and the /boot partition:
1mount /dev/nvme0n1p2 /mnt
2mount /dev/nvme0n1p1 /mnt/boot
We can then chroot into the environment:
1arch-chroot /mnt
Step 3: Repair the installation
We start by removing the pacman lock left by the unfinished update:
1rm /var/lib/pacman/db.lck
Then we can run the update again to ensure all packages are consistent:
1pacman -Syu
We can then reinstall the kernel:
1sudo pacman -S linux
Finally, just to be safe, we can rebuild initramfs, which will repair the boot environment:
1mkinitcpio -P
Optional: Refresh the bootloader config
This step is needed when repairing fully the boot partition due to a broken bootloader. We start by ensuring that the grub package is installed:
1pacman -S grub
Then we can reinstall grub and regenerate the configuration:
1grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
2grub-mkconfig -o /boot/grub/grub.cfg
Final Step: Exit and reboot
1exit
2umount /mnt
3reboot
After rebooting, grub should start normally.