Solved Unable unmount and mount a USB Drive

I have a Fat32 formatted USB drive and I'm not sure what is happening. If I plug in the drive, KDE's Dolphin will mount the drive. However if I try to "eject" or "safely remove" the drive I get an error. Then if I attempt to do anything with the drive, it fails. I cannot transfer files to it or copy files from it.
Even further, if I just remove the drive and plug is back in again, I just get an empty window. It will not show me the files that are already on the drive. It shows that the drive it empty.
If I log out and log back in, it still won't do anything. I need to restart my computer before I am able to use the drive again.

Any thoughts?
 
You have a deal of obfuscation by relying on "file managers". One step at a time:
  • as root, type tail -f /var/log/messages (use Ctrl-C to terminate when you are finished); and
  • insert the USB drive
You should see something in the messages about the USB drive, perhaps "da0", or some higher number (take note and use it below).

After a few seconds, in another window type mount, and (as root) gpart show /dev/da0.

Report the results.
 
You have a deal of obfuscation by relying on "file managers". One step at a time:
  • as root, type tail -f /var/log/messages (use Ctrl-C to terminate when you are finished); and
  • insert the USB drive
You should see something in the messages about the USB drive, perhaps "da0", or some higher number (take note and use it below).

After a few seconds, in another window type mount, and (as root) gpart show /dev/da0.

Report the results.
Code:
root@ALBERT:/usr/home/julx # tail -f /var/log/messages
Sep  5 01:37:41 ALBERT kernel: umass0 on uhub4
Sep  5 01:37:41 ALBERT kernel: umass0: <Flash USB Disk, class 0/0, rev 2.00/0.00, addr 6> on usbus1
Sep  5 01:37:41 ALBERT kernel: umass0:  SCSI over Bulk-Only; quirks = 0xc100
Sep  5 01:37:41 ALBERT kernel: umass0:5:0: Attached to scbus5
Sep  5 01:37:41 ALBERT kernel: da0 at umass-sim0 bus 0 scbus5 target 0 lun 0
Sep  5 01:37:41 ALBERT kernel: da0: <Flash USB Disk 6.8 0> Removable Direct Access SCSI-2 device
Sep  5 01:37:41 ALBERT kernel: da0: Serial Number 37271 6409627810522202
Sep  5 01:37:41 ALBERT kernel: da0: 40.000MB/s transfers
Sep  5 01:37:41 ALBERT kernel: da0: 7680MB (15728640 512 byte sectors)
Sep  5 01:37:41 ALBERT kernel: da0: quirks=0x2<NO_6_BYTE>
^C
Code:
julx@ALBERT:/usr/home/julx $ mount
/dev/ada0p2 on / (ufs, local, journaled soft-updates) 
devfs on /dev (devfs)
/dev/ada0p1 on /boot/efi (msdosfs, local)
/dev/ada1p2 on /media/Backup (ufs, local, journaled sof
t-updates)
/dev/ada3p2 on /media/Movies (ufs, local, journaled sof
t-updates)
/dev/ada2p2 on /media/TV-Series (ufs, local, journaled
soft-updates)
procfs on /proc (procfs, local)
fdescfs on /dev/fd (fdescfs)
/dev/da0s1 on /media/Flash_USB_Disk_3727164096278105222
02_s1 (msdosfs, local)
julx@ALBERT:/usr/home/julx $ gpart show /dev/da0
=>      63  15728577  da0  MBR  (7.5G)
        63         1       - free -  (512B)
        64  15728576    1  fat32lba  (7.5G)

julx@ALBERT:/usr/home/julx $
This is what I got..
Honestly, I like KDE. It is my preferred opensource DE. I've never faced such issues when running KDE on a Linux box. Maybe it is the way Linux is setup. With FreeBSD, you have the privilege of setting everything up yourself.
 
This is what I got..
Your USB stick is /dev/da0.

It's MBR formatted, and has a 7.5GB FAT file system on slice 1 (/dev/da0s1).

Your desktop software has mounted the FAT file system on /media/Flash_USB_Disk_372716409627810522202_s1.

You should be able to navigate the FAT file system from the command line:
Code:
cd /media/Flash_USB_Disk_372716409627810522202_s1
ls -la
I have no knowledge of your file manager, and don't use such things, so can't suggest how it might or might not work.

But everything looks "normal" to me... Your access will depend on the ownership and file modes you see. You might need to be "root" to get full access.
 
It is likely something is using the mounted filesystem (has done chdir to it). From command line, try sudo umount -f /mnt/Flash_USB_Disk*
 
To identify any processes using the mounted file system use:
Code:
fuser -c /media/Flash_USB_Disk_372716409627810522202_s1
 
Is this a KDE / Dolphin issue? Are there others who are using other KDE or even other DE's and have never faced this issue?
It would be nice to not have to type out commands in a terminal window every single time I was to plug in a flash drive and copy some data - like every other mainstream OS out there.
 
I can't help you with dolphin, but I can say that if you can't make it work from first principles on the command line, then dolphin is not likely to work either...

To diagnose the issue any further we need to know what works from the command line and what does not. i.e.
  1. Can you change directory into the FAT file system mount point?
  2. If so, what is the output of ls -la | head -10?
  3. What is your user ID and GID (show us the output of id)?
  4. Can you copy files to and from the FAT file system from the command line?
  5. If not, what error(s) do you get?
 
Is this a KDE / Dolphin issue? Are there others who are using other KDE or even other DE's and have never faced this issue?
It would be nice to not have to type out commands in a terminal window every single time I was to plug in a flash drive and copy some data - like every other mainstream OS out there.
1. You may want to debug your actual problem and find out the root cause, rather than assume or generalize.

2. Each OS culture is different. Best to figure out how the locals do things when your assumptions about how "every other mainstream OS" turn out to be wrong for the new OS you are experimenting with.
 
Is this a KDE / Dolphin issue?
Probably. In particular, the issue "can't unmount, some unknown process is using the file system" is typical for DEs.

But: One can have problems with removable media, non-native file systems, and permissions also from the command line.

It would be nice to not have to type out commands in a terminal window every single time I was to plug in a flash drive and copy some data -
That is a question of taste. I would rather not have to go to a GUI window just to copy some data. Matter-of-fact, even on machines where I have really good GUIs, I use the command line to manage files on memory sticks.

like every other mainstream OS out there.
The definition of mainstream is in the eye of the beholder.
 
I have a Fat32 formatted USB drive and I'm not sure what is happening. If I plug in the drive, KDE's Dolphin will mount the drive. However if I try to "eject" or "safely remove" the drive I get an error. Then if I attempt to do anything with the drive, it fails. I cannot transfer files to it or copy files from it.
Even further, if I just remove the drive and plug is back in again, I just get an empty window. It will not show me the files that are already on the drive. It shows that the drive it empty.
If I log out and log back in, it still won't do anything. I need to restart my computer before I am able to use the drive again.

Any thoughts?
I just read through all the replies and your comments and at no stage have specified the exact error message you are seeing. However, all the symptoms you describe above point almost exclusively to a mounted device being "in use" at the time you try to unmount it. More than likely you are trying to unmount it with the file manager still opened into a directory on the USB stick. This will stop a normal umount command from completing and stop you accessing it since its now trying to unmount and blocks further access while it waits for exising process accessing it to end. Unfortunately, umount doesn't appear to time out which causes further problems, such as when you remove and re-insert the device it will no longer mount. Logging out/in normally can't fix this either. All of this happens on the few Linux versions I've tried. Windows doesn't have this issue because it's looking at the attached devices and effectively kills any process trying to use the device if the device disappears, potentially leading to lost data. You may or may not remember having similar issues with optiocal drives. Windows will let you press the physical eject button in the middle of an operation. FreeBSD and Linux "locks" the eject button until you unmount the optical drive. This is the same situation, except the OS can't stop you physically unlugging the device while it's in use.

