LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (https://www.linuxquestions.org/questions/ubuntu-63/)
-   -   Is it possible to automount usb disks with acl enabled? (https://www.linuxquestions.org/questions/ubuntu-63/is-it-possible-to-automount-usb-disks-with-acl-enabled-878844/)

nokangaroo 05-04-2011 04:00 PM

Is it possible to automount usb disks with acl enabled?
 
Is it possible to automatically mount usb disks with access control lists enabled? I mean, WITHOUT adding a line to /etc/fstab for a specific disk;
I want to mount ALL ext4 disks automatically with the acl option (to preserve acls in backups. I don't want to set specific acls on my backup disks; just preserve existing acls). I already tried enabling acl in /etc/fstab for / and modifying the acl for /media; it did not work (the modification was not even accepted). Also, I cannot find anything in /etc/hal or /etc/udev that would be modifiable with my knowledge.

nokangaroo 05-04-2011 05:21 PM

Solved - of sorts (though this is really not elegant). I added a remount option to my backup script - it turns out the acls are not destroyed when you mount the volume initially without acl support. But I still think that acls in ubuntu are not well handled.

So the script reads as follows (must be run as root):
Edit: cleaned up the script.
Edit: added code to allow for default options set with tune2fs -o and avoid unnecessary remounts.
Edit: corrected a typo. Sorry. Of course that was intentional to see if people are paying attention :)

#!/bin/bash

#PATH is necessary if run as a cronjob
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

#test for plugged-in disks named "backup":
TARGET=$(find /media/backup* -maxdepth 0 -type d 2> /dev/null)
if [ -z "$TARGET" ]; then
echo "no backup disk plugged in"
exit
fi

for i in $TARGET; do

#test for empty target directory in /media (can happen if you experiment with udev):
if [ "$(ls -A ${i})" ]; then

#check for acl option set with tune2fs -o acl:
OPT=""
if [ ! -z "$(tune2fs -l LABEL=`echo ${i} | sed "s/\/media\///g"` | grep acl)" ]; then
OPT="-f"
echo "${i} has tune2fs mount option set; this script will update /etc/mtab, but not /proc/mounts"
fi

#if disk is not already mounted with acl option, remount it:
if [ -z "$(cat /etc/mtab | grep ${i} | grep acl)" ]; then
mount $OPT -o remount,acl ${i}
fi

#actual backup (adjust to your liking). ${i}, or the directory it points to, must NEVER be empty, hence the tests above:
rsync -aHAXxv --delete --exclude="*/.gvfs" --exclude="*/.thumbnails/*" /home/ ${i}/`hostname`-home-complete

#in case of empty target directory, delete it:
else
echo "Error: directory ${i} is empty"
rmdir ${i}

fi
done

#clean up:
TARGET=""

nokangaroo 05-07-2011 05:55 PM

It can be done! Many thanks to the Archlinux people. See https://wiki.archlinux.org/index.php...out_udev_rules


So I created a rule named 11-media-by-label-automount.rules in /etc/udev/rules.d, and it actually works. Problem is, I cannot unmount the drive now except with sudo; I get the following error: umount: /media/backup is not in the fstab (and you are not root). I'll keep working on it, but I'd better post this to encourage others to help me.

##Code:
# Leave sda to fstab
KERNEL!="sd[b-z][0-9]", GOTO="media_by_label_auto_mount_end"

# Import FS info
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}="usbhd-%k"

# Mount options
ACTION=="add", ENV{ID_FS_TYPE}=="ext3|ext4", ENV{mount_options}="rw,nosuid,nodev,relatime,acl,uhelper=udisks"
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="rw,relatime,utf8,gid=46,umask=002,uhelper=udisks"
ACTION=="add", ENV{ID_FS_TYPE}=="hfsplus", ENV{mount_options}="rw,nosuid,nodev,uhelper=udisks"

# Mount the device (The "EFI" and "swap" entries are only necessary if you have a Mac and use usb boot disks with swap partitions on them)
ACTION=="add", ENV{ID_FS_LABEL}!="EFI", ENV{ID_FS_TYPE}!="swap", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -t %E{ID_FS_TYPE} -o %E{mount_options} /dev/%k /media/%E{dir_name}"

# Clean up after removal
ACTION=="remove", ENV{ID_FS_LABEL}!="EFI", ENV{ID_FS_TYPE}!="swap", RUN+="/bin/umount /dev/%k", RUN+="/bin/rmdir /media/%E{dir_name}"

# Exit
LABEL="media_by_label_auto_mount_end"


This works when copied to /etc/udev/rules.d/11-some-name.rules or /etc/udev/user.rules (the exact number does not seem to matter much), but unmounting as user does not work, also the devices appear twice in the nautilus side pane (a sure sign that something is fishy). Does udev use mount at all by default? And what else is there?

The file /lib/udev/rules.d/50-udev-default.rules does not seem to have a KERNEL=="sd*" entry at all, so maybe that's the problem. Another problem is that the entries in /media will remain if the disk is unmounted but not actually unplugged, which will cause my backup scripts to fill up the root partition (this never happens with the default udev setup. Of course I could rewrite the scripts if necessary, but I'd rather fix this behaviour).

Edit: Cleaned up the udev rule and backup script. The new rule will at least allow me to select all partitions with rubber-band selection an unmount them all at once, which was not possible before. But the devices still appear twice in the nautilus side pane (a bug that goes back several years apparently), and after unmounting the empty directories in /media are not removed until the disk is actually unplugged. I think I'll just use the script. It seems udev is just too buggy to mess with.

I wish I could mark this thread as solved, but it isn't.

nokangaroo 05-08-2011 03:25 AM

(superseded)

nokangaroo 05-11-2011 09:43 PM

Update: I find that if the disk is plugged in at boottime, I get "Safely remove Drive" AND acl support, and the boot log contains lots of entries "udevd-work [xxx]" where xxx is a 3-digit number, but it does not contain the words "ext4","sdb"(except for devices not handled by the rule), or the UUID of the disk, and it is encyclopaedic, so I guess it makes no sense printing it here (I will do so on request).


Edit: I've taken a deep breath and run tune2fs -o acl on one of my backup volumes without accident. (Why do I post anyway? I am sure somebody could have told me that you can do that without reformatting the disk). Anyway, in /proc/mounts and /etc/mtab the disk is still listed without acl option. I'll mark this thread as aolved but ask a separate question about this.


All times are GMT -5. The time now is 01:00 AM.