CHS寻址模式将硬盘划分为磁头(Heads)、柱面(Cylinder)、扇区(Sector)。
知道了磁头数,柱面数,扇区数,就可以很容易地确定数据保存在硬盘的哪个位置。也很容易确定硬盘的容量。
MBR:Master Boot Record(主要启动记录区)
MBR包含两个部分
它们在整个磁盘的第一个扇区,一个扇区通常是 512 bytes 大小
而MBR所在扇区的大小可以按照下面这种表格形式来理解
查看磁盘挂载情况
[root@jiewli dev]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 39G 0 part
├─centos-root 253:0 0 20G 0 lvm /
├─centos-swap 253:1 0 4G 0 lvm [SWAP]
└─centos-home 253:2 0 15G 0 lvm /home
sr0 11:0 1 4.3G 0 rom
[root@jiewli ~]# ls /dev/ | grep sda
sda
sda1
sda2
确认/dev/sda
存在。
直接读取磁盘第一个扇区数据
[root@jiewli ~]# xxd -g 1 -l 512 /dev/sda
0000000: eb 63 90 10 8e d0 bc 00 b0 b8 00 00 8e d8 8e c0 .c..............
0000010: fb be 00 7c bf 00 06 b9 00 02 f3 a4 ea 21 06 00 ...|.........!..
0000020: 00 be be 07 38 04 75 0b 83 c6 10 81 fe fe 07 75 ....8.u........u
0000030: f3 eb 16 b4 02 b0 01 bb 00 7c b2 80 8a 74 01 8b .........|...t..
0000040: 4c 02 cd 13 ea 00 7c 00 00 eb fe 00 00 00 00 00 L.....|.........
0000050: 00 00 00 00 00 00 00 00 00 00 00 80 01 00 00 00 ................
0000060: 00 00 00 00 ff fa 90 90 f6 c2 80 74 05 f6 c2 70 ...........t...p
0000070: 74 02 b2 80 ea 79 7c 00 00 31 c0 8e d8 8e d0 bc t....y|..1......
0000080: 00 20 fb a0 64 7c 3c ff 74 02 88 c2 52 be 05 7c . ..d|<.t...R..|
0000090: b4 41 bb aa 55 cd 13 5a 52 72 3d 81 fb 55 aa 75 .A..U..ZRr=..U.u
00000a0: 37 83 e1 01 74 32 31 c0 89 44 04 40 88 44 ff 89 7...t21..D.@.D..
00000b0: 44 02 c7 04 10 00 66 8b 1e 5c 7c 66 89 5c 08 66 D.....f..\|f.\.f
00000c0: 8b 1e 60 7c 66 89 5c 0c c7 44 06 00 70 b4 42 cd ..`|f.\..D..p.B.
00000d0: 13 72 05 bb 00 70 eb 76 b4 08 cd 13 73 0d 5a 84 .r...p.v....s.Z.
00000e0: d2 0f 83 de 00 be 85 7d e9 82 00 66 0f b6 c6 88 .......}...f....
00000f0: 64 ff 40 66 89 44 04 0f b6 d1 c1 e2 02 88 e8 88 d.@f.D..........
0000100: f4 40 89 44 08 0f b6 c2 c0 e8 02 66 89 04 66 a1 .@.D.......f..f.
0000110: 60 7c 66 09 c0 75 4e 66 a1 5c 7c 66 31 d2 66 f7 `|f..uNf.\|f1.f.
0000120: 34 88 d1 31 d2 66 f7 74 04 3b 44 08 7d 37 fe c1 4..1.f.t.;D.}7..
0000130: 88 c5 30 c0 c1 e8 02 08 c1 88 d0 5a 88 c6 bb 00 ..0........Z....
0000140: 70 8e c3 31 db b8 01 02 cd 13 72 1e 8c c3 60 1e p..1......r...`.
0000150: b9 00 01 8e db 31 f6 bf 00 80 8e c6 fc f3 a5 1f .....1..........
0000160: 61 ff 26 5a 7c be 80 7d eb 03 be 8f 7d e8 34 00 a.&Z|..}....}.4.
0000170: be 94 7d e8 2e 00 cd 18 eb fe 47 52 55 42 20 00 ..}.......GRUB .
0000180: 47 65 6f 6d 00 48 61 72 64 20 44 69 73 6b 00 52 Geom.Hard Disk.R
0000190: 65 61 64 00 20 45 72 72 6f 72 0d 0a 00 bb 01 00 ead. Error......
00001a0: b4 0e cd 10 ac 3c 00 75 f4 c3 00 00 00 00 00 00 .....<.u........
00001b0: 00 00 00 00 00 00 00 00 7b 1d 0a 00 00 00 80 20 ........{......
00001c0: 21 00 83 aa 28 82 00 08 00 00 00 00 20 00 00 aa !...(....... ...
00001d0: 29 82 8e fe ff ff 00 08 20 00 00 f8 df 04 00 00 )....... .......
00001e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00001f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa ..............U.
输出结果:
Offset | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0000000 | eb | 63 | 90 | 10 | 8e | d0 | bc | 00 | b0 | b8 | 00 | 00 | 8e | d8 | 8e | c0 |
0000020 | fb | be | 00 | 7c | bf | 00 | 06 | b9 | 00 | 02 | f3 | a4 | ea | 21 | 06 | 00 |
0000040 | 00 | be | be | 07 | 38 | 04 | 75 | 0b | 83 | c6 | 10 | 81 | fe | fe | 07 | 75 |
0000060 | f3 | eb | 16 | b4 | 02 | b0 | 01 | bb | 00 | 7c | b2 | 80 | 8a | 74 | 01 | 8b |
0000100 | 4c | 02 | cd | 13 | ea | 00 | 7c | 00 | 00 | eb | fe | 00 | 00 | 00 | 00 | 00 |
0000120 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 80 | 01 | 00 | 00 | 00 |
0000140 | 00 | 00 | 00 | 00 | ff | fa | 90 | 90 | f6 | c2 | 80 | 74 | 05 | f6 | c2 | 70 |
0000160 | 74 | 02 | b2 | 80 | ea | 79 | 7c | 00 | 00 | 31 | c0 | 8e | d8 | 8e | d0 | bc |
0000200 | 00 | 20 | fb | a0 | 64 | 7c | 3c | ff | 74 | 02 | 88 | c2 | 52 | be | 05 | 7c |
0000220 | b4 | 41 | bb | aa | 55 | cd | 13 | 5a | 52 | 72 | 3d | 81 | fb | 55 | aa | 75 |
0000240 | 37 | 83 | e1 | 01 | 74 | 32 | 31 | c0 | 89 | 44 | 04 | 40 | 88 | 44 | ff | 89 |
0000260 | 44 | 02 | c7 | 04 | 10 | 00 | 66 | 8b | 1e | 5c | 7c | 66 | 89 | 5c | 08 | 66 |
0000300 | 8b | 1e | 60 | 7c | 66 | 89 | 5c | 0c | c7 | 44 | 06 | 00 | 70 | b4 | 42 | cd |
0000320 | 13 | 72 | 05 | bb | 00 | 70 | eb | 76 | b4 | 08 | cd | 13 | 73 | 0d | 5a | 84 |
0000340 | d2 | 0f | 83 | de | 00 | be | 85 | 7d | e9 | 82 | 00 | 66 | 0f | b6 | c6 | 88 |
0000360 | 64 | ff | 40 | 66 | 89 | 44 | 04 | 0f | b6 | d1 | c1 | e2 | 02 | 88 | e8 | 88 |
0000400 | f4 | 40 | 89 | 44 | 08 | 0f | b6 | c2 | c0 | e8 | 02 | 66 | 89 | 04 | 66 | a1 |
0000420 | 60 | 7c | 66 | 09 | c0 | 75 | 4e | 66 | a1 | 5c | 7c | 66 | 31 | d2 | 66 | f7 |
0000440 | 34 | 88 | d1 | 31 | d2 | 66 | f7 | 74 | 04 | 3b | 44 | 08 | 7d | 37 | fe | c1 |
0000460 | 88 | c5 | 30 | c0 | c1 | e8 | 02 | 08 | c1 | 88 | d0 | 5a | 88 | c6 | bb | 00 |
0000500 | 70 | 8e | c3 | 31 | db | b8 | 01 | 02 | cd | 13 | 72 | 1e | 8c | c3 | 60 | 1e |
0000520 | b9 | 00 | 01 | 8e | db | 31 | f6 | bf | 00 | 80 | 8e | c6 | fc | f3 | a5 | 1f |
0000540 | 61 | ff | 26 | 5a | 7c | be | 80 | 7d | eb | 03 | be | 8f | 7d | e8 | 34 | 00 |
0000560 | be | 94 | 7d | e8 | 2e | 00 | cd | 18 | eb | fe | 47 | 52 | 55 | 42 | 20 | 00 |
0000600 | 47 | 65 | 6f | 6d | 00 | 48 | 61 | 72 | 64 | 20 | 44 | 69 | 73 | 6b | 00 | 52 |
0000620 | 65 | 61 | 64 | 00 | 20 | 45 | 72 | 72 | 6f | 72 | 0d | 0a | 00 | bb | 01 | 00 |
0000640 | b4 | 0e | cd | 10 | ac | 3c | 00 | 75 | f4 | c3 | 00 | 00 | 00 | 00 | 00 | 00 |
0000660 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 7b | 1d | 0a | 00 | 00 | 00 | 80 | 20 |
0000700 | 21 | 00 | 83 | aa | 28 | 82 | 00 | 08 | 00 | 00 | 00 | 00 | 20 | 00 | 00 | aa |
0000720 | 29 | 82 | 8e | fe | ff | ff | 00 | 08 | 20 | 00 | 00 | f8 | df | 04 | 00 | 00 |
0000740 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
0000760 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 55 | aa |
0001000 |
每组最多有64 / 4 = 16
bytes
16 bytes = 16 * 8 = 128
bits
每组平均分配大小展示:
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
分区表分成四组的示意图
CHS模式切割重组:
在MBR分区的一组数据中,8 bit 的磁头单独一个字段标识,6 bit 的扇区和 10 bit 的柱面放在一起作为一个字段
而这个字段在读取时,需要按照下面的规则进行分割和重排例如:
00101000 10000010
- 先将高字节的低6位切割出来
101000
,这就是扇区号- 然后把高字节的高2位,拼接到低字节的高位:“00” + “10000010” =
0010000010
,这就是柱面号
BootIndicator (引导标志) | StartHead (开始磁头) | StartSector and StartCylinder (起始扇区和柱面) | PartitionType (分区类型) | EndHead (结束磁头) | EndSector and EndCylinder (结束扇区和柱面) | StartLBA (LBA寻址模式开始位置) | TotalSector (总扇区数) |
---|---|---|---|---|---|---|---|
活动分区 | 32磁头 | 0柱面33扇区 | Linux | 170磁头 | 130柱面40扇区 | 2,048 | 2,097,152 |
非活动分区 | 170磁头 | 130柱面41扇区 | Linux LVM | 分区超过8G,CHS寻址模式无法表达 | 2,099,200 | 81,786,880 |
fdisk
命令输出的结果查看磁盘详情(扇区作为单位)
[root@jiewli ~]# fdisk -l
磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000a1d7b
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
两个分区的起始扇区和结束扇区数字都和上面的分析结果对应良好,微小的差异,是因为分区1不在柱面边界上结束。
查看磁盘详情(柱面作为单位)
[root@jiewli ~]# fdisk -u=cylinders -l
磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 柱面 of 16065 * 512 = 8225280 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000a1d7b
设备 Boot Start End Blocks Id System
/dev/sda1 * 1 131 1048576 83 Linux
/dev/sda2 131 5222 40893440 8e Linux LVM
两个分区的其实柱面和结束柱面数字也和上面的分析结果对应良好,微小的差异,是因为数量从1开始,柱面号索引从0开始,以及实际柱面超出CHS表达范围。