Due to a misconfiguration I had to shrink a LVM 2 volume group and its physical volume running on a software RAID.
First of all: ensure you have a working backup!
Check if the end of the physical volume is not used:
pvs -v --segments /dev/md2
Set the new PV size (use KiB as unit to use the same value as for mdadm):
pvresize --setphysicalvolumesize 83753984K /dev/md2
Shrink the raid device (size unit is KiB):
mdadm --grow /dev/md2 --size=83753984
Resize the RAID partitions of the disk using fdisk: Delete and recreate the partitions with the machting sizes.
Finally after reconfiguration of the RAID, update intramfs:
update-initramfs -u
Useful commands:
# show details of a RAID partition
mdadm --examine /dev/sda2
# show details of a RAID array
mdadm --details /dev/md2
# show details of a PV
pvdisplay /dev/md2
Due to rounding errors (I did not use the same units initially) the system could not restart with the resized RAID array. ("no valid superblock" in syslog, even if mdadm showed correct sizes)
Therefore I had to manually assemble the RAID:
mdadm /dev/md2 --assemble --update=devicesize /dev/sda2 /dev/sdb2
The --update=devicesize attribute fixes the invalid size in the meta data.