View previous topic :: View next topic |
Author |
Message |
blackst0ne n00b
Joined: 14 Jul 2007 Posts: 6 Location: YS, Russia
|
Posted: Mon Apr 02, 2012 11:45 pm Post subject: [solved] Unmount usb drives by non-root user mounted by udev |
|
|
Hello!
I used to mount my USB flash drives this way:
Code: |
[ blackst0ne at work: ~ ]% cat /etc/udev/rules.d/10-flash-mounts.rules
#! /bin/sh
#######################################
# USB Flash Drives automounting #
#######################################
# start at sdb to ignore the system hard drive
KERNEL!="sd[b-z]*", GOTO="exit"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="exit"
# import some useful filesystem info as variables
IMPORT{program}="/sbin/blkid -o udev -p %N"
# get the label if present, otherwise assign one based on device/partition
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="flash_drive_%k"
# create the dir in /media and symlink it to /mnt
ACTION=="add", RUN+="/bin/mkdir -p '/mnt/%E{dir_name}'"
# global mount options
ACTION=="add", ENV{mount_options}="users"
# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat)
ACTION=="add", ENV{ID_FS_TYPE}=="vfat", ENV{mount_options}="$env{mount_options},gid=100,dmask=000,fmask=111,utf8,flush"
# automount ntfs filesystems using ntfs-3g driver
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options} /dev/%k '/mnt/%E{dir_name}'"
# automount all other filesystems
ACTION=="add", ENV{ID_FS_TYPE}!="ntfs", RUN+="/bin/mount -t auto -o %E{mount_options} /dev/%k '/mnt/%E{dir_name}'"
# clean up after device removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/mnt/%E{dir_name}'", RUN+="/bin/rmdir '/mnt/%E{dir_name}'"
# exit
LABEL="exit"
|
So the question is, how do I unmount such devices by non-root users?
Code: |
[ blackst0ne at work: ~ ]% umount /dev/sdb1
umount: /dev/sdb1 is not in the fstab (and you are not root) |
Is there a simple way to do that?
Thanks.
Last edited by blackst0ne on Wed Apr 04, 2012 4:05 am; edited 1 time in total |
|
Back to top |
|
|
ultraincognito Guru
Joined: 03 Jun 2011 Posts: 346 Location: Ukraine
|
|
Back to top |
|
|
blackst0ne n00b
Joined: 14 Jul 2007 Posts: 6 Location: YS, Russia
|
Posted: Wed Apr 04, 2012 4:05 am Post subject: |
|
|
Okay, I got it.
Here is my /etc/udev/rules.d/10-flash-mounts.rules file:
Code: |
[ blackst0ne at home: /etc/udev/rules.d ]% cat ./10-flash-mounts.rules
#! /bin/sh
#######################################
# USB Flash Drives automounting #
#######################################
# start at sdb to ignore the system hard drive
KERNEL!="sd[b-z]*", GOTO="exit"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="exit"
# import some useful filesystem info as variables
IMPORT{program}="/sbin/blkid -o udev -p %N"
# get the label if present, otherwise assign one based on device/partition
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="flash_drive_%k"
# create the dir in /media and symlink it to /mnt
ACTION=="add", RUN+="/bin/mkdir -p '/mnt/%E{dir_name}'"
# global mount options
#ACTION=="add", ENV{mount_options}="relatime"
# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat)
########
# vfat #
########
# vfat specific mount options
ACTION=="add", ENV{mount_options_vfat}="gid=100,dmask=000,fmask=111,utf8,flush,rw,noatime,users"
# add device to /etc/fstab
ACTION=="add", ENV{ID_FS_TYPE}=="vfat", RUN+="/bin/sed -i '$a\/dev/%k /mnt/%E{dir_name} vfat %E{mount_options_vfat} 0 0' /etc/fstab"
# mount device
ACTION=="add", ENV{ID_FS_TYPE}=="vfat", RUN+="/bin/mount -t auto -o %E{mount_options_vfat} /dev/%k '/mnt/%E{dir_name}'"
########
# ntfs #
########
# ntfs specific mount options
ACTION=="add", ENV{mount_options_ntfs}="gid=100,dmask=000,fmask=111,utf8,flush,rw,noatime,users"
# add device to /etc/fstab
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/sed -i '$a\/dev/%k /mnt/%E{dir_name} ntfs-3g %E{mount_options_ntfs} 0 0' /etc/fstab"
# mount device
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options_ntfs} /dev/%k '/mnt/%E{dir_name}'"
#####################
# other filesystems #
#####################
# ntfs specific mount options
ACTION=="add", ENV{mount_options_other}="gid=100,dmask=000,fmask=111,utf8,flush,rw,noatime,users"
# automount all other filesystems
ACTION=="add", ENV{ID_FS_TYPE}!="(ntfs|vfat)", RUN+="/bin/mount -t auto -o %E{mount_options_other} /dev/%k '/mnt/%E{dir_name}'"
#################################
# clean up after device removal #
#################################
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/mnt/%E{dir_name}'", RUN+="/bin/rmdir '/mnt/%E{dir_name}'"
ACTION=="remove", ENV{ID_FS_TYPE}!="", RUN+="/bin/sed -i '/\/dev\/%k /d' /etc/fstab"
# 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
|
|