Complete guide to partitioning disks, creating filesystems, and configuring persistent mounts on Linux.

Table of Contents#

  1. Overview
  2. Partition Table Types: MBR vs GPT
  3. Partitioning with fdisk
  4. Partitioning with parted
  5. Partition Type GUIDs
  6. Filesystem Comparison
  7. Creating Filesystems
  8. Swap Setup
  9. UEFI Boot Partition Setup
  10. Mounting Filesystems
  11. Persistent Mounting with fstab
  12. Troubleshooting
  13. See Also
  14. Sources

1. Overview#

Setting up storage on Linux involves three steps: partitioning the disk, creating filesystems on the partitions, and mounting those filesystems into the directory tree. The choice of partition table (MBR vs GPT), filesystem type (ext4, XFS, Btrfs), and mount options all affect performance, reliability, and compatibility.

2. Partition Table Types: MBR vs GPT#

AspectMBR (Master Boot Record)GPT (GUID Partition Table)
Maximum disk size2 TiB9.4 ZiB (effectively unlimited)
Maximum partitions4 primary (or 3 + 1 extended with logical)128 (default, configurable)
Boot firmwareLegacy BIOSUEFI (protective MBR allows limited BIOS use)
RedundancySingle copy of partition tablePrimary and backup copy at disk end
CRC protectionNoneCRC32 checksum on header and entries
Partition identification1-byte type code128-bit GUID

Recommendation: use GPT for all new installations. MBR is only necessary for legacy BIOS systems that cannot boot from GPT.

3. Partitioning with fdisk#

fdisk is an interactive, text-based partition editor. It supports both MBR and GPT (since util-linux 2.26+).

Launch fdisk#

sudo fdisk /dev/<device>

Create a GPT Partition Table#

Command: g       # Create a new GPT partition table

Create Partitions#

Command: n       # New partition
Partition number: 1
First sector: (press Enter for default)
Last sector: +512M        # 512 MiB EFI partition

Command: t       # Change partition type
Partition type: 1          # EFI System

Command: n       # New partition
Partition number: 2
First sector: (press Enter for default)
Last sector: +4G           # 4 GiB swap

Command: t       # Change partition type
Partition number: 2
Partition type: 19         # Linux swap

Command: n       # New partition
Partition number: 3
First sector: (press Enter for default)
Last sector: (press Enter for remaining space)

Command: w       # Write changes and exit

Verify#

sudo fdisk -l /dev/<device>

4. Partitioning with parted#

parted is a non-interactive alternative that supports scripting and handles GPT natively.

Interactive Mode#

sudo parted /dev/<device>
(parted) mklabel gpt
(parted) mkpart "EFI" fat32 1MiB 513MiB
(parted) set 1 esp on
(parted) mkpart "swap" linux-swap 513MiB 4609MiB
(parted) mkpart "root" ext4 4609MiB 100%
(parted) print
(parted) quit

Non-Interactive (Scripting)#

sudo parted -s /dev/<device> \
  mklabel gpt \
  mkpart "EFI" fat32 1MiB 513MiB \
  set 1 esp on \
  mkpart "swap" linux-swap 513MiB 4609MiB \
  mkpart "root" ext4 4609MiB 100%

parted vs fdisk#

Featurefdiskparted
InterfaceInteractive TUIInteractive + scriptable CLI
GPT supportYes (util-linux 2.26+)Native
Resize partitionsNoYes
AlignmentManualAutomatic (optimal)
Disk label typesMBR, GPTMBR, GPT, Sun, Mac, BSD

5. Partition Type GUIDs#

GPT partitions are identified by GUIDs. Common partition type GUIDs:

