2

I connect my USB stick to my LUbuntu PC running a media player app. I unplug it. I connect it again, the media player app gives a "Permission denied" for "/media/myName/stickName". If I delete the "folder" "/media/myName/stickName", plug the stick again, the media app runs fine and there is no permission error.

At this point I need to understand what Linux considers connected usb drives and why they remain as folders when unplugged, so I can prevent this issue from happening again, maybe by changing some OS settings.

2
  • Did you cleanly unmount the USB stuck before removing it from your computer? It sounds like you just unplugged it while it was in use.
    – jsbillings
    Sep 26 '15 at 12:32
  • In my media player device there is no desktop, no keyboard-mouse, no monitor. So no way to unmount from desktop/console. It's an embedded device running Linux and my app on top of it. Other similar media player devices don't seem to have problem just requiring the user to plug the usb stick and unplug when he wishes. I'm sure some of these devices use Linux and I'd e very surprised if the Linux folks hadnt thought of a situation like this and a solution for it.
    – Leo Ervin
    Sep 27 '15 at 8:08
0

A filesystem (e.g. the files on an external drive) needs to be mounted before its files are accessible, and it needs to be unmounted to make the files inaccessible.

Your environment automatically mounts USB drives just after they're plugged in. It can't automatically unmount them when you pull out the drive, because that would violate causality — the unmounting has to happen before the drive is pulled out, but the system only knows that you've pulled it out after the fact.

If you pull out a drive without unmounting it, the system should detect that the drive isn't there and unmount it. That's ok if you're only reading from the drive, but if you've written to it, this is likely to lead to data loss. The reason is that data isn't written immediately, it's written after a delay. This both improves performance, and improves the longevity of flash media. (Some operating systems, notably Windows, write all data to external drives immediately, but this makes writing slower, especially on flash media, and it can kill cheap flash drives pretty quickly, especially if you write lots of small files.)

You should get into the habit of unmounting USB sticks before unplugging them. You can do that by clicking on the drive icon in your file manager and selecting “unmount” or “eject” in the menu, or clicking the ⏏ icon next to the drive if there is one. Wait until the message notifying you that the operation is complete before pulling out the drive.

If you've only read from the drive and not written to it, it's ok to pull out the drive. But you may need to unmount it explicitly even after pulling it out.

7
  • How can I unmount explicitly? On my media player device there is no desktop, no keyboard-mouse, no monitor. It's an embedded device running Linux and my app on top of it. Other similar media player devices don't seem to have problem just requiring the user to plug the usb stick and unplug when he wishes. I'm sure some of these devices use Linux and I'd e very surprised if the Linux folks hadnt thought of a situation like this and a solution for it. "If you pull out a drive without unmounting it, the system should detect that the drive isn't there and unmount it."-It doesnt. Can i change that?
    – Leo Ervin
    Sep 27 '15 at 0:50
  • @LeoErvin That's looking like a problem with your media player app: it shouldn't offer the directory any longer when it gets unmounted. What application is that? How are you deleting the folder if you don't have a file manager? Sep 27 '15 at 0:56
  • "it shouldn't offer the directory any longer when it gets unmounted." - its not getting unmounted, thats the problem. It's a Python program I wrote. If I can unmount myself (eg via some shell script) please tell me how. If I can change Linux settings to auto-unmount if unplugged, please tell me how to do that instead.
    – Leo Ervin
    Sep 27 '15 at 8:07
  • @LeoErvin To unmount, call umount. Sep 27 '15 at 12:20
  • Can I call it after the drive is physically unplugged (which is the only way I can know it has to be unmounted)? I seem to have a problem calling the shell command umount /media/userName/driveName from my Python script via subprocess.call() ,it doesn't seem to do anything, the drive folder is still there.
    – Leo Ervin
    Sep 27 '15 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.