Can't Mount USB Drive As User Under FreeBSD 10

B J va6bmj at
Mon Feb 17 02:43:32 UTC 2014

On 2/14/14, Roland Smith <rsmith at> wrote:
> On Fri, Feb 14, 2014 at 04:39:46AM +0000, B J wrote:
>> I searched the mailing list archives for an answer to my problem but
>> didn't find anything.
>> I recently installed FreeBSD 10 on a T42 Thinkpad.  The configuration
>> uses Gnome as the desktop.
>> I've had problems configuring the machine to mount external USB
>> drives.  I can mount USB thumb drives when logged in as root using:
>> mount -t msdosfs -o -m=644,-M=755 /dev/da0s1 /mnt/root
>> after creating the directory /mnt/root.
> To be able to mount as a user several settings have to be made.
> First, in /etc/sysctl.conf:
>     vfs.usermount=1
> Next the permissions for the devices have to be set. Since USB devices can
> be
> plugged in at random, this has to be set in /etc/devfs.rules, not
> etc/devfs.conf! You can make a choice here;
>     1) give _everybody_ read/write access by using mode 666
>     2) restrict r/w access to a group, e.g. a group 'usb'. This is the path
>        I've chosen.
> So, in /etc/devfs.rules I've put the following;
>     [my_usb=10]
>     add path 'da*' mode 0660 group usb
>     add path 'msdosfs/*' mode 0660 group usb
>     add path 'usb/*' mode 0660 group usb
>     add path 'ugen*' mode 0660 group usb
> Additionally, in /etc/rc.conf we have to activate this ruleset:
>     devfs_system_ruleset="my_usb"
> What I like to do is have USB drives mount automatically. To this end I'm
> using sysutils/automount. This uses devd notifications. Configuration is
> done
> with two files;
> /usr/local/etc/devd/automount_devd.conf:
>     notify 20 {
>     match "system" "DEVFS";
>     match "type" "CREATE";
>     match "cdev" "da[0-9]s1$";
>     action "/usr/local/sbin/automount $cdev attach";
>     };
>     notify 20 {
>     match "system" "DEVFS";
>     match "type" "DESTROY";
>     match "cdev" "da[0-9]s1$";
>     action "/usr/local/sbin/automount $cdev detach";
>     };
> N.B.: /usr/local/etc/devd must be named as a directory option in
> devd.conf(5).
> But this is the default.
> Next we have /usr/local/etc/automount.conf:
>     MNTPREFIX="/media"
>     USER="your_name_here"
>     ATIME="NO"
> The directory '/media' has to be created. Under this directory,
> subdirectories
> named after the device will be created owned by $USER. So if a /dev/da0s1
> is
> detected by devd, it will be mounted at '/media/da0s1' owned by $USER. If
> the
> USB cable is unplugged the filesystem will be unmounted. Note that it is
> better to unmount filesystems by hand before unplugging them!

I got something to work.  As we used to say while I worked in
industry, if it works, don't fix it.

Here's what I did:

- installed automount
- added the commands listed above (spelling things correctly helps!  ;-))
- put "mount -t msdosfs -o -m=644,-M=755 /dev/da0s1 /media" in a file
(I called it mountusb)
- put "umount /media" in another file (I called it unmountusb), and
- make a link to /media and put it on the desktop.

I created identical files in my user account.  Putting those commands
into files saves me the headache of typing them each time.

While operating as root, I:

- mounted the USB drive by typing "source mountusb"
- clicked on the link, the contents of the USB drive appeared, and
- umounted the USB drive by typing "source unmountusb"

While operating in my personal account, I:

- changed to the C shell, and
- used "source mountusb" and "source unmountusb" as before.

I copied files from the USB onto my desktop without any problems.

Anyway, it works and it's good enough for my purposes.  Thanks for the

B.M. Jatzeck

More information about the freebsd-questions mailing list