LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices



Reply
 
Search this Thread
Old 05-04-2011, 05:00 PM   #1
nokangaroo
Member
 
Registered: Nov 2009
Posts: 140

Rep: Reputation: 23
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.

Last edited by nokangaroo; 05-04-2011 at 05:51 PM. Reason: Title was not formulated as a question
 
Old 05-04-2011, 06:21 PM   #2
nokangaroo
Member
 
Registered: Nov 2009
Posts: 140

Original Poster
Rep: Reputation: 23
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=""

Last edited by nokangaroo; 05-24-2011 at 09:34 AM.
 
Old 05-07-2011, 06:55 PM   #3
nokangaroo
Member
 
Registered: Nov 2009
Posts: 140

Original Poster
Rep: Reputation: 23
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.

Last edited by nokangaroo; 05-22-2011 at 04:41 PM.
 
Old 05-08-2011, 04:25 AM   #4
nokangaroo
Member
 
Registered: Nov 2009
Posts: 140

Original Poster
Rep: Reputation: 23
(superseded)

Last edited by nokangaroo; 05-23-2011 at 09:22 AM.
 
Old 05-11-2011, 10:43 PM   #5
nokangaroo
Member
 
Registered: Nov 2009
Posts: 140

Original Poster
Rep: Reputation: 23
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.

Last edited by nokangaroo; 05-23-2011 at 09:29 AM.
 
  


Reply

Tags
acl, hal, ubuntu, udev, usb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HAL automount permissions differs between USB HD and USB memory stick Olaus Slackware 5 06-28-2010 07:34 PM
ioctl know if write caching enabled on disks mannu Linux - Newbie 2 03-23-2010 11:52 PM
USB Automount: /media/USB Disk morxy Linux - Hardware 3 10-20-2006 09:08 AM
ZipSlack on USB drive--Need a USB-enabled floppy? Adrohak Linux - Hardware 0 11-15-2004 10:14 AM
Automount - releases disks but drives stay mounted JohnKFT Slackware 8 04-19-2004 06:07 PM


All times are GMT -5. The time now is 12:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration