DC
Daniella Coleman
May 14, 2020
Updated August 7, 2022

How to expand disk space on CentOS 7

CentOS VPS

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

Vote:
4 out of 5
Аverage rating : 4.7
Rated by: 3
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.