How to Partition Linux

How to Partition Linux Partitioning a Linux system is a foundational skill that empowers users to organize their storage efficiently, enhance system performance, improve data security, and simplify backups and recovery. Whether you're installing Linux for the first time, upgrading an existing system, or optimizing a server environment, understanding how to partition Linux correctly can make the di

Nov 6, 2025 - 09:55
Nov 6, 2025 - 09:55
 2

How to Partition Linux

Partitioning a Linux system is a foundational skill that empowers users to organize their storage efficiently, enhance system performance, improve data security, and simplify backups and recovery. Whether you're installing Linux for the first time, upgrading an existing system, or optimizing a server environment, understanding how to partition Linux correctly can make the difference between a stable, high-performing machine and one plagued by disk space issues, boot failures, or data loss.

Unlike Windows, which often relies on a single C: drive, Linux embraces a modular approach to storage. Each partition serves a distinct purposefrom holding the operating system files to storing user data, logs, or temporary files. Proper partitioning ensures that one components failure or excessive growth doesnt cripple the entire system. For example, if /var fills up due to log files, a well-partitioned system prevents it from consuming all available space and crashing the system.

This guide provides a comprehensive, step-by-step walkthrough of Linux partitioningfrom planning your layout to executing it with industry-standard tools. Whether you're a system administrator, a developer, or an enthusiast setting up a home server, this tutorial will equip you with the knowledge to partition Linux confidently and securely.

Step-by-Step Guide

Step 1: Understand Your Storage Goals

Before touching any partitioning tool, define your objectives. Ask yourself:

  • Will this system be used for personal computing, web hosting, database storage, or development?
  • Do you need to dual-boot with another OS like Windows?
  • How much data will users generate? Will logs, caches, or containers grow rapidly?
  • Do you require encryption or separate mount points for security or compliance?

Answering these questions informs your partition layout. For example, a server running Docker and databases will benefit from separate partitions for /var/lib/docker and /var/lib/mysql. A desktop user may prioritize a large /home partition for personal files.

Step 2: Choose a Partitioning Scheme

Linux supports several partitioning schemes, but the most common are:

  • Traditional MBR (Master Boot Record): Supports up to 4 primary partitions or 3 primary + 1 extended partition. Limited to 2TB disk size. Suitable for older hardware.
  • GPT (GUID Partition Table): Modern standard. Supports disks larger than 2TB, up to 128 partitions, and includes redundancy for partition table recovery. Recommended for all new installations.

Use fdisk -l or lsblk to check your disks current partition table. If the disk is new or unpartitioned, GPT is the default choice on most modern Linux installers.

Step 3: Identify Your Disk

Before partitioning, identify the target disk. Use the following commands:

lsblk

This lists all block devices. Look for your target disk (e.g., /dev/sda, /dev/nvme0n1). Avoid selecting the wrong diskpartitioning erases all data on the selected device.

To get more details, use:

sudo fdisk -l /dev/sda

Ensure the disk is not mounted. If it contains a mounted filesystem, unmount it first:

sudo umount /dev/sda1

Step 4: Launch a Partitioning Tool

Linux offers multiple partitioning tools. The most reliable for manual partitioning are:

  • fdisk: Text-based, ideal for MBR and basic GPT tasks.
  • gdisk: GPT-specific, more robust for modern disks.
  • cfdisk: Curses-based interface, user-friendly for beginners.
  • parted: Scriptable, supports advanced operations like resizing.

For this guide, well use gdisk for GPT disks and fdisk for MBR. Launch gdisk:

sudo gdisk /dev/sda

Youll see a prompt like:

Command (? for help):

Step 5: Create Partitions

Use the following commands within gdisk or fdisk:

  • n: Create a new partition.
  • p: Print partition table.
  • w: Write changes and exit.
  • d: Delete a partition.
  • t: Change partition type.

Heres a recommended partition layout for a typical desktop or server:

Mount Point Size Type Purpose
/boot/efi 512 MB EFI System Partition (ESP) Bootloader storage for UEFI systems
/boot 1 GB Linux filesystem Kernel and initramfs files
/ 2050 GB Linux filesystem Root filesystem (OS binaries, config files)
/home Remaining space Linux filesystem User data and settings
swap 28 GB Linux swap Virtual memory

