Can't Mount USB Drive As User Under FreeBSD 10

Roland Smith rsmith at xs4all.nl
Fri Feb 14 17:16:12 UTC 2014


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"
    USERUMOUNT="YES"
    USER="your_name_here"
    ATIME="NO"
    REMOVEDIRS="YES"

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!


Roland
-- 
R.F.Smith                                   http://rsmith.home.xs4all.nl/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20140214/f9ed356e/attachment.sig>


More information about the freebsd-questions mailing list