devd based AUTOMOUNTER

vermaden vermaden at
Mon Feb 27 19:49:45 UTC 2012


I have been pretty busy lately because of boring things
work/life stuff, but here is the new version, with more
options of course and some bugs fixed, it now displays
help when triggered as 'automount --help', at least a
substitute of a man page ;)

I have a quastion, which devd(8) events should I 'catch'
to enable CD automount? Is there an event for a CD being
entered into the CD-ROM at devd(8)?

Second question, how to commit a port? I have a working
port if I put all needed files when they need to be, but
its PITA to install it that way ...

Of course latest version is available here:

An example usage display:

% automount --help                                                   
AUTOMOUNT is a devd(8) based automounter for FreeBSD.

It supports following file systems:

It needs these ports to mount NTFS/exFAT/EXT4 respectively:
 o sysutils/fusefs-ntfs
 o sysutils/fusefs-exfat
 o sysutils/fusefs-ext4fuse

By default it mounts/unmounts all removable media but
it is possible to set some additional options at the
/usr/local/etc/automount.conf config file.

Below is a list of possible options with description.

MNTPREFIX (set to /media by default)
  With this options You can alter the default root
  for mounting the removable media, for example to
  the /mnt directory.

  example: MNTPREFIX="/media"

ENCODING (set to en_US.ISO8859-1 by default)
  Only used with FAT32 mounts, specifies which
  encoding to use at the mount.

  example: ENCODING="pl_PL.ISO8859-2"

CODEPAGE (set to cp437 by default)
  Only used with FAT32 mounts, specifies which
  code page to use at the mount.

  example: CODEPAGE="cp852"

USER (unset by default)
  If set to some username, the mount command will
  chown(1) the mount directory with the user and
  its primary user group. If used with FM option
  allows to launch the specified file manager after
  a successful mount.

  example: USER="vermaden"

FM (unset by default)
  If set to file manager command, the mount will
  launch the specified command after successful
  mount. Works only if USER parameter is also set.

  example: FM="nautilus --browser --no-desktop"

USERUMOUNT (set to NO by default)
  When set to YES it will 'chmod +s /sbin/umount'
  which would allow an USER to unmount the file
  system with their selected file manager.

  example: USERUMOUNT="YES"

ATIME (set to YES by default)
  When set to NO it will mount filesystems with
  noatime options when possible.

  example: ATIME="NO"

REMOVEDIRS (set to NO by default)
  When set to YES it will remove empty directories
  under the used  after device detach.

  example: REMOVEDIRS="YES"

Now for the questions ...

>> Added 'noatime' as a default mount option when possible.
> Good idea for many use cases, but could that be optional?
Its optional now, then ATIME option.

>> The USERMOUNT otions if set to YES (default to NO)
>> will 'chmod +s /sbin/umount', so You can click the ^
>> button on the devices list in NAUTILUS.
> Someone might explain why I needn't feel a bit
> uncomfortable about that chmod, even though it is
> optional, and even though I've been guilty myself of
> a 'chown root:nobody /sbin/tc' on a linux firewall box
Well, its optional, You do not have to use it ;)

>> These newly mounted devices appear on NAUTILUS
>> sidebar (only with /media prefix).

> I wonder how it goes with KDE4? (still 3.5 here)

Freddie Cash reported that they also appear at
Konqueror and Dolphin, both KDE 3.x and 4.x.

> Er, who's user 1000 ?  Another config item perhaps?
> Or should that be the particular user currently
> invoking the script via devd (if that can be determined?)?

It was 'development' branch ;) I tried many things then,
its now a configurable option as USER.

> Also, are you using sysctl vfs.usermount=1?

No, its not needed, the mount is done by root and
umount even by user with USERUMOUNT=YES does
not require the vfs.usermount=1 option.

> Mmm, fsck on every attachment? Maybe running
> fsck should be optional? We might be attaching,
> perhaps, a 2TB backup HD? ..

> Ouch! I agree. Why not just fsck_ufs -p. (I realize
> this is done to fix systems that were unplugged
> rather than umounted, but it's a pretty expensive
> operation when not needed.

I have added -C option to fsck for UFS, so it will
onlt check filesystem if clean flag is not set.

>> mount -o noatime ${I} ${MNT}

> Again, I'd rather see that optional in an intended
> system tool, although  it's an option I'd tend to use myself.

Its optional now with ATIME option.

>> find ${MNTPREFIX} -type d -empty -delete

> I don't see the need to remove all empty subdirs
> of, say, /media - this tool may not be the only
> thing wanting to manage that space? Removing 
> directories that were added by this tool itself
> makes sense of course.

It only removed EMPTY directories, which was mostly
harmless, but I made it to not delete them by default
and added an option to enable that as well.

> Looks like a neat gadget, don't mind me picking
> up on a few aspects :)

Thanks mate, try latest version ;)

>> I don't see the need to remove all empty subdirs
>> of, say, /media - this tool may not be the only
>> thing wanting to manage that space?  Removing
>> directories that were added by this tool itself
>> makes sense of course.
> This is an interesting one. Gnome and hald have
> a problem here that have caused me to add sudo
> /bin/rmdir /media/* to.xinitrc to work around.
> It's just too easy for 'junk' directories to live on
> when the system does not exit everything cleanly
> and, while hald tries to keep track, it is very hard
> to do in the real world. I suspect it is really
> needed. And what else is creating directories in
> /media?

I made it configurable via option if someone has
a habbit to put other things over there ;)

Thanks for interesting input mates, king regards,


More information about the freebsd-stable mailing list