I want to be sure that a removable hard drive (USB, but this shouldn't matter) is safe to remove. Let's say this drive is
Obviously I need to make sure that there is no mounted filesystem on that drive.
grep /dev/sdb /proc/mounts will tell me.
But that's not the whole story. For example, if there is an LVM physical volume on
sdb, I need to deactivate all volume groups that contain a physical volume located on
lvchange -an my_volume_group/my_logical_volume then
vgchange -an my_volume_group). If there is a RAID volume, I may need to deactivate it (
mdadm -S), or I may want to mark the component as failed (
Is there a way to list all the ways a disk is in use? For my use case, I need to be confident that this list is exhaustive, so that I can unplug the device if the list is empty.