1. 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 partition is regarded as a single hard drive.

1.1. 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”.

1.2. 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 also allows you to install various operating systems on the same physical drive.

  • For performance reasons, an 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.

  • Because 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.

1.3. Defining the Structure of Your Disk

1.3.1. The Simplest Way

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

[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 or more), this rule isn't critical, and smaller sizes are acceptable. Please bear in mind that the swap partition's size may be limited depending on which platform you are using. For example it is limited to 2GB in x86, PowerPC and MC680x0; to 512MB on MIPS; to 128GB on Alpha and to 3TB on Ultrasparc. Bear in mind also that the larger the swap partition, the greater the amount of OS resources (notably RAM memory) needed to manage it.

1.3.2. 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 size 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 not great, 400MB is generally enough. However, if you plan to install commercial applications, which are often located in the /opt directory, you will need to increase the size of the root partition accordingly. Alternatively, you could 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 could simply be a directory inside the root (/) partition, however you would need to increase the size of your root (/) partition accordingly.

Finally, you could also only create the Swap and root (/) partitions, in case you're not sure what you want to do with your computer. In this case, your /home directory would be located on the root partition, and so would the /usr and /var directories.

1.3.3. Exotic Configurations

When setting up your machine for specific uses –– such as a web server or a firewall –– the needs are radically different to that of 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.



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