Tuesday, 25 March 2014

How to remove stale SCSI-device (SCSI/SAN/iSCSI) without rebooting linux

Hey Guys,

Hope you are doing well, I hope everyone has gone through my last post on “How to add a SCSI disk to Linux (RHEL 6) without reboot (Online)”.

I have received some requests and feedback to write a new topic on how to remove the stale SCSI device from Linux OS without rebooting the server. This topic would be useful scenario like if we have a SAN changes or un-present some LUN from storage end and we missed to remove it from OS or you want to safely remove the disk from OS before physical removal / un-present etc. (you need to remove the disk from LVM or mount points & recommend to have a valid data backup Jif you are removing a good disk).


If you have removed a scsi-device (This can be SAN/iSCSI or SCSI), but forgot to un-mount it, you'll get messages in /var/log/messagessomething similar to the below.

Mar 24 08:11:11 vinil kernel: Buffer I/O error on device sdc, logical block 1310719


Now let me explain how to remove the stale device (non-exist device)  or you want to remove a good disk from the Linux.

Here I am explaining how to remove the disk sdc from the linux before the disk physical removal.(Same procedure applicable for stale SCSI device)


Now the command to remove the “dead" SCSI-devices are :

#echo 1> /sys/block/sdX/device/delete
Where sdX is the dead SCSI device
Or

# echo 1 > /sys/class/scsi_host/hostX/device/target::/:::/delete

where ::: refers to Host, Bus, Target and Lun, you can find it using lsscsi or #cat /proc/scsi/scsi command. 
First command would be easy you can identify with the non-existent device name.

Be careful, don't remove devices you are currently using! To rescan for (new) scsi-devices type
#echo "- - -" > /sys/class/scsi_host/hostX/scan

The following command re-reads the volume size and check the fdisk again for double confirmation on stale device.
echo 1 > /sys/block/sdc/device/rescan

So run the following command to remove the stale SCSI device/ SCSI disk:


or

Once you have executed the command you can see the sdcis missing from the fdisk –l command output.

The same procedure can be used for SCSI , SAN and iSCSI  stale /non-existent LUNs.
Hope you enjoyed the topic ! I am curious to listen your feedback!


1 comment:

  1. This helped a lot. Exactly the one i'm looking for.
    Hope you keep adding new stuff.

    Thanks

    ReplyDelete