Tuesday, March 5, 2019

CENTOS7 LVM Resize

I have been received disk warning for about two weeks and figured out how to resize LVM include shrink.
When I first setup this CENTOS7 VM I have just configured as default by system and it set up the /dev/mapper/centos-root with 50G and /dev/mapper/centos-home with 950G.

Firstly, I have allocated another 1T to virtual hdd and it requires physical volume resize.
pvresize /dev/sda2

Then I need to resize the logical volume centos-root to fill all the free space.
lvresize -l +100%FREE /dev/mapper/centos-root

And I have xfs volume so run the following to grow volume to fit size.
xfs_growfs /

Then I realize /dev/mapper/centos-home is too big so I have done
lvreduce -L 100G /dev/mapper/centos-home

then I had to resize /dev/mapper/centos-root with another 900G
lvresize -l +100%FREE /dev/mapper/centos-root

and then I ran again
xfs_growfs /

then now it seems like

[root@localhost librenms]# fdisk -l

Disk /dev/sda: 2148.6 GB, 2148557389824 bytes, 4196401152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x00005fbb

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 4196401151 2097150976 8e Linux LVM

Disk /dev/mapper/centos-root: 2031.6 GB, 2031649554432 bytes, 3968065536 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/centos-swap: 8455 MB, 8455716864 bytes, 16515072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/centos-home: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes




Resources,
https://serverfault.com/questions/806107/trying-to-increase-centos-root-partition-size-to-consume-full-ssd-capacity
https://www.rootusers.com/lvm-resize-how-to-decrease-an-lvm-partition/