How hard disk drive work? How are data accessed by an OS?

Ishan Rijal
23 min readJun 6, 2021

Most probably we all know about the hard disk. But does everyone know electromagnetism plays an important role in a hard disk? If you don’t believe me then read this post completely. You gonna find the science beyond the working of a hard disk.

Magic of Electromagnetism

This post gonna be long as I am going to explain all the things in detail. Please read it all to know how actually the small disk is capable of storing our data.

A hard disk drive is an electromechanical data storage device that uses magnetic storage to store and retrieve digital data. It is a non-volatile storage device (i.e. keep data even when the computer is shut off). Data is stored on a hard drive in binary code, using 1s and 0s.

A mechanical hard disk is made up of two parts: the control circuit board and the disk body which is also known as head disk assembly(HDA).

1. Control circuit board

Picture of the control circuit board of a hard disk drive.
Control Circuit Board

It is the control circuit board. It is a circuit that translates computer instructions into hard disk actions as well as sends various control signals to the hard drive. It also checks the hard disk’s state and writes/reads data to and from the hard drive in the chosen data format. It comes in a variety of shapes and sizes, but its essential structure and operation are the same. It is mainly composed of a control logic circuit and a microprocessor connected to the computer system bus to complete the read and write data separation and write data compensation. It is also composed of data decoding and encoding circuit, data error detection and correction circuit, a logic circuit that controls data transmission, serial-to-parallel conversion and formatting according to computer commands, read-only memory for storing basic input and output programs of hard disks, the data exchange buffer among other components, spindle speed control circuit, magnetic head drive and servo positioning circuit, read-write circuit, control and interface circuit.

2. Hard disk body (Head Disk Assembly (HDA))

Head Disk Assembly(HDA)

It is a mechanical component of a disk that includes a spindle, platter, head, actuator, actuator arm, and other components that are common in HDD construction. The cleanliness of the hard disk body is quite important in order to ensure normal operation. The disk body is completely sealed but in order to prevent dust from entering. Now, you might think the internal part or HDA must be made a vacuum in order to prevent dust from entering?

Before talking about the principle of reading and writing, let’s talk about some of the common terms and different components of HDA.

Different components of HDA

i. Spindle-It is a shaft that holds the disc called platters in place. It is connected with a spindle motor. You will see the picture of the spindle below.

ii. Motor- A HDD contains two electric motors, a spindle motor for spinning the disks, and an actuator (voice coil motor) for positioning the read/write head arm across the spinning disks.

a. Spindle motor- The hard disk platters are turned by the spindle motor. A spindle motor must provide stable, reliable, and consistent turning power for thousands of hours, to allow the hard disk to function properly because many drive failures are actually failures with the spindle motor, not the data storage systems. It rotates up to 10,000 revolutions per minute (rpm) or more.

b. Actuator- The actuator (voice coil motor) is a permanent magnet and moving coil motor. The voice coil motor is made up of one or two magnets with a closed magnetic field and high magnetic field intensity. It has a magnetic head arm attached to it. It receives commands from the circuit board to regulate the read/write arm’s movement and supervise data transmission to and from the platters. It ensures the read/write heads are in exactly the right place at all times.

iii. Read/ Write head- It’s an electromagnetic device that reads and writes data to a hard disk. It is made by winding a coil on a magnetic core. The working principle is that the resistance value of special material changes with the magnetic field to read and write data on the disc. It is simply a thin-film coil that produces a magnetic field when the current is sent across it. It’s attached to the end of a magnetic head arm that’s driven by an actuator motor. It is placed just above a platter. An electromagnet in the read/write head writes information to the disk by magnetizing small sections of the disk, called sectors, in one direction or another to indicate a 1 or a 0.

Read/Write Head above the platter
Read/Write Head

iv. Platter- It is made of a hard substance like glass, ceramic, or aluminum. Each platter has two sides, one on top and one on the bottom. Both sides are coated with a thin ferromagnetic layer and protective layers that have the ability to store data. Hard disks with an odd number of sides are uncommon. Each platter has a number, which is sequentially numbered from top to bottom, beginning with “0.” Since each platter surface has a read-write head, the platter surface number is also known as the head number in the hard disk system. Data is stored on a hard disk by magnetizing a platter.

