View previous topic :: View next topic |
Author |
Message |
Heimfrost n00b
Joined: 02 Jul 2007 Posts: 21 Location: in the swapspace of Germany
|
Posted: Sat Dec 18, 2010 12:29 pm Post subject: an udev rule for mounting usb hdds with pmount |
|
|
I have made an udev rule called 99-usbstorage.rules with the following content in modification of https://wiki.archlinux.org/index.php/Udev#Mount_under_.2Fmedia.3B_use_partition_label_if_present:
Code: | KERNEL!="sd[a-z][1-9]*", DRIVERS!="usb-storage", GOTO="exit"
# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"
# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usb-%k"
# Global mount options
ACTION=="add", ENV{pmount_options}="--noatime"
# File system specific mount options to avoid auto probing
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs|vfat", ENV{pmount_options}="%E{pmount_options} --umask 007 --charset utf8"
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", ENV{pmount_options}="%E{pmount_options} -t ntfs-3g"
ACTION=="add", ENV{ID_FS_TYPE}=="vfat", ENV{pmount_options}="%E{pmount_options} -t vfat"
ACTION=="add", ENV{ID_FS_TYPE}=="ext2", ENV{pmount_options}="%E{pmount_options} -t ext2"
ACTION=="add", ENV{ID_FS_TYPE}=="ext3", ENV{pmount_options}="%E{pmount_options} -t ext3"
ACTION=="add", ENV{ID_FS_TYPE}=="ext4", ENV{pmount_options}="%E{pmount_options} -t ext4"
# Mount the device
ACTION=="add", RUN+="/usr/bin/pmount $env{pmount_options} /dev/%k /media/%E{dir_name}"
# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/usr/bin/pumount /dev/%k"
# Exit
LABEL="exit" |
If a new usb storage device like stick or external hdd is plugged in, it makes the dirs (by an available or generated label) under /media and mounts the devices.
Any user of the group "plugdev" is able to unmount them via pumount.
If a device was removed, pumount delete the dirs.
And here is my problem:
If usb devices were mounted and you halt/reboot your machine and remove the usb media or maybe the system crashes, then the directories under /media are still present, but they aren't mounted, because they're plugged off.
So in worst case, you could get a folder of empty dirs, nobody removes.
So the problem is, I want to look for remaining dirs under /media at boot process, after udevd has started.
But how can I do that ?
I just need some tips or hints from the experts how to make the initscript or anything else, I could do.
Or maybe a daily cron job is the better solution ?
In my imagination i thought about a combination of looking what is mounted with "mount | grep /media" and "ls /media" or like that and then rmdir the folders, which aren't mounted.
Or I could look to /media, if there are empty subdirs with an available file ".created_by_pmount", because pmount creates them, if it was called before.
But I have no experience in the right syntax of an initscript or the proper commands. (I use baselayout 2) |
|
Back to top |
|
|
Heimfrost n00b
Joined: 02 Jul 2007 Posts: 21 Location: in the swapspace of Germany
|
Posted: Sun Dec 19, 2010 2:14 pm Post subject: |
|
|
I have updated the rule, because != with parent devices, like in "DRIVERS" doesn't work as I thought
Code: | KERNEL!="sd*[1-9]*", GOTO="exit"
# Import FS infos
SUBSYSTEMS=="usb", IMPORT{program}="/sbin/blkid -o udev -p %N"
# Get a label if present, otherwise specify one
SUBSYSTEMS=="usb", ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
SUBSYSTEMS=="usb", ENV{ID_FS_LABEL}=="", ENV{dir_name}="usb-%k"
# Global mount options
SUBSYSTEMS=="usb", ACTION=="add", ENV{pmount_options}="--noatime"
# File system specific mount options to avoid auto probing
SUBSYSTEMS=="usb", ACTION=="add", ENV{ID_FS_TYPE}=="ntfs|vfat", ENV{pmount_options}="%E{pmount_options} --umask 007 --charset utf8"
SUBSYSTEMS=="usb", ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", ENV{pmount_options}="%E{pmount_options} -t ntfs-3g"
SUBSYSTEMS=="usb", ACTION=="add", ENV{ID_FS_TYPE}=="vfat", ENV{pmount_options}="%E{pmount_options} -t vfat"
SUBSYSTEMS=="usb", ACTION=="add", ENV{ID_FS_TYPE}=="ext2", ENV{pmount_options}="%E{pmount_options} -t ext2"
SUBSYSTEMS=="usb", ACTION=="add", ENV{ID_FS_TYPE}=="ext3", ENV{pmount_options}="%E{pmount_options} -t ext3"
SUBSYSTEMS=="usb", ACTION=="add", ENV{ID_FS_TYPE}=="ext4", ENV{pmount_options}="%E{pmount_options} -t ext4"
# Mount the device
SUBSYSTEMS=="usb", ACTION=="add", RUN+="/usr/bin/pmount $env{pmount_options} /dev/%k /media/%E{dir_name}"
# Clean up after removal
SUBSYSTEMS=="usb", ACTION=="remove", ENV{dir_name}!="", RUN+="/usr/bin/pumount /dev/%k"
# Exit
LABEL="exit" |
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|