TypeGUIDfdisk Code
EFI System PartitionC12A7328-F81F-11D2-BA4B-00A0C93EC93B1
Linux filesystem0FC63DAF-8483-4772-8E79-3D69D8477DE420
Linux swap0657FD6D-A4AB-43C4-84E5-0933C84B4F4F19
Linux LVME6D6D379-F507-44C2-A23C-238F2A3DF92830
Linux RAIDA19D880F-05FC-4D3B-A006-743F0F84911E29
Linux /home933AC7E1-2EB4-4F13-B844-0E14E2AEF91528 (Linux home)
Linux root (x86-64)4F68BCE3-E8CD-4DB1-96E7-FBCAF984B70923
Microsoft basic dataEBD0A0A2-B9E5-4433-87C0-68B6B72699C711

These GUIDs enable auto-discovery by systemd-gpt-auto-generator, allowing the system to identify partition purposes without fstab entries.

6. Filesystem Comparison#

Featureext4XFSBtrfs
Max volume size1 EiB8 EiB16 EiB
Max file size16 TiB8 EiB16 EiB
JournalingYes (metadata + optional data)Yes (metadata)Copy-on-write (no journal needed)
ChecksumsMetadata only (optional)Metadata onlyData + metadata
SnapshotsNoNoYes (native, cheap)
CompressionNoNoYes (zlib, zstd, lzo)
RAID supportNo (use mdadm/LVM)No (use mdadm/LVM)Yes (native RAID 0/1/10, experimental 5/6)
Online resizeGrow onlyGrow onlyGrow and shrink
DeduplicationNoNoYes (offline)
ReflinksNoYes (since 5.1+)Yes
MaturityVery matureVery matureMature (RAID 5/6 still experimental)
Best forGeneral purpose, databasesLarge files, high throughputSnapshots, compression, flexible storage
Default onDebian, UbuntuRHEL, Rocky, FedoraopenSUSE, Fedora (Workstation option)

Choosing a Filesystem#

  • ext4 - safe default for most workloads. Well-tested, excellent fsck tooling, broad compatibility.
  • XFS - best for large files and high-throughput sequential I/O. Preferred for media servers, databases with large tablespaces.
  • Btrfs - best when you need snapshots, transparent compression, or flexible multi-device management. Excellent for desktops and NAS.

7. Creating Filesystems#

ext4#

# Basic
sudo mkfs.ext4 /dev/<device><partition>

# With label and options
sudo mkfs.ext4 -L "rootfs" -O metadata_csum /dev/<device><partition>

# With reserved block percentage (default 5%, reduce for data-only partitions)
sudo mkfs.ext4 -m 1 -L "data" /dev/<device><partition>

XFS#

# Basic
sudo mkfs.xfs /dev/<device><partition>

# With label
sudo mkfs.xfs -L "data" /dev/<device><partition>

# Force overwrite existing filesystem
sudo mkfs.xfs -f /dev/<device><partition>

Btrfs#

# Basic
sudo mkfs.btrfs /dev/<device><partition>

# With label
sudo mkfs.btrfs -L "data" /dev/<device><partition>

# RAID1 across two devices
sudo mkfs.btrfs -d raid1 -m raid1 /dev/sda1 /dev/sdb1

FAT32 (for EFI)#

sudo mkfs.fat -F 32 -n "EFI" /dev/<device><partition>

Verify Filesystem#

# Show filesystem details
sudo blkid /dev/<device><partition>

# ext4 details
sudo tune2fs -l /dev/<device><partition>

# XFS details
sudo xfs_info /dev/<device><partition>

# Btrfs details
sudo btrfs filesystem show /dev/<device><partition>

8. Swap Setup#

Partition Swap#

sudo mkswap /dev/<device><partition>
sudo swapon /dev/<device><partition>

Swap File (Alternative)#

# Create a 4 GiB swap file
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Verify Swap#

swapon --show
free -h

9. UEFI Boot Partition Setup#

UEFI systems require an EFI System Partition (ESP) formatted as FAT32.

Requirements#

  • Minimum 100 MiB (512 MiB recommended for multiple boot loaders and kernels)
  • FAT32 filesystem
  • GPT partition type EFI System (GUID C12A7328-...)
  • Mounted at /boot/efi (most distros) or /efi (systemd-boot)

Create and Configure ESP#

