Failure of the Master Boot Record (MBR) often results in messages such as Operating system not found or a stuck GRUB prompt, leaving the machine unable to start from disk. Recovering a known‑good MBR backup restores the bootloader so the installed system becomes accessible again.

On BIOS-based systems, the MBR occupies the first 512 bytes of a disk, containing both the initial boot code and the partition table metadata. A backup taken from that region can be written back with tools such as dd, provided the correct disk device (for example /dev/sda/) is targeted. Accessing the disk from a Linux live environment avoids interference from the unbootable installed system.

Writing to the MBR is inherently destructive and misdirected writes can erase the partition table or affect the wrong disk. The procedure assumes a traditional MBR partitioned disk booted in BIOS mode and a valid backup file that matches the same disk; systems using GPT with UEFI firmware may require reinstalling the bootloader into an EFI system partition instead of restoring an MBR sector.

Steps to restore MBR from a backup in Linux:

  1. Boot a Linux Live CD or USB into the live session mode so the system disk can be accessed without booting from it.
  2. Open a terminal window in the live session.
  3. Ensure the MBR backup file such as mbr.bak is available in the current directory or mounted from external media.
  4. Verify the correctness of the MBR backup file before writing it to the disk.
    $ file mbr.bak
    mbr.bak: DOS/MBR boot sector
    $ strings mbr.bak | head
    GRUB

    Output indicating a DOS/MBR boot sector and recognizable GRUB strings confirms that the file contains boot code rather than arbitrary data.

  5. Identify the disk that contains the damaged MBR using a block-device listing.
    $ lsblk
    NAME      MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
    loop0       7:0    0     1G  0 loop /mnt/data
    loop1       7:1    0   512M  0 loop 
    loop2       7:2    0    64M  0 loop 
    loop7       7:7    0    64M  0 loop 
    `-loop7p1 259:0    0    31M  0 part 
    ##### snipped #####
    vda       254:0    0   1.8T  0 disk 
    `-vda1    254:1    0   1.8T  0 part /etc/hosts
                                        /etc/hostname
                                        /etc/resolv.conf
    vdb       254:16   0 606.5M  1 disk

    Confirm the target disk by size and partition layout because systems may use names like /dev/sda/, /dev/sdb/, or /dev/nvme0n1/ depending on the hardware.

  6. Restore the MBR boot code from the backup file to the start of the selected disk.
    $ sudo dd if=mbr.bak of=/dev/loop2 bs=446 count=1 conv=notrunc
    1+0 records in
    1+0 records out
    446 bytes copied, 0.000248833 s, 1.8 MB/s

    Writing the wrong file or targeting the wrong disk can corrupt the partition table or overwrite boot code on another drive; double-check the device path and backup source before running dd.

  7. Confirm that the first 446 bytes of the disk now contain a valid bootloader signature that matches the backup.
    $ sudo head -c 446 /dev/loop2 | strings | head
    GRUB

    Presence of the same GRUB strings as in the backup indicates that the boot code portion of the MBR has been restored correctly.

  8. Reboot the computer from the system disk to verify that the operating system boots successfully without the live media.

Regular MBR backups reduce the impact of future bootloader corruption and simplify recovery after accidental overwrites.

Discuss the article:

Comment anonymously. Login not required.