Backing up the Master Boot Record (MBR) before changing partitions, installing another operating system, or experimenting with boot loaders preserves a known-good boot path. A small backup image created in advance can be restored quickly if the primary disk stops booting after modifications, avoiding longer recovery work.

On Linux systems that use BIOS-style partitioning, the MBR occupies the first 512 bytes of a disk and contains the initial boot loader code, the primary partition table, and a signature. The dd utility reads and writes raw blocks from devices such as /dev/sda and can copy this 512-byte region into a regular file without altering its structure, which is ideal for saving and restoring the MBR.

Running dd with elevated privileges against the wrong device or in the wrong direction can destroy data, so disk names must be checked carefully before proceeding. Keeping the backup on separate storage such as a USB drive or network share protects it from disk failures, and including the disk name and date in the file name helps track which backup belongs to which system.

Steps to back up Master Boot Record (MBR) in Linux:

  1. Open a terminal with access to sudo on the Linux system.
    $ whoami
    user
  2. List available disks to identify the device that holds the MBR to be backed up.
    $ lsblk
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    loop0    7:0    0   89M  1 loop /snap/core/7713
    loop1    7:1    0 54.6M  1 loop /snap/lxd/11964
    loop2    7:2    0 54.6M  1 loop /snap/lxd/11985
    loop3    7:3    0 88.7M  1 loop /snap/core/7396
    sda      8:0    0   20G  0 disk
    ├─sda1   8:1    0    1M  0 part
    └─sda2   8:2    0   20G  0 part /
    sr0     11:0    1  748M  0 rom
  3. Note the full device name of the target disk such as /dev/sda or /dev/nvme0n1 instead of a partition entry.

    Using a partition like /dev/sda1 instead of the whole disk omits the MBR region and produces an unusable backup for boot recovery.

  4. Back up the first 512 bytes from the selected disk into a regular file using dd.
    $ sudo dd if=/dev/sda of=/home/user/mbr-sda-2024-05-13.bin bs=512 count=1
    [sudo] password for user:
    1+0 records in
    1+0 records out
    512 bytes copied, 0.00140727 s, 364 kB/s

    Reversing the if and of parameters or pointing either one at the wrong device can overwrite the MBR or another disk region, which may prevent the system from booting.

  5. Check the backup file size to confirm that exactly 512 bytes were written.
    $ ls -l /home/user/mbr-sda-2024-05-13.bin
    -rw-r--r-- 1 user user 512 May 13 10:55 /home/user/mbr-sda-2024-05-13.bin

    A size of 512 bytes indicates that the full MBR sector, including partition table and signature, has been saved.

  6. Inspect the backup contents for recognizable strings such as the boot loader name.
    $ strings /home/user/mbr-sda-2024-05-13.bin
    ZRr=
    `|f 
    \|f1
    GRUB 
    Geom
    Hard Disk
    Read
     Error
    ##### snipped #####

    Strings like GRUB suggest that the boot loader code was captured correctly when using the GRUB boot loader.

  7. Copy the backup file to external storage such as a USB drive or network share.
    $ cp /home/user/mbr-sda-2024-05-13.bin /media/user/usb-backups/

    Storing backups on a separate device protects them from failures or accidental overwrites on the main disk.

  8. Record the source disk, backup file name, and storage location in notes or documentation for future reference.
Discuss the article:

Comment anonymously. Login not required.