Platter

a. Track- Platter is divided into many concentric circles (circular ring) called track. From the edge of a platter, the tracks are numbered in order, starting with 0 on the exterior. There are a number of tracks on each platter’s surface. In the outermost circle, farthest from the spindle, near the edge of the platter is track “0”, and the storage of hard disk data starts from the outermost circle. Track 0 plays an important role. Important of track 0 will come below. These tracks are invisible to the naked eye because they are only some magnetized areas on the disk surface that are magnetized in a special way, and the data on the disk is stored along such tracks in the form of pulse trains.

b. Cylinder- All tracks that are the same distance from the edge of the platter are called a cylinder i.e. the same track of all the platter is a cylinder. To understand more preciously let’s take an example of a hard disk having two platters. Since both the upper and lower layers of a platter can store data, let’s number them as 0, 1 of 1st platter, and 2, 3 of 2nd platter. 0, 1, 2, and 3 are divided into a number of tacks. Let’s assume it has 100 tracks numbering like 0, 1, 2….99. Now the group of the same number of the track is cylinder i.e. ( the collection of track numbering 0 from 0,1,2and 3 platter(i.e. all platters) is known as a cylinder or the collection of track numbering 1 from 0, 1, 2 and 3 platter is a cylinder i.e. the collection of the same number of the track is a cylinder). Data reading/ writing is performed on the cylinder. Since the tracks with the same number in the disk will form a cylinder, the number of cylinders on a disk is equal to the number of tracks on a disk.

c. Sector- Each track is further divided into smaller segments, using some special magnetic pattern written on the disks at the time of manufacturing. These special patterns are known as sectors and data is written in these sectors. On each platter of an HDD, the number of sectors per track is the same. Each sector has the same angular velocity but a different linear velocity. The radial length has an effect on the linear velocity. The outer ring’s linear velocity is greater than the inner ring’s i.e. the length of the arc drawn by the outer ring is longer than the inner ring at the same rotation speed. Sectors are numbered starting from “1”. It is the basic unit of data storage on a hard disk. The data size of a sector is always a power of two and is almost either 512 bytes or 4096 bytes.

d. Cluster- Sectors are grouped into a fixed number to form a cluster. It is the smallest possible unit of storage on a hard disk. A cluster need not be physically contiguous on the disk; it may span more than one track. Our data is stored in a cluster and every cluster in a hard disk has a fixed size. The size of the cluster is allocated during the formatting of our hard disk.

After knowing the basic component of the hard disk know lets learn about the basic structure of a hard disk drive.

Structure of hard disk

A rod that runs through the middle of the platters is a spindle. Each platter is securely fixed to the spindle and ensures that all the platters rotate together at the same speed. All the platters are perfectly parallel. The spindle is directly attached to a motor that rotates the spindle and controls the platter speed.

An actuator is placed nearby the platter. The actuator is a voice coil motor that is responsible for controlling the movement of the arms. An arm is connected to an actuator directly and moves as a single unit. There is one arm for each side of each platter. At the end of each arm is a slider that holds the read/write head in place and supports the electrical connection between the head and the drive’s logic board. A flexible ribbon cable connects the actuator to the HDD’s logic board to manage the reading and writing processes. HDD’s logic board is a small circuit that operates the actuators, selects specific tracks for reading and writing, and converts parallel streams of data going from the computer into serial streams of data being written to the disk (and vice versa). In order to prevent damage to the magnetic head and disc, the magnetic head is hung just above the high-speed rotating platter with a small gap of only 0.01 μm, which is only one-thousandth of the diameter of a human hair. This assembly is called HDD arm assembly.

HDD Arm Assembly

In order to prevent damage to the magnetic head and disc, the magnetic head is hung just above the high-speed rotating platter with a small gap of only 0.01 μm, which is only one-thousandth of the diameter of a human hair.

Structure of a Hard disk Drive

The calculation formula to calculate HDD storage is:-
storage capacity = number of heads X number of tracks (cylinders) X sectors per track Number X bytes per sector

