Skip to content

Instantly share code, notes, and snippets.

@wipash
Created June 11, 2020 21:24
Show Gist options
  • Save wipash/20aad0005e6ed715ed6093a8c862d7f3 to your computer and use it in GitHub Desktop.
Save wipash/20aad0005e6ed715ed6093a8c862d7f3 to your computer and use it in GitHub Desktop.
Tool to list drives that are unused by ZFS. Useful when you've just added a stack of new drives to a big ZFS system.
#Get all drive info from ZDB, trim all path off the front and drop partition info from the back
used=$(zdb | grep -e ' path:' | sed -r "s/^.*(ata-.*)/\1/" | sed -r "s/(.*)-part1'|'/\1/" | sort)
#Get all ATA disks from the system
all=$(ls /dev/disk/by-id/ | grep -v part | grep -e ata- | sort)
#Compare both lists
unmatched=$(comm -13 <( echo "$used" ) <( echo "$all" ))
#Zpool status output to catch cache drives
zpool_status=$(zpool status)
#Print comparison output, highlight cache drices
while read -r line; do
if grep -q $line <( echo "$zpool_status" ); then
echo -e "\e[1;30m$line \e[1;33m**cache**\e[0m"
else
echo "$line"
fi
done <<< "$unmatched"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment