Other USB mount point retained even after the device is detached

Rajesh

Member

Reaction score: 4
Messages: 68

Hi,

I have a Windows formatted USB drive mounted in FreeBSD using the "mount_msdosfs" command.

# mount_msdosfs /dev/da0s1 /mnt/usb0

After this, "mount" and "df -h" output shows the mount point. At this point, I hot un-plugged the USB device and I see the dmesg showing the device is detached and I don't see /dev/da0s1. But "mount" and "df -h" output still shows the mount point, which I have to manually unmount.

I have to try whether this is the same behavior when I mount UFS. But, Is this behavior expected behavior when using mount_msdosfs?
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 7,293
Messages: 29,742

But, Is this behavior expected behavior when using mount_msdosfs?
It is expected behavior for any mount, not just this one. You're lucky the system didn't panic, because up until a few years ago that would happen if a disk disappears while it's mounted.

But "mount" and "df -h" output still shows the mount point, which I have to manually unmount.
Always remember to umount(8) first, then you can safely remove it.
 
OP
OP
R

Rajesh

Member

Reaction score: 4
Messages: 68

Thanks SirDice

But, just curious. Without device, the mount point is invalid. So, any specific reason why that's retained after the device is detached? I don't see this behavior in Linux.
 
OP
OP
R

Rajesh

Member

Reaction score: 4
Messages: 68

I haven't tried with MacOS, but I have tried with Ubuntu 18.04. When I hot-plug the USB device, they get automount and when I hot-unplug, they get unmounted automatically. That's why I am wondered this should be the case with FreeBSD as well.
 

k.jacker

Aspiring Daemon

Reaction score: 364
Messages: 633

...the get automount and when I hot-unplug, they get unmounted automatically.
On Ubuntu you have an automount daemon running by default, that's not the case on FreeBSD.
You can set that up if you want to.

So are you just wondering how to automatically get rid of the remaining dead mountpoint, or do you want usb devices´ partitions to mount and unmount automatically?

To only get rid of remaining mountpoints, after a mounted usb-drive has been forcefully removed, something like the following does the trick:

to /etc/devd.conf add:
Code:
notify 100 {
    match "system"        "USB";
    match "type"        "DETACH";
    device-name "!umass[0-9]+";
    action "/root/bin/hot-umount.sh";
};
create a executable file, e.g. /root/bin/hot-umount.sh and add
Code:
#!/bin/sh

active_mounts=$( mount | grep -e '^/dev/da[[:digit:]]' | cut -w -f1 )
kern_disks=$( sysctl -n kern.disks | tr ' ' '\n' | grep -e '^da[[:digit:]]' )

for removed in $active_mounts
do
     check_dev_exists=$( echo $removed | cut -c 6-8 )
     if [ -z "$( echo $check_dev_exists $kern_disks | tr ' ' '\n' | sort | uniq -d )" ]; then
         umount $removed
     fi
done
# service devd restart
 
Top