Your options, as others have also mentioned, is to either user use the command line umount with -f to force an unmount, possibly needing to be root, or to identify and close whatever is holding an open file lock on the device, eg close Dolphin.
 
You could turn off auto mounting in Dolphin settings and mount manually.

Yes, this is the key point here.

If auto mounting is turned off, Dolphin should still show the drive, and let you (knightjp) mount it whenever you want, then umount / "safely eject" it when you want.

Also then you can leave it unmounted so you can do things manually from a console (or konsole), root or user, in the normal FreeBSD manner ... such as providing the info gpw928 is asking for, without interference from the 'greedy" automounter.

'gpart show daX' and 'dd' for example don't need /dev/daX to be mounted at all.
 
Here is a list of commands to become more familiar with the FreeBSD environment. You might wish to be the 'root' user if the 'regular joe' user does not work for your needs.

Code:
 su -
password
camcontrol devlist
geom disk list
gpart status
gpart show
gpart show -l

Code:
mount
mount -p
cat /etc/fstab

Read the Fine Manuals to learn more details and a few examples. Use Google-FUto obtain more examples FreeBSD gpart or FreeBSD geom disk list
Code:
man camcontrol
man geom
man gpart
man mount
man glabel

search "FreeBSD gpt gptid diskid label"
ls -l /dev/gpt /dev/gptid /dev/diskid /dev/label /dev/ada* /dev/da*

cat /etc/rc.conf /boot/loader.conf
enable gpt or gptid or label or diskid in the rc.conf file
 
I raised this question again and was directed to vermaden's blog.

It is impressive. However automount does not seem to work properly despite me following the instruction to a tee.
I plug in the drive. I'm able to copy files to and from it. Then after I click the eject button and I get the error you see in the image.
Screenshot_20230325_005815.png


Screenshot_20230325_002454.png

When I remove the drive and then plug it back in, this is what I get. It says "Folder is Empty".. I don't get it. There must be an issue with KDE. Maybe I should raise it with the KDE community - if they care about us BSD users.
 
At the request of vermaden on twitter, I'm uploading the log here.
I hope that this helps solve the issue.
 

Attachments

  • automount.pdf
    31.7 KB · Views: 88
I saw your log.

Its really strange like a failing USB port or like a situation when the USB device attaches and detaches itself while automount(8) trying to make its work.

To be honest I have one or two such USB drives that when I attach them 'fully' to the end - they are not detected - and if I move them outside about 1-2mm then they are 'recognized' as 'attached'.

Maybe that is the problem ...
 
I looked at your photo screenshots and your logs too.
To be honest I have one or two such USB drives that when I attach them 'fully' to the end - they are not detected - and if I move them outside about 1-2mm then they are 'recognized' as 'attached'.

Maybe that is the problem ...
This automount daemon is looking for changes in the file system ( or device connections not sure which ) to then announce the changes to a user and create a mount point directory /media/da0s1 and attach the device and filesystem to that mount directory with issuing a command like " mount_msdosfs /dev/da0s1 /media/da0s1". When the next change interrupt is detected, and the USB flash drive is removed, the command " umount /dev/da0s1" or " umount /media/da0s1". One has to read the automount code to determine the exact useage of commands. My question is, "How long after the USB Flash drive is physically removed, before the mount point directory is removed /media/da0s1? 10 seconds, 60 seconds, 3 minutes? I see when you re insert the USB flash drive stick, the automount.log file shows

