2015年8月3日 星期一

How To Backup / Restore Master Boot Record (MBR) in Linux

Structure of a classical generic MBR
Address Description Size
(bytes)
Hex Dec
+000h +0 Bootstrap code area 446
+1BEh +446 Partition entry #1 Partition table
(for primary partitions)
16
+1CEh +462 Partition entry #2 16
+1DEh +478 Partition entry #3 16
+1EEh +494 Partition entry #4 16
+1FEh +510 55h Boot signature[a] 2
+1FFh +511 AAh
Total size: 446 + 4×16 + 2 512

Backup / Restore Bootstrap code w/wo Partition Table

Use 446 bytes to backup / restore your /dev/s(h)dx MBR boot code.
Use 512 bytes to backup / restore your /dev/s(h)dx MBR boot code and disk partition table.

*** Use the following commands with CAUTION or it will destroy your data! ***

Clone the MBR From One Disk to Another (With Identical Sized Partitions)


Copy the MBR (first 512 bytes) from disk sda to disk sdb:
$ dd if=/dev/sda of=/dev/sdb bs=512 count=1

Clone the MBR From One Disk to Another (With different Sized Partitions)

Backup the MBR of target disk (sdb):
$ dd if=/dev/sdb of=/tmp/sdb_mbr.bak bs=512 count=1

Copy the MBR (first 446 bytes, without partition table) from disk sda to disk sdb:
$ dd if=/dev/sda of=/dev/sdb bs=446 count=1

Backup / Restore the Primary and Extended Partitions

Backup:
$ sfdisk -d /dev/sda> sda.out

Restore:
$ sfdisk /dev/sda < sda.out

Reference:

https://wiki.archlinux.org/index.php/Disk_Cloning
https://en.wikipedia.org/wiki/Master_boot_record
http://manpages.ubuntu.com/manpages/natty/man1/dd.1.html
http://manpages.ubuntu.com/manpages/hardy/man8/sfdisk.8.html

沒有留言:

張貼留言