For servers with heavy I/O or databases, consider:

  • /var: 1020 GB (logs, mail, databases)
  • /tmp: 510 GB (temporary files, often mounted with noexec and nosuid)
  • /opt: For third-party software

Create partitions one by one:

  1. Type n to create a new partition.
  2. Press Enter to accept the default first sector.
  3. Enter size: +512M for /boot/efi.
  4. When prompted for a type code, enter ef00 (EFI System).
  5. Repeat for /boot: n, accept defaults, size +1G, type 8300 (Linux filesystem).
  6. For root: n, size +30G, type 8300.
  7. For swap: n, size +8G, type 8200 (Linux swap).
  8. For /home: n, accept default last sector to use remaining space, type 8300.

Verify your layout with p. If correct, type w to write changes.

Step 6: Format Partitions

After partitioning, each partition must be formatted with a filesystem. Linux supports many, but the most common are:

  • ext4: Default for most Linux systems. Journaling, reliable, good performance.
  • xfs: High-performance, ideal for large files and servers.
  • btrfs: Advanced features like snapshots and RAID, but less mature for production.
  • fat32: Required for EFI system partition.

Format each partition:

sudo mkfs.vfat -F 32 /dev/sda1        

EFI partition

sudo mkfs.ext4 /dev/sda2

/boot

sudo mkfs.ext4 /dev/sda3

/

sudo mkswap /dev/sda4

swap

sudo mkfs.ext4 /dev/sda5

/home

For XFS (recommended for servers):

sudo mkfs.xfs /dev/sda3

sudo mkfs.xfs /dev/sda5

Step 7: Enable Swap

After formatting the swap partition, activate it:

sudo swapon /dev/sda4

To make it permanent, add it to /etc/fstab after mounting (covered next).

Step 8: Mount Partitions

Mount the partitions to their respective directories to prepare for OS installation:

sudo mount /dev/sda3 /mnt          

mount root

sudo mkdir -p /mnt/boot

sudo mount /dev/sda2 /mnt/boot

sudo mkdir -p /mnt/boot/efi

sudo mount /dev/sda1 /mnt/boot/efi

sudo mkdir -p /mnt/home

sudo mount /dev/sda5 /mnt/home

These mounts are temporary. After installing the OS, the system will auto-mount them via /etc/fstab.

Step 9: Install the Operating System

Now that partitions are created and formatted, proceed with your Linux installer (e.g., Ubuntu, Fedora, Arch). During installation:

  • Select Manual partitioning or Something else.
  • Assign each partition to its mount point.
  • Set the EFI partition as boot loader device.
  • Ensure swap is enabled.
  • Do NOT format the /home partition if upgrading or preserving data.

If installing manually (e.g., Arch Linux), continue with:

pacstrap /mnt base linux linux-firmware

genfstab -U /mnt >> /mnt/etc/fstab

arch-chroot /mnt

Then install a bootloader like GRUB:

grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB

grub-mkconfig -o /boot/grub/grub.cfg

Step 10: Verify and Reboot

After installation, reboot and verify:

df -h

This should show all partitions mounted correctly. Check swap:

swapon --show

Use lsblk to confirm the partition layout matches your plan. If everything looks correct, your Linux system is now properly partitioned.

Best Practices

Use Separate Partitions for Critical Directories

Never rely on a single root partition. Isolating /home, /var, /tmp, and /boot prevents system-wide failures. For example:

  • If /var fills with logs, the system remains bootable.
  • If /tmp overflows, user data in /home remains untouched.
  • If /boot becomes corrupted, you can reinstall the kernel without touching user files.

Choose the Right Filesystem

ext4 is safe for most use cases. For high-throughput environments (databases, media servers), use XFS. Avoid Btrfs unless you need snapshots or RAID and understand its trade-offs. For EFI, FAT32 is mandatory.

Plan for Growth

Leave 1015% free space on every partition. Filesystems degrade in performance as they approach full capacity. Also, consider future expansion: if you plan to add more users or applications, over-provision /home and /var.

Enable Encryption for Sensitive Data

Use LUKS (Linux Unified Key Setup) to encrypt /home or the entire root filesystem. This is critical for laptops or systems handling personal or confidential data. Encryption can be applied during installation in most modern distributions.

Use UUIDs, Not Device Names, in /etc/fstab

Device names like /dev/sda1 can change after hardware updates. Use UUIDs instead:

sudo blkid

