News
Faster Speeds: Bandwidth for vStack Servers in Kazakhstan Increased to 200 Mbps
DC
May 14 2020
Updated June 1 2025

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

CentOS VPS

Using another OS?

Select the desired version or distribution.

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

  • Q: Why do I need to resize the partition and file system after increasing the disk size in the control panel?
    A: Increasing the disk size at the virtualization or hosting level only adds physical or virtual capacity to the disk device. However, the operating system, CentOS 7 in this case, does not automatically recognize or use this additional space. To make the new space available for storing files, you must manually resize the disk partitions and update the file system so the OS can fully utilize the expanded storage.
  • Q: Is it safe to delete and recreate a partition during this process?
    A: Yes, but only if you follow the exact steps without altering the starting sector of the partition. Deleting and recreating the partition with the same starting sector preserves your existing data. This process is necessary to allow the partition to extend into the new available space.
  • Q: What if my disk uses LVM (Logical Volume Manager)?
    A: After resizing the partition, you also need to resize the physical volume (PV) and logical volume (LV) managed by LVM. This ensures the additional space is properly allocated and accessible by your file system.
  • Q: Will this process cause data loss?
    A: When done correctly, this procedure should not cause data loss. However, it is highly recommended to back up important data before starting, as disk operations always carry some risk.
  • Q: Which file system types does this guide support?
    A: This guide uses xfs_growfs to expand the file system, which means it assumes the root partition is formatted with XFS, the default for CentOS 7. For other file systems like ext4, different commands are required.
Vote:
4 out of 5
Аverage rating : 4.8
Rated by: 14
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300

You might also like...

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.