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, up to 67 (3 primary partitions and a secondary partition containing up to 64 logical partitions inside): 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 with 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 may be 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 across different partitions could limit data loss if your hard disk is physically damaged.

Normally, the partition type specifies the file system which 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

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

[Tip]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 isn't 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 root and labelled as /. It will contain the programs required to start your system and to perform basic maintenance.

Therefore 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 also acts as a mount point for other partitions (see Chapter 8, File Systems and Mount Points).

The needs of the root partition in terms of size are very limited, 400MB 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 the /usr/ directory. 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 100MB for a very lightweight installation, to several GB for a full installation. A compromise of two or three GB (depending on your disk size) is usually sufficient.

Home directories: /home/

This directory contains the personal directories for all of the users hosted on your machine. The partition size depends on the number of users 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 could be relatively small. In these situations, you're encouraged to carefully think about your needs before even beginning the installation process.

[Tip]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'll even be able to move a crowded partition to a brand new hard drive.



[1] the default file system under Mandrakelinux is called ext3