Introduction
Whether in a private or public cloud, the storage space distributed to virtual machines in production environments is generally not very large. However, as business grows, storage space often becomes insufficient, requiring an increase in capacity. This article will introduce how to resize storage space on a Linux system in a private cloud environment.
Preparation
- In the virtualization platform, select the disk to be resized, click on resize, enter the new size, click confirm, and wait for the resizing to complete.
- Execute
df -Thto check the file system type. - Log in to the Linux system and install the
growparttool:
sudo yum install -y cloud-utils-growpartsudo apt install -y cloud-guest-utilsFor operations in a private cloud production environment for the first time, it is highly recommended to create a backup snapshot beforehand to prevent system crashes caused by operational errors.
Pre-operation Information Check
Check the root directory. Due to program caching, the disk usage frequently exceeds 80%, triggering frequent monitoring alerts, thus the root directory needs to be resized.
[root@localhost ~]# df -ThFilesystem Type Size Used Avail Use% Mounted on/dev/mapper/centos-root xfs 31G 22G 9.7G 69% /devtmpfs devtmpfs 7.8G 0 7.8G 0% /devtmpfs tmpfs 7.8G 0 7.8G 0% /dev/shmtmpfs tmpfs 7.8G 43M 7.7G 1% /runtmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup/dev/vda1 xfs 1014M 145M 870M 15% /boottmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0/dev/mapper/storage-data xfs 994G 724G 271G 73% /dataOriginally, 40GB was allocated for the root directory. We are adding 40GB, making the total space 80GB, so there is 40GB shown as unallocated.
[root@localhost ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 428K 0 romvda 252:0 0 80G 0 disk├─vda1 252:1 0 1G 0 part /boot└─vda2 252:2 0 39G 0 part ├─centos-root 253:0 0 31G 0 lvm / └─centos-swap 253:1 0 8G 0 lvm [SWAP]vdb 252:16 0 1000G 0 disk└─vdb1 252:17 0 994G 0 part └─storage-data 253:2 0 994G 0 lvm /dataView current LVM physical volume information:
[root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/vda2 VG Name centos PV Size <39.00 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 9983 Free PE 0 Allocated PE 9983 PV UUID b10ba6bb-f834-4586-b2ed-d4cd48a380e7
--- Physical volume --- PV Name /dev/vdb1 VG Name storage PV Size <994.00 GiB / not usable 2.98 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 254463 Free PE 0 Allocated PE 254463 PV UUID b2cc8a3b-f303-4aed-9e64-1d7106f8dc2fView current LVM volume group information:
[root@localhost ~]# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size <39.00 GiB PE Size 4.00 MiB Total PE 9983 Alloc PE / Size 9983 / <39.00 GiB Free PE / Size 0 / 0 VG UUID 1f9a2057-a09e-4b44-9653-d9a9cdb7bf97
--- Volume group --- VG Name storage System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size <994.00 GiB PE Size 4.00 MiB Total PE 254463 Alloc PE / Size 254463 / <994.00 GiB Free PE / Size 0 / 0 VG UUID 83fd0dd2-03c7-4eb3-abf7-a8e1c8ab03efView LVM logical volume information:
[root@localhost ~]# lvdisplay--- Logical volume ---LV Path /dev/centos/swapLV Name swapVG Name centosLV UUID 6add95fe-d525-449d-9b73-9220738be6ffLV Write Access read/writeLV Creation host, time localhost, 2024-12-25 16:23:51 +0800LV Status available# open 2LV Size 8.00 GiBCurrent LE 2048Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:1
--- Logical volume ---LV Path /dev/centos/rootLV Name rootVG Name centosLV UUID abf6ca1d-ceb0-4cec-a2a7-f510b9dce3b9LV Write Access read/writeLV Creation host, time localhost, 2024-12-25 16:23:51 +0800LV Status available# open 1LV Size <31.00 GiBCurrent LE 7935Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:0
--- Logical volume ---LV Path /dev/storage/dataLV Name dataVG Name storageLV UUID fe6f9801-c930-4aec-9fd0-39e7b39ccfafLV Write Access read/writeLV Creation host, time localhost.localdomain, 2025-11-03 14:09:57 +0800LV Status available# open 1LV Size <994.00 GiBCurrent LE 254463Segments 1Allocation inheritRead ahead sectors auto- currently set to 256Block device 253:2Execution of Resize Operations
Expand specified block device size:
[root@localhost ~]# growpart /dev/vda 2CHANGED: partition=2 start=2099200 old: size=81786880 end=83886080 new: size=165672927 end=167772127[root@localhost ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 428K 0 romvda 252:0 0 80G 0 disk├─vda1 252:1 0 1G 0 part /boot└─vda2 252:2 0 79G 0 part ├─centos-root 253:0 0 31G 0 lvm / └─centos-swap 253:1 0 8G 0 lvm [SWAP]vdb 252:16 0 1000G 0 disk└─vdb1 252:17 0 994G 0 part └─storage-data 253:2 0 994G 0 lvm /dataResize the LVM physical volume:
[root@localhost ~]# pvresize /dev/vda2 Physical volume "/dev/vda2" changed 1 physical volume(s) resized or updated / 0 physical volume(s) not resized[root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/vda2 VG Name centos PV Size <79.00 GiB / not usable 1.98 MiB Allocatable yes PE Size 4.00 MiB Total PE 20223 Free PE 10240 Allocated PE 9983 PV UUID b10ba6bb-f834-4586-b2ed-d4cd48a380e7
--- Physical volume --- PV Name /dev/vdb1 VG Name storage PV Size <994.00 GiB / not usable 2.98 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 254463 Free PE 0 Allocated PE 254463 PV UUID b2cc8a3b-f303-4aed-9e64-1d7106f8dc2fExtend the LVM logical volume:
[root@localhost ~]# lvextend -l +100%FREE /dev/centos/root Size of logical volume centos/root changed from <31.00 GiB (7935 extents) to <71.00 GiB (18175 extents). Logical volume centos/root successfully resized[root@localhost ~]# lvdisplay --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID 6add95fe-d525-449d-9b73-9220738be6ff LV Write Access read/write LV Creation host, time localhost, 2024-12-25 16:23:51 +0800 LV Status available # open 2 LV Size 8.00 GiB Current LE 2048 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1
--- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID abf6ca1d-ceb0-4cec-a2a7-f510b9dce3b9 LV Write Access read/write LV Creation host, time localhost, 2024-12-25 16:23:51 +0800 LV Status available # open 1 LV Size <71.00 GiB Current LE 18175 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0
--- Logical volume --- LV Path /dev/storage/data LV Name data VG Name storage LV UUID fe6f9801-c930-4aec-9fd0-39e7b39ccfaf LV Write Access read/write LV Creation host, time localhost.localdomain, 2025-11-03 14:09:57 +0800 LV Status available # open 1 LV Size <994.00 GiB Current LE 254463 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2The above steps complete the resizing of the LVM physical and logical volumes. Next, we need to resize the file system itself. Different file system types require different commands, as shown below:
[root@localhost ~]# xfs_growfs /dev/mapper/centos-rootmeta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2031360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0data = bsize=4096 blocks=8125440, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal bsize=4096 blocks=3967, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 8125440 to 18611200sudo resize2fs /dev/mapper/centos-rootCheck the final resizing result:
[root@localhost ~]# df -ThFilesystem Type Size Used Avail Use% Mounted on/dev/mapper/centos-root xfs 71G 17G 55G 24% /devtmpfs devtmpfs 7.8G 0 7.8G 0% /devtmpfs tmpfs 7.8G 0 7.8G 0% /dev/shmtmpfs tmpfs 7.8G 43M 7.7G 1% /runtmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup/dev/vda1 xfs 1014M 145M 870M 15% /boottmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0/dev/mapper/storage-data xfs 994G 724G 271G 73% /data