How to Extend a Linux Disk Partition and Filesystem
15 Nov 2026, 10:36:52
In Linux, you can increase the size of an existing partition without reinstalling the operating system or losing data. This can be done using standard system utilities such as parted, fdisk, growpart, resize2fs, and xfs_growfs.In this article, we will explain how to increase the size of a Linux partition and extend the filesystem so that the operating system can use all available disk space.
Important: Before modifying the partition table, it is recommended to create a backup of important data. Errors when working with partitions can result in data loss.
Checking the Current Disk Layout
Before proceeding, you need to determine:- Which disk is used by the system.
- Which partition needs to be extended.
- Which filesystem the partition uses.
- Whether unallocated space is available on the disk.
lsblk
To display filesystem information and mount points, run:
lsblk -f
Check disk space usage:
df -h
To view the partition table, run:
fdisk -l
To determine the partition table type, you can use:
parted /dev/sda print
Expanding the Disk
If you are using a VPS, you must first increase the virtual disk size through your hosting provider's control panel.On a physical server, you will need to increase the available disk capacity or connect an additional storage device.
After expanding the disk, Linux may not immediately detect the new size. In this case, rescan the device:
echo 1 > /sys/class/block/sda/device/rescanCheck the updated disk size:lsblkIf the disk size has changed but the partition size remains the same, you can proceed to the next step.Increasing the Partition Size
You can use growpart or parted to increase the partition size.Option 1. Using growpart
growpart allows you to extend an existing partition into the maximum amount of available contiguous free space immediately following it.Check whether the utility is installed:
which growpart
If the utility is not installed, install the required package.
Debian / Ubuntu:
apt update
apt install cloud-guest-utilsAlmaLinux / Rocky Linux:dnf install cloud-utils-growpartBefore making changes, you can preview the result without modifying the partition table:growpart -N /dev/sda 1Where:- /dev/sda — the disk.
- 1 — the number of the partition you want to extend.
growpart /dev/sda 1
After that, check the updated partition table:
lsblk
Important: growpart can extend a partition only into free space located immediately after it. If other partitions are located between the target partition and the free space, you will need to modify the partition layout manually.
Option 2. Using parted
The parted utility allows you to modify partition sizes directly through the partition table.Start the utility:
parted /dev/sdaView the current disk layout:printTo extend partition 1 to the end of the disk, run:resizepart 1 100%
Exit the utility:
quitUpdate the kernel's partition information:partprobe /dev/sdaCheck the result:lsblk
Note: resizepart changes the partition boundary but does not resize the filesystem. This must be done separately.
You must also not move the beginning of a partition without proper preparation. If the partition contains system data, incorrectly changing its boundaries may prevent the operating system from booting.
Extending the Filesystem
After extending the partition, you must also resize the filesystem so that the operating system can use the newly available space.The command depends on the filesystem type.
For ext4
If the partition uses the ext4 filesystem, run:resize2fs /dev/sda1
In most cases, ext4 can be extended without unmounting the partition, including the root filesystem mounted at /.
For XFS
For the XFS filesystem, use a different command:xfs_growfs /In this case, you must specify the filesystem's mount point rather than the device.XFS supports online filesystem expansion without unmounting, but it does not support shrinking.
Verifying the Result
After completing all operations, check the partition size and available disk space:lsblk
Check the filesystem size:
df -h
If the filesystem size has increased, the operation was successful.
What to Do If the Partition Is Not at the End of the Disk
Sometimes, the unallocated space is not located immediately after the partition you want to extend.For example, the disk layout may look like this:
/dev/sdaIn this case, you cannot automatically extend /dev/sda2 using the available free space because /dev/sda3 is located between the target partition and the unallocated space.
├─sda1 1 GB /boot
├─sda2 20 GB /
├─sda3 5 GB swap
└─Free 30 GB Unallocated
Possible solutions include:
- Move or delete the intermediate partition, if appropriate.
- Disable the swap partition, delete it, and recreate it in a different location.
- Use a LiveCD or GParted to move partitions.
- If necessary, back up your data and modify the disk partition layout.
Useful Commands
| Command | Description |
|---|---|
| lsblk -f | Displays disks, partitions, and filesystems |
| df -h | Checks disk space usage |
| fdisk -l | Displays the partition table |
| parted -l | Displays disk partition information |
| growpart | Extends an existing partition |
| partprobe | Updates partition information |
| resize2fs | Extends an ext2/ext3/ext4 filesystem |
| xfs_growfs | Extends an XFS filesystem |
Conclusion
You can increase the size of a Linux partition without reinstalling the operating system or losing data.The general procedure is as follows:
- Increase the size of the virtual or physical disk.
- Check the newly available disk capacity.
- Extend the required partition using growpart or parted.
- Extend the filesystem using resize2fs or xfs_growfs.
- Verify the result using the df -h command.