mbr

Introduce

MBR, is abbreviate from Master Boot Record.

MBR(512Bytes) =

partition entry

0 1byte partition flag
1~3 3bytes CHS address
4 1bytes File system flag
5~7 3bytes CHS address
8~11 4bytes start of sector
12~15 4bytes count of sector

File system flag:
00H
01H FAT12
04H FAT16 small than 32MB
05H Extended
06H FAT16 large than 32MB
07H HPES or NTFS
0BH Windows95 FAT32
0CH Windows95 FAT32
0EH Windows95 FAT16
0FH Windows95 Extended(large than 8G)
82H Linux swap
83H Linux
85H Linux extended
86H NTFS volume set
87H NTFS volume set

A case

The current os is CentOS 6.4 X86_64, running on /dev/sdb, which is a SSD disk.

[root@localhost ~]# dd if=/dev/sdb of=/root/ssd.dat bs=1 count=512
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.00146756 s, 349 kB/s
[root@localhost ~]# hexdump -C ssd.dat 
00000000  eb 48 90 d0 bc 00 7c fb  50 07 50 1f fc be 1b 7c  |.H....|.P.P....||
00000010  bf 1b 06 50 57 b9 e5 01  f3 a4 cb bd be 07 b1 04  |...PW...........|
00000020  38 6e 00 7c 09 75 13 83  c5 10 e2 f4 cd 18 8b f5  |8n.|.u..........|
00000030  83 c6 10 49 74 19 38 2c  74 f6 a0 b5 07 b4 03 02  |...It.8,t.......|
00000040  80 00 00 80 98 3e 04 00  00 08 fa 90 90 f6 c2 80  |.....>..........|
00000050  75 02 b2 80 ea 59 7c 00  00 31 c0 8e d8 8e d0 bc  |u....Y|..1......|
00000060  00 20 fb a0 40 7c 3c ff  74 02 88 c2 52 f6 c2 80  |. ..@|<.t...R...|
00000070  74 54 b4 41 bb aa 55 cd  13 5a 52 72 49 81 fb 55  |tT.A..U..ZRrI..U|
00000080  aa 75 43 a0 41 7c 84 c0  75 05 83 e1 01 74 37 66  |.uC.A|..u....t7f|
00000090  8b 4c 10 be 05 7c c6 44  ff 01 66 8b 1e 44 7c c7  |.L...|.D..f..D|.|
000000a0  04 10 00 c7 44 02 01 00  66 89 5c 08 c7 44 06 00  |....D...f.\..D..|
000000b0  70 66 31 c0 89 44 04 66  89 44 0c b4 42 cd 13 72  |pf1..D.f.D..B..r|
000000c0  05 bb 00 70 eb 7d b4 08  cd 13 73 0a f6 c2 80 0f  |...p.}....s.....|
000000d0  84 f0 00 e9 8d 00 be 05  7c c6 44 ff 00 66 31 c0  |........|.D..f1.|
000000e0  88 f0 40 66 89 44 04 31  d2 88 ca c1 e2 02 88 e8  |..@f.D.1........|
000000f0  88 f4 40 89 44 08 31 c0  88 d0 c0 e8 02 66 89 04  |..@.D.1......f..|
00000100  66 a1 44 7c 66 31 d2 66  f7 34 88 54 0a 66 31 d2  |f.D|f1.f.4.T.f1.|
00000110  66 f7 74 04 88 54 0b 89  44 0c 3b 44 08 7d 3c 8a  |f.t..T..D.;D.}<.|
00000120  54 0d c0 e2 06 8a 4c 0a  fe c1 08 d1 8a 6c 0c 5a  |T.....L......l.Z|
00000130  8a 74 0b bb 00 70 8e c3  31 db b8 01 02 cd 13 72  |.t...p..1......r|
00000140  2a 8c c3 8e 06 48 7c 60  1e b9 00 01 8e db 31 f6  |*....H|`......1.|
00000150  31 ff fc f3 a5 1f 61 ff  26 42 7c be 7f 7d e8 40  |1.....a.&B|..}.@|
00000160  00 eb 0e be 84 7d e8 38  00 eb 06 be 8e 7d e8 30  |.....}.8.....}.0|
00000170  00 be 93 7d e8 2a 00 eb  fe 47 52 55 42 20 00 47  |...}.*...GRUB .G|
00000180  65 6f 6d 00 48 61 72 64  20 44 69 73 6b 00 52 65  |eom.Hard Disk.Re|
00000190  61 64 00 20 45 72 72 6f  72 00 bb 01 00 b4 0e cd  |ad. Error.......|
000001a0  10 ac 3c 00 75 f4 c3 00  00 00 00 00 00 00 00 00  |..<.u...........|
000001b0  00 00 00 00 00 00 00 00  a9 51 05 00 00 00 80 20  |.........Q..... |
000001c0  21 00 83 65 24 41 00 08  00 00 00 00 10 00 00 65  |!..e$A.........e|
000001d0  25 41 82 90 85 4b 00 08  10 00 00 00 80 00 00 90  |%A...K..........|
000001e0  86 4b 83 fe ff ff 00 08  90 00 00 20 2a 03 00 00  |.K......... *...|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200

/dev/sda is a virtual disk of raid1(raid with two disks);
boot.disk, which is backup with dd if=/dev/sda1 of=/root/backup/boot.disk,
not had mbr info!

[root@localhost ~]# dd if=/root/backup/boot.disk of=/root/b.dat bs=1 count=512
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.0019702 s, 260 kB/s
[root@localhost ~]# hexdump -C b.dat 
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200

The new raid1 logic disk not had any mbr info, what I had done before was:
dd if=/root/backup/boot.disk of=/dev/sda1
dd if=/root/backup/root.disk of=/dev/sda2

[root@localhost ~]# dd if=/dev/sda of=/root/raid1.dat bs=1 count=512
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.00175408 s, 292 kB/s
[root@localhost ~]# hexdump -C raid1.dat 
00000000  fa b8 00 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |................|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  c2 02 0b 00 00 00 80 20  |............... |
000001c0  21 00 83 9f 06 19 00 08  00 00 00 40 06 00 00 9f  |!..........@....|
000001d0  07 19 83 fe ff ff 00 48  06 00 00 00 00 01 00 fe  |.......H........|
000001e0  ff ff 82 fe ff ff 00 48  06 01 00 20 80 00 00 00  |.......H... ....|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200

With such virtual disk, I can’t boot to run OS normal, it stop with an flashing
underline, if normal it should show a grub to boot the os.

So, I think, when I backup the OS, I should backup the MBR also, when restore I
should restore it to new disk.

Below, I using DVD to write the MBR to /dev/sda, then it show correct 512B info

[root@localhost ~]# dd if=/dev/sda of=/root/raid1-ok.dat bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000300859 s, 1.7 MB/s
[root@localhost ~]# hexdump -C raid1-ok.dat 
00000000  eb 48 90 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |.H..............|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 03 02  |.........|...t..|
00000040  80 00 00 80 7a 61 00 00  00 08 fa 90 90 f6 c2 80  |....za..........|
00000050  75 02 b2 80 ea 59 7c 00  00 31 c0 8e d8 8e d0 bc  |u....Y|..1......|
00000060  00 20 fb a0 40 7c 3c ff  74 02 88 c2 52 f6 c2 80  |. ..@|<.t...R...|
00000070  74 54 b4 41 bb aa 55 cd  13 5a 52 72 49 81 fb 55  |tT.A..U..ZRrI..U|
00000080  aa 75 43 a0 41 7c 84 c0  75 05 83 e1 01 74 37 66  |.uC.A|..u....t7f|
00000090  8b 4c 10 be 05 7c c6 44  ff 01 66 8b 1e 44 7c c7  |.L...|.D..f..D|.|
000000a0  04 10 00 c7 44 02 01 00  66 89 5c 08 c7 44 06 00  |....D...f.\..D..|
000000b0  70 66 31 c0 89 44 04 66  89 44 0c b4 42 cd 13 72  |pf1..D.f.D..B..r|
000000c0  05 bb 00 70 eb 7d b4 08  cd 13 73 0a f6 c2 80 0f  |...p.}....s.....|
000000d0  84 f0 00 e9 8d 00 be 05  7c c6 44 ff 00 66 31 c0  |........|.D..f1.|
000000e0  88 f0 40 66 89 44 04 31  d2 88 ca c1 e2 02 88 e8  |..@f.D.1........|
000000f0  88 f4 40 89 44 08 31 c0  88 d0 c0 e8 02 66 89 04  |..@.D.1......f..|
00000100  66 a1 44 7c 66 31 d2 66  f7 34 88 54 0a 66 31 d2  |f.D|f1.f.4.T.f1.|
00000110  66 f7 74 04 88 54 0b 89  44 0c 3b 44 08 7d 3c 8a  |f.t..T..D.;D.}<.|
00000120  54 0d c0 e2 06 8a 4c 0a  fe c1 08 d1 8a 6c 0c 5a  |T.....L......l.Z|
00000130  8a 74 0b bb 00 70 8e c3  31 db b8 01 02 cd 13 72  |.t...p..1......r|
00000140  2a 8c c3 8e 06 48 7c 60  1e b9 00 01 8e db 31 f6  |*....H|`......1.|
00000150  31 ff fc f3 a5 1f 61 ff  26 42 7c be 7f 7d e8 40  |1.....a.&B|..}.@|
00000160  00 eb 0e be 84 7d e8 38  00 eb 06 be 8e 7d e8 30  |.....}.8.....}.0|
00000170  00 be 93 7d e8 2a 00 eb  fe 47 52 55 42 20 00 47  |...}.*...GRUB .G|
00000180  65 6f 6d 00 48 61 72 64  20 44 69 73 6b 00 52 65  |eom.Hard Disk.Re|
00000190  61 64 00 20 45 72 72 6f  72 00 bb 01 00 b4 0e cd  |ad. Error.......|
000001a0  10 ac 3c 00 75 f4 c3 00  00 00 00 00 00 00 00 00  |..<.u...........|
000001b0  00 00 00 00 00 00 00 00  c2 02 0b 00 00 00 80 20  |............... |
000001c0  21 00 83 9f 06 19 00 08  00 00 00 40 06 00 00 9f  |!..........@....|
000001d0  07 19 83 fe ff ff 00 48  06 00 00 00 00 01 00 fe  |.......H........|
000001e0  ff ff 82 fe ff ff 00 48  06 01 00 20 80 00 00 fe  |.......H... ....|
000001f0  ff ff 05 fe ff ff 00 68  86 01 00 d0 2d e7 55 aa  |.......h....-.U.|
00000200

Questions

  1. Why maximum of partitions is 4 primary or 3 primary with another extended?
    Because for MBR, there only 64 bytes for partition, and each partition used 16
    bytes.

Reference