How are files managed?

Each file is saved in “unused” sectors and can be read later using its known size and position. How do we know which sectors are occupied and which are unoccupied? What is the location of the file, position, and name? This is precisely what the file system is in charge of. A file system is a structured representation of data and a set of metadata describing this data. It is applied to the storage during the format operation. It controls how data is stored and retrieved. Data stored in a storage medium without a file system would be one huge body of data with no way of knowing where one piece of data ends and the next begins. The data may be easily extracted and identified by dividing it into pieces and assigning each one a name. In file systems, a cluster (sometimes also called allocation unit or block) is a unit of disk space allocation for files and directories. To reduce the overhead of managing on-disk data structures, the file system does not allocate individual disk sectors by default, but contiguous groups of sectors, called clusters. On a disk that uses 512-byte sectors, a 512-byte cluster contains one sector, whereas a 4-kibibyte (KiB) cluster contains eight sectors.

In the above figure, allocation unit size is selected as 4096 bytes during the formatting of a hard disk. I have selected 4096 bytes for the cluster i.e. HDD used 8 sectors to form 1 cluster. The allocation size unit is the smallest bit of data that a drive can store i.e. in 1 cluster, 4KB of data is store. To store 8 KB data, HDD allocates 2 clusters. If a file is smaller than 4096 bytes, it will still take up the entire cluster. So, If you have lots of small files, then it’s a good idea to keep the allocation size small so your hard drive space won’t be wasted. In terms of space efficiency, smaller allocation unit sizes perform better.

How is the sector identified?

A sector has two basic parts i.e. the sector header(typically called “ID” or location identifier) and the data area.

The sector header contains information used by the drive and controller; this information includes sync bytes, address identification, flaw flag, and error detection and correction information. The header includes three numbers that make up the 3-dimensional address of the sector. One number includes the platter number i.e. in which the platter sector is located, another number includes the cylinder number and 3rd number includes the location of the sector on the track i.e. the sector number. The header also includes a field with a flag indicating if the sector can reliably store data or if a specific malfunction has been discovered and it is not suitable for usage. Some hard disk controller also records pointers in the header, which can direct the platter to a replacement sector or track when the original sector fail. The address identification is needed to ensure that the read/write head is positioned over the correct spot by the drive’s mechanics.

The second part of the sector is the data segment for storing data, which is be divided into data and error correction codes (ECC) for data protection. The ECC is used to check and perhaps rectify any problems that may have been introduced into the data. During the initial preparation period, the computer fills this part with 512 virtual information bytes (where the actual data is stored) and the ECC numbers corresponding to these virtual information bytes.

Movement of the magnetic head

The magnetic head can move along the radius of the disc (actually in a diagonal movement). Each magnetic head must also be coaxial at the same time, which means that all magnetic heads must overlap at all times when viewed from directly above (but currently there is already a multi-head independent technology, which is not subject to this limitation).

Movement of the read/write head

The platter spins at thousands of revolutions per minute, allowing the magnetic head to read and write data to a specific place on the disk. The slider has an aerodynamic design that enables the head to float above the platter when it is spinning. You might wonder how the head is raised up while rotating. You will come in a while.

Position Of Head During Rest

When the hard disk is not working, the platter is stationary and the magnetic head is close to the spindle contact. It is the surface with the smallest linear velocity, a special area that does not store any data known as the start-stop zone or landing zone, or parking zone.

When data needs to be read and written from the hard drive, the platter begins to rotate at thousands of revolutions per minute. When the rotation speed reaches the rated high speed, the magnetic head will lift up due to the airflow generated by the rotation of the disk, and then migrate to the area where the disk is storing data. This process is based on aerodynamics. The magic of aerodynamics is the reason due to which the head is lifted up. The airflow generated by the platter’s spin is strong enough to hold the head up and maintain a small distance from the disk surface in a strictly controlled state. The magnetic head must fly above the disk surface instead of touching the disk surface. This position can avoid scratching the magnetic coating, and more importantly, prevent the magnetic coating from damaging the magnetic head. However, the magnetic head should not be too far away from the disk surface, otherwise, the disk surface cannot be magnetized sufficiently strong. The flying height of the magnetic head of the hard disk drive is low and the speed is fast. The smaller the distance, the higher the sensitivity of the magnetic head to read and write data. The magnetic head reads data by sensing the change of the magnetic field on the rotating disk and writes data by changing the magnetic field on the disk.

Writing the data

When the computer wants to write new information, it takes a look at the file system to find some free sectors. Then the disk control starts to locate the sector with the help of the sector header. Then the disk controller moves the magnetic head component to the corresponding cylinder, gates the magnetic head, and waits for the required sector to pass under the magnetic head. When the disk controller finds the header of the sector, it decides whether to switch the write circuit or read the data and the tail record according to whether its task is to write the sector or read the sector. After finding the sector, the disk controller must post-process the sector information before continuing to search for the next sector.

Then for writing, the HDD’s logic board sends small electrical pulses to the head. When current is allowed to flow through the head, the magnetic field is induced in it which polarizes the portion of the disk that passes under the head. By altering the polarity of the current flowing through the coil, the polarity of the magnetic field, and thus the magnetization of the media, may be changed. The direction of the electrical current determines the magnetic direction, which in turn determines whether a bit is written as a 1 or 0. In this way, our data is written in a sector of the hard disk. Then the controller calculates the ECC code of this data and stores it together with the data.

Reading the data

When data needs to be read from the disk, the system sends the data logical address to the disk, and the disk control circuit converts it into a physical address according to the addressing logic, determining which track and sector the data must be read from. Then the disk controller is commanded to read the cylinder number, head number, and sector number (the three components of the physical address) where the sector is located. The disk controller moves the magnetic head component to the corresponding cylinder, gates the magnetic head, and waits for the required sector to pass under the magnetic head.

When the sector arrives, the disk controller reads the header of each sector, compares the address information of these headers with the received address, and then searches for the required Sector number. When the disk controller finds the header of the sector, it decides whether to switch the write circuit or read the data and the tail record according to whether its task is to write the sector or read the sector. After finding the sector, the disk controller must post-process the sector information before continuing to search for the next sector. Then for reading data, the controller calculates the ECC code of the data and then compares the ECC code with the recorded ECC code. Since the data is stored in a magnetic field, for reading the data from the sector, the platter’s magnetic field is transformed into an electrical current. In order to read the data of this sector, the head needs to be placed above this sector, in order to achieve this:

1) Firstly, the cylinder must be found i.e. the head needs to move to align with the corresponding track. This process is called seek, and the time spent is called seek time

2) Then wait for the target sector to rotate under the head, the time spent in this process is called spin time.

3) Then the data transfer starts i.e. data transfer time.

So, we can say, the complete process of a disk access request (read/write) is composed of three actions:

i. Seek (time): the head moves and locates to the specified track

ii. Rotation delay (time): waits for the specified sector to rotate under the head

iii. Data transfer (time): the actual transfer of data between disk and memory

Therefore, the time required to read sector data (a piece of data) on the disk:

T= t seek + t la + n * t wm

Where,

tseek is the seek time, tla is the rotation time, twm is the transmission time

In this way, data is read from the hard disk.

Order of Reading and writing data

Data reading/writing is performed on the cylinder. When the magnetic head reads/ writes data, the operation begins with the “0” head in the same cylinder and then proceeds to the various platter surfaces of the same cylinder. After all the magnetic heads on the same cylinder have been read/written, the magnetic head will move to the next cylinder, because the selection of the magnetic head only needs to be switched electronically, and the selection of the cylinder must be switched mechanically. Electronic switching is quite fast, much faster than moving the magnetic head to the adjacent track mechanically. Therefore, the reading/writing of data is carried out on the cylinder surface, not on the disk surface. Simply, after one track is full of data, it is written on the next platter surface of the same cylinder, and after one cylinder is full, it moves to the next cylinder to start writing data. Reading data is also performed in this way, which improves the read/write efficiency of the hard disk. Data reading/writing starts from the top to the bottom then from outside to inside.

