Mounting USB sticks autmatically in FreeBSD

Mon 01 January 2018, tagged: FreeBSD

Getting USB devices to automount in FreeBSD is harder and more complex that it needs to be. All the parts are there but what makes it hard is that it’s changed over the years so you can get yourself in a right pickle. Here is what I did to get it working with FreeBSD 11.1-RELASE. If you follow the handbook you end up with USB sticks that mount but are readonly and can’t be unmounted by a non-root user.

Firstly follow FreeBSD Handbook section on USB sections 17.4.1 and 17.4.2 BUT DO NOT uncomment the

1
/media -media -nosuid

line in /etc/auto_master and DO NOT uncomment the lines in devd.conf (or move them above the comment as the file says).

Next install Freshports/automount from ports or pkg.

1
pkg install automount

Automount is going to be called by devfs when a USB device is detected on insertion. The installer installs the devd additions in to /usr/local/etc/devd/automount_devd.conf for you (which is why you don’t need to do it yourself).

Automount itself needs to be configured. So cp /usr/local/etc/automount.conf.sample /usr/local/etc/automount.conf and then open it in your favourite editor.

1
2
3
4
5
6
7
USERUMOUNT=YES
ATIME=NO
REMOVEDIRS=YES
FM="thunar"
USER="USERNAME"
ENCODING=pl_PL.ISO8859-2
CODEPAGE=cp852

I changed USER to my username and FM to launch thunar when a USB is inserted. In a multi user system this isn’t ideal as there is only one user. My only thought on this is to create a user called USBThumb that can’t login and add all users to the USBThumb group. I’ve not done this but you can see where I am going with it.

Anyway, this should get you going. Hope it helps someone.