Skip to content

Instantly share code, notes, and snippets.

@dash17291
Last active December 16, 2015 17:41
Show Gist options
  • Save dash17291/5472439 to your computer and use it in GitHub Desktop.
Save dash17291/5472439 to your computer and use it in GitHub Desktop.
#!/bin/bash
#place this script to /usr/local/bin/stop-disk
if [ "" = "$1" ]; then
echo "Usage: `basename $0` device"
else
umount -l $1
#extract the SCSI ID numbers from the output of lsscsi:
read -d ] A B C D < <(IFS=':'; echo $(lsscsi | grep $1))
#remove the "[" from begining of A:
A=${A##*[} #quicker version: A=${A:1}
#stop the disk spinning
sg_start -i -v --stop $1
echo "Host adapter ID=$A, SCSI channel=$B, ID=$C, LUN=$D"
#and remove it from the scsi bus
echo 1 > /sys/class/scsi_device/$A:$B:$C:$D/device/delete
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment