TMPDEV=/dev/mapper/$TMPDM
TMPDM2=tmpbar
TMPDEV2=/dev/mapper/$TMPDM2
-METADATASIZE=3.5m
+METADATASIZE=8128k
# - pvresize the old PV to half the space
pvresize --setphysicalvolumesize=${HALFSIZETiB}t $DISK
# - pvremove the old PV
-vgreduce $VG $DISK
-pvremove $DISK
+LVM_SYSTEM_DIR=lvm vgreduce $VG $DISK
+dmsetup create $TMPDM2 --table "0 $((2 * 1024 * 20)) linear $DISK 0"
+pvremove $TMPDEV2
# - pvcreate a new PV in the old space,
# with --setphysicalvolumesize <half size>
# and with --metadatasize <huge> (the point of this exercise)
shortsize=$(python -c "print $HALFSIZETiB - 0.01")t
-dmsetup create $TMPDM2 --table "0 $((2 * 1024 * 4)) linear $DISK 0"
pvcreate $TMPDEV2 --setphysicalvolumesize $shortsize --metadatasize $METADATASIZE
dmsetup remove $TMPDM2
pvscan
-vgextend $VG $DISK
+LVM_SYSTEM_DIR=lvm vgextend $VG $DISK
# - pvmove all the LVs back