Then edit /etc/fstab using UUIDs:

UUID=1234-5678 / ext4 defaults 0 1

UUID=abcd-efgh /home ext4 defaults 0 2

This ensures reliable mounting regardless of hardware order.

Separate /tmp with Security Flags

Mount /tmp with noexec, nosuid, and nodev to prevent malicious code execution:

/dev/sda6 /tmp ext4 defaults,noexec,nosuid,nodev 0 2

Backup /etc/fstab Before Editing

Always create a backup before modifying fstab:

sudo cp /etc/fstab /etc/fstab.bak

A misconfigured fstab can prevent your system from booting. If this happens, boot from a live USB and repair the file.

Test Your Setup

After partitioning and mounting, simulate a disk fill:

dd if=/dev/zero of=/tmp/testfile bs=1M count=500

Then delete it:

rm /tmp/testfile

This tests write permissions and space allocation. Monitor with df -h during the process.

Document Your Partition Layout

Keep a written record of your partition scheme: mount points, sizes, filesystems, and UUIDs. This is invaluable for troubleshooting, backups, or future upgrades.

Tools and Resources

Core Linux Tools

  • fdisk: Classic partitioning tool for MBR and basic GPT. Available on all Linux systems.
  • gdisk: GPT-specific, more reliable than fdisk for modern disks. Part of the gptfdisk package.
  • cfdisk: Interactive ncurses interface. Easier for beginners than fdisk.
  • parted: Supports advanced operations like resizing and aligning partitions. Scriptable.
  • lsblk: Lists block devices in a tree format. Excellent for quick overviews.
  • blkid: Displays UUIDs and filesystem types of partitions.
  • mkfs: Creates filesystems (mkfs.ext4, mkfs.xfs, mkfs.vfat).
  • swapon and swapoff: Enable/disable swap partitions.

GUI Tools (For Desktop Users)

  • GParted: Most popular GUI partition editor. Supports resizing, moving, and formatting partitions. Requires a live environment for system disk changes.
  • Disks (gnome-disks): Built into GNOME. Simple interface for formatting and managing partitions.

While GUI tools are user-friendly, they are not recommended for servers or remote systems. Command-line tools offer precision and automation.

Automation and Scripting

For deploying multiple systems, automate partitioning with scripts. Example using parted:

!/bin/bash

DISK="/dev/sda"

parted -s $DISK mklabel gpt

parted -s $DISK mkpart primary fat32 1MiB 513MiB

parted -s $DISK mkpart primary ext4 513MiB 1513MiB

parted -s $DISK mkpart primary ext4 1513MiB 32GiB

parted -s $DISK mkpart primary linux-swap 32GiB 40GiB

parted -s $DISK mkpart primary ext4 40GiB 100%

parted -s $DISK set 1 esp on

Run this script during a PXE boot or cloud-init deployment to standardize installations.

Online Resources

Real Examples

Example 1: Desktop Linux Installation

Scenario: A user installs Ubuntu 22.04 on a 500GB SSD for personal use (documents, media, development).

Partition Layout:

  • /boot/efi: 512MB (FAT32)
  • /boot: 1GB (ext4)
  • /: 50GB (ext4)
  • /home: 420GB (ext4)
  • swap: 8GB (swap)

Justification:

  • Large /home accommodates photos, videos, and downloads.
  • 8GB swap is sufficient for 16GB RAM (used for hibernation).
  • Separate /boot ensures bootloader compatibility with UEFI.

Post-installation check:

df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 47G 12G 33G 27% /

/dev/sda5 410G 45G 345G 12% /home

/dev/sda1 511M 6.1M 505M 2% /boot/efi

/dev/sda2 976M 186M 723M 21% /boot

Example 2: Web Server with Database

Scenario: A CentOS 8 server hosts Apache, MySQL, and PHP for a high-traffic website.

Partition Layout:

  • /boot/efi: 1GB (FAT32)
  • /boot: 1GB (ext4)
  • /: 20GB (XFS)
  • /var: 50GB (XFS)
  • /var/lib/mysql: 100GB (XFS)
  • /tmp: 10GB (ext4, noexec,nosuid,nodev)
  • /home: 10GB (ext4)
  • swap: 16GB (swap)

Justification:

  • Separate /var/lib/mysql ensures database performance and prevents log growth from affecting data.
  • XFS chosen for large file handling and scalability.
  • 16GB swap compensates for memory-intensive database processes.
  • /tmp with security flags prevents exploitation via temporary file uploads.

