1

I am confused about the interaction between the auto and user mount options in fstab.

After mistakenly setting auto rather than noauto, I noticed that my mount would take place when a device was inserted, but that the user could not subsequently unmount the device (the "user" being an executable running without root privileges). This is the /etc/fstab entry:

/dev/mmcblk1p1 /home/user/importexport auto rw,user,auto,exec,uid=1000,gid=100,umask=0022,nobootwait 0 2

When I replace auto with noauto, the user can explicitly mount and unmount the device.

This is on an embedded system where I have no runtime visibility, meaning no shell access to interactively explore the problem. All I can do is write debugging information to files that I can view on the next boot. My kernel is 3.10.0.

So why is the user unable to unmount a device that has been auto-mounted with the user option?


Note: In Option “user” work for mount, not for umount, somebody asked about the permissions on /etc/mtab. Mine are -rw-r--r-- by root, but /etc/mtab contains none of the user information alluded to in that question, so I think this may not be relevant.

  • auto means that the partition will be automatically mounted at boot time and with a mount -a. noauto means that neither is true; it must be explicitly and manually mounted. The manual page for fstab states that the user option specifies that a (non-root) user may mount the partition, but is silent as to whether or not the same user may unmount it. – DopeGhoti May 27 '16 at 23:25
  • @DopeGhoti Agreed. The man page also states "Only the user that mounted a filesystem can unmount it again." Unfortunately, neither /etc/mtab nor /proc/mounts reveal who mounted the partition. Any suggestions on how I might determine that? – Josh Sanford May 31 '16 at 12:39

1 Answers1

1

i believe auto(option in fstab) is always performed as root, and user option is only tells to the mounter that it allows accept requests from simple users. here is what happening: you insert drive, system recognize it, automount it (as root) and user become unable to unmount it if user is not in the root group.

you can delete auto option (or better supply other one - noauto) from fstab, leave user option and write script by user (for it being executed by user) to mount it every time when you insert the drive.

edit:
it seems that whatever automounter uses user account it is not same as yours.

edit #2:
you can find out who have mounted a device by executing a command

ls /mnt/ -l

edit #3:

alternatively

sudo cat /etc/passwd | cut -f -3 -d ':' | sed -re 's/(.*):(.*):(.*)/\3 \2 \1/g' | while read p1 p2 p3 ; do printf "%05i $p2 $p3\n" "$p1" ; done | sort -r | while read p1 p2 p3 ; do echo $p3 ; done | while read p ; do sudo -u $p umount /dev/ice 2>/dev/null && echo $p >> /tmp/busted ; done

substitute /dev/ice with device you are interested in
make sure you have your sudoers file have been properly setup
you will find your wanted suspected user in /tmp/busted

  • Is there any documentation to confirm that automount is always performed as root? I thought that /etc/mtab and /proc/mounts were supposed to indicate who mounted that partition, but I see no such information in those files. – Josh Sanford May 31 '16 at 12:46
  • imagine, you supply an -a option to mount program, it parses fstab and see dev/root should be mounted at /. who else, except root would be allowed to do that? there is no option in fstab responsible to indicate under what credentials mount should be made. mount is system utility, it always performed as root, but after that a root can delegate permissions to read and write to other users. – user3694243 May 31 '16 at 14:37
  • automount in answer is not a tool - "automount". i tried to say "automatically mount", i.e. "mount -a" (which is mount all what is in the fstab with auto option and/or without noauto option). the option noauto and user are often used together, so the filesystem will not be mounted at boot time and user explicitly can mount it when wishes later. – user3694243 May 31 '16 at 14:54
  • I understood what you meant by "automount": The functionality, not the tool name. But as for mount -a mounting everything in fstab with both auto and noauto, the man page states that mount -a mounts everything "except for those whose line contains the noauto keyword" (emphasis in original). – Josh Sanford May 31 '16 at 18:18
  • When I perform ls -l /home/user/importexport, the system shows the ownership as user:users regardless of whether the mount was performed automatically by the system or explicitly by the user. But user attempts to unmount the partition fail if it was automatically mounted by the system, and succeed if it was explicitly mounted by the user, so ls -l /home/user/importexport doesn't help in my case. – Josh Sanford May 31 '16 at 18:25
  • only thing that come in mind that system upon mounting the relevant partition by the root, then assign to the folder the owner user:user. System startup mounting is happened by the root, it is by design. If you need to mount disk by user then supply noauto + user options to fstab respective entry. – user3694243 Jun 01 '16 at 00:34
  • I am upvoting your answer, but not marking it as the answer because it seems that both of us are speculating, and I am still unable to definitively identify who owns the mount. (The upvote will go into effect when I have enough rep.) – Josh Sanford Jun 01 '16 at 12:40