devd based AUTOMOUNTER

Hi,

I have finally made some effort on writing flexible yet very simple automounter for FreeBSD desktop.

Feel free to submit me BUG reports to this thread ;)

It currently supports these file formats:
-- NTFS requires sysutils/fusefs-ntfs for R/W
-- FAT/FAT32
-- exFAT requires sysutils/fusefs-exfat
-- EXT2
-- EXT3
-- EXT4 requires sysutils/fusefs-ext4fuse
-- UFS

It keeps state of the mounted devices at /var/run/automount.state and logs all activities to /var/log/automount.log file.

The place for the script is at /usr/local/sbin/automount.sh executable.

The only additional configuration it requires is /usr/local/etc/devd/automount_devd.conf file.

I have created repository @ GITHUB here:
https://github.com/vermaden/automount
 
Added a check if ntfs-3g is available, if not then mount_ntfs is used instead.
Added deleting of empty directories at ${MNTPREFIX}.
Added ${MNTPREFIX} to be set to /mnt or /media according to preference
Adddd additional checks for NTFS filesystem with label "FAT".
Adddd additional checks for FAT filesystem with label "NTFS".
 
Thanks for the effort.

Is the fat mount part able to handle windows utf-16 characters such 猪 and display them correctly under freebsd FreeBSD?
 
Why is this not in howto section?

A question. Is it possible to geli attach a USB disk based on its label, and pass locally stored password at the same time? That would be neat.

Thanks!
 
fat mount and propper characters

@vermaden

The following might be an interesting addition to you script.

background:
If I create a few files with chinese/japanese names in the filename under windows and then put it onto an USB stick with fat and try to mount it under FreeBSD it will only show rubbish instead of the propper characters (even if all the fonts are installed).

For this reason I have managed a work-around that handles the compatibility by using sysutils/fusefs-fusexmp_fh.

Here is what I do:

Code:
root> mount_msdosfs -L zh_CN.GBK /dev/msdosfs/device /mnt/tmp
root> fusexmp_fh -oallow_other,modules=iconv:subdir,from_code=GBK,subdir=/mnt/tmp /media/CW-P7EOS-X
This will mount the device on /mnt/tmp and fysexmp_fh will take this and does an extra mount on /media/CW-P7EOS-X with the proper encodings.

I have created a script that does this automatically, still the unmount part is missing.
Code:
#!/usr/local/bin/bash

# path to the actual mount_msdosfs binary
MOUNT_MSDOSFS="/sbin/mount_msdosfs.bak"

# dir where the normal (no unicode) mount will be
TEMP_DIR="/mnt"
LOG_FILE="$TEMP_DIR/mount_msdosfs.log"


