Increase Root Partition Size with Free Disk Space in Linux
In this article
To increase your root partition size using free disk space in Linux, you need to extend the partition and then resize the filesystem, typically using tools like fdisk, parted, or growpart, followed by resize2fs for ext4 or xfs_growfs for XFS. This guide walks you through the process safely, whether you have unallocated space adjacent to the root partition or need to move partitions first.
Understanding Partitions and Filesystems
Linux systems store data on partitions, which are logical sections of a disk. Each partition holds a filesystem (e.g., ext4, XFS, Btrfs) that manages files and directories. The root partition (/) is where the operating system and installed software reside. When it runs out of space, the system can become unstable or fail to boot. Increasing its size involves two steps: first, enlarge the partition itself, and second, grow the filesystem to fill the new space. The filesystem must support online resizing—most modern ones (ext4, XFS, Btrfs) do, but the exact command differs.
Prerequisites and Safety Checks
Before making any changes, back up important data. While resizing is generally safe when done correctly, a power failure or mistake can corrupt the filesystem. Also, ensure you have a live USB or recovery media in case the system becomes unbootable. Check current disk usage with df -h and list partitions with lsblk or fdisk -l. You must have unallocated space on the same disk. If the free space is not immediately after the root partition, you will need to move partitions, which is riskier and time-consuming.
Method 1: Using GParted (Graphical)
For desktop users, GParted is the easiest tool. Boot from a live USB (e.g., Ubuntu live), open GParted, and select the disk. Right-click the root partition and choose Resize/Move. Drag the slider to fill the unallocated space, or enter the new size manually. Click Resize, then apply the operation. GParted will resize the partition and the filesystem in one go. This method works for ext4, XFS, and others, but it requires the partition to be unmounted, which is why you boot from a live environment.
Method 2: Command-Line with growpart and resize2fs
On servers or if you prefer the terminal, use growpart to expand the partition and then resize the filesystem. First, identify the disk and partition number (e.g., /dev/sda2). Unmount the partition if it’s not the root (but for root, you may need to boot from a live environment or use a rescue mode). Then run:
sudo growpart /dev/sda 2— expands partition 2 on /dev/sda to fill unallocated space.sudo resize2fs /dev/sda2— grows the ext4 filesystem to occupy the new partition size.
For XFS, use sudo xfs_growfs / (or the mount point) after growing the partition. This method requires the partition to be mounted for XFS, but ext4 can be resized online if the kernel supports it.
What If Free Space Is Not Adjacent?
If the unallocated space is not directly after the root partition, you must move partitions. This is riskier because moving changes the start sector, which can break boot loaders or other references. Tools like GParted can move partitions, but the operation takes time and has a higher chance of failure. A safer alternative is to create a new partition in the free space and mount it to a directory (e.g., /home or /var) to offload data, effectively freeing space on root without resizing.
Common Problems and How to Avoid Them
- Partition is mounted: You cannot resize a mounted partition with GParted. Use a live environment or unmount it.
- Wrong disk: Double-check the disk name (e.g.,
/dev/sdavs/dev/nvme0n1). A mistake can wipe data. - Filesystem not recognized: If you use a custom filesystem, ensure the correct resize tool is installed.
- Boot loader issues: After resizing, GRUB may need updating. Run
sudo update-grub(on Debian/Ubuntu) orgrub2-mkconfig(on RHEL/Fedora). - LVM complications: If you use LVM, you must extend the physical volume, logical volume, and filesystem separately (e.g.,
pvresize,lvextend,resize2fs).
Frequently Asked Questions
Can I resize the root partition while the system is running?
For ext4, you can grow the filesystem online, but you cannot grow the partition itself while it is mounted. You must boot from a live USB or use a rescue mode to modify the partition table. XFS can grow both partition and filesystem online, but only if the partition is extended first, which still requires unmounting or a live environment for the partition table change.
What is the difference between partition and filesystem?
A partition is a physical division of the disk, defined in the partition table. A filesystem is the structure (like ext4 or XFS) that organizes files within that partition. You must enlarge both: first the partition, then the filesystem, unless using a tool like GParted that does both automatically.
How do I know if I have unallocated space?
Run lsblk or fdisk -l. Unallocated space appears as free sectors or not listed as a partition. In GParted, it shows as grey unallocated space. If there is no free space, you cannot increase the root partition without shrinking another partition or adding a new disk.
Is it safe to resize a partition?
Generally yes, but there is always a risk of data loss if the power fails or if you make a mistake. Always back up critical data before proceeding. Moving partitions carries a higher risk than resizing in place.
What if my root partition is on LVM?
With LVM, you can extend the logical volume without moving partitions. First, extend the physical volume (if you added disk space), then extend the logical volume with lvextend, and finally resize the filesystem. This can often be done online without unmounting.
Can I use unallocated space from another disk?
No, you cannot merge space from a different physical disk into an existing partition. You would need to create a new partition on the other disk and mount it to a directory, or use LVM to combine disks into a volume group.
Alternatives to Resizing
If resizing is not feasible, consider these alternatives: move data to a new partition (e.g., mount /var or /home on a separate partition), use symbolic links to redirect large directories to another disk, or use LVM from the start for easier management. In cloud environments, you can often expand the virtual disk and then grow the partition without moving data.