Expand partitions with growpart on vps

Expand partitions with growpart on vps

Intro

we often encountered that the virtual machine disk is full and then needs to be expanded, and record the process

Operation

First check the size of the current system disk

[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors

Then change your disk size in esxi just example 200 GiB

Rescan the disk

The command is similar to the following

echo "---" > /sys/class/scsi_device/0\:0\:1\:0/device/rescan

Of course, you can also choose to restart the machine

[root@localhost ~]# fdisk -l
GPT PMBR size mismatch (209715199 != 419430399) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors

Install growpart

yum install cloud-utils-growpart

Expand the partition

growpart /dev/sda 3

Because I use Rocky Linux, I use lvm when installing by default, so first expand the PV, if you do not have LVM configured, then jump directly to the expansion file system

View the current PV size

[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name rl
PV Size 98.41 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25193
Free PE 1
Allocated PE 25192
PV UUID TGVCwX-lv6Z-ZPhn-5ffp-KO7j-poBh-CKa92M

Resize the physical volume

[root@localhost ~]# pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized

View the physical volume size

[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name rl
PV Size 198.41 GiB / not usable 1.98 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 50793
Free PE 25601
Allocated PE 25192
PV UUID TGVCwX-lv6Z-ZPhn-5ffp-KO7j-poBh-CKa92M

It’s already 200g, expand the logical volume

View the logical volume size

[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/rl/swap
LV Name swap
VG Name rl
LV UUID PO9f7n-7DJH-xv8z-vZNp-4Nm3-4S16-OCOrlk
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2022-03-08 21:11:54 +0800
LV Status available
# open 2
LV Size <7.88 GiB
Current LE 2016
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1

--- Logical volume ---
LV Path /dev/rl/root
LV Name root
VG Name rl
LV UUID YhzOQ2-uNmL-QHKx-NU3o-iSbo-GgTI-dMeDCs
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2022-03-08 21:11:54 +0800
LV Status available
#open 1
LV Size 90.53 GiB
Current LE 23176
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

Expand the logical volume

lvextend -l +100%FREE /dev/rl/root

Finally, expand the file system

xfs_growfs /dev/mapper/rl-root

Finally look at the capacity

[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs 7.7G 0 7.7G 0% /dev/shm
tmpfs 7.7G 11M 7.7G 1% /run
tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/mapper/rl-root 191G 28G 163G 15% /

Article Tags:
· ·
Article Categories:
blog · meocloud · vps

Leave a Reply

Your email address will not be published. Required fields are marked *

Don't Miss! random posts ..