How to Partition Linux

How to Partition Linux Partitioning a Linux system is a foundational skill for anyone managing servers, workstations, or embedded systems. Whether you're installing Linux for the first time, optimizing performance, enhancing security, or preparing for a multi-boot setup, understanding how to partition your disk correctly is essential. Unlike Windows, where the default partitioning scheme often suf

Oct 30, 2025 - 10:10
Oct 30, 2025 - 10:10
 0

How to Partition Linux

Partitioning a Linux system is a foundational skill for anyone managing servers, workstations, or embedded systems. Whether you're installing Linux for the first time, optimizing performance, enhancing security, or preparing for a multi-boot setup, understanding how to partition your disk correctly is essential. Unlike Windows, where the default partitioning scheme often suffices, Linux offers granular control over how storage is allocated — a feature that, when used wisely, leads to greater system stability, easier maintenance, and improved data integrity.

Partitioning involves dividing a physical storage device into logically separate sections, each functioning as an independent volume. In Linux, these partitions can be assigned specific mount points such as / (root), /home, /var, or /boot, allowing you to isolate system files from user data, logs, or temporary files. This separation prevents one component from consuming all available disk space and simplifies backups, upgrades, and recovery procedures.

This tutorial provides a comprehensive, step-by-step guide to partitioning Linux systems using modern tools and industry best practices. We’ll cover everything from basic concepts to advanced configurations, including real-world examples, recommended partition schemes, and troubleshooting tips. By the end of this guide, you’ll have the knowledge and confidence to partition any Linux system — from a small Raspberry Pi to a high-performance enterprise server.

Step-by-Step Guide

Before You Begin: Understanding Your Hardware and Goals

Before diving into partitioning, take a moment to assess your system’s hardware and intended use case. Ask yourself:

  • Is this a desktop, server, or embedded device?
  • Will you be running multiple operating systems (dual/multi-boot)?
  • Do you need to preserve existing data?
  • What is the total disk capacity?

These factors will determine your partitioning strategy. For example, a server handling high-volume logs may require a large /var partition, while a desktop user might prioritize a sizable /home partition for personal files.

Also, ensure you have a backup of all critical data. Partitioning involves modifying disk structures, and errors can result in data loss. Even if you plan to wipe the disk, always verify that your backups are complete and accessible.

Step 1: Boot into a Live Environment (If Needed)

If you’re partitioning a system that already has an operating system installed, it’s safest to boot from a Linux Live USB or DVD. This ensures no partitions are mounted or in use during the process. Popular live environments include Ubuntu Live, Fedora Live, or SystemRescueCD.

To create a bootable USB:

  1. Download an ISO image of your preferred Linux distribution.
  2. Use a tool like dd (Linux/macOS) or Rufus (Windows) to write the ISO to a USB drive.
  3. Reboot your system and enter the BIOS/UEFI settings (typically by pressing F2, F12, DEL, or ESC during startup).
  4. Set the USB drive as the primary boot device.
  5. Save and exit. The system should now boot into the live environment.

Once booted, open a terminal. You’ll need root privileges to manage partitions, so use sudo or log in as root if available.

Step 2: Identify Your Storage Devices

Use the lsblk command to list all block devices and their current partition structure:

lsblk

This outputs a tree-like structure showing disks and their partitions. For example:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT

sda 8:0 0 500G 0 disk

├─sda1 8:1 0 1G 0 part /boot

├─sda2 8:2 0 50G 0 part /

├─sda3 8:3 0 400G 0 part /home

└─sda4 8:4 0 9G 0 part [SWAP]

sdb 8:16 0 1T 0 disk

In this example, sda is the primary disk with four partitions, and sdb is an unpartitioned 1TB drive.

To get more detailed information, use fdisk -l or parted -l. These commands display partition tables, filesystem types, and boot flags.

Step 3: Choose Your Partitioning Tool

Linux offers several command-line and graphical tools for partitioning. For this guide, we’ll focus on two widely used and reliable tools:

  • fdisk – Legacy but robust, ideal for MBR (Master Boot Record) disks.
  • gdisk – Modern tool for GPT (GUID Partition Table) disks, recommended for UEFI systems.
  • parted – Scriptable and supports both MBR and GPT.

For most modern systems (post-2012), use GPT with gdisk. GPT supports disks larger than 2TB, allows up to 128 primary partitions, and includes redundancy for partition table recovery.

To launch gdisk on a disk (e.g., /dev/sdb):

sudo gdisk /dev/sdb

You’ll see a prompt like:

Command (? for help):

Step 4: Create a New Partition Table (GPT)

If the disk is new or you’re starting fresh, create a new GPT partition table:

Command (? for help): o

This option deletes all partitions and creates a new protective MBR.

Proceed? (Y/N): Y

Confirm with Y. This erases all existing partitions, so ensure you’ve backed up data.

