Save 10%Pay yearly on any plan. 6% half-yearly, 3% quarterly. Help centreWhatsAppTelegram TeamsOpen a ticket

Disk Partitioning in Linux: What It Is and How to Lay Out a Disk

What a partition is, MBR and GPT, which partitions a Linux system needs, sensible layouts for a desktop and a server, and the tools that create them.

3 min readBy Swati

Reviewed by the AmazingRDP technical team

Disk partitioning in Linux

Practise on a server you can reinstall in minutes. A Linux VPS gives you root access. See Linux VPS from $6.99

A disk is one long row of storage blocks. Partitioning divides that row into sections, and each section can hold its own filesystem, be mounted at its own place, or belong to a different operating system. Linux can live in a single partition, and often should. Knowing when to use more is what this page is about.

Why split a disk at all

  • Containment. If logs fill a separate /var, the rest of the system keeps working.
  • Reinstalling without losing data. With /home on its own partition, the system can be replaced around it.
  • Different rules per area: a data partition without permission to run programs, or encrypted while the system is not.
  • Several systems on one disk, such as Windows beside Linux.

The price is rigidity: space left over in one partition cannot be used by another without resizing.

MBR or GPT

The partition table at the start of the disk records where the partitions are. Two formats exist.

MBR (older)GPT (current)
Largest disk2 TBFar beyond any disk you can buy
PartitionsFour primary; more only inside an "extended" one128 by default, no tricks
Safety copyNoneA second copy at the end of the disk
Starts withClassic BIOSUEFI (and BIOS, with a small extra partition)

Use GPT for anything new. MBR remains on old machines and on some small virtual server images.

The partitions a Linux system uses

PartitionPurposeTypical size
/ (root)The system itself. The only one that is always required25 GB or more
EFI system partitionStart-up files on UEFI machines; mounted at /boot/efi500 MB to 1 GB
SwapOverflow for memory; can also be a file inside /2 to 8 GB; equal to memory if the machine hibernates
/homeUsers' filesThe rest, on a desktop
/varLogs, databases, mail, containersBy what the server does
/bootKernels; needed separately with some encryption and LVM setups1 GB

Sensible layouts

  • Desktop or laptop: EFI, root and a swap file. Add a separate /home if you reinstall often. This is what installers choose by themselves.
  • Small server or VPS: one root partition. The disk is small, and a wrong split wastes more than it protects.
  • Larger server: EFI, /boot, and the rest handed to LVM, with logical volumes for root, /var and data. Volumes can be grown later while the system runs, which removes the main drawback of partitions: see setting up LVM.
  • Data disks: one partition across the whole disk, mounted where the data belongs.

How Linux names disks and partitions

NameIs
/dev/sda, /dev/sdbFirst and second SATA or SCSI disk
/dev/sda1First partition on the first disk
/dev/nvme0n1, /dev/nvme0n1p2First NVMe disk; its second partition
/dev/vdaA virtual disk on many VPS platforms

Look before you touch

lsblk -f
sudo fdisk -l
sudo parted -l

lsblk -f is the clearest: every disk and partition as a tree, with filesystem type and mount point. None of the three changes anything.

The tools that change things

ToolStyle
fdiskInteractive, in the terminal; nothing is written until you type w
partedTerminal; changes apply at once; good in scripts
cfdiskMenus in the terminal
GParted, GNOME DisksGraphical; can also resize and move

These tools erase data without a second question if pointed at the wrong disk. Check the device name twice with lsblk, and have a backup.

From empty disk to usable space

Adding a second disk to a server takes four steps: create a partition table and a partition, make a filesystem on it, mount it, and make the mount permanent.

sudo parted /dev/sdb --script mklabel gpt mkpart primary ext4 0% 100%
sudo mkfs.ext4 /dev/sdb1
sudo mkdir /data
sudo mount /dev/sdb1 /data

The last step, the line in /etc/fstab, is explained in how to mount and automount drives. Check the result with findmnt.

Changing a layout later

  • Growing the last partition into free space is routine: growpart, then resize2fs or xfs_growfs. This is what happens after a VPS is moved to a bigger plan.
  • Shrinking and moving are slow and risky; do them from a USB system with a full backup. XFS cannot be shrunk at all.
  • Encryption is best decided at the start: see encrypting a disk with LUKS.

How full each partition is: monitoring disk space in Linux. For a server on which a mistake costs only a reinstall, see our Linux VPS plans.

Questions

What is disk partitioning?

Dividing a disk into sections that can each hold their own filesystem and be mounted or used separately.

Should I use MBR or GPT?

GPT for anything new. MBR is limited to 2 TB and four primary partitions.

Which partitions does Linux need?

Only a root partition, plus an EFI system partition on UEFI machines. Swap, /home and /var are optional.

How do I list partitions in Linux?

Run lsblk -f.