Last active
December 16, 2015 17:41
-
-
Save dash17291/5472439 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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