How a hard drive is logically organized to hold data?

A hard drive is a data storage device used in computers to store digital information. The data is stored on rotating magnetic disks known as platters and is accessed using read/write heads that float just above the surface of the platters (Computer Organization. Rowan University. https://users.rowan.edu/~polikar/CLASSES/ECE241/ppt/chp3.pdf). Logical organization refers to the way the data on the hard drive is arranged logically using partitions, file systems, folders, files, etc. so that the operating system can store and retrieve data efficiently.

This article provides an overview of how data is logically organized on a hard drive. It will cover key concepts like partitions, file systems, folders and directories, files, booting, cylinders, clustering, bad sectors, and defragmentation. The goal is to explain the logical structure of a hard drive to help readers understand how operating systems organize and access data on these storage devices.

Partitions

A partition is a section of the hard drive that functions as if it were a separate drive (Frisch, 2002). Partitions divide the total storage capacity of a hard drive into logical sections that can be managed separately. There are two main types of partitions on a hard drive:

Primary partitions – Up to four primary partitions are allowed on a hard drive. A primary partition can be bootable and have an operating system installed on it. Primary partitions are accessible and can be formatted with a file system.

Extended partitions – An extended partition is a special type of primary partition that is further divided into logical drives. There is a limit of one extended partition per disk. Extended partitions are used when more than four partitions are needed (Learn.microsoft.com, 2022).

The partition layout on a hard drive determines how the available storage capacity will be allocated. Partitions allow running multiple operating systems by dedicating a separate primary partition for each OS. They also enable separating data for security or organizational purposes. The maximum number of partitions allowed varies by the partition table type, either MBR (Master Boot Record) or GPT (GUID Partition Table).

File Systems

Hard drives and other storage media can be formatted with different file systems that organize data in different ways. Some common file systems include:

  • NTFS (New Technology File System) – Developed by Microsoft for use in Windows. Supports large partition sizes and file sizes. Allows permissions and encryption. Preferred for internal Windows drives. 1
  • FAT32 (File Allocation Table) – Simple file system used across operating systems. Supports smaller partition and file sizes. No permissions or encryption. Sometimes used for external drives. 2
  • exFAT – Designed for large capacity external storage. Supports very large file sizes. Compatible with Windows and macOS. No encryption or permissions.
  • HFS+ (Hierarchical File System) – Developed by Apple for use in macOS. Allows permissions and encryption. Used for Mac internal drives.

The choice of file system depends on the intended OS, storage capacity, portability needs, and security features. NTFS is optimal for internal Windows drives, HFS+ for Mac internal drives. FAT32 and exFAT can enable cross-platform external storage.

Folders and Directories

The data on a hard drive is organized into a folder hierarchy or directory tree. The base of the hierarchy is known as the root directory and is denoted by “/” on Mac/Linux systems or “\” on Windows systems. Folders can contain files as well as other folders, allowing for complex nested folder structures (Media Manager).

Every folder and file has a unique path that describes its location in the folder hierarchy starting from the root directory. For example, the path “/Users/JohnDoe/Documents/report.docx” points to a file called report.docx located in the Documents folder of user JohnDoe on a Mac/Linux system. Paths use the folder separator “/” on Mac/Linux and “\” on Windows to delimit folder names in the hierarchy (folder-structure).

Files

Files are one of the fundamental ways that data is organized and stored on a hard drive. A file represents a discrete collection of data that is stored under a specific name. Every file has certain attributes associated with it, including:

  • File name – This is the unique name given to the file when it was created.
  • Timestamps – Files have timestamps indicating when they were created, last modified, and last accessed.
  • Size – The size of the file in bytes.

The way files are physically organized and stored on a hard drive depends on the file system being used. On many file systems, files may be stored in distinct blocks that are scattered across the disk platters. The file system keeps track of which blocks belong to each file. When a request is made to access a file, the file system looks up the location of the relevant blocks and reassembles them to retrieve the file contents. Some other file systems may store small files entirely within the file system metadata itself for faster access.

On many file systems, related files are also grouped together in folders or directories. This provides a hierarchical organization for files that makes it easier for users to browse files. The full path to a file includes the folder structure leading down to that specific file.

Booting

When a computer first turns on, it goes through a boot process to load the operating system. This boot process starts by loading code from the boot sector on the hard drive, which contains the master boot record (MBR) and a partition table. The MBR contains boot loader code and the partition table contains information about the partitions on the drive.

The MBR boot loader code is executed first. This examines the partition table to find the active primary partition, and then loads the boot sector from that partition, which contains more boot loader code. For example, on a Windows system, the MBR boot code would load the boot sector from the active NTFS or FAT32 partition, which contains the Windows boot loader.

The boot sector code continues the boot process by loading the operating system kernel files and preparing the OS to take over. The partition table defines where the boot sectors for each partition are located on the drive, allowing the MBR boot code to find and load the correct one.

In summary, the boot process relies heavily on the MBR and partition table to locate the necessary boot loader code and data to start the operating system. The hard drive is organized this way to facilitate a structured boot sequence.

References:

US6308264B1 – Dual use master boot record

Cylinders

Hard drives are physically organized into concentric circles called tracks and sectors. Each track is divided into many sectors. The tracks on all platter surfaces that line up vertically comprise a cylinder. The number of tracks per platter and number of sectors per track varies based on the hard drive’s total capacity. Generally, higher capacity hard drives have more tracks and sectors, allowing for greater data density.

The tracks near the center of a platter have shorter circumferences and hold less data than tracks near the edge. To maximize capacity, zones of tracks are grouped into “zones” with variable sectors per track. Outer zones have more sectors per track than inner zones to take advantage of the larger circumference. This zone bit recording helps optimize data density across the drive.

Data is written sequentially track-by-track within a zone. The drive head moves up and down vertically to access all surfaces, reading and writing one cylinder’s worth of data at a time. This reduces seek time compared to random head movements. The basic organization into tracks, sectors and cylinders allows the drive head to locate data quickly.

Clustering

Data on hard drives is stored in clusters, which are the smallest unit of storage that can be allocated on a disk. A cluster is a group of sectors, typically 512 bytes to 4KB in size. When a file is saved to a hard drive, it occupies one or more clusters depending on the file size. The clusters occupied by a file may not necessarily be contiguous. This allows files to be fragmented and scattered across different parts of the disk while optimizing storage space.

Cluster size is set when a disk is formatted and depends on the operating system. For example, NTFS formats disks with 4KB clusters by default while FAT32 uses smaller 512 byte clusters. Larger cluster sizes improve performance for large files while smaller clusters allow more efficient storage for many small files.

The file system keeps track of which clusters belong to each file in its allocation tables or maps. When a file is opened, the file system looks up the clusters allocated to that file and assembles them to reconstruct the file. This allows files to be stored non-sequentially and retrieved transparently by the operating system.

Clustering enables efficient use of disk space through fragmentation but can lead to slower reads/writes as the disk head moves between clusters. Periodic defragmentation consolidates files into contiguous clusters for better performance.

According to EaseUS, bad sectors are hard drive clusters that appear to be malfunctioning and can no longer reliably store data. They are detected and marked by the operating system as bad clusters to prevent data loss.

Bad Sectors

Bad sectors are areas on a hard drive that are physically damaged and can no longer reliably store data. They can occur due to manufacturing defects or physical damage to the drive from impacts or wear and tear over time (Source: https://www.howtogeek.com/173463/bad-sectors-explained-why-hard-drives-get-bad-sectors-and-what-you-can-do-about-it/).

When the hard drive encounters a bad sector, it marks it as unusable and no longer attempts to store data there. The data that was stored in that location is lost unless it is redundant across other sectors. The drive remaps the bad sector to a spare good sector, so it can continue operating normally. The drive maintains a list of bad sectors that continues to grow as more develop over time.

Most drives can tolerate a small number of bad sectors with no noticeable impact on performance or reliability. However, if the number of bad sectors exceeds the spare sector pool, data loss and performance degradation can occur. Drives with high bad sector counts may eventually fail completely. Bad sector scanning tools can identify developing problems before failure.

Defragmentation

Defragmenting a hard drive is the process of reorganizing data on the drive to improve performance. When a computer writes data to a hard drive, it attempts to store each file in contiguous blocks. However, over time as files are modified, deleted, and new data is written, files can become fragmented across the disk. This means a single file may be split into many pieces located in different areas of the hard drive.

Reading a fragmented file requires more movements of the hard drive’s read/write heads, slowing down file access. Defragmenting the drive rearranges file fragments and directory entries so that data is once again stored contiguously. This reduces the number of fragments and file access times. According to Iolo, defragmenting hard drives reorganizes scattered data, which boosts file access speed and extends the life of the drive.

Modern operating systems like Windows automatically defragment hard drives in the background. However, it can still be useful to manually defragment on occasion, especially if the computer is experiencing performance issues. There are also third party defragmentation tools that provide more options and control compared to the built-in Windows defragmenter.