Other USB mount point retained even after the device is detached

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?
 
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.
 
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.
 
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.
 
...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
 
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.

Thanks k.jacker. Sorry about the delayed response. I just got to try your suggestions and it helps. I did some more tests and I have few questions.

1) I see the default unmount timeout for hot-unplugged and unaccessed devices seems to 10 mins (autounmountd(8) -r and -t option respectively I assume). Since, this being the flags, how to change it to low values during the boot time?

2) Also, with windows formatted USB devices I see the default automountd/autounmountd services (Without any custom script like you gave) working as expected. I don't see any issue. But with FreeBSD formatted UFS devices, I observed system reboot (may be panic, but unfortunately I couldn't get the coredump) when I try to access the mount point /media/da0p1 (before it's unmounted) after a hot-unplug. With windows formatted devices, I don't see this issue. Is it known? I have tried this with 11.2 though. I have to try with 12.0.
 
By default, UFS filesystems are created with softupdates journaling enabled. Journaled filesystems must be unmounted (in any OS) to flush caches and write data to the disk that has not been written. Otherwise fs and data corruption (or crash) may occur.

The difference with Fat32 to most other filesystems, is that it‘s not journaled, so data will always be written to disk immediately. For that reason, you can remove the drive when it‘s „idle“ (no writing in progress) without the risk of damaging the filesystem or data.

To change autounmountd‘s timeouts use
autounmountd_flags=„-r N -t N“

in /etc/rc.conf

Sorry for lack of formatting, writing on small phone.
 
Back
Top