I found that if I detach a disk from my Linux server (CentOS 7), the related /dev/sd* file will disappear automatically about 10 seconds later.

I'm wondering how does Linux know a disk has been detached? Is there something like a sweeper keep scanning all the devices?

And is it possible to make this quicker?


The delay is likely caused by udisk2 & udev.


$ ps -eaf|grep [u]disk
root     17041     1  0 09:48 ?        00:00:00 /usr/libexec/udisks2/udisksd

Can query it for storage devices like so:

$ udisksctl status
MODEL                     REVISION  SERIAL               DEVICE
VBOX HARDDISK             1.0       VBc5aaf476-f419b1f1  sda

If you look at the udisk2 process:

$ lsof -p $(pidof udisksd) | tail
udisksd 17041 root    3u     unix 0xffff88003a49d400      0t0     611852 socket
udisksd 17041 root    4u  a_inode                0,9        0       4852 [eventfd]
udisksd 17041 root    5u  a_inode                0,9        0       4852 [eventfd]
udisksd 17041 root    6u     unix 0xffff88003a49c000      0t0     611853 socket
udisksd 17041 root    7u  a_inode                0,9        0       4852 [eventfd]
udisksd 17041 root    8r      REG                0,3        0     611907 /proc/17041/mountinfo
udisksd 17041 root    9r      REG                0,3        0 4026532019 /proc/swaps
udisksd 17041 root   10r  a_inode                0,9        0       4852 inotify
udisksd 17041 root   11u  netlink                         0t0     611910 KOBJECT_UEVENT
udisksd 17041 root   12u  a_inode                0,9        0       4852 [eventfd]

Not a lot to go on there, the thing that catches my eye there is inotify. Whenever I see that, I immediately think udev.

Looking for udev rules

$ find /etc/udev/rules.d/ /usr/lib/udev/rules.d  | grep sto

the 2nd file looks interesting, take a look inside. This line looks like the cause:

$ cat /usr/lib/udev/rules.d/60-persistent-storage.rules
# enable in-kernel media-presence polling
ACTION=="add", SUBSYSTEM=="module", KERNEL=="block", ATTR{parameters/events_dfl_poll_msecs}=="0", ATTR{parameters/events_dfl_poll_msecs}="2000"

ATTR{parameters/events_dfl_poll_msecs}=="0", ATTR{parameters/events_dfl_poll_msecs}="2000"


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.