Ok, it's been a long time, but I'll still answer my question with the best option I found as of now.
The best way is to create a udev
rule, associated with some scripts (that will create / remove directories and mount / unmount removable devices), and attached to partition
udev
device event type.
1 - Creating add / remove scripts
Add this script storage-automount.sh
in /lib/udev/
and set it to executable (sudo chmod +x /lib/udev/storage-automount.sh
):
#!/bin/sh
# set the mountpoint name according to partition or device name
mount_point=$ID_FS_LABEL
if [ -z $mount_point ]; then
mount_point=${DEVNAME##*/}
fi
# if a plugdev group exist, retrieve its gid set & it as owner of mountpoint
plugdev_gid="$(grep plugdev /etc/group|cut -f3 -d:)"
if [ -z $plugdev_gid ]; then
gid=''
else
chown root:plugdev $mount_point
gid=",gid=$plugdev_gid"
fi
# create the mountpoint directory in /media/ (if not empty)
if [ -n $mount_point ]; then
mkdir -p /media/$mount_point
# other options (breaks POSIX): noatime,nodiratime,nosuid,nodev
mount -t $ID_FS_TYPE \
-o rw,flush,user,uid=0$gid,umask=002,dmask=002,fmask=002 \
$DEVNAME /media/$mount_point
fi
Add this script storage-autounmount.sh
in /lib/udev/
and set it to executable (sudo chmod +x /lib/udev/storage-autounmount.sh
):
#!/bin/sh
# set the mountpoint name according to partition or device name
mount_point=$ID_FS_LABEL
if [ -z $mount_point ]; then
mount_point=${DEVNAME##*/}
fi
# remove the mountpoint directory from /media/ (if not empty)
if [ -n $mount_point ]; then
umount -l /media/$mount_point
rm -R /media/$mount_point
fi
2 - Creating the udev
rule to attach those scripts to events
And finally, add a udev
rule in /etc/udev/rules.d
, for instance 85-storage-automount.rules
:
ENV{DEVTYPE}=="partition", RUN+="/lib/udev/storage-automount.sh", ENV{REMOVE_CMD}="/lib/udev/storage-autounmount.sh"
And that's it.
Now, when you plug a storage device in, a directory will be created in /media/
according to the partition name (I don't remember but I think it's working with NTFS partitions as well) and your partition will be mounted into it. It's R/W for users if you have a plugdev
group on your system. Also, the devices are mounted in synchronous mode in order to limit the risks of data loss in case of hot unplugging.
When the device is removed, it's unmounted and the directory is removed from /media
.
Also, the tool to monitor the udev
events is udevadm monitor
, with options like --env
or --property
:
$ udevadm monitor --env
This is tested and working fine on both Debian and Arch, but probably works on all distributions that rely on udev
.
You can do a chmod after you mounted the partition, but that wouldn't be persistent accross reboots.
You should try this fstab line:
/dev/sda1 /media/josiah vfat user,umask=0000 0 0
Or this mount options:
mount -t vfat -ouser,umask=0000 /dev/sda1 /media/josiah
That will make the mounted partition world readable and writable.
If you need a less permissive setup, you should create a new group and mount as follows:
mount -t vfat -ouser,gid=1010,umask=0007 /dev/sda1 /media/josiah
It assumes your new group's gid is 1010. All users that need access to the mountpoint will need to be added to the new group.
Best Answer
A
noauto
entry in fstab is one which, for different reasons, you do not want to have mounted automatically, at boot and with themount -a
command. It is mounted by specifying the device or the mount point explicitly, like inor
The cases in which you do not necessarily wish a device to be mounted at boot are numerous,for instance when we are talking about a network device, which may or may not be available at boot time (you could be on a laptop, and away from home). Or it might be an encrypted device, for which you have to provide a password, and you want to have to do that only when you truly need that. And so on.
In fact,
fstab
is used to provide rules by which devices are mounted, whether at boot time or not.