UNIX / Linux: Copy Master Boot Record (MBR)

How do I copy MBR from one hard disk to another hard disk under Debian Linux?

To copy MBR simply use the dd command. dd command works under all Linux distros and other UNIX like operating systems too. A master boot record (MBR) is the 512-byte boot sector that is the first sector of a partitioned data storage device of a hard disk.

MBR Total Size

446 + 64 + 2 = 512


  • 446 bytes – Bootstrap.
  • 64 bytes – Partition table.
  • 2 bytes – Signature.

512 vs 446 Bytes

  • Use 446 bytes to overwrite or restore your /dev/XYZ MBR boot code only with the contents of $mbr.backup.file.
  • Use 512 bytes to overwrite or restore your /dev/XYZ the full MBR (which contains both boot code and the drive’s partition table) with the contents of $mbr.backup.file.

dd command to copy MBR (identically sized partitions only)

Type dd command as follows:
dd if=/dev/sda of=/dev/sdb bs=512 count=1
Above command will copy 512 bytes (MBR) from sda to sdb disk. This will only work if both discs have identically sized partitions.

dd command for two discs with different size partitions

# dd if=/dev/sda of=/tmp/mbrsda.bak bs=512 count=1
Now to restore the image to any sdb:
# dd if=/tmp/mbrsda.bak of=/dev/sdb bs=446 count=1
The above commands will preserve the partitioning schema.

Linux sfdisk Command Example

Linux sfdisk command can make a backup of the primary and extended partition table as follows. It creates a file that can be read in a text editor, or this file can be used by sfdisk to restore the primary/extended partition table. To back up the partition table /dev/sda, enter:
# sfdisk -d /dev/sda > /tmp/sda.bak
To restore, enter:
# sfdisk /dev/sda < /tmp/sda.bak
The above command will restore extended partitions.

Task: Backup MBR and Extended Partitions Schema

Backup /dev/sda MBR, enter:
# dd if=/dev/sda of=/tmp/backup-sda.mbr bs=512 count=1
Next, backup entries of the extended partitions:
# sfdisk -d /dev/sda > /tmp/backup-sda.sfdisk
Copy /tmp/backup-sda.sfdisk and /tmp/backup-sda.mbr to USB pen or somewhere else safe over the network based nas server.

Task: Restore MBR and Extended Partitions Schema

