Skip to content

Instantly share code, notes, and snippets.

@chuckwagoncomputing
Created January 1, 2021 04:27
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 chuckwagoncomputing/54a0e506b818862908cc01e36bae011b to your computer and use it in GitHub Desktop.
Save chuckwagoncomputing/54a0e506b818862908cc01e36bae011b to your computer and use it in GitHub Desktop.
Graphically un-hotplug drives
#!/usr/bin/env bash
LINE=""
DRIVES=$(ls /sys/block)
for DRIVE in $DRIVES; do
if ls /dev/$DRIVE 2>/dev/null >/dev/null && ls /sys/block/$DRIVE/device/delete 2>/dev/null >/dev/null; then
SIZE=$(blockdev --getsize64 /dev/$DRIVE | awk '{ split( "B KB MB GB TB" , v ); s=1; while( $1>1024 ){ $1/=1024; s++ } print int($1) v[s] }')
LINE="$LINE p $DRIVE $SIZE"
fi
done
BLOCK=$(zenity --list --title "Choose drive to remove" --radiolist --column="Remove" --column="Device" --column="Size" $LINE)
if [ $? -eq 0 -a $(echo $BLOCK | wc -c) -gt 1 ]; then
echo 1 > /sys/block/$BLOCK/device/delete
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment