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:
- Open a terminal with access to sudo on the Linux system.
$ whoami root
- List available disks to identify the device that holds the MBR to be backed up.
$ 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 - 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.
- Back up the first 512 bytes from the selected disk into a regular file using dd.
$ sudo dd if=/dev/loop2 of=/root/sg-work/disk-lab/mbr-lab.bin bs=512 count=1 1+0 records in 1+0 records out 512 bytes copied, 0.000135583 s, 3.8 MB/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.
- Check the backup file size to confirm that exactly 512 bytes were written.
$ ls -l /root/sg-work/disk-lab/mbr-lab.bin -rw-r--r-- 1 root root 512 Dec 22 08:02 /root/sg-work/disk-lab/mbr-lab.bin
A size of 512 bytes indicates that the full MBR sector, including partition table and signature, has been saved.
- Inspect the backup contents for recognizable strings such as the boot loader name.
$ strings /root/sg-work/disk-lab/mbr-lab.bin GRUB
Strings like GRUB suggest that the boot loader code was captured correctly when using the GRUB boot loader.
- Copy the backup file to external storage such as a USB drive or network share.
$ cp /root/sg-work/disk-lab/mbr-lab.bin /media/usb-backups/
Storing backups on a separate device protects them from failures or accidental overwrites on the main disk.
- Record the source disk, backup file name, and storage location in notes or documentation for future reference.
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.
Comment anonymously. Login not required.
