Target system is CentOS 6.x but resizing operations will be done in %pre section of CentOS 7.6 kickstart.
I have already run resize2fs -M /dev/mapper/centos-home
successfully.
If I mount the volume, df says it's 100% full. This is good.
Now I need to reduce the size of the logical volume to match the size of the ext4 filesystem. I don't want to use rough estimates. I also don't need to conserve every possible extent. Within a >= 1GB range is fine. i.e. volume can be reduced to 1GB >= filesystem size.
The target volume does contain data I can't lose. I don't have shell (or any other) access to the system. The system has no CentOS repos available so I cannot upgrade it. I don't even have remote hands I can talk to. I'm using a different computer to build and test my install ISO on.
My %pre syntax/script needs to safely reduce /dev/mapper/centos-home so I can create a new root volume for CentOS 7.6 install. Yes, this entire proposition is nuts.
usedGB=$(df -h $homevol | tail -1 | awk '{print $2}' | awk '{printf("%d\n",$1 + 1)}') ; echo $usedGB
prints '5' How do I use pass my variable $usedGB to lvreduce ?lvreduce -L -$usedGB\G /dev/mapper/centos-home
WARNING: Reducing active logical volume to 15.00 GiB. . . . but echo $usedGB reports only 5GB . . .$usedGB\G
not-$usedGB\G
Had to remove the hyphen.