Try to understand the hard drive again.

Source: Internet
Author: User

Written in front of the words: "Understand hard disk", the basic composition of the hard disk and the basic concept of said, basically from the hardware point of view, this article to write hard disk, the basic concept is not said, directly to see the previous article can be, focus on the file and system partition in the hard disk inside the location, Also answer the question of the Golden Ocean (Jyk) Sunshine Boy.

= = = Text Start = =

One, my disk parameters

We know a few important concepts in the hard drive: Head (head), Cylinder (Cylinder), Sector (Sector), which is the data of my computer, which is viewed with Diskgenius:

A total of 60801 cylinder,255 heads, each sector number of each, total number of sectors:976773168, here is two points:

(1) The number of heads is odd: we know that there are two sides of a disk in the disc can store data, but some of the disk face only use one side, so the head number may appear odd, here you can know that the head number is from 0~255. ( Multi-head technology not used )

(2) Number of sectors per sector: we know that for a disk surface, the longer the perimeter of the track, for the previous old-fashioned disk, the number of sectors per track is the same, resulting in the external track storage data density is too low, so the modern disk is the number of external track sector, the number of sectors in the few, Here the number of each sector is actually converted , that is, the total number of sectors divided by the number of heads divided by the number of cylinders.

(3) Number of cylinders: A total of 60801, so you can know that the cylinder and track number is 0~60800

(4) Total number of sectors:976773168, This is my hard disk total number of sectors, these sectors can store data, each sector 512Bytes, so my disk capacity is probably also: 465GB

Second, low-level format 

Above we list the number of cylinders and sectors in my disk, How are these numbers coming? a blank hard disk can be imagined as a "iron brick", and do not have these so-called track, cylinder, sector and other parameters, before the factory, hard disk manufacturers will often format, determine the hard disk cylinder, sector and so on physical parameters, this is called "low-level format", This format is not related to the operating system.

Three, disk addressing

After the disk is low-level formatted, there is a sector, we can write the data inside, but how to determine which sector of our data to write? If we don't tell the computer, it's not known. So we should find the sector where we need to write or read the data, and we'll use disk addressing.

(1) Find a specific sector, you can provide a cylinder number (Cylinder), magnetic number (Header), the sector area code (SECTOR), you can uniquely determine that sector , this address is called CHS addressing mode. For example, CHS for 0/0/1 represents the No. 0 cylinder, the No. 0 head, the 1th sector, which is the first sector of the entire disk, and 60800/254/63, which represents the No. 60800 cylinder, the No. 255 head, and the 63rd sector, representing the last sector of my disk.

(2) To find a specific sector, you can also use another way, that is, just provide the sector area code to determine, called LBA, logical addressing, or linear addressing, such as No. 0 cylinder NO. 0 Head sector number of 100 (this is not 68, because the outer ring than the number of inner circle sector), Its corresponding physical number is 1~100, but the corresponding LBA logic number is 0~99 (the logical number starts from 0 ), the number No. 0 cylinder 1th head corresponding sector physical number is 1~100, but the corresponding LBA logical label is 100~199, and so on, So all sectors are numbered: 0~976773167, which is equivalent to expanding a single cylinder and then connecting it together.

Iv. Partitioning of disks

After reading the previous, a physical parameter has been determined by the disk, if we want to install the operating system, such as windows, then we need to partition the disk, that is, the C drive occupies which sectors, the D disk occupies which sectors and so on, occupied by the size of the sector we assigned to their decision. is the sector occupied by my partition:

You can see the sectors occupied by the system reserved partitions, where the CHS and LBA two addressing methods can be seen:

(1) For CHS addressing: The system reserved partition starts from the 33rd sector of the 0 cylinder 32 head, to 12 cylinders, 223 sectors of the head are cut off.

(2) for LBA addressing: The start sector number of the system reserved Partition is: 32*63+33-1=2048, Note that the CHS in this sector number starts at 1, while the LBA address has a sector number starting from 0.

Here, you can also answer the @ Golden Ocean (JYK) Sunshine Boy's first question, where is the C disk in the hard disk: starting at 12 cylinder 223 Head 20th sector, ending in No. 7649 cylinder 13th head 44th sector. and the operating system is generally stored on the disk on the outside track, it is said that heretics access faster than the inner lane, and the operating system files need to be frequently accessed.