How are sectors Magnetized?

I have been saying HDD stores data by the process of magnetization. But how actually the sectors are magnetized? Since 1956, when the first commercial hard drive was produced, the longitudinal recording has been the standard mode of recording. The sectors on the platters were magnetized parallel to the surface of the platter. This style of recording was called longitudinal recording. We moved from 5.25-inch drives to 2.5-inch drives, reducing the number of platters and heads while increasing the areal density(or Bit density). It refers to the maximum amount of bits that may be stored on a square inch of disk media. Gigabits per square inch (Gb/sq. inch) is a common unit of measurement for areal density.

Areal density was increased by decreasing the size of magnetic grains that make up data bits. Now, more data could be stored on a disk as the magnetic grains became smaller. But unfortunately, magnetic grains have their limits. Shrinking them leads to the emergence of superparamagnetic effects.

The superparamagnetic effect refers to the fluctuation of magnetization caused by thermal agitation in magnetic disk drive storage technology. When a disk medium’s areal density hits 150 gigabits per square inch, the magnetic energy keeping the bits in place on the medium becomes equal to the ambient thermal energy within the disk drive itself. As this happens, the bits are no longer held in a reliable state and can “flip,” and scramble the data that was previously recorded Simply, the magnetization direction of the magnetic recording particles is parallel to the disc, and the particles are arranged end-to-end along the disc circumference, so there is a chance of SS (South) and NN ( North) mutually exclusive arrangement.

When the size of the particles continues to decrease and the density continues to increase, the particles are extremely sensitive to random thermal motion at room temperature and lose their stability, resulting in a bit (0 and 1) flipping, and the recorded data is therefore damage.

Hard drive technologies were projected to stop expanding once they achieved densities of 150 gigabits per square inch due to the superparamagnetic effect. You used to see a hard drive with 500GB capacity and now you might wonder what happened to the superparamagnetic effect? How was it possible to make a 400GB HDD? Here I have an answer, this type of drive would actually have three platters, each capable of storing up to 133GB, resulting in a 400GB HDD, not 400GB on a single platter.

Longitudinal Recording

However, a breakthrough was made by magnetizing the platters perpendicular to the platter, allowing for more information to be stored in the same amount of physical space. This new style, called the perpendicular recording, has allowed for hard drive capacities to increase greatly. It achieves higher storage densities by aligning the poles of the magnetic elements, which represent bits, perpendicularly to the surface of the disk platter. Now, you might think the superparamagnetic effect was overcome. But it’s not true. Perpendicular recording only moves the superparamagnetic barrier back a bit, it doesn’t eliminate it.

Perpendicular Recording

Track0

It is an important track of a hard disk located at the start of a platter and is mainly used to store information regarding the layout of the disk (the partition table) and executable code needed to boot an operating system. Track0 typically consists of the first 64 sectors of the disk (since each sector is normally 512 bytes, this corresponds to 32,768 bytes = 32KiB). Since the first sector of a disk is sector zero, the first 64 sectors are sectors 0 to 63. The first sector of Track0 is known as the master boot record (MBR) and contains the initial code used to boot the operating system (bootstrap code). Near the end of the MBR is the Partition Table: a predefined structure containing the layout of the disk. Track0 is also increasingly used to store licensing information for particular pieces of software because it is an area of the disk outside of the OS file system and not seen or used by most computer users (and therefore cannot be easily modified or replicated).

Why HDA internal cannot be made vacuum?

HDA is not an internal vacuum, because the magnetic head cannot fly in a vacuum environment. It cannot be a sealed metal box, and the pressure inside and outside must be balanced to prevent excessive temperature explosion (except for helium gas disk). In this way, vents and filter components are an indispensable part of HDA. The vent hole is opened on the top cover, and some manufacturers use more eye-catching signs to remind users not to cover it. The air filter with a tortuous air inlet is glued to the position of the air vent below the top cover by double-sided adhesive.

Why you should never unscrew hard disks at home?

