Structure of a Hard Disk

Abstract

A disk is physically divided into sectors. A sequence of sectors can form a partition. Roughly speaking, you can create as many partitions as you wish: each of them is regarded as a single hard drive.

Sectors

To simplify, a hard disk is merely a sequence of sectors, which are the smallest data unit on a hard disk. The typical size of a sector is 512 bytes. The sectors on a hard disk of “n” sectors are numbered from “0” to “n-1”.

Partitions

The use of multiple partitions enables you to create many virtual hard drives on your real physical drive. This has many advantages:

  • Different operating systems use different disk structures (called file systems): this is the case for Windows and GNU/Linux. Having multiple partitions on a hard drive allows you to install various operating systems on the same physical drive.

  • For performance reasons, a single operating system may prefer different drives with various file systems on them because they are used for completely different things. One example is GNU/Linux which requires a second partition called “swap”. The latter is used by the virtual memory manager as virtual memory.

  • Even if all of your partitions use the same file system, it may prove useful to separate the different parts of your OS into different partitions. A simple configuration example would be to split your files into two partitions: one for your personal data, and another one for your programs. This allows you to update your OS, completely erasing the partition containing the programs while keeping the data partition safe.

  • Physical errors on a hard disk are generally located on adjacent sectors, not scattered across the disk. Distributing your files onto different partitions will limit data loss in case your hard disk is physically damaged.

Normally, the partition type specifies the file system that the partition is supposed to contain. Each operating system might recognize some partition types, but not others. Please see Chapter 8, File Systems and Mount Points and Chapter 9, The Linux File System for more information.

Defining the Structure of Your Disk

The Simplest Way

That scenario would imply only two partitions: one for the swap space, the other one for the files[1].

Tip

A rule of thumb is to set the swap partition size to twice the size of your RAM memory (i.e.: if you have 128 MB of RAM memory the swap size should be of 256 MB). However for large memory configurations (>512 MB), this rule is not critical, and smaller sizes are acceptable.

Another Common Scheme

Separate data from programs. To be even more efficient, one usually defines a third partition called the root” and labelled as /. It will contain the programs required to start up your system and perform basic maintenance.

Hence we could define four partitions:

Swap

A swap partition whose size is roughly twice the amount of physical RAM.

Root: /

The most important partition. Not only does it contain critical data and programs for the system, it will also act as a mount point for other partitions.

The needs of the root partition in terms of size are very limited, 300MB is generally enough. However, if you plan to install commercial applications, which are most often located in the /opt directory, you will need to increase the size of the root partition. Alternatively, you may create a separate partition for /opt.

Static data: /usr

Most packages install the majority of their executables and data files under /usr. The advantage of creating a separate partition is that it allows you to easily share it with other machines over a network.

The recommended size depends on the packages you wish to install, and can vary from 100 MB for a very lightweight installation, to several GB for a full installation. A compromise of one or two GB (depending on your disk size) is usually sufficient.

Home directories: /home

This directory contains the personal directories for all the users hosted on the machine. Generally speaking, it also hosts the directories served by HTTP for web browsers and FTP for file transfers.

The partition size depends on the number of users (or services) hosted and their needs.

Another solution is to not create a separate partition for the /usr files: /usr will simply be a directory inside the root (/) partition.

Exotic Configurations

When setting up your machine for specific uses –– such as a web server or a firewall ––, the needs are radically different than for a standard desktop machine. For example, a FTP server will probably need a large separate partition for /var/ftp, while the /usr directory will be relatively small. In these situations, you are encouraged to carefully think about your needs before even beginning the installation process.

Tip

If you need to resize your partitions or use a different partition scheme, note that it is possible to resize most partitions without the need to reinstall your system and without losing your data. Please consult Managing Your Partitions of the Starter Guide .

With some practice, you will even be able to move a crowded partition to a brand new hard drive.



[1] the file system currently used for GNU/Linux files is called ext3