To resize a Linux partition without losing data, you need to shrink or expand it while the filesystem is offline. This guide shows you exactly how to resize Linux partition safely using built-in tools like GParted and command-line utilities. Whether you’re freeing up space or expanding a root drive, these steps work for ext4, XFS, and Btrfs filesystems.
Partition resizing is a common task when you run out of disk space or need to dual-boot. The process involves shrinking the partition, then growing it—or the opposite. You must always backup important data before starting, because mistakes can wipe your system.
This article covers both graphical and terminal methods. You’ll learn how to resize partitions on a live USB, handle LVM volumes, and avoid common pitfalls. Let’s get started with the basics.
Why Resize A Linux Partition
You might need to resize a partition for several reasons. Maybe your root partition is full and you want to expand it into unallocated space. Or you need to shrink a large data partition to make room for a new OS. Resizing helps you manage storage without reinstalling.
Linux partitions use filesystems that support online or offline resizing. Most desktop users prefer offline resizing for safety. The key is to unmount the partition first, then use tools like resize2fs for ext4 or xfs_growfs for XFS.
Remember: shrinking a partition is riskier than expanding it. Always check the filesystem for errors before resizing. This prevents data corruption.
Common Scenarios For Resizing
- Freeing up space from a large home partition to expand root
- Creating a new partition for a different Linux distribution
- Shrinking a Windows partition to dual-boot Linux
- Expanding a virtual machine disk in KVM or VirtualBox
How To Resize Linux Partition
Now we dive into the actual steps. The exact keyword “How To Resize Linux Partition” is the focus here. You’ll learn two methods: using GParted (graphical) and using command-line tools (terminal). Both work on most Linux distributions like Ubuntu, Fedora, and Debian.
Method 1: Using GParted (Graphical)
GParted is a free partition editor with a user-friendly interface. It supports resizing, moving, and creating partitions. You need a live USB or CD to run GParted because the partition must be unmounted.
Step 1: Boot from a live USB
Create a bootable Ubuntu or GParted live USB. Boot into it and select “Try Ubuntu” or the live environment. This ensures all partitions are unmounted.
Step 2: Open GParted
Search for “GParted” in the menu. It will show your disk layout. Select the partition you want to resize from the list.
Step 3: Resize the partition
Right-click the partition and choose “Resize/Move”. A dialog appears where you can drag the edges or enter exact sizes. For shrinking, reduce the “New size” value. For expanding, increase it if unallocated space exists after the partition.
Step 4: Apply changes
Click the green checkmark to apply all pending operations. GParted will resize the filesystem and partition. This may take a few minutes depending on size.
Step 5: Verify
After completion, reboot into your installed system. Use df -h to confirm the new size.
Method 2: Using Command-Line Tools
If you prefer the terminal, use fdisk or parted along with filesystem-specific tools. This method gives you more control but requires careful attention.
Step 1: Identify the partition
Run lsblk or fdisk -l to list disks and partitions. Note the device name like /dev/sda2.
Step 2: Unmount the partition
If the partition is mounted, unmount it with sudo umount /dev/sda2. For root partitions, boot from a live USB.
Step 3: Check filesystem
Run sudo e2fsck -f /dev/sda2 for ext4. This checks for errors before resizing.
Step 4: Resize the filesystem
Use sudo resize2fs /dev/sda2 20G to shrink the filesystem to 20GB. For expanding, just run sudo resize2fs /dev/sda2 after enlarging the partition.
Step 5: Resize the partition
Use sudo fdisk /dev/sda to delete and recreate the partition with a new size. Delete the partition (option d), then create a new one (option n) with the same start sector but a smaller or larger end sector. Write changes with w.
Step 6: Expand filesystem
After partition resize, run sudo resize2fs /dev/sda2 to grow the filesystem to fill the partition.
Resizing LVM Partitions
Logical Volume Manager (LVM) makes resizing easier because you can shrink or expand logical volumes without touching the physical disk. First, unmount the volume, then use lvreduce or lvextend.
For shrinking an LVM volume:
- Unmount:
sudo umount /dev/vg_name/lv_name - Check:
sudo e2fsck -f /dev/vg_name/lv_name - Shrink filesystem:
sudo resize2fs /dev/vg_name/lv_name 10G - Shrink LV:
sudo lvreduce -L 10G /dev/vg_name/lv_name - Mount and verify
For expanding, just extend the LV first, then the filesystem.
Precautions Before Resizing
Resizing partitions carries risk. Always follow these precautions:
- Backup important data to an external drive or cloud
- Use a live USB to ensure partitions are unmounted
- Check filesystem integrity with fsck before resizing
- Do not interrupt the process—power loss can corrupt data
- Leave some free space for system operations (at least 5-10%)
What If Something Goes Wrong
If you encounter errors, stop immediately. Use fsck to repair the filesystem. If the partition becomes unbootable, boot from a live USB and restore from backup. Tools like testdisk can recover lost partitions, but success is not guaranteed.
For minor issues like “filesystem is not clean,” run sudo e2fsck -f /dev/sdaX again. If the partition table is corrupted, use gdisk or fdisk to recreate it with correct start sectors.
Resizing Specific Filesystems
Different filesystems require different tools. Here’s a quick reference:
- ext2/3/4: Use
resize2fsfor both shrink and grow - XFS: Only grow online with
xfs_growfs; cannot shrink - Btrfs: Use
btrfs filesystem resizefor online resizing - NTFS: Use
ntfsresize(usually for dual-boot with Windows)
For XFS, you must shrink by recreating the filesystem. This means backing up data, deleting the partition, creating a smaller one, and restoring. It’s not ideal for shrinking.
Resizing Root Partition
Resizing the root partition (/) is tricky because it’s mounted during normal operation. You must boot from a live USB. The steps are the same as above, but you need to identify the correct device (e.g., /dev/sda1).
After resizing, you may need to update the bootloader. For GRUB, run sudo update-grub from the live environment if the partition UUID changed. Usually, it stays the same.
Common Mistakes And Fixes
Here are mistakes users often make when learning how to resize Linux partition:
- Not unmounting the partition: GParted or resize2fs will fail with “device is busy.” Use
lsofto find processes using it. - Shrinking too much: If you shrink below the data size, filesystem corruption occurs. Always leave headroom.
- Forgetting to resize filesystem after partition: The partition may show new size but the filesystem doesn’t. Run
resize2fsagain. - Using wrong start sector: When deleting and recreating partitions, ensure the start sector matches exactly. Otherwise, data is lost.
To avoid start sector errors, use parted with unit s to see sectors. Or better, use GParted which handles this automatically.
Advanced: Resizing With System Rescue
For servers or headless systems, you can use SystemRescueCd. It includes GParted and command-line tools. Boot from the ISO, then follow the same steps. This is useful when you don’t have a GUI.
You can also use parted in rescue mode. For example, to shrink a partition from the command line:
sudo parted /dev/sdaresizepart 2 20GB(resize partition 2 to 20GB)quit- Then resize filesystem with
resize2fs
This method is faster but requires precise numbers.
Automating Resizing With Scripts
If you resize partitions frequently, write a script. For example, a bash script to shrink a partition:
#!/bin/bash
DEVICE="/dev/sda2"
MOUNT="/mnt"
sudo umount $DEVICE
sudo e2fsck -f $DEVICE
sudo resize2fs $DEVICE 10G
sudo fdisk /dev/sda <<EOF
d
2
n
p
2
+10G
w
EOF
sudo resize2fs $DEVICE
sudo mount $DEVICE $MOUNT
Test the script in a virtual machine first. Typos in fdisk commands can destroy data.
Resizing On Virtual Machines
Virtual machines often need partition resizing after increasing the virtual disk. First, expand the disk in your hypervisor (VirtualBox, VMware, KVM). Then boot the VM with a live ISO and resize the partition to fill the new space.
For KVM, use qemu-img resize to expand the disk image. Then follow the GParted steps. The process is identical to physical disks.
Resizing With LVM On Virtual Machines
If your VM uses LVM, you can add the new space to a physical volume. After expanding the virtual disk, run sudo pvresize /dev/sda2 to extend the PV. Then extend the LV and filesystem.
This is safer than partition resizing because you don’t need to delete and recreate partitions.
Frequently Asked Questions
Can I resize a Linux partition without losing data?
Yes, as long as you follow proper steps: backup, unmount, check filesystem, and use reliable tools. Shrinking is riskier than expanding, but both are safe if done correctly.
What is the best tool to resize Linux partitions?
GParted is the most user-friendly for beginners. For advanced users, command-line tools like fdisk and resize2fs offer more control. Both are free and included in most live distributions.
Can I resize the root partition while the system is running?
No, you cannot resize a mounted partition. You must boot from a live USB or use a rescue environment. The only exception is expanding an XFS filesystem, which can be done online.
How long does it take to resize a Linux partition?
It depends on the size and disk speed. A 100GB partition may take 10-20 minutes for shrinking, but expanding is faster. Always allocate enough time and avoid interruptions.
What happens if I resize a partition and the system won’t boot?
Boot from a live USB and check the partition table. Use fdisk -l to verify the partition exists. If the filesystem is corrupted, run fsck. If the bootloader is broken, reinstall GRUB.
Final Tips For Success
Learning how to resize Linux partition takes practice. Start with a test virtual machine or a spare disk. Always double-check the partition number and size before applying changes.
Keep your system updated with the latest tools. For example, newer versions of GParted support more filesystems and are more stable. Also, consider using LVM for future flexibility—it makes resizing much simpler.
If you’re unsure, ask for help on forums like LinuxQuestions or Reddit’s r/linuxquestions. Provide your disk layout and the exact error message. Most issues are solvable with patience.
Remember: the key to safe resizing is preparation. Backup, verify, and then act. With these steps, you can manage your disk space effectively without data loss.