Now, create your first partition:

Command (? for help): n

You’ll be prompted for:

  • Partition number (default: 1)
  • First sector (default: 2048 — recommended)
  • Last sector or size (e.g., +50G for 50GB)

Enter +50G to create a 50GB partition. Press Enter to accept defaults where appropriate.

Next, assign a partition type. For the root filesystem (/), use Linux filesystem type (code 8300):

Command (? for help): t

Partition number (1-128): 1

Hex code or GUID (L to show codes, Enter = 8300): 8300

Repeat the process to create additional partitions:

  • /home: +200G, type 8300
  • /var: +30G, type 8300
  • Swap: +8G, type 8200 (Linux swap)

For UEFI systems, you must create an EFI System Partition (ESP):

Command (? for help): n

Partition number: 5

First sector: (default)

Last sector: +512M

Hex code: EF00

EF00 is the GPT code for EFI System Partition.

Step 5: Review and Write Changes

Before writing changes, review your partition layout:

Command (? for help): p

Verify that:

  • Partition sizes match your plan.
  • Types are correctly assigned (e.g., 8300 for Linux, EF00 for EFI).
  • No overlaps or gaps exist.

If everything looks correct, write the changes to disk:

Command (? for help): w

Confirm with Y. The system will write the GPT table and exit.

Step 6: Format the Partitions

After partitioning, each partition must be formatted with a filesystem. Linux supports several, but ext4 is the most widely used due to its reliability, journaling, and performance.

Format the root partition:

sudo mkfs.ext4 /dev/sdb1

Format the home partition:

sudo mkfs.ext4 /dev/sdb2

Format the swap partition:

sudo mkswap /dev/sdb4

Enable the swap space:

sudo swapon /dev/sdb4

For the EFI partition, use FAT32:

sudo mkfs.fat -F32 /dev/sdb5

Step 7: Mount the Partitions

Before installing the OS or copying data, mount the partitions to temporary directories:

sudo mkdir -p /mnt/root

sudo mkdir -p /mnt/home

sudo mkdir -p /mnt/var

sudo mkdir -p /mnt/efi

sudo mount /dev/sdb1 /mnt/root

sudo mount /dev/sdb2 /mnt/home

sudo mount /dev/sdb3 /mnt/var

sudo mount /dev/sdb5 /mnt/efi

These mount points will be used during OS installation or when manually configuring the system.

Step 8: Install the Operating System (Optional)

If you’re installing Linux from scratch, proceed with your distribution’s installer (e.g., Ubuntu, Fedora, Arch). During installation, choose “Manual Partitioning” or “Something Else.”

Assign each partition to its mount point:

  • /dev/sdb1/
  • /dev/sdb2/home
  • /dev/sdb3/var
  • /dev/sdb4 → swap
  • /dev/sdb5/boot/efi

Ensure the bootloader is installed to the correct device (e.g., /dev/sdb, not a partition).

Step 9: Update /etc/fstab

After installation, the system must know how to mount partitions at boot. This is configured in /etc/fstab.

Find the UUIDs of your partitions:

sudo blkid

Example output:

/dev/sdb1: UUID="a1b2c3d4-..." TYPE="ext4"

/dev/sdb2: UUID="e5f6g7h8-..." TYPE="ext4"

/dev/sdb4: UUID="i9j0k1l2-..." TYPE="swap"

/dev/sdb5: UUID="M3N4O5P6-..." TYPE="vfat"

Edit /etc/fstab:

sudo nano /etc/fstab

Add entries like:

UUID=a1b2c3d4-... / ext4 defaults 0 1

UUID=e5f6g7h8-... /home ext4 defaults 0 2

UUID=i9j0k1l2-... none swap sw 0 0

UUID=M3N4O5P6-... /boot/efi vfat umask=0077 0 2

Save and test the configuration:

sudo mount -a

If no errors appear, your fstab is correct.

Best Practices

Use GPT Over MBR for Modern Systems

MBR (Master Boot Record) is outdated. It supports only up to 2TB of storage and a maximum of four primary partitions. GPT (GUID Partition Table) is the modern standard, especially for UEFI-based systems. Always choose GPT unless you’re working with legacy hardware that doesn’t support it.

Separate /home for Data Persistence

One of the most valuable Linux partitioning practices is isolating /home. This directory contains all user data — documents, downloads, configurations, and application data. By placing it on a separate partition, you can reinstall the OS without losing personal files. This is especially useful during major version upgrades or system crashes.

Allocate Sufficient Swap Space

Swap space acts as virtual memory when RAM is exhausted. While modern systems with 8GB+ RAM may not rely heavily on swap, it’s still essential for hibernation and system stability.

