Your Linux partition is running low on space, and resizing it requires careful command-line steps to avoid data loss. Learning how to resize partition in linux is a critical skill for managing disk space, whether you’re expanding a root partition or shrinking a data volume. This guide walks you through the entire process with clear, practical steps.
Before you start, understand that partition resizing carries risks. A single mistake can corrupt your data or make your system unbootable. Always back up important files first. This article assumes you have basic familiarity with the Linux terminal.
Understanding Linux Partition Resizing
Partition resizing involves changing the size of a disk partition without deleting its contents. You can either shrink a partition to free up space or expand it to use unallocated space. The tools you use depend on your filesystem type—ext4, XFS, Btrfs, or others.
The core principle is that you must unmount a partition before resizing it, unless you’re using a live USB environment. For system partitions like root (/), you’ll need to boot from a live Linux USB to perform the operation safely.
Key Tools You Need
- GParted: A graphical partition editor (GUI) for beginners
- fdisk: Command-line tool for viewing and editing partition tables
- parted: Another command-line tool for partition management
- resize2fs: Specifically for ext2/3/4 filesystems
- lvextend: For LVM (Logical Volume Manager) partitions
Filesystem Compatibility
Not all filesystems support online resizing. Ext4 allows online expansion but not shrinking. XFS only supports expansion. Btrfs supports both but with limitations. Always check your filesystem type with df -T before proceeding.
How To Resize Partition In Linux
This section provides a step-by-step guide using both graphical and command-line methods. Choose the approach that fits your comfort level.
Method 1: Using GParted (Graphical)
GParted is the easiest way for most users. It provides a visual interface for resizing partitions. Install it with your package manager if you don’t have it.
- Boot from a live USB: Since you can’t resize a mounted system partition, boot from a Linux live USB (like Ubuntu live).
- Open GParted: Launch it from the system menu or terminal with
sudo gparted. - Select the disk: Choose the correct disk from the top-right dropdown (e.g.,
/dev/sda). - Unmount the partition: Right-click the partition you want to resize and select “Unmount”.
- Resize/Move: Right-click the partition again and choose “Resize/Move”.
- Adjust size: Drag the edges or enter new values in the “New size” field. Leave some free space for filesystem overhead.
- Apply changes: Click the green checkmark to apply. This may take several minutes depending on partition size.
Tip: For expanding a partition, you must have unallocated space immediately after it. If not, you’ll need to move partitions first—a risky operation that can break bootloaders.
Method 2: Using Command-Line (Fdisk + Resize2fs)
For advanced users, the command line offers more control. This example resizes an ext4 partition.
- Identify the partition: Run
sudo fdisk -lto list all partitions. Note the device name (e.g.,/dev/sda2). - Unmount the partition:
sudo umount /dev/sda2(if it’s mounted). - Check filesystem:
sudo e2fsck -f /dev/sda2to check for errors. This is mandatory before resizing. - Resize the filesystem: For shrinking, use
sudo resize2fs /dev/sda2 [new size](e.g.,resize2fs /dev/sda2 20G). For expanding, just runsudo resize2fs /dev/sda2after enlarging the partition. - Resize the partition: Use
sudo fdisk /dev/sdato delete and recreate the partition with new boundaries. This is the tricky part—you must start at the same sector. - Write changes: In fdisk, delete the partition (d), create a new one (n) with the same start sector and desired end sector, then write (w).
- Reboot: Restart your system to apply changes.
Warning: Deleting and recreating a partition in fdisk can cause data loss if you don’t match the start sector exactly. Use fdisk -l to record the start sector before deleting.
Method 3: Resizing LVM Partitions
LVM offers more flexibility. You can resize logical volumes without touching the underlying partitions.
- Check LVM status:
sudo lvdisplayto list logical volumes. - Expand a logical volume:
sudo lvextend -L +10G /dev/vg_name/lv_nameto add 10GB. - Resize the filesystem:
sudo resize2fs /dev/vg_name/lv_name(for ext4) orxfs_growfsfor XFS. - Shrink a logical volume: First shrink the filesystem with
resize2fs, then uselvreduce -L -5G /dev/vg_name/lv_name.
LVM shrinking is safer than traditional partitions because you don’t need to delete and recreate the partition table.
Common Scenarios And Solutions
Resizing The Root Partition
Your root partition (/) is always mounted during normal operation. To resize it:
- Boot from a live USB
- Use GParted or command-line tools
- Ensure you have unallocated space adjacent to the root partition
- If expanding, you may need to move the swap partition first
Shrinking A Partition With Data
Shrinking is more dangerous than expanding. You must:
- Defragment the filesystem if possible (not always necessary)
- Calculate the minimum size with
resize2fs -P /dev/sdXY - Leave at least 5-10% free space for filesystem overhead
- Never shrink below the minimum size
Resizing A Windows Partition From Linux
Linux can resize NTFS partitions using ntfsresize. First, safely shut down Windows (disable fast startup). Then:
- Use GParted with ntfs-3g installed
- Or command-line:
sudo ntfsresize -s [new size] /dev/sdXY - Always check with
ntfsresize --info /dev/sdXYfirst
Precautions And Best Practices
Resizing partitions is a high-risk operation. Follow these rules to protect your data:
- Always back up: Use tools like
ddorrsyncto create a full backup before resizing - Use a live environment: Never resize a mounted system partition
- Check filesystem first: Run
fsckore2fsckbefore any resize operation - Start small: If shrinking, reduce by a small amount first to test
- Document partition layout: Write down start sectors, sizes, and filesystem types
- Have a recovery plan: Know how to restore from backup if something goes wrong
What To Do If Something Goes Wrong
If your system won’t boot after resizing:
- Boot from a live USB
- Check partition table with
fdisk -l - Try to mount the partition manually
- Use
fsckto repair filesystem errors - Restore from backup if necessary
Advanced Techniques
Resizing With Parted
The parted tool can resize partitions non-interactively. Example:
sudo parted /dev/sda resizepart 2 30GB
This resizes partition 2 to 30GB. You must then resize the filesystem separately with resize2fs.
Using System Rescue CDs
Dedicated rescue CDs like SystemRescue include advanced tools. They provide a minimal environment with all necessary utilities pre-installed.
Resizing Btrfs Partitions
Btrfs supports online resizing. To shrink:
sudo btrfs filesystem resize -10G /mount/point
To expand:
sudo btrfs filesystem resize +10G /mount/point
Note that Btrfs has limitations on shrinking—you cannot shrink below the amount of data stored.
Troubleshooting Common Errors
“Partition Is Busy” Error
This means the partition is mounted. Unmount it first, or use a live environment. For swap partitions, use swapoff.
“Filesystem Has Errors”
Run e2fsck -f to fix errors. Never resize a corrupted filesystem.
“No Space Left For Resize”
You don’t have enough unallocated space. Check with fdisk -l or parted print free.
“Kernel Does Not Support Resize”
Your kernel may lack support for online resizing. Boot into a newer kernel or use a live USB.
Automating Partition Resizing
For repeated tasks, you can script the process. Example bash script for expanding an ext4 partition:
#!/bin/bash
PART=/dev/sda2
sudo umount $PART
sudo e2fsck -f $PART
sudo resize2fs $PART
sudo mount $PART /mnt
This script assumes you’ve already expanded the partition with fdisk or parted.
Frequently Asked Questions
Can I Resize A Partition Without Losing Data?
Yes, if done correctly. Always back up first, use the right tools, and follow the steps carefully. Data loss usually occurs from user error or power failures during the process.
How Do I Resize A Partition In Linux Without Formatting?
Use GParted or command-line tools like resize2fs combined with fdisk. These tools resize the filesystem and partition table without reformatting.
What Is The Difference Between Resizing A Partition And Resizing A Filesystem?
Resizing a partition changes the boundaries in the partition table. Resizing a filesystem changes the internal structure to use the new space. You must do both, usually in the correct order (filesystem first for shrinking, partition first for expanding).
Can I Resize A Partition While It’s Mounted?
Some filesystems (ext4, XFS) support online expansion but not shrinking. For shrinking or any operation on system partitions, you must unmount or use a live environment.
How Long Does Partition Resizing Take?
It depends on partition size and disk speed. A 100GB partition might take 10-30 minutes. Larger partitions can take hours. Never interrupt the process.
Final Thoughts
Resizing partitions in Linux is a powerful skill that gives you control over your disk space. Whether you use GParted for simplicity or command-line tools for precision, the key is preparation and caution. Always back up, double-check your steps, and never rush the process.
With practice, you’ll find that resizing partitions becomes a routine task. Start with non-critical partitions to build confidence, then tackle system partitions when you’re ready. Remember that a live USB is your best friend for these operations—it provides a safe environment to work without risking your running system.
If you encounter errors, don’t panic. Most issues are recoverable with proper tools and a backup. The Linux community is also a great resource—forums and documentation can help with specific problems.
Now you have the knowledge to manage your disk space effectively. Go ahead and resize that partition with confidence, knowing you’ve taken the right precautions.