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

    file output confirming a DOS/MBR boot sector indicates the backup contains boot code; some backups do not include readable strings.

  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   512M  0 loop /mnt/bench
    loop1       7:1    0    64M  0 loop 
    loop2       7:2    0    32M  0 loop 
    loop3       7:3    0    64M  0 loop 
    `-loop3p1 259:0    0    15M  0 part 
    nbd0       43:0    0     0B  0 disk 
    nbd1       43:32   0     0B  0 disk 
    nbd2       43:64   0     0B  0 disk 
    nbd3       43:96   0     0B  0 disk 
    nbd4       43:128  0     0B  0 disk 
    nbd5       43:160  0     0B  0 disk 
    nbd6       43:192  0     0B  0 disk 
    nbd7       43:224  0     0B  0 disk 
    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 
    nbd8       43:256  0     0B  0 disk 
    nbd9       43:288  0     0B  0 disk 
    nbd10      43:320  0     0B  0 disk 
    nbd11      43:352  0     0B  0 disk 
    nbd12      43:384  0     0B  0 disk 
    nbd13      43:416  0     0B  0 disk 
    nbd14      43:448  0     0B  0 disk 
    nbd15      43:480  0     0B  0 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/loop3 bs=446 count=1 conv=notrunc
    1+0 records in
    1+0 records out
    446 bytes copied, 0.000152296 s, 2.9 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/loop3 | strings | head

    Some boot code does not include readable strings; compare outputs when possible to verify a successful restore.

  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.