#!/usr/bin/env bash function create_thinpool_from_block_device() { local block_dev="$1" local vg_name="$2" # Create physical volume pvcreate "$block_dev" # Create volume group vgcreate "$vg_name" "$block_dev" # Create logical volumes (one for data, another for metadata) lvcreate --wipesignatures y -n thinpool "$vg_name" -l 95%VG lvcreate --wipesignatures y -n thinpoolmeta "$vg_name" -l 1%VG # Convert data volume to a thin volume, using metadata volume for thin volume metadata lvconvert -y --zero n -c 512K --thinpool "$vg_name/thinpool" --poolmetadata "$vg_name/thinpoolmeta" # Ensure both volumes are extended as necessary # 1. Create a profile cat > "/etc/lvm/profile/$vg_name-thinpool.profile" <&2 <