3

Quick summary: How can I arrange for USB FAT32 thumb drives to be auto-mounted as /media/USER/LABEL, with non-root read/write permissions?

(There are a lot of questions here about automounting USB drives, but I don't see one that's directly relevant.)

I'm running 14.04.4 LTS on an x86_64 system. I'm using the Cinnamon desktop if that matters. I have a FAT32-formatted USB thumb drive. I've run fsck on the drive, and it shows no errors.

Until recently, when I inserted the drive into a USB port it would not auto-mount. It would show up in the output of lsusb, as:

Bus 001 Device 008: ID 058f:6387 Alcor Micro Corp. Flash Drive

I was able to mount it manually, using something like:

sudo mkdir /tmp/usb ; sudo mount /dev/sdg1 /tmp/usb

but that was less than ideal.

I recently installed the usbmount package. After that (and a reboot), when I insert the drive it automatically mounts as /media/usb0:

$ df /media/usb0
Filesystem     1K-blocks  Used Available Use% Mounted on
/dev/sdg1       15712248  9080  15703168   1% /media/usb0
$ 

The problem: I can read everything on the drive, but it all appears to be owned by root and I can't write to the drive without using sudo or equivalent.

What I want to happen is this: When I insert the drive, it's automatically mounted as /media/username/label, where username is my user name and label is the volume label on the drive -- and all files on the drive are owned and writable by my account.

This used to happen automatically, but I don't know how I set it up. Some time ago, I upgraded my workstation from Debian 6 to Ubuntu 14.04. I had the auto-mounting worked the way I want it when I was running Debian 6. I was also using a different desktop environment (some version of Gnome, perhaps?). (The transition from Debian 6 to Ubuntu 14.04 happened to coincide with me not using USB drives as much; now I need to start using them again, so I haven't tried this in a while.)

2 Answers 2

1

I think I've figured out what happened.

I had installed a package called usbmount. With that package installed, inserting a USB drive would automatically mount it as something like /media/usb0, with everything on the drive owned by root. (This is for a drive with a FAT32 filesystem, which for various reasons is what I need to use. I don't know how it would work with a filesystem that actually supports file ownership.)

I've since uninstalled the usbmount. Now when I insert a USB thumb drive, it isn't automatically mounted -- but it does show up in the GUI file manager. (I use the Cinnamon desktop, so my GUI file manager is Nemo; Nautilus does the same thing.) It appears as an entry in the left column, labeled "16 GB Volume"). If I then double-click on that, it's then mounted as, for example, /media/kthompson/EC1C-4374. And if I then use gparted to set the drive's label to THUMB, it's mounted as /media/kthompson/THUMB, which is exactly what I want.

It's likely I didn't notice this because I don't use the GUI file manager very often, and that I incorrectly remembered it being mounted automatically.

It would be nice to have the drive mounted under /media/$USER automatically, but opening a GUI file manager and double-clicking an icon isn't much of a burden. And if it were mounted automatically, it's probably not 100% clear which user should own it; that's probably why usbmount mounts it as root.

-1

Possible answer:

I'm not sure how to do this for all USB drives universally, but if you have specific drives, you can edit /etc/fstab to set up their mounts how you like them. You can use Disks (gnome-disks), or if you don't mind getting your hands dirty, you can edit it manually. You'll want to set a <mount point> and I think you'll want these options:

uid=1000,gid=1000,dmask=022,fmask=022,users

Run man fstab for more info. There's also some info here on the community wiki.

4
  • Good information, but there's definitely a way to do it that works for drives in general, and automatically names the mount point based on the drive's label. Commented Jul 1, 2016 at 22:40
  • very bad answer: vague (I think you'll want ...), misleading (where did you get uid=1000 and gid=1000?) incomplete (what about the other parts of the fstab line?) and pointless because no sane person would want to mount USB thumb drives by first enquiring there UUID or device number and then editing the fstab as root. And what about automounting a drive which is inserted after the boot? I am looking for a solution myself, it's 2023 and still this fstab solution keeps cargoculting its way in every post mentioning automount usb. Thanks for spreading this bad solution.
    – bliako
    Commented Feb 17, 2023 at 13:48
  • @bliako It's been a long time since I wrote this, but IIRC, this is a good way to set mount options for a drive manually, but it's not presented well, I agree. And I still don't know how to automount drives inserted after boot. IIRC, uid=1000 and gid=1000 correspond with the first user account and group created, so that is cargo-culty, yeah; it'd be better to use your user ID and group ID. I think even another problem that could happen is if the drive isn't inserted at boot, the OS wouldn't load; this question has info on that.
    – wjandrea
    Commented Feb 17, 2023 at 20:03
  • @bliako Lastly, I did write "Possible answer" at the top. I'm not asserting it's complete or conclusive. For example, the other parts of the fstab line are up to you.
    – wjandrea
    Commented Feb 17, 2023 at 20:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .