~hruske Hruške, jabuke, jablane, čežane. » Blog Archive » Disconnecting the hard drive, the software way
Home Contact Sitemap

Hruške, jabuke, jablane, čežane.

Ste se gdaj vprašali, zakaj Najboljšega soseda nikoli ni doma, ko pridete na obisk?

Disconnecting the hard drive, the software way

Posted on Maj 8th, 2008 in debian, linux |

A hard drive recently died, taking away lots of data and filling the logs with failed ide requests. Annoying in too many ways. So, how do you make the disk stop yelling?

The easiest is to make the kernel not see it. There’s a neat trick that enables you to do just that, and it’s called module unbinding. So, basically you unmount the drive (or what’s left of it), then you only need to figure out what device to disconnect from which driver, which isn’t that hard. If you do “ls -al /sys/block/sda/”, you’ll see something like this:

drwxr-xr-x  8 root root    0 maj  8 21:47 .
drwxr-xr-x 20 root root    0 maj  8 21:47 ..
-r--r--r--  1 root root 4096 maj  8 21:47 capability
-r--r--r--  1 root root 4096 maj  8 21:47 dev
lrwxrwxrwx  1 root root    0 maj  8 21:47 device -> ../../devices/pci0000:00/0000:00:1f.2/host2/target2:0:1/2:0:1:0
drwxr-xr-x  2 root root    0 maj  8 21:47 holders
drwxr-xr-x  2 root root    0 maj  8 21:47 power
drwxr-xr-x  3 root root    0 maj  8 21:47 queue
-r--r--r--  1 root root 4096 maj  8 21:47 range
-r--r--r--  1 root root 4096 maj  8 21:47 removable
drwxr-xr-x  4 root root    0 maj  8 21:47 sda1
drwxr-xr-x  4 root root    0 maj  8 21:47 sda2
-r--r--r--  1 root root 4096 maj  8 21:47 size
drwxr-xr-x  2 root root    0 maj  8 21:47 slaves
-r--r--r--  1 root root 4096 maj  8 21:47 stat
lrwxrwxrwx  1 root root    0 maj  8 21:47 subsystem -> ../../block
-rw-r--r--  1 root root 4096 maj  8 21:47 uevent

The line of our interest is

lrwxrwxrwx  1 root root    0 maj  8 21:47 device -> ../../devices/pci0000:00/0000:00:1f.2/host2/target2:0:1/2:0:1:0

where you can see, that the device id is “2:0:1:0″. The last step is to actually unbind the device:

cd /sys/block/sda/device/driver
echo -n "2:0:1:0" > unbind

Et voila, your hard drive is no more as far as the kernel knows.

Comments are closed.

Komentarji so izklopljeni