Linux – In linux, how can I determine what processes are using a block device

linuxlvmpartition

I have a disk in a server that I'm migrating to a LVM volume group. Previously, it was using traditional DOS-disk partitioning, hdb[1-5].

I've unmounted every filesystem from hdb, shut off swap using hdb, removed a smaller VG on the device already, and went to repartition it using fdisk, deleted existing partitions, and created 2 partitions, but upon writing it out, linux refused to re-read the partition table. Trying again using hdparm -z reports: BLKRRPART failed: Device or resource busy.

I've checked the following places to ensure the device and it's partitions arn't listed anywhere:

  • /proc/swaps
  • /proc/mdadm
  • output from 'pvs' command
  • output from 'mount' command
  • /etc/mtab
  • lsof | grep hdb

But cat /proc/partitions still lists the partitioning, and hdparm -z /dev/hdb still gives me device busy.

Is there a something I'm missing, or a secret place I don't yet know about to find what's still holding on to my block device? and more importantly, How can I release it's hold so I can reload the partition table?

FWIW, on this specific case, I can simply reboot the server w/o much worry, but this has plagued me before, and I'm curious if there is a better way.

(Edit: added more precise wording)
(Edit: details re repartitioning)

Update: I used partprobe /dev/hdb, and it did change things: in /dev /hdb1, /deb/hdb[3-5] are now gone, and partprobe is reporting Error: Error informing the kernel about modifications to partition /dev/hdb1 -- Device or resource busy. <– specifically about hdb1. hdb1 formerly was a Physical Volume (PV) in a LVM Volume Group (VG), abut i vgremove + pvremoved em before I repartitioned……

Update 2: FWIW, I still haven't corrected this problem, fortunatly it's not urgent. I've learned that partprobe is using a newer API call which is why it did seem to do something earlier. I still haven't found an simple and effective way to, given a device, and it's major/minor numbers, figure out which resources (kernel or userspace) are using it. Any ideas?

Best Answer

Try using fuser

fuser -vam /dev/hdb1