01.06.2025

How to Expand Disk Space on CentOS 7: Step-by-Step Guide

After increasing your disk size in the hosting control panel or virtualization platform, the next crucial step is to make the operating system recognize and utilize the newly added space. Simply expanding the disk at the hardware or virtual layer does not automatically make the extra storage available to CentOS 7. You need to perform additional steps within the operating system itself—such as resizing partitions, updating the file system, and possibly adjusting logical volumes—so that your system can effectively use the expanded disk capacity. This guide will walk you through each step carefully, ensuring a smooth and safe process to increase your available disk space on CentOS 7.

Open a terminal as root and type the following commands:

[root@Serverspace ~]# echo 1 > /sys/block/sda/device/rescan

Run the command below using fdisk:

[root@Serverspace ~]# fdisk /dev/sda

Delete the /dev/sda2 section:

Command (m for help): d
Partition number (1,2, default 2): 2

Create a section:

Command (m for help): n

Select the section type (p) - main

Select (default p): p
Partition number (2-4, default 2): 2

Press Enter twice - accept the values by default

First sector (XXX-YYY, default ZZZ):
Last sector, +sectors or +size{K,M,G} (XXX-YYY, default ZZZ):

Change the section type

Command (m for help): t
Partition number (1-2): 2
Hex code (type L to list all codes): 8e
...

Save the changes:

Command (m for help): w

Notify the kernel of the change:

[root@Serverspace ~]# partx -u /dev/sda2

Make changes to the physical volume:

[root@Serverspace ~]# pvresize /dev/sda2

Now you need to get the name of the logical volume:

lvdisplay

Look for the name of the volume ending with XXXXXXX/root (in the example below it is /dev/centos_vg/root).

--- Logical volume ---
LV Path /dev/centos_vg/swap
....
--- Logical volume ---
LV Path /dev/centos_vg/var
...
--- Logical volume ---
LV Path /dev/centos_vg/root
...

Expand the logical volume:

[root@Serverspace ~]# lvextend -l +100%FREE /dev/XXXXXXX/root
......
Logical volume root successfully resized

Expand the file system:

[root@Serverspace ~]# xfs_growfs /dev/XXXXXXX/root

FAQ