How to Partition Linux

How to Partition Linux: A Comprehensive Tutorial Introduction Partitioning Linux is a fundamental task for system administrators, developers, and enthusiasts who want to optimize their Linux installation for performance, security, and manageability. Partitioning involves dividing a physical disk into multiple logical sections called partitions, each acting as an independent storage unit. Proper pa

Nov 17, 2025 - 12:02
Nov 17, 2025 - 12:02
 0

How to Partition Linux: A Comprehensive Tutorial

Introduction

Partitioning Linux is a fundamental task for system administrators, developers, and enthusiasts who want to optimize their Linux installation for performance, security, and manageability. Partitioning involves dividing a physical disk into multiple logical sections called partitions, each acting as an independent storage unit. Proper partitioning ensures better data organization, easier system backups, improved security, and efficient use of disk space.

This tutorial covers everything you need to know about how to partition Linux effectively. Whether you are installing Linux for the first time or managing an existing system, understanding partitioning will empower you to make informed decisions that enhance your Linux experience.

Step-by-Step Guide

Step 1: Understand Linux Partitioning Basics

Before diving into partitioning, it’s important to understand key concepts:

  • Partition: A section of a physical disk with its own filesystem.
  • Primary and Extended partitions: MBR disks support up to 4 primary partitions. To create more, an extended partition is used as a container for logical partitions.
  • Filesystems: Linux supports multiple filesystems like ext4, xfs, btrfs, etc., that define how data is organized on partitions.
  • Swap Partition: A dedicated partition used as virtual memory when RAM is full.

Step 2: Backup Important Data

Partitioning can lead to data loss if done improperly. Always back up your important data before modifying disk partitions.

Step 3: Identify the Disk to Partition

Use the lsblk or fdisk -l commands to list available disks and partitions:

sudo lsblk

This will display all disks (e.g., /dev/sda, /dev/sdb) and their partitions.

Step 4: Start Partitioning Using Command Line Tools

Linux provides several tools for partitioning. The two most common are:

Using fdisk (for MBR disks)

  1. Open fdisk for your disk:
  2. sudo fdisk /dev/sda
  3. Press m to view commands.
  4. Press p to print the current partition table.
  5. Press n to create a new partition.
  6. Choose primary (p) or logical (l), enter partition number, and specify size.
  7. Press w to write changes and exit.

Using parted (for GPT disks and larger drives)

  1. Start parted:
  2. sudo parted /dev/sda
  3. To create a GPT partition table:
  4. mklabel gpt
  5. Create a partition:
  6. mkpart primary ext4 1MiB 20GiB
  7. Print partition table:
  8. print
  9. Exit parted:
  10. quit

Step 5: Format the Partitions

After creating partitions, format them with a filesystem:

sudo mkfs.ext4 /dev/sda1

Replace ext4 with your preferred filesystem type.

Step 6: Configure Swap Partition

If you created a swap partition, initialize it:

sudo mkswap /dev/sda2

sudo swapon /dev/sda2

Step 7: Mount the Partitions

Create mount points and mount the partitions:

sudo mkdir /mnt/data

sudo mount /dev/sda1 /mnt/data

Step 8: Update /etc/fstab for Persistent Mounts

To ensure partitions mount automatically at boot, add entries to /etc/fstab:

/dev/sda1   /mnt/data   ext4   defaults   0 2

/dev/sda2 none swap sw 0 0

Best Practices

Separate System and Data Partitions

Keep your root (/) partition separate from data partitions like /home. This prevents system issues from affecting user data.

Use Swap Wisely

Allocate swap space based on your RAM size and workload. For systems with ample RAM, less swap is needed.

Consider Filesystem Choice

Choose filesystems that suit your needs. ext4 is reliable and widely supported; btrfs offers advanced features like snapshots.

Align Partitions for SSDs

Proper alignment improves SSD lifespan and performance. Most modern tools handle this automatically, but verify if unsure.

Keep Backup and Recovery in Mind

Regularly back up your partition tables and data. Tools like parted and fdisk can export partition tables.

Tools and Resources

Command Line Tools

  • fdisk: Classic tool for MBR partitions.
  • parted: Supports GPT and advanced partitioning.
  • lsblk: Lists block devices.
  • mkfs: Creates filesystems on partitions.
  • swapon/swapoff: Manage swap spaces.

Graphical Tools

  • GParted: User-friendly graphical partition editor.
  • KDE Partition Manager: KDE environment partitioning tool.

Documentation and References

Real Examples

Example 1: Partitioning a New Disk with fdisk

Suppose you added a new 100GB disk at /dev/sdb. You want to create two partitions: 80GB for data and 20GB for backup.

  1. Run fdisk:
  2. sudo fdisk /dev/sdb
  3. Create a new primary partition of 80GB:
  4. n → p → 1 → default start → +80G
  5. Create a second primary partition of 20GB:
  6. n → p → 2 → default start → +20G
  7. Write changes and exit:
  8. w
  9. Format partitions:
  10. sudo mkfs.ext4 /dev/sdb1
    

    sudo mkfs.ext4 /dev/sdb2

  11. Mount partitions:
  12. sudo mkdir /mnt/data
    

    sudo mount /dev/sdb1 /mnt/data

Example 2: Using parted to Create a GPT Disk

For a new disk /dev/sdc, create a GPT partition table with three partitions:

  • 20GB root
  • 4GB swap
  • Remaining space for home
sudo parted /dev/sdc

mklabel gpt

mkpart primary ext4 1MiB 20GiB

mkpart primary linux-swap 20GiB 24GiB

mkpart primary ext4 24GiB 100%

quit

Format accordingly:

sudo mkfs.ext4 /dev/sdc1

sudo mkswap /dev/sdc2

sudo mkfs.ext4 /dev/sdc3

FAQs

What is the difference between MBR and GPT partition tables?

MBR (Master Boot Record) supports up to 4 primary partitions and is limited to disks smaller than 2TB. GPT (GUID Partition Table) supports more partitions (up to 128) and works with disks larger than 2TB. GPT is recommended for modern systems.

Can I resize partitions without losing data?

Yes, tools like GParted allow resizing partitions safely, but always back up data before proceeding to avoid accidental loss.

Do I always need a swap partition?

Not necessarily. Systems with large RAM may not require swap partitions, but having swap helps with memory management and hibernation.

How do I check my current partition layout?

Use commands like lsblk, fdisk -l, or parted -l to view partition tables and sizes.

Is it better to have one big partition or multiple smaller partitions?

Multiple partitions provide better data isolation, easier backups, and improved security. For example, separating /home from / prevents user data loss during system reinstalls.

Conclusion

Partitioning Linux is a crucial skill that enhances system organization, security, and performance. Whether you use command line tools like fdisk and parted or graphical interfaces like GParted, understanding how to create, format, and manage partitions empowers you to tailor your Linux environment to your specific needs.

Always remember to back up your data before making partition changes, choose appropriate filesystems, and follow best practices to ensure a smooth and efficient Linux experience. With this tutorial, you are well-equipped to partition Linux systems confidently and effectively.