An introduction to disk partitions

Strictly applicable to AMD64 and Intel 64 architectures. General concepts may apply to other systems.

Hard disks perform a very simple function – they store data and reliably retrieve it on demand.

An unused disk drive can be thought of as an empty wall. To store data on a drive, it is necessary to format the disk drive first. Formatting (also known as “making a file system“) writes information to the drive, creating order out of the empty space in an unformatted drive. Extending our empty room analogy, formatting is akin to putting storage shelves on the wall.

The order imposed by a file system involves some trade-offs:

  • a small portion of available space is used to store file system metadata, this can be considered as overhead
  • the remaining space is quantised, i.e. split into small, consistently-sized segments. Linux calls these segments blocks.

There are many file systems, each with their own pros and cons. Different file systems tend to be incompatible and operating system may not support all the file systems out there.

Above is an example of a partially filled disk. It’s not possible to determine how many files reside on this drive from that picture. There may only be one file or many. All files use at least one block and some use multiple blocks. Moreover, blocks do not have to form a contiguous region; used and unused blocks may be interspersed. This is known as fragmentation.

Partitions

Disk drives can be divided into partitions. Each partition can be treated as a separate disk, called a logical drive. Partitioning enables:

  • logical separation of the operating system data from user data
  • use of different file systems
  • running multiple operating systems on one machine

Partitioning is achieved through the introduction of a partition table. A partition table is stored at the very start of the disk, before any file system or user data. Each partition table entry contains:

  • the points on the disk where the partition starts and ends. This defines a partition’s size and location on the disk.
  • whether the partition is active. The active flag is used by some operating systems’ boot loaders, in that, the OS in the partition that is marked active is booted.
  • the partition’s type. It’s a number that indicates a partition’s anticipated usage. Some OS use this value to indicate that the partition has:
    • a specific file system type, or
    • a particular operating system, or
    • a bootable operating system, or
    • some combination of the above

Primary partitions

The partition table is divided into sections and each section can hold the information necessary to define a single partition. These canonical partitions are called primary partitions.

Logical partitions

A primary partition can be of type Extended. Such an extended partition has its own partition table which points to one or more partitions, which are called logical partitions. Logical partitions are contained entirely within the extended partition (which is a primary partition mind).

Standards

There are currently two partitioning layout standards for physical hard disks: Master Boot Record (MBR) and GUID Partition Table (GPT). MBR is older and used with BIOS-based computers. GPT is newer and part of the Unified Extensible Firmware Interface (UEFI).

Partition LayoutPrimaryLogicalMax. addressable space (in TB)
MBR4∞*2.2
GPT128∞*2,000,888,344
* = due to the way partitioned are accessed in Linux, no more than 12 logical partitions should be defined on a physical disk.
† = GPT by default supports 128 primary partitions but this can be extended by allocating more space to the partition table.

Partition Naming Schemes

In Windows, each partition gets a “drive letter”. You then use the correct drive letter to refer to files and directories on its corresponding partition. This is entirely different from how Linux deals with partitions and disk storage.

Partitions in Linux uses a naming scheme that is file-based, with file names in the form of /dev/xxyN.

/dev/Name of the directory in which all device files reside. Because partitions reside on hard disks, and hard disks are devices, the files representing all possible partitions are stored here.
xxIndicate the type of device on which the partition lives, usually sd.
yIndicates which device the partition is on. E.g. /dev/sdb for the second hard disk.
NDenotes the partition. In MBR, the first four primary partitions are number 1 through 4. Logical partitions start at 5. E.g. /dev/sda3 is the third primary partition on first hard disk. /dev/sdb6 is the second logical partition on the second hard disk.

Mount points

To create a single set of files and directories, each partition is associated with a directory through a process known as mounting. Mounting a partition makes its storage available starting at the specified directory known as the mount point.

For example, if partition /dev/sda5 is mounted on /usr/, then all files and directories under /usr/ are physically stored on /dev/sda5. But a file in say /etc/dnf would not.

Continuing the example above, it is also possible that one or more directories below /usr/ would be mount points for other partitions. For instance, /dev/sda6 could be mounted on /usr/local, meaning that /usr/local/man/whatis would then reside on /dev/sda6 rather than /dev/sda5.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s