Sub topic 4
Partitioning, Filesystems and Swap
This chapter assumes you can use a Linux shell, know what a disk and a mount point are, and have chosen a distribution and boot mode in earlier chapters. Here you decide how the installer divides the disk, which filesystems go on each part, and how much swap to give the server.
What partitioning decides
A partition table divides one physical or virtual disk into regions. Each region can hold a filesystem, swap space, or a bootloader helper. The layout you pick at install time is hard to change later, so it is worth a few minutes of thought.
Two table formats exist:
- GPT (GUID Partition Table) works with both UEFI and BIOS firmware, supports disks over 2 TiB, and stores a backup copy of the table at the end of the disk.
- MBR (Master Boot Record) is the older format. It works only up to 2 TiB and allows four primary partitions.
Use GPT for new installs. The boot mode you chose in the previous chapter sets what the layout must contain.
| Boot mode | Table | Required small partition | Mount point |
|---|---|---|---|
| UEFI | GPT | EFI System Partition (ESP), FAT32, 512 MiB to 1 GiB | /boot/efi |
| BIOS with GPT | GPT | BIOS boot partition, 1 MiB, no filesystem | none |
| BIOS with MBR | MBR | none | none |
If the installer reports that it cannot install the bootloader, a missing ESP or BIOS boot partition is the usual cause.
Choosing a layout
Simple layout
For a single-purpose server, the simplest layout is often enough:
- The boot partition (ESP or BIOS boot partition).
- An optional
/bootpartition of 1 GiB. Needed mainly with encryption or some LVM setups. - One root filesystem
/using the rest of the disk. - Swap, as a partition or a file.
One big root filesystem wastes no space. The risk is that a runaway log or upload directory can fill / and stop the whole system.
Separate mount points
Splitting directories onto their own filesystems limits that damage and lets you apply different mount options.
| Mount point | Why separate it | Typical use |
|---|---|---|
| /var | Logs, package caches and spools grow without bound | Always worth it on busy servers |
| /var/log | Keeps logs from filling the rest of /var | Log-heavy servers |
| /home | Survives a reinstall of the system | Multi-user machines |
| /tmp | Allows `nodev,nosuid,noexec` mount options | Hardened systems |
| /srv or /var/lib/... | Holds web, database or container data | Data-heavy services |
Do not over-split. Each extra partition is a fixed size that you may guess wrong. Without LVM, growing one means moving others.
Filesystems
A filesystem is the on-disk structure that stores files and metadata. For servers the realistic choices are:
| Filesystem | Strengths | Trade-offs |
|---|---|---|
| ext4 | Mature, well understood, good recovery tools | No built-in snapshots or checksums |
| XFS | Scales well with large files and parallel I/O, default on RHEL family | Can grow but cannot shrink |
| Btrfs | Snapshots, checksums, compression | More complex; RAID 5/6 modes are not recommended |
| ZFS | Snapshots, checksums, built-in RAID | Not in the mainline kernel; license issues; needs more RAM |
If you have no special need, use the distribution default: ext4 on Debian and Ubuntu, XFS on Rocky and Alma. Defaults get the most testing and the most documentation.
LVM and encryption
LVM (Logical Volume Manager) puts a flexible layer between disks and filesystems. Physical volumes (PVs) join into a volume group (VG), and you carve logical volumes (LVs) from it.
The main benefit is that you can leave free space in the volume group and grow a volume later, often while it is mounted:
# Grow the /var logical volume by 10 GiB and resize its filesystem in one step
sudo lvextend -r -L +10G /dev/vg0/varThe -r option resizes the filesystem too. This works for ext4 and XFS growth. Shrinking is possible for ext4 only, and only when unmounted.
LVM adds a layer to debug and does nothing for you if you never resize. Skip it for a VM that you can rebuild or whose disk you can enlarge. Use it when you expect storage to change on a long-lived machine.
For disk encryption, LUKS encrypts a partition or volume. It protects data on lost or stolen hardware. It does not help against a running, compromised server. It also means someone must enter a passphrase at every boot, unless you set up network-bound unlocking. A remote server with no console access is a poor fit for a passphrase prompt, so decide this before installing.
Swap
Swap is disk space the kernel uses when memory is short. It also lets the kernel move rarely used pages out of RAM to leave more room for file cache.
Common guidance for servers:
| RAM | Suggested swap |
|---|---|
| Under 2 GiB | 2x RAM |
| 2 to 8 GiB | Equal to RAM |
| Over 8 GiB | 2 to 8 GiB, or none if the workload never needs it |
Hibernation needs swap at least the size of RAM, but servers rarely hibernate. Some databases advise very little swap. Follow your application's documentation.
You can use a partition, a logical volume, or a swap file. A swap file is easier to resize:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabOn Btrfs, or on filesystems where fallocate creates holes, create the file with dd or btrfs filesystem mkswapfile instead.
The vm.swappiness setting (default 60) controls how readily the kernel swaps. Values of 10 to 30 are common on servers that should favor RAM.
Zram, a compressed swap area held in RAM, is an alternative on small machines. Fedora enables it by default.
fstab and mount options
The installer writes /etc/fstab, which lists what to mount at boot. Use UUIDs rather than device names like /dev/sdb1, because device names can change between boots.
# Show UUIDs and filesystem types
lsblk -f
# Show the current layout and mount options
findmnt --real
# Test fstab for syntax errors without rebooting
sudo findmnt --verifyA typo in fstab for a non-root mount can drop the server into emergency mode at boot. Adding nofail to non-essential mounts, such as an external data disk, lets the boot continue if that disk is missing.
Common errors
- Installer cannot install the bootloader: the ESP or BIOS boot partition is missing, or the boot mode does not match the table type.
- Root fills up: logs or data share
/. Fix by moving data to its own volume and adding limits such as log rotation. - Out of inodes with free space showing:
df -ishows inode use. This happens on ext4 with millions of small files. - Cannot shrink XFS: back up, recreate, and restore, or avoid XFS where shrinking is likely.
- Swap not active after reboot: the
/etc/fstabentry is missing. - Server hangs at boot after an
fstabedit: boot into rescue mode and fix the line.
Guided versus manual partitioning
Guided installers apply a sensible default: ESP or boot partition, a root filesystem, and swap. Use manual mode when you need a separate /var, LVM with spare space, RAID, or encryption. Write down the plan first, with sizes, so you are not deciding under installer prompts.
Exercise
A UEFI server boots from a GPT disk. Your plan has a root filesystem and swap but no other partition. The installer fails at the bootloader step. What is missing, what filesystem type does it need, and where is it mounted?
Show answer
It is missing the EFI System Partition. It must be formatted as FAT32, be around 512 MiB to 1 GiB, and be mounted at /boot/efi.
Exercise
A busy web server stores logs and uploads under /var on a single root filesystem. The root filesystem filled up last month and services stopped. Name two changes to the layout that would limit this, and one risk of making many small separate partitions.
Show answer
Put /var (or /var/log and the upload directory) on its own filesystem, preferably on LVM so it can grow, and leave free space in the volume group. The risk of many small fixed partitions is that you guess a size wrong, and without LVM you cannot easily grow one without moving others.