2023-03-25 00:15:14 /dev/ugen0.2: no MTP devices found
2023-03-25 00:19:02 /dev/ugen1.6: attach
2023-03-25 00:19:03 /dev/ugen1.6: no MTP devices found
2023-03-25 00:19:03 /dev/da0: attach
2023-03-25 00:19:03 /dev/da0: not a block device
2023-03-25 00:19:03 /dev/da0s1: attach
2023-03-25 00:19:04 /dev/da0s1: create '/media/da0s1' dir
2023-03-25 00:19:04 /dev/da0s1: fsck_msdosfs ** /dev/da0s1 (NO WRITE)
2023-03-25 00:19:04 /dev/da0s1: fsck_msdosfs ** Phase 1 - Read FAT and checking connectivity
2023-03-25 00:19:04 /dev/da0s1: fsck_msdosfs ** Phase 2 - Checking Directories
2023-03-25 00:19:04 /dev/da0s1: fsck_msdosfs ** Phase 3 - Checking for Lost Files
2023-03-25 00:19:04 /dev/da0s1: fsck_msdosfs 44 files, 7.4 GiB free (122044 clusters)
2023-03-25 00:19:04 /dev/da0s1: fsck_msdosfs MARK FILE SYSTEM CLEAN? no
2023-03-25 00:19:04 /dev/da0s1: fsck_msdosfs
2023-03-25 00:19:04 /dev/da0s1: fsck_msdosfs ***** FILE SYSTEM IS LEFT MARKED AS DIRTY *****
2023-03-25 00:19:06 /dev/da0s1: filesystem mount retry: 1/5
2023-03-25 00:19:08 /dev/da0s1: filesystem mount retry: 2/5
2023-03-25 00:19:10 /dev/da0s1: filesystem mount retry: 3/5
2023-03-25 00:19:12 /dev/da0s1: filesystem mount retry: 4/5
2023-03-25 00:19:14 /dev/da0s1: filesystem mount retry: 5/5
2023-03-25 00:19:14 /dev/da0s1: mount FAIL: 'mount_msdosfs -o ro -o longnames -m 775 -M 775 -D cp437
-L en_US.UTF-8 -u 0 -g 0 -o noatime /dev/da0s1 /media/da0s1'
2023-03-25 00:23:41 /dev/ugen1.6: detach
2023-03-25 00:23:41 /dev/da0: detach
2023-03-25 00:23:41 /dev/da0s1: detach

This is 4 minutes, 00:19:02 to 00:23:41

Below is the
: already mounted on '/media/Flash_USB_Disk_372716409627810522202_s1'
mount point

error

2023-03-25 00:23:44 /dev/ugen1.6: attach
2023-03-25 00:23:45 /dev/ugen1.6: no MTP devices found
2023-03-25 00:23:45 /dev/da0: attach
2023-03-25 00:23:45 /dev/da0: not a block device
2023-03-25 00:23:45 /dev/da0s1: attach
2023-03-25 00:23:45 /dev/da0s1: already mounted on '/media/Flash_USB_Disk_372716409627810522202_s1'
mount point
2023-03-25 00:24:25 /dev/ugen1.6: detach
2023-03-25 00:24:25 /dev/da0: detach
2023-03-25 00:24:25 /dev/da0s1: detach
2023-03-25 00:24:27 /dev/ugen1.6: attach
2023-03-25 00:24:29 /dev/ugen1.6: no MTP devices found
2023-03-25 00:24:29 /dev/da0: attach
2023-03-25 00:24:29 /dev/da0: not a block device
2023-03-25 00:24:29 /dev/da0s1: attach
2023-03-25 00:24:29 /dev/da0s1: already mounted on '/media/Flash_USB_Disk_372716409627810522202_s1'
mount point
2023-03-25 00:43:56 /dev/ugen1.6: detach
2023-03-25 00:43:56 /dev/da0: detach
2023-03-25 00:43:56 /dev/da0s1: detach
2023-03-25 00:44:23 /dev/ugen1.6: attach
2023-03-25 00:44:24 /dev/ugen1.6: no MTP devices found
2023-03-25 00:44:24 /dev/da0: attach
2023-03-25 00:44:24 /dev/da0: not a block device
2023-03-25 00:44:24 /dev/da0s1: attach
2023-03-25 00:44:24 /dev/da0s1: already mounted on '/media/Flash_USB_Disk_372716409627810522202_s1'
mount point
2023-03-25 00:47:28 /dev/ugen0.2: attach
2023-03-25 00:47:28 /dev/ugen1.2: attach
2023-03-25 00:47:28 /dev/ugen2.2: attach
2023-03-25 00:47:28 /dev/ugen1.3: attach
2023-03-25 00:47:28 /dev/ugen1.4: attach

