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:
Run the command below using fdisk:
Delete the /dev/sda2 section:
Partition number (1,2, default 2): 2
Create a section:
Select the section type (p) - main
Partition number (2-4, default 2): 2
Press Enter twice - accept the values by default
Last sector, +sectors or +size{K,M,G} (XXX-YYY, default ZZZ):
Change the section type
Partition number (1-2): 2
Hex code (type L to list all codes): 8e
...
Save the changes:
Notify the kernel of the change:
Make changes to the physical volume:
Now you need to get the name of the logical volume:
Look for the name of the volume ending with XXXXXXX/root (in the example below it is /dev/centos_vg/root).
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:
......
Logical volume root successfully resized
Expand the file system:
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.