Mounts in /etc/fstab:

UUID=abc123 / xfs defaults 0 1

UUID=def456 /var xfs defaults 0 2

UUID=ghi789 /var/lib/mysql xfs defaults 0 2

UUID=jkl012 /tmp ext4 defaults,noexec,nosuid,nodev 0 2

UUID=mno345 /home ext4 defaults 0 2

UUID=pqr678 none swap sw 0 0

Example 3: Docker Host

Scenario: A server running multiple Docker containers with persistent volumes.

Partition Layout:

  • /boot/efi: 512MB (FAT32)
  • /boot: 1GB (ext4)
  • /: 30GB (ext4)
  • /var/lib/docker: 200GB (ext4)
  • /opt: 20GB (ext4)
  • /home: 10GB (ext4)
  • swap: 8GB

Why? Docker images and containers grow rapidly. Isolating them in /var/lib/docker prevents the root partition from filling up and crashing the system. The /opt partition holds custom scripts and third-party binaries.

FAQs

Can I partition a disk without losing data?

Generally, no. Partitioning requires deleting existing partitions, which erases all data. However, tools like GParted can resize existing partitions without data lossprovided theres enough free space. Always backup critical data before any partitioning operation.

Do I need a swap partition if I have 16GB of RAM?

Its still recommended. Swap acts as a safety net for memory spikes and enables hibernation. Even with ample RAM, systems can benefit from swap during heavy I/O or memory leaks. A swap file can be created later if needed, but a dedicated partition is more reliable.

What is the difference between primary, extended, and logical partitions?

Primary partitions are direct entries in the MBR partition table (max 4). An extended partition is a container that holds logical partitions, allowing more than 4 partitions on MBR disks. GPT eliminates this limitationno extended or logical partitions exist in GPT.

Can I change partitions after installing Linux?

Yes, but its risky. You can resize partitions using tools like GParted or parted, but only if unmounted. For root partitions, you must boot from a live USB. Always backup first. Moving or resizing partitions can cause boot failure if the bootloader or fstab references old locations.

Why is my EFI partition not mounting?

Ensure its formatted as FAT32 and has the esp flag set. In gdisk, use type code ef00. In fdisk, set type to EFI System. Also, check that /boot/efi is mounted in fstab with the correct UUID.

Should I use LVM for partitioning?

LVM (Logical Volume Manager) adds flexibility by allowing dynamic resizing and snapshots. Its ideal for servers or environments where storage needs change frequently. However, it adds complexity. For desktop users or simple setups, traditional partitioning is sufficient.

How do I check if my disk uses GPT or MBR?

Run:

sudo fdisk -l /dev/sda

If you see Disklabel type: gpt, its GPT. If it says dos, its MBR. Alternatively:

parted /dev/sda print

Look for Partition Table: gpt or msdos.

What happens if I delete the wrong partition?

If you accidentally delete a partition, stop using the disk immediately. Use data recovery tools like TestDisk or PhotoRec to attempt recovery. Success depends on whether new data has overwritten the old partition table. Prevention through careful verification is always better than recovery.

Is it safe to partition an SSD?

Yes. Modern SSDs handle partitioning the same way as HDDs. However, ensure partitions are aligned to 1MB boundaries (which modern tools do automatically) to optimize performance and lifespan. Avoid excessive writes during partitioning, but normal use is safe.

Conclusion

Partitioning Linux is not merely a technical taskits a strategic decision that impacts system reliability, security, and scalability. By understanding the purpose of each partition, selecting the right filesystem, and following best practices, you lay the groundwork for a robust, long-lasting Linux environment.

This guide has walked you through everything from identifying your storage needs to creating and mounting partitions with industry-standard tools. Whether youre installing Linux on a desktop, configuring a production server, or deploying containers, the principles remain the same: isolate, plan, document, and verify.

Remember: the best partition scheme is not the most complex oneits the one that fits your use case, is easy to maintain, and protects your data. Avoid the temptation to use a single partition. Embrace modularity. Use UUIDs. Secure your /tmp. Monitor your space.

As Linux continues to evolve across cloud, edge, and IoT environments, the ability to partition effectively will remain a core competency. Master this skill, and you empower yourself to manage systems with confidence, precision, and foresight.