CentOS7中MBR分区的前2048个扇区

您所在的位置:网站首页 硬盘分区提示写扇区错误 CentOS7中MBR分区的前2048个扇区

CentOS7中MBR分区的前2048个扇区

2024-06-24 08:02| 来源: 网络整理| 查看: 265

在学习给硬盘分区的时候,小编发现一个问题,当使用fdisk给新的硬盘分区,第一个扇区是从2048扇区开始的。并且系统盘的第一个分区,也是从第2048个扇区开始的!

[root@CentOS7 ~]# fdisk -l Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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 Disk label type: dos Disk identifier: 0x000c5079 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1953791 975872 83 Linux /dev/sda2 1953792 99608575 48827392 83 Linux /dev/sda3 99608576 197263359 48827392 83 Linux /dev/sda4 197263360 419430399 111083520 5 Extended /dev/sda5 197265408 203556863 3145728 83 Linux /dev/sda6 203558912 209850367 3145728 83 Linux Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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 fdisk: cannot open /dev/sdc: Input/output error [root@CentOS7 ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x8a0fba5a. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-209715199, default 2048):

我们都知道,硬盘按照分区类型来划分,有MBR分区和GPT分区。 对于MBR分区类型的硬盘,他们的第1个扇区存的是mbr,(512字节=主引导程序Bootloader(446字节)Grub+磁盘分区表DPT(64字节)+标识位(2字节)55 aa),这样充其量也只是占了1个扇区的空间!而对于GPT分区类型的硬盘,第1个扇区为:Proctive MBR;第2个扇区Primary GUID Partition Header;第3~34个扇区记录着分区表;这样他只是占用了34个扇区! 因此,小编分别对两种类型的硬盘做了一个测试。 首先,我使用fdisk命令对一块新的硬盘(sdb)分区,我发现,分区的第一个扇区就是只能是2048以后的扇区。为了确定一下,该硬盘的分区方式,分完区后,我使用gdisk查看,该硬盘的分区类型:MBR分区(MBR only)。

[root@CentOS7 ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xe23f07bf. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-209715199, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): p Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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 Disk label type: dos Disk identifier: 0xe23f07bf Device Boot Start End Blocks Id System /dev/sdb1 2048 20973567 10485760 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@CentOS7 ~]# gdisk /dev/sdb GPT fdisk (gdisk) version 0.8.6 Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: not present *************************************************************** Found invalid GPT and valid MBR; converting MBR to GPT format. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if you don't want to convert your MBR partitions to GPT format! *************************************************************** Command (? for help):

然后,当我用gdisk命令,对一块新的硬盘(sdc)分区,很奇怪,他标明的第一个扇区可以是:34-209715166扇区。但是,当我输入:34扇区的时候,系统输出“Information: Moved requested sector from 34 to 2048 in order to align on 2048-sector boundaries.(大致含义是:为了保证与2048扇区对齐,将34扇区移至2048扇区)”!但是,当我继续对sdc硬盘分区的时候,系统标明第一个扇区可以是:34-209715166扇区;我输入:34,系统标明,结束扇区最大为:2047。(并且,小编将/dev/sdc格式化后,挂载到/mnt/sdc2目录下后,存入了两个文件,可以使用hexdump命令查看。这就说明,34~2047扇区是可以记录数据的。) 问题来了,为什么第一个分区最小只能是2048扇区呢?

[root@CentOS7 ~]# gdisk /dev/sdc GPT fdisk (gdisk) version 0.8.6 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries. Command (? for help): n Partition number (1-128, default 1): 1 First sector (34-209715166, default = 2048) or {+-}size{KMGTP}: 34 Information: Moved requested sector from 34 to 2048 in order to align on 2048-sector boundaries. Use 'l' on the experts' menu to adjust alignment Last sector (2048-209715166, default = 209715166) or {+-}size{KMGTP}: +10G Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): p Disk /dev/sdc: 209715200 sectors, 100.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 791DA65D-2F00-4BD2-99B3-F06F32102DB8 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 209715166 Partitions will be aligned on 2048-sector boundaries Total free space is 188743613 sectors (90.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 20973567 10.0 GiB 8300 Linux filesystem Command (? for help): n Partition number (2-128, default 2): First sector (34-209715166, default = 20973568) or {+-}size{KMGTP}: 34 Last sector (34-2047, default = 2047) or {+-}size{KMGTP}: Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): p Disk /dev/sdc: 209715200 sectors, 100.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 791DA65D-2F00-4BD2-99B3-F06F32102DB8 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 209715166 Partitions will be aligned on 2048-sector boundaries Total free space is 188741599 sectors (90.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 20973567 10.0 GiB 8300 Linux filesystem 2 34 2047 1007.0 KiB 8300 Linux filesystem Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/sdc. The operation has completed successfully.