Recommended swap sizes:

  • Up to 2GB RAM: 2x RAM size
  • 2GB–8GB RAM: Equal to RAM size
  • 8GB–64GB RAM: 0.5x RAM size
  • Over 64GB RAM: 4GB–8GB minimum

For systems using SSDs, consider using a swap file instead of a swap partition for easier resizing.

Isolate /var for Logs and Temporary Files

The /var directory stores logs, caches, databases, and spool files. These can grow rapidly, especially on servers. A separate /var partition prevents log floods from filling the root filesystem and crashing the system.

On high-traffic web or mail servers, allocate at least 20–50GB to /var.

Use /boot for Kernel Files

The /boot partition holds kernel images and bootloader files. It’s often kept small (500MB–1GB) and formatted as ext4 or FAT32 (for UEFI). This ensures the bootloader can access these files even if the root filesystem uses advanced features like LVM or encryption.

Consider LVM for Flexibility

Logical Volume Management (LVM) allows you to create resizable, flexible storage pools. Instead of fixed partitions, you create volume groups and logical volumes. This is ideal for servers where storage needs change over time.

Example LVM setup:

  • One physical partition for the LVM physical volume
  • Volume group named “vg0”
  • Logical volumes: /, /home, /var, swap

LVM enables online resizing, snapshots, and striping — features not available with traditional partitioning.

Enable Filesystem Journaling

Always use journaling filesystems like ext4, XFS, or Btrfs. Journaling protects against data corruption during unexpected shutdowns by logging changes before committing them to disk.

Leave Unallocated Space for Future Use

Don’t allocate 100% of your disk. Leave 5–10% unallocated to accommodate future partition expansion, especially if using LVM or if you later need to add another OS.

Use UUIDs, Not Device Names, in fstab

Device names like /dev/sda1 can change between boots (e.g., if you add or remove a drive). UUIDs are unique identifiers assigned to each filesystem and remain constant. Always use UUIDs in /etc/fstab for reliability.

Secure Sensitive Partitions

For enhanced security, consider encrypting sensitive partitions using LUKS (Linux Unified Key Setup). This is especially important for laptops or systems handling confidential data. Encryption can be applied to /home, /var, or even the entire root filesystem.

Tools and Resources

Command-Line Tools

  • fdisk – Legacy partitioning tool for MBR disks. Simple and reliable.
  • gdisk – Modern replacement for fdisk, designed for GPT. Supports larger disks and more partitions.
  • parted – Scriptable partition editor with support for both MBR and GPT. Useful for automation.
  • lsblk – Lists block devices and their mount points. Essential for planning.
  • blkid – Displays UUIDs and filesystem types. Critical for configuring fstab.
  • mkfs.ext4, mkfs.xfs, mkswap – Tools to format partitions with specific filesystems.
  • swapon, swapoff – Enable or disable swap space.
  • mount, umount – Mount and unmount filesystems manually.

Graphical Tools

  • GParted – User-friendly GUI tool available in most Linux live environments. Ideal for beginners.
  • KDE Partition Manager – Feature-rich GUI for KDE desktop users.
  • Disks (gnome-disks) – Default disk utility in GNOME. Supports partitioning, formatting, and SMART monitoring.

While GUI tools are easier for beginners, command-line tools offer greater precision and are essential for headless servers.

Documentation and Learning Resources

Recommended Distributions for Learning

If you’re learning partitioning from scratch, consider installing:

  • Ubuntu Server – Offers manual partitioning during install.
  • Debian – Very transparent installation process.
  • Arch Linux – Requires manual partitioning and configuration — excellent for deep learning.

These distributions force you to understand each step, unlike Ubuntu Desktop, which often auto-partitions.

Real Examples

Example 1: Desktop Linux System (500GB SSD)

Use case: Personal workstation running Ubuntu for development and media.

  • /boot/efi – 512MB (FAT32, GPT)
  • / – 80GB (ext4)
  • /home – 350GB (ext4)
  • Swap – 16GB (swap)

Rationale: Large /home for documents, photos, and downloads. 80GB for root is ample for applications and system files. 16GB swap supports hibernation on a system with 16GB RAM.

Example 2: Web Server (2TB HDD)

Use case: Apache/Nginx server hosting multiple websites with high traffic.

  • /boot/efi – 1GB (FAT32)
  • / – 30GB (ext4)
  • /var – 500GB (ext4) — logs, web content, databases
  • /tmp – 20GB (ext4, mounted with noexec,nosuid)
  • Swap – 8GB
  • Unallocated – 1441GB (for future LVM expansion)

Rationale: /var is large to accommodate growing log files and website assets. /tmp is isolated and secured. Unallocated space allows adding more logical volumes later without repartitioning.

Example 3: Headless Server with LVM (1TB SSD)

