Expanding Disks in Linux

Tadios Abebe | Jan 4, 2025 min read

Expanding disk space in a Linux system is a common task, especially in virtual environments. Whether you’re using a generic distribution or specialized distribution, the process involves expanding the partition, resizing the physical volume, logical volume (if using LVM), and finally the filesystem.

Expanding Disk on Generic Linux Systems

1. Expand the Partition

Use cfdisk to resize the partition to utilize the remaining unallocated space on the disk:

cfdisk /dev/vda

Select the partition (e.g. /dev/vda2), resize it, To take the remaining free space

2. If using LVM

1. Resize the Physical Volume (PV)

Update LVM’s metadata to recognize the new partition size:

pvresize /dev/vda2

2. Extend the Logical Volume (LV)

Resize the logical volume to use 50% of the available free space in the volume group:

lvextend -l +50%FREE /dev/rhel/root

You can use +100%FREE if you want to allocate all free space.

3. Resize the Filesystem

Choose the appropriate command depending on your filesystem:

  • For XFS:
xfs_growfs /dev/rhel/root
  • For EXT4:
resize2fs /dev/rhel/root

Expanding Disk on Oracle Linux

Oracle Linux uses slightly different tools and naming conventions, but the process is nearly identical.

1. Resize the Partition with parted

parted -s /dev/vda resizepart 2 100%

2. Resize the Physical Volume (PV)

pvresize /dev/vda2

3. Extend the Logical Volume (LV)

Resize the logical volume to consume all free space in the volume group:

lvextend -l +100%FREE /dev/ol/root

4. Resize the Filesystem

  • For XFS:
xfs_growfs /dev/ol/root
  • For EXT4:
resize2fs /dev/ol/root
comments powered by Disqus