To restore the MBR and the extended partitions copy backup files from backup media and enter:
# dd if=backup-sda.mbr of=/dev/sda
# sfdisk /dev/sda < backup-sda.sfdisk

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 20 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
20 comments… add one
  • caiken Dec 21, 2007 @ 22:02

    This is correct for EXACTLY the same partition sizes. In the case you want the MBR only on a drive that has a root partition of a different size then issue the same command with a smaller block size.

    dd if=/dev/sda of=/dev/sdb bs=446 count=1

    Thus preserving the partitioning schema.

  • graysky Oct 31, 2009 @ 14:11

    Right… be VERY careful with doing this w/ two discs with different size partitions! In fact, the safest way to backup/restore JUST THE MBR:

    dd if=/dev/sda of=mbrbackup bs=512 count=1

    To restore the MBR (on to the same drive or any drive):

    dd if=mbrbackup of=/dev/sdb bs=446 count=1

  • graysky Oct 31, 2009 @ 14:14

    Caiken is right! BEWARE of using the above dd line on two discs that don’t have IDENTICALLY sized partitions! You will lose data!

    Here’s what I do to copy just the MBR from a hdd:

    dd if=/dev/sda of=mbrbackup bs=512 count=1

    Now to restore the image to any hdd:

    dd if=mbrbackup of=/dev/sdb bs=446 count=1

  • Sicarius Nov 11, 2009 @ 21:15

    Thanks a lot, this was just the kind of short note I was looking for ,)

  • Brandon Nov 27, 2009 @ 0:33

    MBR is 512 or 446 bytes?

  • Bolo Dec 21, 2009 @ 20:57

    MBR is divided into 3 sections
    1. Bootstrap . 446 bytes
    2. Partition table. 64 bytes
    3. Signature. 2 bytes

  • Pavel Apr 19, 2010 @ 12:31

    Very useful comments about 446 bytes. Thanks!

  • Ashrock Nov 15, 2010 @ 18:52

    I am not sure what MBR is until i found this post.
    But this is not exactly what i want to do.
    I want to copy all the files and directories of a root hard disk with a disk size of 70GB into a external hard drive with a disk capacity of 250GB mounted on /mnt/sda2 .
    I can use only cp command as my Debian OS crashed and i want to take immediate backup of all the files.
    Is this command useful in any way to do that.


    • Fionn Nov 21, 2010 @ 0:50


      If you can use ‘cp’, then you can use ‘dd’; they’re both required for Posix-compliant systems (such as is Debian).

      Also, you cannot make a ‘backup’ after the system has crashed. Backups are made before crashes happen so that Recovery may be performed. What you are attempting to do is called ‘salvage’.

  • Niko Dec 2, 2010 @ 15:26

    Since this is the first Google result for “linux copy mbr”, please edit original post adding a BIG FAT WARNING about the 512/446 size values.

  • clfapujc Dec 31, 2010 @ 10:31

    # sfdisk -d /dev/sda > /tmp/sda.bak
    # sfdisk /dev/sda < /tmp/sda.out
    it should be bak also

  • Nick Mar 17, 2011 @ 15:58

    Hi .. there are numerous info about this nowadays on all sites…
    but one thing i never sure of is ….
    No sites explain this really…..

    • 🐧 nixCraft Mar 17, 2011 @ 17:31

      It can be done on both mounted and unmouted file system.

  • Mike May 18, 2011 @ 15:16


    I tried this twice to virtualize a physical machine to ESX but each time, on boot, I only have
    GRUB _
    displayed and no more. I used the 446 bytes size. The partitionning is right and all data have been copied from old to new disk.
    I finally startup from a rescue disk, chrooted and used grub-install.

    But could grub store data somewhere else ?
    (I tried on grub 1 and grub 2 …)

  • Ndoum Feb 8, 2012 @ 22:31

    I found myself with the MBR on one drive (sda) (which seems to have packed up), Ubuntu 11.04 install (sdb) on another drive and all I have access to is the the 8.04 live disc. I was unable to therefore use things like grub-install since I couldn’t mount my drives (kep getting unrecoginzed file extensions or some such….)

    So this seemed the most practical way of doing things since all I wanted to do was create a new MBR where my 11.04 install is with the info from the packed up drive. But a quick check using Boot Info Script:


    shows that core.img is missing from after using dd to replace the MBR on sdb. Mind you I did use 446 since sda is 80Gb and sdb is 160Gb. I assumed I’m dealing with two different sized partitions.

    I’d appreciate any insigths…

  • Rashid Aug 26, 2012 @ 7:00

    this is a very good article.

    I take the backup of mbr as above mentioned procedure
    dd if=/dev/sda of=/tmp/mbrsda.bak bs=512 count=1

    How can I restore the mbr(I take the backup of mbrsda.bak file on usb/cd) I case my harddisk craches.


  • srrikanth Sep 13, 2012 @ 15:14

    How to decrease mbr size, if it is posible ?
    How to increase mbr size, if it is posible ?

  • venturi Nov 2, 2012 @ 3:11

    I am interested in using dd command to transfer a fully working ( and licensed with OEM key ) XP Home OS on a bootable 10GB Western Digital hard drive to a 16GB flash USB thumb drive. The Western Digital is at /dev/sda and the USB thumb drive is at /dev/sdc ( Ubuntu 10.10 is running on a USB thumb drive at /dev/sdb ). I use the command sudo dd if=/dev/sda of=/dev/sdc bs=64k. I partitioned and formatted the thumb first to full 16GB for NTFS ( I don’t thingk that matters using dd bit for bit image ). All files transferred ok BUT when I try to boot off the new thumb XP Home goes to the safe mode warning menu saying “Windows shut down in an unexpected manner. Do you want to boot normal, safe, command prompt, etc”. Selecting ANY of the boot modes simply shuts down the computer. Any suggestions ?

  • Joix Dec 6, 2016 @ 7:36

    that worked

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum