Score:0

Force the kernel to unregister a drive and then initialize it again

in flag

I had a drive that would seem to be mounted and busy no matter what I did. But since I didn't want to reboot the whole system, I ran echo 1 > /sys/block/sd*/device/delete to force the kernel to "unplug" or unregister the drive.

Then I unplugged and replugged the SATA power cable of the disk, it showed up again in the system and worked as expected.

But what could I've done if I didn't have physically access to it? What would be the alternative to physically unplugging the SATA cable so the system could see it again after running echo 1 > /sys/block/sd*/device/delete ?

Score:2
vn flag

You could rescan the SCSI host bus by running the following command

echo "- - -" > /sys/class/scsi_host/host0/scan

NOTE: The host0 part of the command above is the host ID. And you might have multiple/other host ID's on your machine. Which means that if the command above doesn't get you the drive back, you might have to change the host ID to match what you have on your machine.

You can look up which host ID's you have available on your machine by running

ls /sys/class/scsi_host

Which on my machine returns

host0  host1  host2  host3  host4  host5

So look up your host ID's and run the first command on each ID to make sure that the drive gets detected.

Edit:

To repeat this command for each host ID you could just put in into a loop like this:

for host in /sys/class/scsi_host/host*/scan; do echo "- - -" > $host; done
ThomasHunter avatar
in flag
Thank you. I seem to have 73 host devices on that one machine. Is there a way how to simply scan them all without specifying just one? Or maybe do some loop script?
BitGen01100000 avatar
vn flag
@ThomasHunter That's a lot of host ID:s! I have added some code to my answer that allows you to run the command for each host ID. Note however that it can take a few seconds, maybe up to a few minutes (depending on your hardware) when scanning that many hosts in a row! BTW If my answer solved your problem I would appreciate if you marked my answer as the accepted answer! :)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.