Changing partition tables or boot loaders on an older BIOS-booted Linux disk can leave the machine without a working boot path if the first sector is overwritten. A Master Boot Record (MBR) backup saves that sector before the change so the boot code and partition-table bytes can be inspected or restored from a known source.
The MBR is the first 512 bytes of a whole disk, not of an individual partition. It contains the first-stage boot code, the primary partition table, and the 0x55AA boot signature. The examples use /dev/sda as the source disk and write the backup under /mnt/backup/mbr, which should be separate storage such as a mounted USB drive or network share.
This procedure is for traditional MBR or dos partition tables. GPT disks still contain a protective MBR, but a GPT and UEFI boot problem usually needs EFI system partition or bootloader repair instead of a 512-byte MBR restore. Read from the disk and write to a regular backup file only, because reversing dd input and output can overwrite the disk immediately.
Steps to back up Master Boot Record (MBR) in Linux:
- List whole disks and partition table types.
$ lsblk --output NAME,SIZE,TYPE,PTTYPE,MOUNTPOINTS NAME SIZE TYPE PTTYPE MOUNTPOINTS sda 100G disk dos |-sda1 512M part /boot `-sda2 99.5G part / sdb 2T disk gpt `-sdb1 2T part /data
Use the whole disk row with PTTYPE shown as dos, such as /dev/sda. Do not use a partition path such as /dev/sda1, because that starts after the MBR sector.
- Create a backup directory on separate storage.
$ sudo mkdir -p /mnt/backup/mbr
Replace /mnt/backup with a mounted USB drive, network share, or other storage that is not on the disk being backed up.
- Copy the first 512 bytes from the whole disk into the backup file.
$ sudo dd if=/dev/sda of=/mnt/backup/mbr/mbr-sda-20260613.img bs=512 count=1 conv=fsync status=none
Confirm if= points to the source disk and of= points to the backup file before pressing Enter. Reversing them or using the wrong disk path can overwrite boot code or save the wrong sector.
- Confirm that the backup file is exactly 512 bytes.
$ stat --format="%n %s bytes" /mnt/backup/mbr/mbr-sda-20260613.img /mnt/backup/mbr/mbr-sda-20260613.img 512 bytes
A different size means the backup is not a full MBR sector; recheck the source device and run the copy again before relying on the file.
- Check that the backup file is recognized as a boot sector.
$ file /mnt/backup/mbr/mbr-sda-20260613.img /mnt/backup/mbr/mbr-sda-20260613.img: DOS/MBR boot sector
file may print extra partition details on some systems. If it reports only data, verify that the source disk really uses an MBR partition table and that the backup was taken from the whole disk.
- Create a checksum beside the backup file.
$ sha256sum /mnt/backup/mbr/mbr-sda-20260613.img > /mnt/backup/mbr/mbr-sda-20260613.img.sha256
- Verify the checksum while the backup storage is still mounted.
$ sha256sum --check /mnt/backup/mbr/mbr-sda-20260613.img.sha256 /mnt/backup/mbr/mbr-sda-20260613.img: OK
Keep the checksum with the backup so later restore work can detect a copied, truncated, or changed file before writing anything back to disk.
- Record the source disk, backup file name, date, and storage location in recovery notes.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.