Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've got many FAT32 drives that I'd like to mount in Ubuntu such that they have permission mode 700 for directories and 600 for all other files. By default, they have 755 for all files, which is not particularly useful since almost no non-directories should be executable, and it screws up version control repos hosted on the drives.

"Back in the day" I would have had the drives listed in /etc/fstab with the umask/dmask I want and there was no such thing as a default. These days, drives automount under their volume names. Which is great, except now I have no idea how to set the default.

I have tried changing the /system/storage/default_options/vfat/mount_options gconf key with no apparently effect. It was 077 initially but the mounted drive reflected a default of 022; changing it and re-inserting the drives resulted in the files still having permission bits of 755.

share|improve this question
    
huh. thought your username looked familiar. i've been using mutagen for years. welcome to Super User. :) –  quack quixote Apr 25 '10 at 8:22
    
also, which version of ubuntu are you using? i'd assume Karmic, but you might be talking about the Lucid RC, or even something earlier. –  quack quixote Apr 25 '10 at 8:32
    
Clarified in the title. I was hoping it wouldn't matter, since I do have some older installations, and something like mounting shouldn't be changing every six months consarnit. –  user35138 Apr 25 '10 at 8:34
    
unfortunately the HAL stuff has undergone quite a few changes in recent versions. 9.04 and previous are probably the same; some solutions might apply to all; but 9.10 uses DeviceKit and HAL is deprecated. i don't trust any of the DBus/HAL/DeviceKit stuff to stay stable at the moment. –  quack quixote Apr 25 '10 at 8:40
    
comment from pagin: I think the issue is much more fundamental: I want to modify the umask for automounting regardless which device connects to the computer. I.e. if a friend of mine drops by with his usb stick and I want just to copy some file from this one, I want them automatically to be transferred as chmod 750, not 000 or 777, 770 or whatever. There should really be an option somewhere to configure this... –  quack quixote Jun 11 '10 at 19:24
add comment

5 Answers 5

up vote 6 down vote accepted

Updated
Unfortunately there is no built-in means to do this. The "right way", the supported way, is setting an /etc/fstab line with the default mount options you want. This means your defaults must be set per-device, though you can use the partition label or UUID to avoid requiring a specific device path. In particular, this method seems to take place before the PolicyKit desktop authorization.

The Ubuntu forums, Launchpad and Gnome's bugzilla have many posts from users looking for the same functionality you're looking for, on both NTFS and FAT32. Ubuntu 9.10 and 10.04 provide the default automounting via a combination of DeviceKit-Disks, GVFS, and Nautilus.

DeviceKit-disks provides a FilesystemMount interface whose options argument appears to be the proper way to configure your mount options. But GVFS/Nautilus does not appear to provide any means, via the UI or a configuration file, to specify this option when automounting a USB key.

There are a couple of workarounds:

  • This Launchpad bug contains a user-provided patch that alters the DeviceKit-Disks defaults in a custom-built devicekit-disks package.

    On the plus side, this may be the easiest way to set your preferred defaults for all devices. The disadvantage is that you'll need to repatch again when the package is updated.

  • One Ubuntu Forums post proposes a device-specific workaround script:

    #!/bin/bash
    devkit-disks --unmount /dev/disk/by-uuid/0D3594370C618A2A
    devkit-disks --mount-options "dmask=000" --mount /dev/disk/by-uuid/0D3594370C618A2A
    

    This is also sub-optimal, since you'd have to keep this updated with specific devices. But it does avoid the authorization problem that the supported fstab solution can have.

share|improve this answer
    
comment by Rndmerle: As a side-note, on Ubuntu Lucid (10.4) the devkit-disks command has been replaced by /usr/bin/udisks –  quack quixote Jun 11 '10 at 19:26
    
This workaround with udisks --unmount etc., only works for umask and dmask. Other options are not allowed as you can guess from the patch you linked. –  user39559 Aug 31 '10 at 17:00
add comment

Here's my fstab line for getting my usb stick to mount with permissions suitable for a private ssh key (fmask=177). Trial and error informed me I had to add the 'user' option to get automount to work.

/dev/disk/by-uuid/C2F8-E4F2  /media/TIM_ABELL  vfat  rw,user,nosuid,nodev,dmask=0077,flush,fmask=177

I also had to create the mount point which was previously automatic:

mkdir /media/TIM_ABELL

the disk uuid can be found by plugging in the disk and running

mount
ls -l /dev/disk/by-uuid/

which will allow you to get the mount point -> device -> uuid mapping

share|improve this answer
1  
instead of using the full paths /dev/disk/by-uuid/FOO or /dev/disk/by-label/FOO you can use the shortcut syntax UUID=FOO or LABEL=FOO. –  quack quixote Jun 11 '10 at 19:23
add comment

Have you really, really tried the old /etc/fstab method? It works for me. Ubuntu uses fstab, no matter of the HAL automounter.

share|improve this answer
1  
What do I put in /etc/fstab to make all FAT drives mount like that? My point isn't that "I could do this with fstab" (I can't), it's "this didn't happen under the fstab model because it didn't mount anything unless I told it to". –  user35138 Apr 25 '10 at 8:31
add comment

I did some bash scripting and came out with this improved version of the workaround script that is posted above:

#!/bin/bash
dev_path="/dev/disk/by-id"
usb_drives=$(find $dev_path -name "usb*")
mount_options="utf8=0,codepage=850,iocharset=iso8859-1"

for dev in $usb_drives ; do
  if ( devkit-disks --show-info $dev | \
       grep "is mounted:" | grep -q 1 ) ; then
    devkit-disks --unmount $dev
    devkit-disks --mount $dev \
      --mount-options $mount_options
  fi
done

It finds every devices connected by USB (hopefully all pendrives) which are already mounted, and remounts them using mount_options (in my case, let them use iso-8859-1 charset for compatibility with other limited OSes)

share|improve this answer
2  
What happens if you plug in an ext4 USB? Will it apply masks and other options that you only want (and only make sense) for FAT? –  user39559 Aug 31 '10 at 17:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.