MOUNT_ARGS=${@:1:$((${#@} - 2))}	# get all params except the last two 
DEVICE_PATH=${@:$((${#@} - 1)):1}	# get 2nd last param (/dev/name)
DEVICE_NAME=${DEVICE_PATH##*/}		# basename of device
MOUNT_DIR=${@:${#@}}			# get last param (/mount/dir)

TEMP_MOUNT="$TEMP_DIR/$DEVICE_NAME"

echo "all args:    ${@}"          > $LOG_FILE
echo "MOUNT_ARGS:  $MOUNT_ARGS"  >> $LOG_FILE
echo "DEVICE_PATH: $DEVICE_PATH" >> $LOG_FILE
echo "DEVICE_NAME: $DEVICE_NAME" >> $LOG_FILE
echo "MOUNT_DIR:   $MOUNT_DIR"   >> $LOG_FILE
echo "TEMP_MOUNT   $TEMP_MOUNT"  >> $LOG_FILE

### 1.) Create TMP Mount Dir
if test ! -d $TEMP_MOUNT
then
	echo "creating:    $TEMP_MOUNT" >> $LOG_FILE
	mkdir -p $TEMP_MOUNT
	chmod 777 $TEMP_MOUNT
fi

### 2.) Do temporary mount
echo "[1]: $MOUNT_MSDOSFS -L zh_CN.GBK $DEVICE_PATH $TEMP_MOUNT" >> $LOG_FILE
$MOUNT_MSDOSFS -L zh_CN.GBK $DEVICE_PATH $TEMP_MOUNT


### 3.) Do propper mount
if test ! -d $MOUNT_DIR
then
	echo "creating:    $MOUNT_DIR" >> $LOG_FILE
    mkdir -p $MOUNT_DIR
    chmod 777 $MOUNT_DIR
fi

echo "[2]: fusexmp_fh -oallow_other,modules=iconv:subdir,from_code=GBK,subdir=$TEMP_MOUNT $MOUNT_DIR" >> $LOG_FILE
fusexmp_fh -oallow_other,modules=iconv:subdir,from_code=GBK,subdir=$TEMP_MOUNT $MOUNT_DIR

The only problem (back in HAL days) was that if I moved mount_msdosfs to another place and renamed the above script to mount_msdosfs (which calls the renamed originall msdos mount) it did not create the same results as if invoked by hand. If the script was called by HAL, all filenames with exotic characters in it did not show up.

I still have the log output here. This output shows me how HAL handled the call and as I can see it does the exact thing as i would do.
Code:
all args:    -o nosuid -o longnames -u 1002 -L zh_CN.GBK /dev/msdosfs/CW-P7EOS-X /media/CW-P7EOS-X
MOUNT_ARGS:  -o nosuid -o longnames -u 1002 -L zh_CN.GBK
DEVICE_PATH: /dev/msdosfs/CW-P7EOS-X
DEVICE_NAME: CW-P7EOS-X
MOUNT_DIR:   /media/CW-P7EOS-X
TEMP_MOUNT   /mnt/CW-P7EOS-X
[1]: /sbin/mount_msdosfs.bak -L zh_CN.GBK /dev/msdosfs/CW-P7EOS-X /mnt/CW-P7EOS-X
[2]: fusexmp_fh -oallow_other,modules=iconv:subdir,from_code=GBK,subdir=/mnt/CW-P7EOS-X /media/CW-P7EOS-X

Anyway the fusexmp_fh might be worse experimenting with.
 
@lockdoc

Thanks for suggestions, it can be added, but would add some complexity to the whole setup.

It may be 'stupid' idea, but I personally keep all my files in en_US.iso8859-1 format, I do not use any 'national/regional' characters at all at filenames.

CHANGELOG:

Added check if ntfsfix from sysutils/ntfsprogs is available, if yes then try to fix the NTFS filesystem before mounting it.

Added GPL3 License ... just joking ;) ... added FreeBSD License to the file.

Added 'noatime' as a default mount option when possible.

Added TIMEOUT so when an 'orphan' STATE file lock remains, it will be deleted after a TIMEOUT.

Added /usr/local/etc/devd/automount_devd.conf file instead of messing with the base system config at /etc/devd.conf.

Added config file to be used from /usr/local/etc/automount.conf file, possible options are (these are defaults):

Code:
  MNTPREFIX="/media"
  LOG="/var/log/automount.log"
  STATE="/var/run/automount.state"
  ENCODING="en_US.ISO8859-1"
  CODEPAGE="cp437"
  DATEFMT="%Y-%m-%d %H:%M:%S"
  USERUMOUNT="NO"

My config currently has only these:

Code:
  ENCODING="pl_PL.ISO8859-2"
  CODEPAGE="cp852"
  USERUMOUNT="YES"

The USERMOUNT options if set to YES (default to NO) will 'chmod +s /sbin/umount', so you can click the ^ button on the devices list in NAUTILUS.

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

But THUNAR and PCMANFM do not do that, you know any other FMs that display mounted thumb drives/devices?

EXAMPLE:
qdKdl.png
 
Hi,

I removed the state_lock and stat_unlock mechanisms as they appeared to be not needed, I have shuffled with 3 drives all the time and the 'integrity' has not been lost, and it was a lot faster, because the lock always had to wait for the 'slowest' drive (in term of initializing the device, like USB hard drive).

I simplified the 'attach' section a lot, now each filesystem contains only check/fsck (if possible), mount and log info.

I also simplified and improved the 'detach' section a little.

I have added an option to automatically launch the set-up in config file manager (Yes, like in Windows ;p).

These are options that I currently successfully use for NAUTILUS file manager, You need to set-up all three of them to make it work.

Code:
POPUP=YES
FM="nautilus --browser --no-desktop"
USER=vermaden

My whole config looks like that now:

Code:
USERUMOUNT=YES
POPUP=YES
FM="nautilus --browser --no-desktop"
USER=vermaden
ENCODING=pl_PL.ISO8859-2
CODEPAGE=cp852

All latest updates are available at GITHUB:
https://github.com/vermaden/automount

Regards,
vermaden
 
vermaden said:
It may be 'stupid' idea, but I personally keep all my files in en_US.iso8859-1 format

Sometimes it can't be avoided, for example you download a bunch of mp3's from your favorite Japanese singer and all the names are in Japanese.
 
FAT/NTFS detection improvements.
The 'chown' now uses sets user's group.
MSDOS filesystem is now mounted with -m 644 -M 755 options by default.
Removed POPUP=YES option, just use USER + FM for simplicity.
NTFS filesystem, when mounted by mount_ntfs(8) uses -u and -g options by default.
Even more simplified 'detach' section.
 
Hi,

I have created a PORT at last, its in the 'port' directory in the usual place:
https://github.com/vermaden/automount/

Its my first PORT so feel free to bash me about my mistakes ;)

After latest 'commits' I think that its ready for day-to-day use.

To make 'full advantage' of *automount* install these ports:

sysutils/ntfsprogs
sysutils/fusefs-ntfs
sysutils/fusefs-ext4fuse
sysutils/fusefs-exfat

I will try to add these ports as OPTIONS in the Makefile later.

I will have to think about creating a man page through ...

Feel free to submit Your propositions about next changes/development,
because I think that I already created everything 'I' needed.

Regards,
vermaden
 
Added help page, removed some bugs and added some new features.

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

It supports following file systems:
UFS/FAT/exFAT/NTFS/EXT2/EXT3/EXT4

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"
 
Sorry I have only been doing regular ports installations before, how do I install this as a port? Should I create a folder under /usr/ports and put files in there and do make install?
 
This is the easiest way to get it up and running, just download the needed files and put them in right place. The /usr/local/sbin/automount file needs to have executable bit set.
Code:
# cp automount           /usr/local/sbin/automount
# cp automount.conf      /usr/local/etc/automount.conf
# cp automount_devd.conf /usr/local/etc/devd/automount_devd.conf
# /etc/rc.d/devd restart
 
I've almost got my system recompiled without HAL. Once that's done, I'll give this a try and see if I can get it to work with Dolphin/Solid in KDE4.
 
Here is a complete list of 'dependencies' ;p

awk
cat
chmod
chown
dd
ext4fuse
file
find
fsck.ext2
fsck.ext3
fsck.ext4
fsck_msdosfs
fsck_ufs
grep
head
id
mkdir
mount
mount.exfat
mount_msdosfs
mount_ntfs
ntfs-3g
sed
sh
strings
su
umount
 
Hi,

After some 'fun' with MP3 players I have made some modifications and fixes.

Here is a list of what's changed:
  • Fixed bug about inproper exFAT detection, now mounts fine.
  • Fixed bug about creating mount dirs for all attached devices no matter if needed or not.
  • Revised 'detach' section, now removes only directory that is unmounted (if enabled of course).
  • Simplified FAT/NTFS sections, removed additional check as it break some MP3 players default filesystems automount.
The latest 1.3 version can be found here as usual:
https://github.com/vermaden/automount/

Regards,
vermaden
 
Already at 1.3.1 ...
  • Fixed the 'detach' section (s/PREFIX/MNTPREFIX/g).
  • Fixed removing directories of manually (properly) unmounted filesystems.
 
Have installed as a local port, wait to be in FreeBSD Ports.

automount works very good thanks :)

Use

/usr/local/etc/automount.conf

Code:
USERUMOUNT=YES
FM="nautilus --browser --no-desktop"
#USER=vermaden
#ENCODING=pl_PL.ISO8859-2
CODEPAGE=cp852


# Personal Settings

USER=user
ENCODING=en_GB.UTF-8
REMOVEDIRS=YES
ATIME=NO

Only Nautilus need some more times to umount USB, from CLI works as usual user immediately. And Nautilus doesn't find computer.

Nautilus cannot handle "computer" locations.


Use Fluxbox only, this can be problem but normal use only cli.
 
nemysis said:
Have installed as a local port, wait to be in FreeBSD Ports.
The latest, 1.3.1 version is in the Ports for quite long time now.

nemysis said:
automount works very good thanks :)
Good to hear that ;)

nemysis said:
Only Nautilus need some more times to umount USB, from CLI works as usual user immediately. And Nautilus doesn't find computer.

Nautilus cannot handle "computer" locations.


Use Fluxbox only, this can be problem but normal use only cli.
It's not automount's nor Fluxbox's fault, it's Nautilus when it's running without GNOME from what I recall.
 
Back
Top