4 min read
Restore boot partition with Arch
Just when I had my new Arch installation up and running I deleted the boot partition. Luckily, I did not reboot the computer. There was a high chance of fixing the issue.
The boot partition is at the head of the disk. When you run fdisk -l you should see something like this:
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 133119 131072 64M EFI System
To learn more about EFI see https://en.wikipedia.org/wiki/EFI_system_partition.
Check disk
In my case the fdisk command looked like this:
[root@tuxedo ~] fdisk -l
Disk /dev/nvme0n1: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: Samsung SSD 980 500GB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 16384 bytes / 131072 bytes
Disklabel type: gpt
Disk identifier: E39054B5-6B23-4ADA-8AD6-13E319A06FF6
Device Start End Sectors Size Type
/dev/nvme0n1p2 2099200 976771071 974671872 464.8G Linux root (x86-64)
Disk /dev/zram0: 4 GiB, 4294967296 bytes, 1048576 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
So there is not boot partition. The second partition starts at sector 2099200, so the missing 1 GiB partition occupied sectors 2048 to 2099199.
Restore partition
First we are going to recreate the partition. Run fdisk with the path to your disk:
fdisk /dev/nvme0n1
Then make the following entries:
Command (m for help): n
Partition number (1,3-128, default 1): 1
First sector (34-976773134, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-2099199, default 2099199):
Created a new partition 1 of type 'Linux filesystem' and of size 1 GiB.
Command (m for help): t
Partition number (1,2, default 2): 1
Partition type or alias (type L to list all): 1
Changed type of partition 'Linux filesystem' to 'EFI System'.
Command (m for help): p
Disk /dev/nvme0n1: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: Samsung SSD 980 500GB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 16384 bytes / 131072 bytes
Disklabel type: gpt
Disk identifier: E39054B5-6B23-4ADA-8AD6-13E319A06FF6
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 2099199 2097152 1G EFI System
/dev/nvme0n1p2 2099200 976771071 974671872 464.8G Linux root (x86-64)
Command (m for help): w
The partition table has been altered.
Syncing disks.
The partition is created and ready to format. Install the necessary tools:
pacman -S dosfstool
And format the disk with F32:
[root@tuxedo ~] mkfs.fat -F32 /dev/nvme0n1p1
mkfs.fat 4.2 (2021-01-31)
Fix fstab
When the system starts the disk is mounted to /boot. As the system was still running I had to update the UUID in the fstab.
First check the current UUID:
[root@tuxedo ~] cat /etc/fstab
# Static information about the filesystems.
# See fstab(5) for details.
# /dev/nvme0n1p1
UUID=C85B-94B0 /boot vfat rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2
Then get the new UUID:
[root@tuxedo ~] blkid /dev/nvme0n1p1
/dev/nvme0n1p1: UUID="3BA3-0FDC" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="e74b88a0-5cca-4a59-ae00-15f9988824f6"
And replace it in the fstab:
sed -i 's/C85B-94B0/3BA3-0FDC/' /etc/fstab
Reload services:
systemctl daemon-reload
And mount the disk:
mount /boot
You should find an empty /boot drive:
ls /boot
Reinstall kernel and bootloader
Final step to recovery, we are going to install the bootloader. Install the tools bootstrap the bootloader:
pacman -S linux linux-firmware
Then we are going to regenerate the initramfs images:
mkinitcpio -P
Check if /boot has content:
ls /boot
EFI vmlinuz-linux
Now install the bootloader:
bootctl install
Verify bootloader with these commands:
bootctl list
# Must show "arch-linux.efi" as Type #2 entry
efibootmgr
# Lists "Linux Boot Manager"
[root@tuxedo ~] ls -R /boot/EFI
/boot/EFI:
BOOT Linux systemd
/boot/EFI/BOOT:
BOOTX64.EFI
/boot/EFI/Linux:
arch-linux.efi
/boot/EFI/systemd:
systemd-bootx64.efi
systemd-bootx64.efi is the bootloader, BOOTX64.EFI is a fallback copy of it, and arch-linux.efi is your kernel bundle that the bootloader launches.
Reboot
Now the exciting part: Rebooting system
Cross your finger and run reboot.
If the system starts (in my case it did) congratulation! If not it is probably easiest to start Arch from a USB medium and then retry this process.
Category: linuxTags: 100daystooffload , arch , recovery , linux , bootloader
Edit Page / Show Statistic