There is no bigger frustration then setting up and configuring a new system, only to discover that the drive partitions are too small or won’t properly support some feature (such as encryption or multi-boot). While it is possible to move, resize, add, or remove partitions after the fact, it can get complex and any mistake leave the system unstable, unusable, or unbootable. To avoid these headaches, it is always best to determine the long-term usage and storage needs before installing the operating system, then layout and partition the drives ahead of installation.

To Swap Partition Or Not To Swap Partition

There are plenty of good reasons to prefer a swap partition over a swap file. In general, I tend to use swap files. First, the swap space for hibernation should be at least twice the size of the RAM. So when increasing RAM, I find it easier to change the swap file over increasing the swap partition (especially if there isn’t room in the disk layout to do so). Second, in a multi-boot scenario, sharing a swap partition can lead to issues and corruption if any of the operating systems will hibernated. To prevent this, give each OS its own swap file. However, in a multi-boot scenario, a separate swap file for each operating system requires more disk space, as well as possibly having to expand multiple swap files instead of a single swap partition when (if) the RAM is increased.

Basic Partitions and Mount Points

I typically setup Linux with 5 partitions \ mount points; /boot/EFI, /boot, /, /var, and /home,

/boot/EFI

This is the partition used by the UEFI and serves as the EFI System Partition. It stores the EFI bootloader and other EFI related items. The reason for separating this out from /boot directory is that the kernel is stored in the /boot directory. This allows for multi-boot configurations as each OS will need its own partition for its kernel. Normally 512 MB is enough, but I size it 1 GB so additional space is available if needed during upgrades (or for debug purposes).

/boot

This partition is not needed for UEFI systems, however, if the root (/) partition will be fully encrypted, then this partition is needed to load and access the unencrypted kernel and allow decryption of the encrypted partitions. Normally 512 MB is enough, but I size it 1 GB so additional space is available if needed during upgrades (or for debug purposes).

/ (root directory)

The root directory is the top of the hierarchy of the system. The contents of the root file system must be adequate to boot, restore, recover, and/or repair the system. Therefore, regardless of the intent or needs of the system, I keep the /etc and /usr directories on the same partition as the root (/) directory (i.e. /etc and /usr never get their own partitions or mount points).

/var

The /var directory stores variable system data such as the spool, log, and cache directories and files. As these files are the most frequent disk reads and writes, for old spinning drives there were performance advantages for locating this data in the highest bandwidth part of the disk. With newer SSD, this is no longer a consideration. I separate this solely to prevent run-away software logging (or poor configuration \ maintenance) from filling up the root (/) partition and crashing the entire system. On a typical desktop system 12 to 20 GB is sufficient, but on a database or web server much more may be needed. In addition, I store the swap file here, so that space needs to be included when determining how big to make this partition. For example, on a desktop system setup where the swap file will be 8 GB, I will size this partition to 32 GB. However, on a server with a 32 GB swap file, I would size it to at least 64 GB.

/home

There are pros and cons of having the /home directory on its own partition. As most of my setups are virtual machines, for desktop systems I always have a separate mount for the /home directory. In fact, I use a separate disk for it. First, in a virtual environment, resizing is relatively simple. Secondly it allows moving (or copying) the virtual disk to another setup, thereby preserving and reusing the data and configuration information. However, for dedicated servers where the only users will be basic administrator accounts, there is rarely a need to resize, nor any data or configuration information that needs to be reused. In these cases, I don’t create a separate partition, mount, or disk.

Other Partitions

/opt

The /opt partition directory is for add-on application software packages. Some packages such as desktop environments and related applications can be relatively large. This is especially true If multiple installations and versions are going to be used. In addition, if the intent is to build several applications from source, it may be wise to have a separate partition and disk for the /opt directory.

Application Specific Partitions

Depending on the setup, the log files for a web server can grow quite large, so it may be useful to dedicate a partition (and maybe even a disk) to them (i.e. /var/log/nginx or /var/log/apache2). Likewise there may be reasons to have dedicated partitions for databases and their log files (/var/lib/mysql and /var/log/mysql), or the upper data storage directory for a file server.

Final Layout

When laying out the partitions, and depending on the disk size and the needed sizes of the partitions, it is often useful to leave unallocated space in strategic locations to allow expansion when (if) needed. The following are example layouts for a basic Linux installation using two (2) 64 GB disks. One with a 16 GB swap file in the /var directory, and one with a 16 GB swap partition. Without a swap partition the unallocated space is between the root (/) directory and the /var directory. With the swap partition, the unallocated space is between swap partition and the root (/) partition, and after the /var partition.

Example Layout with 16 GB Swap File
Partition — Size — Mount

——————————-
sda1 ——- 1 GB — /boot/EFI
sda2 ——- 1 GB — /boot
sda3 —— 16 GB — /
unused — 14 GB
sda4 —— 32 GB — /var
——————————-
sdb1 —— 64 GB — /home

Example Layout with 16 GB Swap Partition
Partition — Size — Mount

——————————-
sda1 ——- 1 GB — /boot/EFI
sda2 ——- 1 GB — /boot
sda3 —— 16 GB — swap
unused —– 7 GB
sda4 —— 16 GB — /
sda5 —— 16 GB —/var
unused —- 7 GB
——————————-
sdb1 —— 64 GB — /home

Additional Resources

The following are links to the partition requirements \ suggestions for various Linux distributions.

Leave a Reply