Ensure your Linux system remains bootable by backing up GRUB and the Master Boot Record (MBR).
GRUB (GRand Unified Bootloader) is a critical part of the Linux boot process.
Misconfiguring or damaging it can lead to system boot failures.
This guide walks you through safely backing up and restoring GRUB to prevent such issues and guarantee recoverability.
π‘ Before any system changes, always create a full backup of GRUB and your MBR.
Run the following command to inspect your current disk and partition layout:
df -h
Create a copy of your GRUB directory:
sudo cp -r /boot/grub /boot/grub.bak
or
sudo cp -r /boot/efi /boot/efi.bak
Replace /dev/vda
with your disk if different:
sudo dd if=/dev/vda of=/boot/mbr_backup.img bs=512 count=1
π This command saves the first 512 bytes of the disk (includes the MBR) into an image.
β οΈ Use these steps only if GRUB is corrupted or the system is unbootable.
Revert to your saved backup:
sudo mv /boot/grub.bak /boot/grub
or
sudo cp -r /boot/efi.bak/* /boot/efi/
Write the backed-up image back to the disk:
sudo dd if=/boot/mbr_backup.img of=/dev/vda bs=512 count=1
If needed, perform a full reinstallation of GRUB:
sudo grub-install /dev/vda
sudo update-grub
Creating a backup of GRUB and the MBR is a simple but powerful step to prevent boot-related catastrophes.
By following this guide, you'll ensure you can quickly recover from misconfigurations or accidental changes.