Complete guide to partitioning disks, creating filesystems, and configuring persistent mounts on Linux.
Table of Contents#
- Overview
- Partition Table Types: MBR vs GPT
- Partitioning with fdisk
- Partitioning with parted
- Partition Type GUIDs
- Filesystem Comparison
- Creating Filesystems
- Swap Setup
- UEFI Boot Partition Setup
- Mounting Filesystems
- Persistent Mounting with fstab
- Troubleshooting
- See Also
- 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#
| Aspect | MBR (Master Boot Record) | GPT (GUID Partition Table) |
|---|---|---|
| Maximum disk size | 2 TiB | 9.4 ZiB (effectively unlimited) |
| Maximum partitions | 4 primary (or 3 + 1 extended with logical) | 128 (default, configurable) |
| Boot firmware | Legacy BIOS | UEFI (protective MBR allows limited BIOS use) |
| Redundancy | Single copy of partition table | Primary and backup copy at disk end |
| CRC protection | None | CRC32 checksum on header and entries |
| Partition identification | 1-byte type code | 128-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 tableCreate 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 exitVerify#
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) quitNon-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#
| Feature | fdisk | parted |
|---|---|---|
| Interface | Interactive TUI | Interactive + scriptable CLI |
| GPT support | Yes (util-linux 2.26+) | Native |
| Resize partitions | No | Yes |
| Alignment | Manual | Automatic (optimal) |
| Disk label types | MBR, GPT | MBR, GPT, Sun, Mac, BSD |
5. Partition Type GUIDs#
GPT partitions are identified by GUIDs. Common partition type GUIDs:
| Type | GUID | fdisk Code |
|---|---|---|
| EFI System Partition | C12A7328-F81F-11D2-BA4B-00A0C93EC93B | 1 |
| Linux filesystem | 0FC63DAF-8483-4772-8E79-3D69D8477DE4 | 20 |
| Linux swap | 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F | 19 |
| Linux LVM | E6D6D379-F507-44C2-A23C-238F2A3DF928 | 30 |
| Linux RAID | A19D880F-05FC-4D3B-A006-743F0F84911E | 29 |
| Linux /home | 933AC7E1-2EB4-4F13-B844-0E14E2AEF915 | 28 (Linux home) |
| Linux root (x86-64) | 4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709 | 23 |
| Microsoft basic data | EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 | 11 |
These GUIDs enable auto-discovery by systemd-gpt-auto-generator, allowing the system to identify partition purposes without fstab entries.
6. Filesystem Comparison#
| Feature | ext4 | XFS | Btrfs |
|---|---|---|---|
| Max volume size | 1 EiB | 8 EiB | 16 EiB |
| Max file size | 16 TiB | 8 EiB | 16 EiB |
| Journaling | Yes (metadata + optional data) | Yes (metadata) | Copy-on-write (no journal needed) |
| Checksums | Metadata only (optional) | Metadata only | Data + metadata |
| Snapshots | No | No | Yes (native, cheap) |
| Compression | No | No | Yes (zlib, zstd, lzo) |
| RAID support | No (use mdadm/LVM) | No (use mdadm/LVM) | Yes (native RAID 0/1/10, experimental 5/6) |
| Online resize | Grow only | Grow only | Grow and shrink |
| Deduplication | No | No | Yes (offline) |
| Reflinks | No | Yes (since 5.1+) | Yes |
| Maturity | Very mature | Very mature | Mature (RAID 5/6 still experimental) |
| Best for | General purpose, databases | Large files, high throughput | Snapshots, compression, flexible storage |
| Default on | Debian, Ubuntu | RHEL, Rocky, Fedora | openSUSE, 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/sdb1FAT32 (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 /swapfileVerify Swap#
swapon --show
free -h9. 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(GUIDC12A7328-...) - 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.cfgsystemd-boot Alternative#
# Mount ESP at /efi or /boot
sudo mount /dev/<device>1 /boot
# Install systemd-boot
sudo bootctl install10. Mounting Filesystems#
Basic Mount#
sudo mount /dev/<device><partition> /mntMount 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> /mntMount Options Reference#
| Option | Description |
|---|---|
defaults | Equivalent to rw,suid,dev,exec,auto,nouser,async |
noatime | Do not update access times (best performance) |
nodiratime | Do not update directory access times |
relatime | Update atime only if older than mtime (kernel default) |
discard | Enable continuous TRIM for SSDs |
errors=remount-ro | Remount read-only on filesystem error (ext4) |
compress=zstd | Enable transparent compression (Btrfs) |
nofail | Do not fail boot if device is missing |
x-systemd.automount | Mount on first access (systemd) |
_netdev | Wait 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 blkidExample 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 0fstab Fields#
| Field | Description |
|---|---|
<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 --showTroubleshooting#
| Issue | Cause | Solution |
|---|---|---|
mount: wrong fs type | Filesystem not created or wrong type specified | Run blkid to check; create filesystem with mkfs |
| Boot fails after fstab edit | Typo in fstab or missing UUID | Boot recovery media, fix fstab; use nofail option for non-critical mounts |
mkfs.ext4: Device or resource busy | Partition is mounted or in use | Unmount first with umount; check with lsof |
| GPT partition not recognized by BIOS | System firmware does not support GPT | Use MBR partition table, or update firmware to UEFI |
| EFI partition not detected | Wrong partition type or no FAT32 filesystem | Set partition type to EFI System; format as FAT32 |
| SSD not trimming | discard not in mount options and no fstrim timer | Add discard to fstab, or enable fstrim.timer (preferred) |
| Slow performance on ext4 | Access time updates on busy filesystem | Add noatime mount option |
| Partition alignment warning in parted | Partition not aligned to optimal I/O boundary | Use parted with mkpart ... 1MiB start to ensure alignment |