# Automatic mounting of USB drives, CDs etc.



## multixrulz (Jan 2, 2015)

Hi, I'm a newbie to FreeBSD, potentially migrating myself off ArchLinux (systemd might be the last straw).

I'm trying to work out how to construct an automounting solution of the type I'm used to.  My preferred method of operation is:

Insert USB stick (or whatever).
Machine mounts it automatically, independent of the logged in user, running of X, etc.
Device is available to all users in a specific group, via the mountpoint's group ownership.

Any user can unmount the device.
In Linux I eventually wrote a script to to the mounting on udev events, and used pumount to unmount.  systemd broke this, so I switched to udevil which worked even better.

I've tried sysutils/automount (https://forums.freebsd.org/threads/devd-based-automounter.29895/) and finally got it working with FreeBSD 10.1.  However, unmounting doesn't work as desired, because I'm not keen to make umount suid, and I haven't found any other non-root unmounting programs in FreeBSD.

I had a go with sysutils/automounter too (the one that makes on-the-fly changes to amd(8)), It worked really well and the auto-unmounting could be really handy except that I can't use my normal method of checking if the device is still mounted, to know if it's safe to physically remove.  This is because I've been using ROX-Filer to quickly check the mount status, but the entries in /media are symlinks elsewhere so the mount status doesn't show up.  Personally, I could deal with this, but I have family who are not technically inclined and don't want to push that kind of thing onto them.

How are other people managing this?

[edited for correct ports links]


----------



## vermaden (Jan 2, 2015)

multixrulz



> Insert USB stick (or whatever).
> Machine mounts it automatically, independent of the logged in user, running of X, etc.
> Device is available to all users in a specific group, via the mountpoint's group ownership.
> 
> Any user can unmount the device.


1., 2. and 3. are fulfilled with *automount* (not to confuse with *automounter*), the 4. will have to probably be SUID umount or SUID unmount.sh script that will check if the path for unmount is /media/* or sudo(8).



> In Linux I eventually wrote a script to to the mounting on udev events, and used pumount to unmount. systemd broke this, so I switched to udevil which worked even better.


This is how *automount* works, by 'reacting' to DEVD events.



> I've tried sysutils/automounter (https://forums.freebsd.org/threads/devd-based-automounter.29895/) and finally got it working with FreeBSD 10.1.  However, unmounting doesn't work as desired, because I'm not keen to make umount suid, and I haven't found any other non-root unmounting programs in FreeBSD.



Have You also tried this one:

```
[CMD=%]sysctl -d vfs.usermount[/CMD]
vfs.usermount: Unprivileged users may mount and unmount file systems
```


----------