In Conclusion, I would say move the focus of KDE Dolphin File manager to Home, Then click to detach the USB flash drive. Can you tell me how many file handles are still held open by Dolphin app and the automounter app, when you get the detach error? Are one of those still open file handles pointing to a file on the USB Flash Drive Stick, when it is removed? When I have a single terminal window looking at files on a USB flash drive, I either change directory CD to ~ directory (/home/fred directory) or a / root directory, so the terminal window is not in the path on the mounted USB Flash Drive /media/da0s1, or I close out the terminal window and no longer viewing files on the /media/da0s1 path. If i still get a detach error, I look around at other applications or a hidden open terminal window that is preventing me from closing out path names to the usb Flash drive and detaching with the sudo umount /dev/da0s1 command. Consider what KDE Dolphin File manager is accessing in the way of file names and devices. ie the lower left corner panel showing mounted devices. Feel Free to pose more questions or provide a solution you found, I am no guru, just a dumb John Q. Public user of GhostBSD and FreeBSD 14.0-CURRENT on a raspberry pi 4b with 8 gb dram memory.
 
I saw your log.

Me too.

Its really strange like a failing USB port or like a situation when the USB device attaches and detaches itself while automount(8) trying to make its work.

Is it possible that there's another automounter that we can't see, fighting with this one?

I do all of my mounting manually so I could be way off the mark, but I read the horror stories - and know yours is well-regarded.

To be honest I have one or two such USB drives that when I attach them 'fully' to the end - they are not detected - and if I move them outside about 1-2mm then they are 'recognized' as 'attached'.

Maybe that is the problem ...

I've had some bad sticks, even from usually reputable brands. Might be worth copying this one to a new one (on another machine)?
 
USB_KnightjpScreenshot_2023-03-25_03-26-53.png




Notice up at the Top it says USB? Dolphin File Manager indicates it use the USB for the Present Working Directory, PWD. Now Change Screen View to your Home directory with a click there first, before moving cursor to lower left corner of screen and clicking on "Removable Devices" to eject the USB Flash Drive (ie detach from the file system or umount /dev/da0s1). That is what I am thinking about Suggesting to you. Your thoughts?

What do you see as directory contents, before you get to clicking on the lower left corner USB eject Icon? How do you perform these steps?
 
The comment about another automounter might be something worth looking into. Maybe KDE has its own automounter. However I wouldn't know where to begin in terms of disabling it.
 
OK.. I think I may have solved it.
I figured as some of the comments suggested. KDE's Dolphin is interfering with automount and not letting it do its thing. Basically, the reason that automount was not working for me was that KDE was reverting to default.
I went into settings that there in "removable devices", I unselected "On Attach".
Screenshot_20230326_000957.png

Now, my USB just mounts the way it is supposed to and I have write permissions to it was well. I remove the disk and plug it back in again, it works, perfectly.
What does not work perfectly is the part where I try to click the "eject" icon or "safely remove". It gives the same error.
Screenshot_20230325_005815.png

As it is right now, I am able to plug in a USB, at any point, write to it and any point and even copy files from it and even if I remove the drive and plug it back in again, I am still able to write to it. This is what I wanted to be able to do. Now I can.
What I cannot do is click the 'eject' icon to unmount it. That is all. So right now I can call it solved for me.
 
Glad to hear that you have found a solution and 2nd that you documented it here for others to find and read in the future. Plus you shared beautiful screen shots. Great News. Thanks for your efforts and explicit pictorial feedback! This helps everybody.

Can you change the "Title" on your first post and mark "SOLVED" or place "SOLVED" as first word in title. Look at others that show the green "SOLVED" mark. I am not sure how that is done. Use your best efforts. Thank you.
 
Back
Top