How to Remove Stale SCSI devices (SCSI/SAN/iSCSI) without rebooting Linux

This post outlines the steps to remove the stale SCSI device from Linux OS without rebooting the server. This topic would be a 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 unmount it, you’ll get messages in /var/log/messages something similar to the below.

Mar 24 08:11:11 geeksearch 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).

# fdisk -l | grep -i disk
remove stale scsi disk online in linux

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.

The first command would be easy as you can identify the non-existent device by its name like /dev/sdc. 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 checks the fdisk again for double confirmation on the stale device.

# echo 1 > /sys/block/sdc/device/rescan

Once you are confirmed that “sdc” is the disk you want to remove, run the following command to remove the stale SCSI device/ SCSI disk:

echo 1 > /sys/block/sdc/device/delete

Once you have executed the command you can see the “sdc” is missing from the fdisk –l command output.

# fdisk -l | grep -i disk
remove stale disk online without reboot in linux

The same procedure can be used for SCSI, SAN, and iSCSI stale /non-existent LUNs.