Looking at the diagram above, we will find a few questions:

(1) system reserved partition starting from 2048 sectors, then the front of the 0~2047 sector, the equivalent of 1MB size is not shown, what are they for?

(2) See inside the extended partition to mount the E-disk and the F-disk, of course, the front system reserved Partition, C, D disk is the main partition, what is the difference between them?

(3) The extended partition ends at 60801 cylinders and 47 heads 46 sectors, so what's behind the sector? (Note: Here 60801 should be 60800, because the cylinder is numbered from 0, so it may be a software error, this is not a deep dive)

The following is a brief talk about:

(1) for the problem (1), there are 2048 sectors in front, of which the first sector, that is, the No. 0 cylinder No. 0 Head 1th sector (CHS addressing) or the No. 0 sector (LBA addressing), also known as the MBR zone, has 512 bytes, where the master boot record MBR Take 446 bytes , used to boot the operating system boot, not detailed, there is a chance to introduce, the disk partition table (DPT) occupies 64 bytes , used to record the situation of each partition, such as the sector of the C-drive, which sector D is occupied, and so on, we found it only 64 bytes , can be divided into 4 records, a record accounted for 16 bytes, to record a partition, so there can only be 4 partitions, that is, 4 primary partitions, if you want to divide more areas, you can use one of the main partition as an extended partition, and then expand a few logical partitions, several logical partitions mounted on the extended partition above, Therefore, the extended partition is also one of the primary partitions and can only have one; the last two bytes end with 55AA ; the other 2047 sectors are empty and some are used by others. (This part of the content is not written in detail, or the article is too long)

(2) for the question (2) The difference between the primary partition and the extended partition is briefly explained in the above text.

(3) For questions (3) I'm so surprised, where are all the spaces?

Note: The disk can be expanded according to sectors, numbered 0,1,2, ..., and then divided into several parts: part1,part2,part3,part4,part5,part6,part7 where Part2, Part3, Part4, Part5, Part6 respectively gave the system reserved Partitions, C, D, E, F , Part1 and Part7 vacated space for another use, each part of which each sector is what, what information is stored inside, it is also worth thinking about.

v. Writing files

The partition is finished, let's take a look at writing the file. Write files to the disk, is according to cylinder, head, sector of the order to write, such as first write the 1th cylinder, the 1th head, the 1th sector, and then write the 1th cylinder, 1th heads, 2nd sector, after writing 63 sectors, and then moved to the following a head to write When you finish writing a cylinder, then use the back of the cylindrical face. Next, if you write two files to C disk A.txt,b.txt, they occupy a cylinder, then their sector address is close to each other and a.txt in front, B.txt again, but the next thing is going to happen:

(1) If the content is deleted inside the a.txt, the footprint is reduced, but the space occupied is 1 cylinders.

(2) If the a.txt inside add content, then a cylinder is not occupied, and the cylinder next to it is b.txt to occupy, then it will go from the other cylinders to find a place to put, and then in A.txt to create a reference to the sector of the new content.

From (1) (2), as the system is running, the fragmentation of the disk will be more and more, so the operating system provides a defragmentation tool is to integrate these spaces ( of course, for SSD drives, because the internal structure is different, not recommended defragmentation, here is not explained.) ), you can look at my d disk inside the space utilization, not continuous, such as:

Note: The operation of the operating system on the file is more complicated than this, for example, delete the file does not actually delete from the sector, otherwise the recovery can not recover files, specific to see the operating system knowledge.

  In addition, we usually have this experience: for example, the D disk inside a large file cut to the other folder D, fast, and cut to other drive characters, the speed is relatively slow, because in the same drive, cut the file, actually just changed the file's reference address, Does not change the actual sector address of the file, so it is very fast. This also gives us a hint: after the disk partition does not need to divide so much, two is enough, an installation system, a put some data files, so move the file speed is also fast, of course, if there are other uses, such as the installation of multi-operating system needs, it is another matter.

   Well, write so much, and then see the hard disk, is not it has a different understanding, write a bit messy, please forgive me.

Try to understand the hard drive again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.