『楼 主』:
转载: 关于硬盘结构及分区原理
使用 LLM 解释/回答一下
1.磁道,扇区,柱面和磁头数
硬盘最基本的组成部分是由坚硬金属材料制成的涂以磁性介质的盘片,不同容量硬盘的盘片数不等。每个盘片有两面,都可记录信息。盘片被分成许多扇形的区域,每个区域叫一个扇区,每个扇区可存储128×2的N次方(N=0.1.2.3)字节信息。在DOS中每扇区是128×2的2次方=512字节,盘片表面上以盘片中心为圆心,不同半径的同心圆称为磁道。硬盘中,不同盘片相同半径的磁道所组成的圆柱称为柱面。磁道与柱面都是表示不同半径的圆,在许多场合,磁道和柱面可以互换使用,我们知道,每个磁盘有两个面,每个面都有一个磁头,习惯用磁头号来区分。扇区,磁道(或柱面)和磁头数构成了硬盘结构的基本参数,帮这些参数可以得到硬盘的容量,基计算公式为:
存储容量=磁头数×磁道(柱面)数×每道扇区数×每扇区字节数
要点:(1)硬盘有数个盘片,每盘片两个面,每个面一个磁头
(2)盘片被划分为多个扇形区域即扇区
(3)同一盘片不同半径的同心圆为磁道
(4)不同盘片相同半径构成的圆柱面即柱面
(5)公式: 存储容量=磁头数×磁道(柱面)数×每道扇区数×每扇区字节数
(6)信息记录可表示为:××磁道(柱面),××磁头,××扇区
(7)硬盘的容量=柱面数(CYLINDER)*磁头数(HEAD)*扇区数(SECTOR)*512B
2.硬盘只能最多有四个主分区
MBR(Master Boot Recorder)主要开机扇区,放置硬盘的信息。MBR 可以说是整个硬盘最重要的地方了,因为在 MBR 里面记录了两个重要的东西,分别是:开机管理程序,与磁盘分区表 ( partition table )。所以我们所做的硬盘分区,也就是在修改partition table。
由于这个 MBR 区块的容量有限,所以,当初设计的时候,就只有设计成 4 个分区纪录(这个说法不太准确,下文有详细说明),这些分区记录就被称为 Primary ( 主分区 ) 及 Extended ( 扩展分区 ) ,也就是说,一颗硬盘最多可以有 4 个 Primary + Extended 的扇区,其中,Extended 只能有一个,因此,你如果要分区成四块磁盘分区的话,那么最多就是可以:
P + P + P + P
P + P + P + E
的情况来分区了。需要特别留意的是,如果上面的情况中, 3P +E 只有三个『可用』的磁盘,如果要四个都『可用』,就得分区成 4P 了!( 因为 Extended 不能直接被使用,还需要分区成 Logical 才行)
思考一:如果我要将我的大硬盘暂时分区成四个 partition ,同时,还有其它的空间可以让我在未来的时候进行规划,那么该如何分区?
由刚刚的说明,我们可以知道, Primary + Extended 最多只能有四个 partition,而如果要超过 5 个 partition 的话,那么就需要 Extended 的帮忙。因此,在这个例子中,我们千万不能分区成四个 Primary 为什么呢?假如您是一个 20 GB 的硬盘,而 4 个 primary 共用去了 15 GB ,您心想还有 5 GB 可以利用对吧?错!剩下的 5 GB 完全不能使用,这是因为已经没有多余的 partition table 纪录区可以记录了,因此也就无法进行额外的分区,当然啰,空间也就被浪费掉了!因此,请千万注意,如果您要分区超过 4 槽以上时,请记得一定要有 Extended 分区区,而且必须将所有剩下的空间都分配给 Extended ,然后再以 logical 的分区区来规划 Extended 的空间。
思考二:我可不可以仅分区 1 个 Primary 与 1 个 Extended 呢?
当然可以!基本上, Logical 可以有 64 个,因此,你可以仅分区一个主分区,并且将所有其它的分区都给 Extended ,利用 Logical 分区来进行其它的 partition 规划即可!
思考三:假如我的硬盘安装在 IDE 1 的 Master ,并且我想要分区成 6 个可以使用的硬盘扇区,那么每个磁盘在 Linux 底下的代号为何?
说明:
由于硬盘在 Primary + Extended 最多可以有四个,因此,在 Linux 底下,已经将 partition table 1 ~ 4 先留下来了,如果只用了 2 个 P + E 的话,那么将会空出两个 partition number 呦!再详细的说明一下,假设我将四个 P + E 都用完了。其中Extended /dev/hda4包括三个逻辑分区。
实际可以使用的是 /dev/hda1, /dev/hda2, /dev/hda3, /dev/hda5, /dev/hda6, /dev/hda7 这六个 partition!至于 /dev/hda4 这个 Extended 扇区本身仅是用来规划出让 Logical 可以利用的磁盘空间而已!
那么万一我只想要分区 1 个 Primary 与 1 个 Extended 呢?
因为 1~4 号已经被预留下来了,所以第一个 Logical 的代号由 5 号开始计算起来,而后面在被规划的,就以累加的方式增加磁盘代号啰!而其中 /dev/hda3, /dev/hda4 则是空的,被保留下来的代号。
这个问题,结合历史来说会说得比较准确。为什么最多只可以分四个主要分区,并不是单由操作系统所决定的。
第一,为什么一个扇区只有512字节,为什么不是1024字节呢?
首先,我想说一个扇区是多少字节是可以自己(硬盘生产厂家)定义的,可以是1024字节的。所以说,一个扇区是512字节并不是理论值,而是习惯值。也就是一个扇区的大小为512字节对于硬盘的生产厂家来说都是习惯的这样定义了,谁也不想更改这种习惯。
第二,硬盘的第一扇区可以分成三个部分:第一部分MBR,需要占用446字节,第二部分DPT,需要占用64字节,这是因为一个分区表需要占用16字节,64/16=4,所以刚好能存放四个分区的表,这就是为什么只能分四个分区。还有两个字节就用来存放结束标志。这样
446+64+2=512字节。
对硬盘加密其实就是改写最后两个字节的结束标志。
试想如果当初硬盘厂家将一个扇区设置成1024字节,还是只能分四个分区吗?逻辑驱动器也需要分区表,它存放在扩展分区的第一扇区,所以逻辑驱动器也不是随便想分多少就分多少的。
### 1. Tracks, Sectors, Cylinders, and Number of Heads
The most basic component of a hard disk is a disk platter made of a hard metal material and coated with a magnetic medium. The number of platters varies depending on the hard disk capacity. Each platter has two sides, both of which can record information. The platter is divided into many fan-shaped areas, each area is called a sector, and each sector can store 128×2^N (N = 0, 1, 2, 3) bytes of information. In DOS, each sector is 128×2^2 = 512 bytes. On the surface of the platter, concentric circles with different radii centered on the center of the platter are called tracks. In a hard disk, cylinders are formed by tracks of the same radius on different platters. Tracks and cylinders both represent circles of different radii. In many cases, tracks and cylinders can be used interchangeably. We know that each disk has two sides, and each side has one head. The head number is usually used to distinguish them. The number of sectors, tracks (or cylinders), and heads constitutes the basic parameters of the hard disk structure. With these parameters, the capacity of the hard disk can be obtained. The calculation formula is:
Storage capacity = number of heads × number of tracks (cylinders) × number of sectors per track × bytes per sector
Key points:
(1) A hard disk has several platters. Each platter has two sides, and each side has one head.
(2) The platter is divided into multiple fan-shaped areas, namely sectors.
(3) Concentric circles of different radii on the same platter are tracks.
(4) Cylinders are formed by tracks of the same radius on different platters.
(5) Formula: Storage capacity = number of heads × number of tracks (cylinders) × number of sectors per track × bytes per sector
(6) Information recording can be expressed as: ×× track (cylinder), ×× head, ×× sector
(7) Hard disk capacity = number of cylinders (CYLINDER) × number of heads (HEAD) × number of sectors (SECTOR) × 512B
### 2. A hard disk can have at most four primary partitions
The MBR (Master Boot Recorder) is the main boot sector, which stores information about the hard disk. The MBR can be said to be the most important part of the entire hard disk because it records two important things inside: the boot manager program and the disk partition table (partition table). So the hard disk partitioning we do is to modify the partition table.
Because the capacity of this MBR block is limited, when it was initially designed, it was only designed to have 4 partition records (this statement is not very accurate, and there will be a detailed explanation below). These partition records are called Primary (primary partitions) and Extended (extended partitions). That is to say, a hard disk can have at most 4 Primary + Extended sectors. Among them, there can be only one Extended. Therefore, if you want to partition into four disk partitions, then the maximum situation is:
P + P + P + P
P + P + P + E
for partitioning. It should be specially noted that in the above situation, 3P + E only has three "usable" disks. If you want all four to be "usable", you need to partition into 4P! (Because the Extended cannot be used directly, it needs to be partitioned into Logical first)
Thought 1: If I want to temporarily partition my large hard disk into four partitions, and there is still other space for me to plan in the future, how should I partition?
From the above explanation, we can know that Primary + Extended can have at most four partitions. And if you want to have more than 5 partitions, then you need the help of Extended. Therefore, in this example, we must never partition into four Primary. Why? Suppose you have a 20 GB hard disk, and 4 primary partitions have used up 15 GB. You think there is still 5 GB available, right? Wrong! The remaining 5 GB cannot be used at all because there are no more partition table record areas to record, so additional partitioning cannot be carried out, and of course the space is wasted. Therefore, please pay special attention. If you want to partition more than 4 slots, please remember that there must be an Extended partition area, and all remaining space must be allocated to Extended, and then the space of Extended is planned with Logical partitions.
Thought 2: Can I only partition 1 Primary and 1 Extended?
Of course you can! Basically, there can be 64 Logical partitions. Therefore, you can only partition one primary partition, and allocate all other partitions to Extended, and use Logical partitions to plan other partitions!
Thought 3: Suppose my hard disk is installed on IDE 1's Master, and I want to partition into 6 usable hard disk sectors, then what are the codes of each disk under Linux?
Explanation:
Since the Primary + Extended of the hard disk can have at most four, under Linux, partition numbers 1 to 4 have been reserved first. If only 2 P + E are used, then two partition numbers will be vacant! To explain in more detail, suppose I have used up all four P + E. Among them, the Extended /dev/hda4 includes three logical partitions.
The actually usable ones are /dev/hda1, /dev/hda2, /dev/hda3, /dev/hda5, /dev/hda6, /dev/hda7 these six partitions! As for the Extended sector /dev/hda4 itself, it is only used to plan the disk space available for Logical.
Then what if I only want to partition 1 Primary and 1 Extended?
Because numbers 1 to 4 have been reserved, the code of the first Logical starts from number 5, and the ones planned later are increased in a cumulative way. Among them, /dev/hda3 and /dev/hda4 are empty and reserved codes.
This problem will be more accurately explained in combination with history. Why can there be at most four main partitions, which is not only determined by the operating system.
First, why is a sector only 512 bytes, why not 1024 bytes?
First of all, I want to say that the size of a sector can be defined by itself (by the hard disk manufacturer), and it can be 1024 bytes. So the fact that a sector is 512 bytes is not a theoretical value, but a habitual value. That is to say, the size of a sector being 512 bytes has been habitually defined by hard disk manufacturers, and no one wants to change this habit.
Second, the first sector of the hard disk can be divided into three parts: the first part is MBR, which needs to occupy 446 bytes, and the second part is DPT, which needs to occupy 64 bytes. This is because one partition table needs to occupy 16 bytes, 64/16 = 4, so it can just store the tables of four partitions. This is why there can be only four partitions. The remaining two bytes are used to store the end mark. So
446 + 64 + 2 = 512 bytes.
In fact, encrypting the hard disk is to rewrite the last two bytes of the end mark.
Imagine if the hard disk manufacturer had set a sector to 1024 bytes at the beginning, would there still be only four partitions? Logical drives also need partition tables, which are stored in the first sector of the extended partition, so logical drives are not arbitrarily divided as many as you want.
|