Through some legacy code I'm using dd to save and restore (parts) of a bootsector after unzipping the .iso of the system onto the hard drive (from a live cd).

I use the following command to save the mbr (first 446 bytes thus everything BUT the partition table):

dd if=/dev/sda of=/mnt/mbr.bin bs=446 count=1

Then I restore the .iso of the hard drive and afterwards use the following command to restore the boot sector:

dd if=/mnt/mbr.bin of=/dev/sda bs=446 count=1

Now as I'm having the problem that before I had ONLY a windows xp installed and AFTER using the above method it lets me choose between a linux startup and a windows xp startup I guess something is going severly wrong there.

My question here is: Should these two commands above be sufficient for saving and then later on restoring a boot sector?

2 Answers 2


The MBR is basically a 512 byte segment on the very first sector of your hard drive and it is composed of 3 parts: the boot code (446 bytes long), the partition table (64 bytes long) and the boot code signature (2 bytes long). Not sure what went wrong on your side but this works for me:

This will definetly backup the boot code itself and nothing else:

[root@host]# dd if=/dev/sda of=/tmp/mbr.img_backup bs=446 count=1

Next you want to wipe the MBR clean including partition table which you don't wish to save together with bootcode signature:

[root@host]# dd if=/dev/zero of=/dev/sda bs=512 count=1

And now you restore the boot code:

[root@host]# dd if=/tmp/mbr.img_backup of=/dev/sda bs=446 count=1

  • shouldnt the 2nd step already be done when I restore the .iso of the drive? (thus 1.) backup 2.) drive iso restore, 3.) boot restore)
    – Thomas
    Dec 31, 2015 at 17:32
  • Yes. But i would definetely try to zero those 512 bytes just to be sure it's all nice and clean - that way you are 100% sure what is going on there and it will be easier to nail down the issue if it still doesn't work for some mean reason.
    – monsune
    Dec 31, 2015 at 17:37
  • ok so backup, clear, drive iso restore and then boot restore
    – Thomas
    Dec 31, 2015 at 17:40
  • I would say: backup, drive iso restore, clear and boot restore.
    – monsune
    Dec 31, 2015 at 17:42
  • with that order of things wouldnt the partition table not also be deleted? (as we delete teh 512 bytes or does that not matter in this case?
    – Thomas
    Dec 31, 2015 at 17:43

As I understood that "format" command among one of the operating system package files creates Boot sector. It writes 11 characters long "io sys" and "msdos sys" files in the fixed location, and when operating system reboots. It finds io.sys and msdos.sys files in the root directory and loads the operating system up and running.

  • Welcome to the site, and thank you for your contribution. Unfortunately it is not clear what aspect of the OPs problem you are referring to or trying to solve (in particular what "format" command are you referring to). Please edit your post to make the meaning clearer.
    – AdminBee
    Aug 19, 2020 at 7:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .