This guide shows you how to safely resize and extend a Linux partition, whether you’re freeing up space or growing a filesystem to use unallocated disk space. You’ll learn both command-line and GParted methods, with clear steps for common scenarios like extending the root partition on a live system.
What You’ll Need
- A Linux system with
sudoaccess (or root) - For resizing the root partition: a live USB or CD with GParted (most distro installers include it)
- For non-root partitions: the
gpartedpackage installed (sudo apt install gpartedor equivalent) - Backup of important data (always recommended before partition changes)
- Unallocated space adjacent to the partition you want to extend
Step-by-Step
- Back up your data. Partition resizing carries a small risk of data loss. Use an external drive or cloud backup for anything you can’t afford to lose.
- Identify the partition. Run
lsblkorsudo fdisk -lto list disks and partitions. Note the device name (e.g.,/dev/sda2) and the filesystem type (ext4, xfs, btrfs, etc.). - Check filesystem health. For ext4, run
sudo e2fsck -f /dev/sdXY. For xfs, usesudo xfs_repair -n /dev/sdXY(read-only check). Skip this step if the partition is mounted and you’re using GParted’s live environment. - Unmount the partition. If it’s not your root partition, unmount it:
sudo umount /dev/sdXY. For root, you must boot from a live USB. - Use GParted (graphical method):
- Open GParted (
sudo gparted). Select the correct disk from the dropdown in the top-right. - Right-click the partition you want to resize and choose Resize/Move.
- Drag the right edge (or enter a new size) to extend into unallocated space. Ensure unallocated space is immediately after the partition.
- Click Resize/Move, then click the green checkmark to apply. Confirm the warning.
- Wait for the operation to complete. This may take a while for large partitions.
- Open GParted (
- Use command line (for ext4 and xfs):
- First, extend the partition itself with
sudo parted /dev/sdX resizepart Y 100%(where X is the disk, Y is the partition number). This grows the partition to fill unallocated space after it. - Then resize the filesystem to fill the partition:
- For ext4:
sudo resize2fs /dev/sdXY - For xfs:
sudo xfs_growfs /mountpoint(must be mounted) - For btrfs:
sudo btrfs filesystem resize max /mountpoint
- For ext4:
- First, extend the partition itself with
- For the root partition (ext4 example):
- Boot from a live USB (e.g., Ubuntu installer). Open GParted.
- Resize the root partition as in step 5. Make sure you have unallocated space after it.
- Apply changes, then reboot into your system. The filesystem is automatically resized on first boot for ext4 (if you used GParted).
- If not, run
sudo resize2fs /dev/sdXYafter boot.
- Verify the result. Run
df -h /mountpointto see the new size. Also check withlsblkto confirm partition size.
Common Mistakes
- Resizing a mounted partition. Most filesystems cannot be safely resized while mounted (except xfs grow). Always unmount or use a live environment.
- Not having unallocated space adjacent. You can only extend into space that immediately follows the partition. If it’s not adjacent, you must move partitions (risky) or create a new partition instead.
- Forgetting to resize the filesystem after the partition. If you only grow the partition but not the filesystem, the extra space is unusable. Always run
resize2fsor the equivalent. - Using the wrong device name. Double-check with
lsblkto avoid resizing the wrong disk. - Ignoring filesystem type. Commands differ between ext4, xfs, btrfs. Using the wrong one can cause errors.
Tips
- Always use a live USB for root partition changes – it’s the safest method.
- Defragment the filesystem before shrinking (if you’re shrinking, not extending). For ext4, use
e4defrag. - For LVM logical volumes, you can extend them online with
lvextendand thenresize2fswithout unmounting. - If you’re extending a partition on a virtual machine, you may need to expand the virtual disk first in the hypervisor.
- Keep a log of the original partition layout with
sudo sfdisk -d /dev/sdX > backup.sfdiskfor easy recovery.
Troubleshooting
GParted shows “Cannot resize because the partition is in use” – Ensure the partition is unmounted. If it’s the root, you must boot from a live USB. Also check for swap partitions that might be using the disk.
After resizing, the filesystem still shows old size – Run sudo resize2fs /dev/sdXY (for ext4) or xfs_growfs (for xfs). This is common if you resized the partition with parted but didn’t resize the filesystem.
Error: “e2fsck: Bad magic number in super-block” – You’re trying to run e2fsck on a non-ext filesystem. Check the filesystem type with blkid /dev/sdXY.
Partition table corrupted after resize – If you have a backup of the partition table (from sfdisk), restore it with sudo sfdisk /dev/sdX < backup.sfdisk. Otherwise, use testdisk to recover.
Not enough unallocated space – You need to shrink another partition first or add a larger virtual disk. Shrinking is riskier; make sure to defragment and check filesystem first.
GParted hangs or takes too long – Resizing large partitions (hundreds of GB) can take hours. Be patient. If it seems stuck, check CPU/disk activity with top or iostat. Do not interrupt the process.
Frequently Asked Questions
Can I resize a partition while it's mounted?
Generally no. Ext4 and most filesystems require unmounting for resize operations. The exception is growing an xfs filesystem, which can be done while mounted. LVM logical volumes can also be extended online.
What's the difference between resizing the partition and resizing the filesystem?
The partition is the logical container on the disk; the filesystem is what stores your files inside it. You must grow both to use new space – first the partition, then the filesystem to fill it.
How do I extend a partition to use all free space on the disk?
Use sudo parted /dev/sdX resizepart Y 100% to extend the partition to the end of the disk, then resize the filesystem. In GParted, drag the partition edge to the end.
Is it safe to resize a partition with GParted?
It's generally safe if you have a backup and the power doesn't fail. GParted performs checks before operations. However, there's always a small risk, so backup first.
Can I shrink a partition instead of extending it?
Yes, but shrinking is more complex. You must shrink the filesystem first (resize2fs -M to minimum, then specify size), then shrink the partition. GParted handles this automatically but requires unmounted partition.
What if I don't have unallocated space after the partition?
You can't extend into non-adjacent space. You'll need to move the partition (risky) or create a new partition elsewhere and mount it. Consider using LVM for future flexibility.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- How to Add & Remove Favorites in Windows 10 Photos App
- Fix Links Not Opening in Chrome: 7 Top Ways
- How to Set Up Tips on Twitter (X) for Android & iOS
- Microphone Access: Give Apps Only What They Need
- Fix QuickBooks Error Code: Step-by-Step Guide
- Connect Alexa to a Soundbar: Choose the Right Setup