07.06.2023

How to expand disk space on CentOS 7

After expanding the disk in the control panel, you need to expand it at the operating system level.

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