# Create FAT32 filesystem
sudo mkfs.fat -F 32 -n "EFI" /dev/<device>1

# Create mount point
sudo mkdir -p /boot/efi

# Mount
sudo mount /dev/<device>1 /boot/efi

# Install bootloader (example: GRUB for x86_64 UEFI)
sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB

# Generate GRUB config
sudo grub-mkconfig -o /boot/grub/grub.cfg

systemd-boot Alternative#

# Mount ESP at /efi or /boot
sudo mount /dev/<device>1 /boot

# Install systemd-boot
sudo bootctl install

10. Mounting Filesystems#

Basic Mount#

sudo mount /dev/<device><partition> /mnt

Mount with Options#

# ext4 with noatime for performance
sudo mount -o noatime,discard /dev/<device><partition> /mnt

# Btrfs with compression
sudo mount -o compress=zstd:3,noatime /dev/<device><partition> /mnt

# XFS with noatime
sudo mount -o noatime /dev/<device><partition> /mnt

# Read-only
sudo mount -o ro /dev/<device><partition> /mnt

Mount Options Reference#

OptionDescription
defaultsEquivalent to rw,suid,dev,exec,auto,nouser,async
noatimeDo not update access times (best performance)
nodiratimeDo not update directory access times
relatimeUpdate atime only if older than mtime (kernel default)
discardEnable continuous TRIM for SSDs
errors=remount-roRemount read-only on filesystem error (ext4)
compress=zstdEnable transparent compression (Btrfs)
nofailDo not fail boot if device is missing
x-systemd.automountMount on first access (systemd)
_netdevWait for network before mounting (for NFS, iSCSI)

11. Persistent Mounting with fstab#

Add entries to /etc/fstab to mount filesystems automatically at boot. Always use UUIDs instead of device names for reliability.

Find UUIDs#

sudo blkid

Example fstab#

# <filesystem>                          <mountpoint>   <type>  <options>               <dump> <pass>
UUID=<efi-uuid>                         /boot/efi      vfat    umask=0077              0      1
UUID=<root-uuid>                        /              ext4    defaults,noatime        0      1
UUID=<home-uuid>                        /home          ext4    defaults,noatime        0      2
UUID=<swap-uuid>                        none           swap    sw                      0      0
/swapfile                               none           swap    sw                      0      0
UUID=<data-uuid>                        /data          xfs     defaults,noatime        0      2
UUID=<btrfs-uuid>                       /storage       btrfs   compress=zstd:3,noatime 0      0

fstab Fields#

FieldDescription
<filesystem>Device identifier (UUID=, LABEL=, /dev/...)
<mountpoint>Where to mount (or none for swap)
<type>Filesystem type (ext4, xfs, btrfs, vfat, swap)
<options>Mount options (comma-separated)
<dump>Backup flag for dump utility (0 = skip, rarely used)
<pass>fsck order (0 = skip, 1 = root first, 2 = others)

Verify Without Rebooting#

# Test all fstab entries
sudo mount -a

# Verify
df -h
swapon --show

Troubleshooting#

IssueCauseSolution
mount: wrong fs typeFilesystem not created or wrong type specifiedRun blkid to check; create filesystem with mkfs
Boot fails after fstab editTypo in fstab or missing UUIDBoot recovery media, fix fstab; use nofail option for non-critical mounts
mkfs.ext4: Device or resource busyPartition is mounted or in useUnmount first with umount; check with lsof
GPT partition not recognized by BIOSSystem firmware does not support GPTUse MBR partition table, or update firmware to UEFI
EFI partition not detectedWrong partition type or no FAT32 filesystemSet partition type to EFI System; format as FAT32
SSD not trimmingdiscard not in mount options and no fstrim timerAdd discard to fstab, or enable fstrim.timer (preferred)
Slow performance on ext4Access time updates on busy filesystemAdd noatime mount option
Partition alignment warning in partedPartition not aligned to optimal I/O boundaryUse parted with mkpart ... 1MiB start to ensure alignment

See Also#

Sources#