Master Boot Record (MBR)
这是古老且长久的分区表格式。
MBR位于磁盘的第0个LBA(logical block addressing),现在linux系统已经没有CHS (Cylinder-Head-Sector)的概念了。
MBR还包括boot code,分区表。分区表只是MBR的一部分。
LBA通常是512字节。
MBR中有4个分区表记录,每个是16字节,共64个字节。偏移从446开始,到510结束。LBA的最后2个字节是boot signature
Partition numberOffset
Partition 10x01BE (446)
Partition 20x01CE (462)
Partition 30x01DE (478)
Partition 40x01EE (494)
16个字节的分区内容是:
Element (offset) | Size | Description |
---|---|---|
0 | byte | Boot indicator bit flag: 0 = no, 0x80 = bootable (or "active") |
1 | byte | Starting head |
2 | 6 bits | Starting sector (Bits 6-7 are the upper two bits for the Starting Cylinder field.) |
3 | 10 bits | Starting Cylinder |
4 | byte | System ID |
5 | byte | Ending Head |
6 | 6 bits | Ending Sector (Bits 6-7 are the upper two bits for the ending cylinder field) |
7 | 10 bits | Ending Cylinder |
8 | uint32_t | Relative Sector (to start of partition -- also equals the partition's starting LBA value) |
12 | uint32_t | Total Sectors in partition |
Relative sector是分区的起始扇区。
Total sectors是分区的扇区数。
这两个字段是小端存储的。
一个32M的loop device设备,创建两个分区,分别为4M和8M。sfdisk的显示:
# sfdisk -l /dev/loop17
Disk /dev/loop17: 32 MiB, 33554432 bytes, 65536 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0cfdb114
Device Boot Start End Sectors Size Id Type
/dev/loop17p1 2048 10239 8192 4M 83 Linux
/dev/loop17p2 10240 26623 16384 8M 83 Linux
打印出MBR内容如下:
1 2 3 4 5 6 7 8 9 | # hexdump -C -n 512 /dev/loop17 00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| * 000001b0 ff ff ff ff ff ff ff ff 14 b1 fd 0c 00 00 00 20 |............... | 000001c0 21 00 83 a2 22 00 00 08 00 00 00 20 00 00 00 a2 |!..."...... ....| 000001d0 23 00 83 a7 26 01 00 28 00 00 00 40 00 00 00 00 |#...&..(...@....| 000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.| 00000200 |
第一个分区从0x1be开始,内容就是:00 20 21 00 83 a2 22 00 00 08 00 00 00 20 00 00
第二个分区,紧跟第一个分区,内容:00 a2 23 00 83 a7 26 01 00 28 00 00 00 40 00 00
可以看到第一个分区的起始扇区是:0x00000800,也就是2048。大小是:0x00002000,也就是8192.
和sfdisk是完全吻合的。
参考: