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

  1. 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.
  2. Execute df -Th to check the file system type.
  3. Log in to the Linux system and install the growpart tool:
CentOS 7
sudo yum install -y cloud-utils-growpart
Ubuntu 22.04
sudo apt install -y cloud-guest-utils

For 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.

Terminal window
[root@localhost ~]# df -Th
Filesystem 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% /dev
tmpfs tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs tmpfs 7.8G 43M 7.7G 1% /run
tmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/vda1 xfs 1014M 145M 870M 15% /boot
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/storage-data xfs 994G 724G 271G 73% /data

Originally, 40GB was allocated for the root directory. We are adding 40GB, making the total space 80GB, so there is 40GB shown as unallocated.

Terminal window
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 428K 0 rom
vda 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 /data

View current LVM physical volume information:

Terminal window
[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-1d7106f8dc2f

View current LVM volume group information:

Terminal window
[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-a8e1c8ab03ef

View LVM logical volume information:

Terminal window
[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 <31.00 GiB
Current LE 7935
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:2

Execution of Resize Operations

Expand specified block device size:

Terminal window
[root@localhost ~]# growpart /dev/vda 2
CHANGED: partition=2 start=2099200 old: size=81786880 end=83886080 new: size=165672927 end=167772127
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 428K 0 rom
vda 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 /data

Resize the LVM physical volume:

Terminal window
[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-1d7106f8dc2f

Extend the LVM logical volume:

Terminal window
[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:2

The 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:

XFS File System
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2031360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=8125440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=3967, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 8125440 to 18611200
ext4 File System
sudo resize2fs /dev/mapper/centos-root

Check the final resizing result:

Terminal window
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 71G 17G 55G 24% /
devtmpfs devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs tmpfs 7.8G 43M 7.7G 1% /run
tmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/vda1 xfs 1014M 145M 870M 15% /boot
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/storage-data xfs 994G 724G 271G 73% /data