Last active
August 29, 2015 14:27
-
-
Save nandajavarma/247fa19e807ab18c76ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stripesize=128k | |
stripe_elements=10 | |
dataalign=1280k | |
function create_lv { | |
vgname=$1 | |
lvname=$2 | |
pvname=$3 | |
poolname=$4 | |
KB_PER_GB=1048576 | |
# STRIPESIZE is 128 * 10 | |
STRIPESIZE=$(echo $dataalign | cut -d k -f 1) | |
STRIPE_ELEMENT_KB=$(echo $stripesize | cut -d k -f 1) | |
echo "Create Logical Volume $lvname." | |
[ $dryrun -eq 1 ] && return 0 | |
pvsize=`pvs --noheading --units m -o pv_size $pvname | cut -f1 -d"m"` | |
pvsize=`echo "($pvsize - 4) * 100 / 100" | bc` | |
if [ $pvsize -gt 1000000 ] | |
then | |
METADATA_SIZE_GB=16 | |
(( metadatasize = $METADATA_SIZE_GB * $KB_PER_GB / $STRIPESIZE )) | |
(( metadatasize = $metadatasize * $STRIPESIZE )) | |
else | |
METADATA_SIZE_MB=`echo "$pvsize / 200" | bc` | |
(( metadatasize = $METADATA_SIZE_MB * 1024 / $STRIPESIZE )) | |
(( metadatasize = $metadatasize * $STRIPESIZE )) | |
fi | |
# create metadata LV that has a size which is a multiple of RAID stripe | |
# width | |
lvcreate -L ${metadatasize}K --name metadata $vgname || return $? | |
# create data LV that has a size which is a multiple of stripe width | |
((pool_sz = $pvsize * 1024 / $STRIPESIZE)) | |
((pool_sz = $pool_sz * $STRIPESIZE)) | |
((pool_sz = $pool_sz - $metadatasize)) | |
echo "Creating a ${pool_sz} KB thin pool named $poolname" | |
lvcreate -L ${pool_sz}K --name $poolname $vgname || return $? | |
# create thin-pool without creating a spare metadata area | |
# (though spare metadata area is useful if/when thin-pool metadata repair | |
# is needed) | |
# -- NOTE: could also use --chunksize 256K or 128K here since they are a | |
# factor of stripe width | |
lvconvert --chunksize $dataalign --thinpool $vgname/$poolname \ | |
--poolmetadata $vgname/metadata --poolmetadataspare n || return $? | |
# create stripe-aligned thin volume: | |
lvcreate -V ${pool_sz}K -T /dev/$vgname/$poolname -n $lvname || return $? | |
lvchange --zero n $vgname/$poolname | |
return $? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment