Master Boot Record (MBR) is a type of boot loader that tells a system how the partitions on a disk are organized. Although MBR has been superseded by GUID Partition Table in recent years, MBR is still very prevalent across many systems. Without a boot loader, your system will have a hard time booting into your operating system – whichever Linux distro that may be. As such, it can be useful to learn how to back up and restore the MBR on Linux.
In this guide, we’ll be going over the commands used to backup, restore, destroy, and install MBR to a disk on Linux. Check out the examples below to learn how.
In this tutorial you will learn:
- How to manage MBR on Linux
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Any Linux distro |
Software | install-mbr |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Identify disk partition
First, we need to find our storage device that we’d like to use for backing up or restoring MBR. Use the following fdisk
command to see a list of storage devices on your system.
# fdisk -l
Once you’ve identified the device file of the disk you wish to manage, you can use some of the dd commands below to manipulate the MBR boot loader.
Manage MBR on Linux
We’ll be using the /dev/sdX
partition in our commands below. In order for the commands to work, you’ll need to substitute this example partition with a real one on your own system.
- Back up the master boot record of a disk with the following command.
# dd if=/dev/sdX of=my.mbr bs=446 count=1
The MBR backup will be stored as file
my.mbr
in your present working directory. - To restore a MBR we need to just switch the order of input and output files.
# dd if=my.mbr of=/dev/sdX bs=446 count=1
- If you for any reason want to destroy your MBR, just use
/dev/zero
as an input file in your command:# dd if=/dev/zero of=/dev/sdX bs=446 count=1
- Installing MBR can be very useful, especially when creating Linux USB boot sticks. To install MBR from scratch we can use the
install-mbr
command found in mbr package:# install-mbr /dev/sdX
Closing Thoughts
In this guide, we saw how to identify the disks on a Linux system, and then use that information to back up, restore, destroy, and install an MBR boot loader to the storage device. This is a handy practice when creating USB boot sticks or repairing an operating system which is having trouble booting up.