|Download Links:||download – browse – authenticate|
|Description:||Creates MBR and partition table backups and restores from backups|
|License:||GNU GPL v3 * SEE DISCLAIMER *|
|Feedback:||comments – issues|
mbrback creates a backup of your hard drive’s MBR and its partition table. You can then use mbrback to restore the MBR boot code, full MBR, or partition table from the backup files.
mbrback --help Creates MBR and partition table backups of DEVICE named: HOST-DEVICE-MBR-back HOST-DEVICE-partition-back.sf Restores MBR and partition table from specified backup file Usage: sudo mbrback DEVICE [BACKUPFOLDER] (creates backup files of DEVICE) Usage: sudo mbrback --restoreboot DEVICE [BACKUPFILE] (restores MBR boot code only) Usage: sudo mbrback --restorefullmbr DEVICE [BACKUPFILE] (restores entire MBR) Usage: sudo mbrback --restorepart DEVICE [BACKUPFILE.sf] (restores partition table) Example: sudo mbrback sda (creates MBR and partition table backups of /dev/sda in current folder) Example: sudo mbrback /dev/sda (creates MBR and partition table backups of /dev/sda in current folder) Example: sudo mbrback sda /mybackups (creates MBR and partition table backups of /dev/sda in /mybackups) Example: sudo mbrback --restoreboot sda /mybackups/sys-sda-MBR-back (restores MBR boot code of /dev/sda using /mybackups/sys-sda-MBR-back) Example: sudo mbrback --restorepart sda /mybackups/sys-sda-partition-back.sf (restores partition table of /dev/sda using sfdisk file /mybackups/sys-sda-partition-back.sf) When restoring, mbrback will always tell you what it's going to do and allow you to abort before it writes to disk.
To create backups of your first hard drive’s MBR and partition table:
sudo mbrback sda
That command will create two files: “systemname-sda-MBR-back”, which is a backup of the full MBR, and “systemname-sda-partition-back.sf”, which is a human- and machine-readable partition table backup created by sfdisk.
Note: You can run the above command even if /dev/sda is a mounted system partition.
mbrback will overwrite old backup files without prompting.
For more information on the MBR, consult How The Computer Boots – The MBR Explained.
Restoring MBR Boot Code
There are various ways to use these backup files for restoration. One common scenario is installing Windows after Linux. The Windows installation program will overwrite the MBR boot code, rendering Linux unbootable. To correct this, you can boot with a live Linux CD, such as SystemRescueCD, mount the partition containing mbrback and your backup files, and tell mbrback to restore the MBR boot code. For example:
# Note: You need to specify the full location of mbrback and the backup file sudo /mnt/myscripts/mbrback --restoreboot /mnt/mybackups/systemname-sda-MBR-back
Assuming GRUB was installed when you made your MBR backup, the above command is generally equivalent to reinstalling GRUB to your MBR. One exception is if the physical disk sector locations of GRUB’s stage files have changed, perhaps due to restoration with a tool like FSArchiver. In this case, GRUB will need to be reinstalled to the MBR to prevent a ‘file not found’ error.
Restoring A Partition Table
A less common scenario is having a damaged partition table, or a partition table that has accidentally had a partition entry changed or deleted. In this case you may want to restore the partition table.
IMPORTANT WARNINGS: Most users will never have occassion to restore a partition table or full MBR. Only restore the partition table if it has been damaged. Restoring a partition table or the full MBR from an out-of-date backup file may render ALL the data on your drive unreadable! NEVER restore a partition table or full MBR to a mounted drive.
If you do need to restore a partition table, there are two ways to do this:
The full MBR contains both boot code and the primary partition table. Thus restoring the full MBR will restore the primary partition table. However, it may NOT restore the extended partitions. To restore the full MBR, use a command like:
# Note: You need to specify the full location of mbrback and the backup file sudo mbrback --restorefullmbr "systemname-sda-MBR-back"
A second way to restore the partition table is using the sfdisk backup file, e.g. “systemname-sda-partition-back.sf”. This may also restore the extended partition table. This can be done with a command like:
# Note: You need to specify the full location of mbrback and the backup file sudo mbrback --restorepart "systemname-sda-partition-back.sf"
When restoring, mbrback will always tell you what it’s going to do, issue applicable warnings, and allow you to abort before it writes to disk.
See ‘man sfdisk’ for more information.
Follow the standard Script Installation Instructions. Also, because you will sometimes want to run mbrback when the main system partition is unbootable or unreadable, you may want to save or install a copy to another partition or drive.
mbrback also requires the “util-linux” package (aka “util-linux-ng” in some distributions). This provides sfdisk. However, this package is generally installed by default and does not need to be added when installing mbrback.