A tiny piece of dust can make the read-write head bounce up and down, crashing into the platter and damaging its magnetic material. Once, small dust enters the sealed cavity of the hard disk, or once the magnetic head collides with the disk body, it may cause data loss, formation of bad blocks, and even damage to the magnetic head and disk body. Therefore, the sealing of the hard disk system must be reliable, and the hard disk sealing cavity must not be opened under non-professional conditions, otherwise, the dust will accelerate the damage of the hard disk when it enters. So, it’s a bad idea to open a hard disk by following the YouTube videos to fix it.

Fragmentation

It is one the most important factor which determines the reading/ writing speed of a hard disk. Let’s assume we have taken a new hard disk of each sector of size 512 bytes and set our allocation unit size (cluster) to 4096 bytes i.e. 8 sectors are combined to form 1 cluster. The size of 1 cluster is 4096 bytes i.e. 4 KB. Now we are storing five files naming A, B, C, D, and E of size 4 KB each continuously. There is free space after E.

Now, if we delete file D, 4KB of free space is created and the disk becomes fragmented. Now a file naming F of size 8KB needs to store in a disk then 1st 4 KB size of F is stored in place of empty space of B and the remaining file is stored in the free space next to E. Since the contiguous cluster is not available, the data written is fragmented.

This is called the fragmentation of files. If we need to read file A the head can read it at once but if the head needs to read file F then it goanna take a few milliseconds more.

Let’s take the example of downloading files. While downloading the files most people will do some other things such as browsing the web, playing games, etc. The browser will generate a large number of temporary Internet files during web page browsing, and the game program may also generate temporary files during gameplay, or the operating system may change the size of the page file due to insufficient memory. In this situation, our files may not store in contiguous sectors resulting in disk fragmentation. In actual use, there are often thousands of disk fragments after a movie file is downloaded to the hard disk. Our files may be fragmented as shown below:

Fragmentation of files

In fact, our files are broken most of the time. When the file is not broken, the read/write head only needs to find the track once and read data. It only takes 1 time to read successfully; but if the file is broken into different, location suppose 6 locations, the head must search for 6 times and read 6 times to read the file completely, it becomes lengthy. Now, think yourself this situation for a larger file on a hard disk. Therefore, disk fragmentation is often one of the important factors that slow down the system.

To solve the problem, the defragmentation of hard disks plays an important role. It is the process of reorganizing the data stored on the hard drive so that related files are put back together, all lined up in a continuous fashion in contiguous sectors. It is the operation of moving file extents (physical allocation blocks) so they eventually merge, preferably into one. Doing so usually requires at least two copy operations: one to move the blocks into some free scratch space on the disk so more movement can happen, and another to finally move the blocks into their intended place. In such a paradigm, no data is ever removed from the disk, so that the operation can be safely stopped even in the event of a power loss.

When you start to hear extra grinding from the hard disk or your computer doesn’t open files as quickly as it did before, it’s time to defragment. In windows, you can go to the start menu and search for “Defragment” and then press enter. You can then select a disk and click on defragment the disk.

If you want to find out NTFS partition cluster size/Block size, sectors numbers, or any other information about your hard disk in windows then you can follow the below steps.

1 Launch “PowerShell” or “Command Prompt” and run as administrator

2 Use the following command to show NTFS partition information

Usage : fsutil fsinfo ntfsInfo <volume pathname>
Eg : fsutil fsinfo ntfsInfo C:

Here, the byte per cluster is the same as the allocation unit size or NTFS cluster size.

Large allocation unit size can be beneficial at performance for saving large files but will increase wasted space when saving the small files. It is very important to plan ahead, once the cluster size is set, we can’t change it unless we reformat the whole partition again with a new cluster size. Also, note that the large cluster size may bring some advantages for working with large files performance-wise, it increases wasted space when saving small files, again, plan ahead.

Or

You can go to “run” by pressing “win + R” and then type “msinfo32”. Then a system information container will open. Then on the left side go to component then storage and disks. You will see all the information about your hard drive.

I think it’s clear now, how data is stored in a hard disk and how it is accessed and located in the hard disk. I hope this was fruitful for you.…

--

--

Ishan Rijal

Hey, I am high school graduated computer science student.