How to write this usb stick unmount command line properly?


I sometimes run into issues with unmounting usb sticks and there was this command that is suggested but doesn’t work anymore, what would be the updated version or command to use to reach same effect of unmounting the usb sticks when they do not show the unmount triangular button in caja?

Suggested command but not working anymore:
udisks --unmount /dev/sdb1 && udisks --detach /dev/sdb

Any alternatives you can suggest? :grin:

If the eject icon isn’t displayed in Caja’s panel, it usually means that the drive is plugged but not mounted. So, are you sure it is?

You can also try to use the umount command:

umount /media/yourname/drivename

where yourname is your username and drivename the mount point name. When you mount a drive through Caja (or other file managers), it’s done as user level in a directory named after you in /media.

Disks (aka Gnome Disks or gnome-disk-utility) is a nice tool to show all detected disks, including ones that are not mounted.

I wanted to suggest

umount /dev/sdX

but yours works certainly, too. What’s the difference?

Mickey :slight_smile:

I’m not sure you can use umount on the device itself, I’ve always thought it has to be done one the mount point. But I might be wrong.

Both works.


umount /media/username/drivename

is probably the nicer solution because there you unmount the device directly from its mount point. In the end it does not really care. :smiley:

Mickey :slight_smile:

However if you unmount it that way, even if data is still being written from cache to the usb stick it will then interrupt it without waiting until it’s done? Or is there another way to formulate the unmount command as such that it waits until data written from cache is complete and then unmounts?

You have to use the sync command before unmounting to be sure that the data is finished being written (wait for the shell to bring you back to the prompt, it can take several minutes, don’t assume that it’s stuck).

Doing a quick search, I found a blog post about a bash script to properly eject an USB device; it uses the udiskctl command. Maybe that’s the proper command for the one you had?

I just write sync in the terminal? Or sudo sync? And when the prompt shows up it would be a sign that cache writing on the usb stick is done?

Thanks for the link. Will check.

You don’t need to use sudo (unless maybe if you mounted the USB key as root for some reason but even then I’m not sure).

When you push enter to run the command, the cursor will just go to the next line and nothing will seem to happen. When it’s finished, you’ll get the prompt back and it means that cache writing is done.

OK. I do not need to specify what it has to sync right? Just sync on its own will be enough or do I have to specify the device name to which it is currently writing to?

No need to specify anything, just run the sync command. Not sure how it handles several devices if you happen to copy files to multiple USB devices at once, though, I’ve never tried that kind of case.

1 Like