Use case: Remote Linux server running Docker, PostgreSQL, and backup services.

  • Partition 1: 1GB — /boot/efi (FAT32)
  • Partition 2: 999GB — Physical Volume for LVM
    • Logical Volume 1: 50GB — /
    • Logical Volume 2: 200GB — /var/lib/docker
    • Logical Volume 3: 100GB — /var/lib/postgresql
    • Logical Volume 4: 50GB — /home
    • Logical Volume 5: 8GB — swap
    • Unallocated: 591GB — for future expansion

Rationale: LVM allows dynamic resizing. If Docker containers grow, you can extend the /var/lib/docker volume without downtime. This setup is scalable and ideal for cloud or virtualized environments.

Example 4: Dual-Boot System (Windows + Linux)

Use case: User needs both Windows 11 and Ubuntu for gaming and productivity.

  • Windows C: — 400GB (NTFS)
  • Unallocated — 150GB (for Linux)
  • Linux /boot/efi — 512MB (FAT32 — shared with Windows)
  • Linux / — 50GB (ext4)
  • Linux /home — 90GB (ext4)
  • Swap — 8GB

Rationale: The EFI partition is shared between OSes to avoid boot conflicts. Linux partitions are created in the unallocated space. This setup avoids data loss and allows both OSes to coexist.

FAQs

Can I partition a disk without losing data?

Yes — but with caution. Tools like GParted can resize existing partitions without data loss, provided there’s enough free space. However, resizing carries inherent risk. Always backup data before resizing. Never attempt to resize a partition that is mounted or in use.

What is the difference between a primary and logical partition?

Primary partitions are direct entries in the MBR partition table. MBR allows only four primary partitions. If you need more, one primary partition can be designated as an “extended” partition, which can contain multiple “logical” partitions. GPT eliminates this limitation — all partitions are primary.

Do I need a separate /boot partition?

Not always, but it’s recommended. If you’re using LVM, full-disk encryption, or advanced filesystems like Btrfs, a separate /boot partition ensures the bootloader can access kernel files. On simple setups with ext4 and no encryption, you can combine /boot with /.

How do I know if my system uses UEFI or BIOS?

Run this command:

ls /sys/firmware/efi

If the directory exists, your system uses UEFI. If not, it likely uses legacy BIOS. You can also check in your firmware settings.

Can I change partition sizes after installation?

Yes, but it requires unmounting the partition and using tools like resize2fs (for ext4) or xfs_growfs (for XFS). For root partitions, you’ll need to boot from a live USB. LVM makes this process much easier.

Is it better to use swap files or swap partitions?

Swap partitions are slightly faster and more predictable. Swap files are easier to resize and don’t require repartitioning. For most desktop users, a swap file is sufficient. On servers or systems with frequent memory pressure, a dedicated swap partition is preferred.

What filesystem should I use for /home?

ext4 is the safest and most compatible choice. XFS offers better performance with large files and high concurrency, making it ideal for media servers. Btrfs offers snapshots and compression but is still considered experimental for production use in some environments.

Why is my disk showing less space than advertised?

Manufacturers use decimal (SI) units (1GB = 1,000,000,000 bytes), while operating systems use binary units (1GiB = 1,073,741,824 bytes). Also, filesystem metadata, reserved blocks, and partition alignment consume space. Expect 5–10% less usable space than the labeled capacity.

How do I recover a deleted partition?

Use tools like testdisk or photorec. TestDisk can often restore lost partition tables if the data hasn’t been overwritten. Act quickly — the longer you wait, the higher the chance of permanent data loss.

Can I partition an NVMe drive the same way as SATA?

Yes. NVMe drives appear as /dev/nvme0n1 instead of /dev/sda, but the same partitioning principles apply. Use gdisk or parted as usual. NVMe drives benefit even more from GPT due to their large capacity and speed.

Conclusion

Partitioning Linux is not just a technical task — it’s a strategic decision that impacts system performance, security, and longevity. By carefully planning your partition layout, you gain control over how your data is stored, protected, and accessed. Whether you’re setting up a personal computer, a production server, or a development environment, the principles outlined in this guide provide a solid foundation.

Modern Linux systems offer powerful tools like GPT, LVM, and encrypted volumes that make storage management more flexible than ever. But with great power comes great responsibility. Always backup your data, use UUIDs in fstab, and choose filesystems and partition schemes that align with your use case.

Remember: the goal of partitioning isn’t to fill every byte of your disk — it’s to create a stable, maintainable, and scalable storage architecture. A well-partitioned system can survive OS upgrades, hardware changes, and unexpected failures with minimal disruption.

As you gain experience, experiment with advanced configurations like LVM snapshots, RAID arrays, or encrypted home directories. But always start with the basics — understand your hardware, plan your mount points, and respect the boundaries between system, user, and temporary data.

With the knowledge in this guide, you’re no longer just installing Linux — you’re engineering a resilient, purpose-built system tailored to your needs. That’s the true power of Linux partitioning.