GagA// 0n D nEt

It is currently Tue Aug 21, 2018 10:16 pm

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Linux: Backup & Restore MBR
PostPosted: Wed Mar 25, 2009 1:21 pm 

Joined: Wed Jul 18, 2007 1:14 am
Posts: 181
The following article will help you backup and restore a MBR (Master Boot Record) for a drive.

Backup MBR

The MBR is a 512 byte segment on the very first sector of your hard drive composed of three parts:

1) the boot code which is 446 bytes long;
2) the partiton table which is 64 btyes long; and
3) the boot code signature which is 2 bytes long.

The core of the backup command is dd, which will be familiar to every system administrator, especially to those who intend to clone an entire hard disk. You can find all the options for dd in the manual page. As we want to back up only the first 512 bytes we need to append some arguments to it. Here is the full command you need (and remember to run it as the root user, su (and sudo for Ubuntu users):
[[email protected] ~]# dd if=/dev/hda of=/root/mbr.bkup bs=512 count=1

Restore MBR

You can use a live CD to access your hard drive and read the backup off any removable media such as a USB stick. Here is the command:
[[email protected] ~]# dd if=/dev/sdb/mbr.bkup of=/dev/hda bs=512 count=1

In the above command I assume the usb drive to be mounted as sdb. You need to replace it with a suitable drive for your situation. Also not that the above command needs to be executed as root.

In case you want to remove the entire MBR (including the partition tables) then following will be your command.
[[email protected] ~]# dd if=/dev/null of=/dev/hda bs=512 count=1

Please note that above command is not for testing as this will erase out all the MBR data. Better keep a copy of the current before trying to run these fancy looking commands.

In case you want to erase the MBR but keep the partition tables, then modify the above command to look like something below:
[[email protected] ~]# dd if=/dev/null of=/dev/hda bs=446 count=1

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group