2048个扇区并不大,区区1M的空间,或许只是一个并不引人关注的小问题。可是,存在即合理。平白无故,计算机为什么要空出1M的空间呢? 对于GPT分区的硬盘,34~2047扇区可以存储数据,MBR分区的硬盘,1~2047扇区,可以存储数据吗,还是已经有数据存在了? 为此,小编使用hexdump命令,在命令行中执行命令:hexdump -C -n 1048576 /dev/sdb |less对于该命令的输出结果,小编发现,里面的数据还是挺有规律的,不过,猜想,里面的数据并不太有价值,为此,我又看了第2048扇区之后的数据,发现,前后并没有太大的不同。 另外,当执行命令:hexdump -C -n 1048576 /dev/sdc |less发现sdb(MBR分区)盘与sdc(GPT分区)输出结果,差不多!

000f4000 f4 80 00 00 f4 80 01 00 f4 80 02 00 f4 80 03 00 |................| 000f4010 f4 80 04 00 f4 80 0c 00 f4 80 0d 00 f4 80 18 00 |................| 000f4020 f4 80 28 00 f4 80 3e 00 f4 80 79 00 f4 80 ab 00 |..(...>...y.....| 000f4030 f4 80 38 01 f4 80 6c 01 00 00 00 00 00 00 00 00 |..8...l.........| 000f4040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 000f5000 f5 80 00 00 f5 80 01 00 f5 80 02 00 f5 80 03 00 |................| 000f5010 f5 80 04 00 f5 80 0c 00 f5 80 0d 00 f5 80 18 00 |................| 000f5020 f5 80 28 00 f5 80 3e 00 f5 80 79 00 f5 80 ab 00 |..(...>...y.....| 000f5030 f5 80 38 01 f5 80 6c 01 00 00 00 00 00 00 00 00 |..8...l.........| 000f5040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

“Information: Moved requested sector from 34 to 2048 in order to align on 2048-sector boundaries.(为了保证与2048扇区对齐,将34扇区移至2048扇区)”想了好长时间,一直想不明白这句话什么意思!要保证与2048扇区对齐!为什么要与2048扇区对齐?与谁的2048扇区对齐?是系统盘吗? 为此,小编对系统盘(sda)执行命令:hexdump -C -n 1048576 /dev/sda |less发现输出结果为:

00000130 88 c5 30 c0 c1 e8 02 08 c1 88 d0 5a 88 c6 bb 00 |..0........Z....| 00000140 70 8e c3 31 db b8 01 02 cd 13 72 1e 8c c3 60 1e |p..1......r...`.| 00000150 b9 00 01 8e db 31 f6 bf 00 80 8e c6 fc f3 a5 1f |.....1..........| 00000160 61 ff 26 5a 7c be 80 7d eb 03 be 8f 7d e8 34 00 |a.&Z|..}....}.4.| 00000170 be 94 7d e8 2e 00 cd 18 eb fe 47 52 55 42 20 00 |..}.......GRUB .| 00000180 47 65 6f 6d 00 48 61 72 64 20 44 69 73 6b 00 52 |Geom.Hard Disk.R| 00000190 65 61 64 00 20 45 72 72 6f 72 0d 0a 00 bb 01 00 |ead. Error......| 000001a0 b4 0e cd 10 ac 3c 00 75 f4 c3 00 00 00 00 00 00 |.....


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3