Extend volume on CentOs8 VM/ESXi

Situation: ESXi host – CentOs 8 VM, “/dev/mapper/cl-root” volume at 95%.

Virtual disk capacity needs to be increased.

Access the ESXi host web GUI

Then edit the VM settings

In this case, when I was trying to increase this disk capacity, I got an error:

It results that if you are working on a VM with snapshots, you won’t be able to resize the disk.

So, the next step = Delete all snapshots

But before doing it, Exporting the VM looked like a good thing to do:

The expert process finished with downloading these three files:

Now, remove all snapshots!

This process might take some time.

Wait for it to complete.

Then, Edit the VM settings again, resize the disk – Success!

Now I’ll paste the screen captures of the process in CentOs

df -h

/dev/mapper/cl-root use is 95%, mounted on the root folder

fdisk -l

With this output we confirm partitions location, number, type. In this case I wanted to increase /dev/sda3

fdisk /dev/sda

fdisk to configure the disk “/dev/sda’ – Then pressed “n” to create a new partition, then just enter to accept the default partition number to be created.

Then press

-“n” to create the new partition
-Select partition number, then just enter twice when choosing first and last sector.
-“t”
– select the partition by the number.
-“8e” to set the partition type

Now enter “p”

Command (m for help): p
Disk /dev/sda: 32 GiB, 34359738368 bytes, 67108864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: C57B359C-EC2F-4761-A334-16B40ADB0DE6
Device Start End Sectors Size Type
/dev/sda1 2048 1230847 1228800 600M EFI System
/dev/sda2 1230848 3327999 2097152 1G Linux filesystem
/dev/sda3 3328000 33552383 30224384 14.4G Linux LVM
/dev/sda4 33552384 67108830 33556447 16G Linux filesystem

Then enter “w” to write all changes.

Command (m for help): w
The partition table has been altered.
Syncing disks.

Then list your partitions

[root@hostname ~]# fdisk -l
Disk /dev/sda: 32 GiB, 34359738368 bytes, 67108864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: C57B359C-EC2F-4761-A334-16B40ADB0DE6
Device Start End Sectors Size Type
/dev/sda1 2048 1230847 1228800 600M EFI System
/dev/sda2 1230848 3327999 2097152 1G Linux filesystem
/dev/sda3 3328000 33552383 30224384 14.4G Linux LVM
/dev/sda4 33552384 67108830 33556447 16G Linux filesystem
Disk /dev/mapper/cl-root: 12.8 GiB, 13753122816 bytes, 26861568 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/cl-swap: 1.6 GiB, 1719664640 bytes, 3358720 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

After using “fdisk -l” to list the partitions, notice in the output, I have highlighted the partition we want to resize, and the new partition we are going to use

Continue:

Remember that in my case, the new partition was “sda4” please beware that yours might be different

[root@hostname ~]# pvcreate /dev/sda4
Physical volume “/dev/sda4” successfully created.

[root@hostname ~]# vgdisplay
— Volume group —
VG Name cl
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 14.41 GiB
PE Size 4.00 MiB
Total PE 3689
Alloc PE / Size 3689 / 14.41 GiB
Free PE / Size 0 / 0
VG UUID XFapw6-Ti8u-XroG-J7B3

Remember that in my case, the new partition was “sda4” please beware that yours might be different

[root@hostname ~]# vgextend cl /dev/sda4
Volume group “cl” successfully extended

[root@hostname ~]# lvdisplay
— Logical volume —
LV Path /dev/cl/swap
LV Name swap
VG Name cl
LV UUID nF8cPk-s7TG-Gx2V-nNUx-oxZs-uGrJ-oxHPya
LV Write Access read/write
LV Creation host, time localhost, 2020-10-21 14:48:22 -0400
LV Status available
# open 2
LV Size 1.60 GiB
Current LE 410
Segments 1
Allocation inherit
Read ahead sectors auto


— Logical volume —
LV Path /dev/cl/root
LV Name root
VG Name cl
LV UUID d6a3gM-xVfD-28zy-9UTZ-xmS6-qh3d-q9Ht5F
LV Write Access read/write
LV Creation host, time localhost, 2020-10-21 14:48:22 -0400
LV Status available
# open 1
LV Size <12.81 GiB
Current LE 3279
Segments 1
Allocation inherit
Read ahead sectors auto

[root@hostname ~]# lvextend -l +100%FREE /dev/cl/root
Size of logical volume cl/root changed from <12.81 GiB (3279 extents) to 28.80 GiB (7374 extents).
Logical volume cl/root successfully resized.

Now check the tye for the final step using “df -Th”

[root@hostname ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 878M 0 878M 0% /dev
tmpfs tmpfs 895M 32K 895M 1% /dev/shm
tmpfs tmpfs 895M 8.7M 887M 1% /run
tmpfs tmpfs 895M 0 895M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 13G 13G 713M 95% /
/dev/sda2 ext4 976M 185M 725M 21% /boot
/dev/sda1 vfat 599M 7.3M 592M 2% /boot/efi
tmpfs tmpfs 179M 0 179M 0% /run/user/48
tmpfs tmpfs 179M 0 179M 0% /run/user/0

Notice that the type is “xfs”, so I used “xfs_growfs”

[root@hostname ~]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-root isize=512 agcount=4, agsize=839424 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=3357696, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 3357696 to 7550976

Finally, to confirm: df -Th

[root@hostname ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 878M 0 878M 0% /dev
tmpfs tmpfs 895M 32K 895M 1% /dev/shm
tmpfs tmpfs 895M 8.7M 887M 1% /run
tmpfs tmpfs 895M 0 895M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 29G 13G 17G 43% /
/dev/sda2 ext4 976M 185M 725M 21% /boot
/dev/sda1 vfat 599M 7.3M 592M 2% /boot/efi
tmpfs tmpfs 179M 0 179M 0% /run/user/48
tmpfs tmpfs 179M 0 179M 0% /run/user/0

If your partition type is not “xfs” you may try the command for “ext4”:

resize2fs -p /dev/mapper/cl-root

2 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.