Be aware that the MBR holds two things:
- The first stage of the computer's boot loader (normally GRUB's first stage, on a Fedora system).
- The primary MBR partition table, which defines partitions /dev/sda1 through /dev/sda4 (or equivalent for /dev/sdb or other disks).
Backing up the MBR with dd, as leigh123linux suggests, backs up both these pieces of data; but if you want a backup of the partition table, this will not
back up your logical partitions. (You might luck out on restoration if the extended partition data still exists on the disk, though.) Also, if you want to restore just one thing or the other, you've got to be careful to specify the correct part of the backup file to restore (via bs, seek, and/or skip options to dd). Personally, I don't usually mess with boot loader backups; instead, I re-install the boot loader using grub-install or similar commands, either using Super GRUB Disk
to boot into my regular system or using an emergency CD to boot a recovery system.
For partition table backups, the following command will back up all your partitions (primary and logical) to a text file:
sfdisk -d /dev/sda > backup.txt
You can then restore them with the following command:
sfdisk -f /dev/sda < backup.txt
If your partition table is healthy, this is a bit more reliable than a binary MBR backup, especially if you've got logical partitions (numbered above 5 by Linux). The MBR backup can be better if there's something weird or damaged in your MBR and you want to back it up before attempting to fix it.
Also, all of this assumes you've got a BIOS-based computer and an MBR partition table. If your computer uses EFI firmware and boots in EFI mode, the MBR doesn't hold any boot loader code; that goes in the EFI System Partition (ESP). If the disk uses the new GUID Partition Table (GPT) partitioning system, the MBR's partition table holds nothing but a dummy placeholder partition; the real partitions are defined in the GPT data structures, which are located elsewhere on the disk. To back up GPT partitions, I recommend my GPT fdisk family (gdisk, cgdisk, or sgdisk),
which includes a backup option that creates a binary backup file. Alternatively, you can use dd to back up the first 34 sectors of the disk -- change "count=1" to "count=34" in leigh123linux's command. To restore such a backup, though, you'll need to either use gdisk or do the math to figure out where to put everything and issue three separate dd commands, each with different seek and skip options.