Skip to content

Instantly share code, notes, and snippets.

@nsabine
Created August 9, 2013 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsabine/6196550 to your computer and use it in GitHub Desktop.
Save nsabine/6196550 to your computer and use it in GitHub Desktop.
#!/bin/bash
declare -a DISKS=($(fdisk -l | grep 'dev' | awk '{if ($3 > 1000) print $2}' | sed s/.$//))
declare -a INUSE=($(mount | awk '{if ($1 ~ '/dev/') print $1}'))
declare -a UNUSED=(`comm -23 <(echo ${DISKS[@]} | sed 's/ /\n/g' | sort -u) <(echo ${INUSE[@]} | sed 's/ /\n/g'| sort -u)`)
echo "All Disks larger than 1000 GB:"
for i in ${!DISKS[@]}
do
echo "$i=${DISKS[$i]}"
done
echo
echo "In use Disks:"
for i in ${!INUSE[@]}
do
echo "$i=${INUSE[$i]}"
done
echo
echo "Available Disks larger than 1000 GB:"
for i in ${!UNUSED[@]}
do
echo "$i=${UNUSED[$i]}"
done
# Create Physical Volumes
for i in ${!UNUSED[@]}
do
pvcreate ${UNUSED[$i]}
done
# Create Volume Group from Physical Volumes
vgcreate datavg ${UNUSED[@]}
# Number of stripes to create in Logical Volume
# -- set to number of disks in group
NUMSTRIPES=${#UNUSED[@]}
# Get Volume Group Size
SIZE=$(expr $(vgdisplay datavg | grep "Total PE" | awk '{print $3}') - 100)
echo "SIZE: $SIZE"
# Create Logical Volume
lvcreate -l $SIZE -i${NUMSTRIPES} -n DataVolume datavg
mkfs.ext4 /dev/mapper/datavg-DataVolume -L DataFS
echo "LABEL=DataFS /scratch ext4 defaults 0 0" >> /etc/fstab
mount -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment