Skip to content

Instantly share code, notes, and snippets.

@allaryin
Created April 20, 2017 16:18
Show Gist options
  • Save allaryin/6a1debab3d161725bb8db5dc2cd1ee35 to your computer and use it in GitHub Desktop.
Save allaryin/6a1debab3d161725bb8db5dc2cd1ee35 to your computer and use it in GitHub Desktop.
Checks for newly attached drives and initializes them for LVM.
#!/bin/sh
for SCSI_HOST in /sys/class/scsi_host/*
do
echo '- - -' > ${SCSI_HOST}/scan
done
DRIVES=`dmesg | grep 'unknown partition table' | awk '{print $2}' | awk -F':' '{print $1}' | uniq`
for DRIVE in ${DRIVES}
do
PARTED="parted /dev/${DRIVE}"
TABLE=`${PARTED} print 2>/dev/null | grep '^Partition Table' | awk '{print $3}'`
if [ "${TABLE}" = "unknown" ]; then
echo "(**) ${DRIVE} has unknown partition table, initializing..."
${PARTED} mktable gpt
${PARTED} mkpart P1 0% 100%
${PARTED} print
pvcreate /dev/${DRIVE}1
else
echo "(**) ${DRIVE} already initialized with ${TABLE}."
${PARTED} print
pvs | grep ${DRIVE}
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment