On Sat, Feb 07, 2015 at 12:17:46PM -0800, Paul Rogers wrote:
> Since I'm running a single user system, I've always just used root to
> mount USB & CD drives--it's simple and direct. I suppose there should
> be some way to get UDEV to mount them automagically for me, and set
> permissions so non-root users can read/write to them. But I can't
> recall seeing such configuration in the LFS book, and frankly, I find
> the udev rules arcane and daunting. Can you point me to something
> understandable that will do the job? I have tried Google once or twice,
> but didn't find an "Aha!" moment. TIA.
Since you mention 'automagically', I'm sure that Bruce's reply was
what you were after. But for those who mistrust machines which
think they know what the user wants to do, I'll offer a couple of
examples pulled out of my own scripts, for my cameras and for
various usb sticks I have. The sticks rules have been used in the
last few months, so these rules are probably still usable. I can only
mount _one_ external item at a time, and where I mount it is a matter
of convenience. On my server, I rely on root knowing what he is
doing, and do it all by hand. Comments suggest that I have been
using these rules on my desktops since at least LFS-6.3, but over the
years I've had to revise some of the details.
# A. olympus camera control
# 1. - symlink to the partition
# originally from udevinfo -a -p /sys/class/usb_device/usbdev2.2/
if ! [ -f /etc/udev/rules.d/23-olympus.rules ]; then
echo "SUBSYSTEMS==\"usb\", ATTRS{manufacturer}==\"OLYMPUS\",
KERNEL==\"sd?1\", SYMLINK=\"olympus\", MODE=\"0660\", OPTIONS=\"last_rule\""
>/etc/udev/rules.d/23-olympus.rules
fi
# 2 and create the mount point if needed
if ! [ -d /media/olympus ]; then
mkdir /media/olympus
chown ken:$UGRP /media/olympus # the group was determined in a calling
script
fi
# 3 and add it to fstab for users
# arguably, this should be r/o to prevent the camera(s) getting confused if
they did
# not delete the file.
grep '/media/olympus' /etc/fstab >/dev/null && NEEDFSTAB=false || NEEDFSTAB=true
if [ $NEEDFSTAB = "true" ]; then
echo "/dev/olympus /media/olympus vfat shortname=lower,noauto,user,rw
0 0" >>/etc/fstab
fi
# B. a few excerpts from what I have for USB sticks - similar idea, but various
values
# NOTA BENE : SYSFS attributes have to appear in {curlybraces} NOT [brackets]
# otherwise parsing fails and ANY device that matches the rest of the rule will
# trigger it.
# update: later stick reports itself as 'DISK 2.0' - confirm this with
# udevinfo -a -p `udevinfo -q path -n /dev/sda` as per the arch wiki.
#
# as of 2011, /sbin/udevadm info --name=/dev/sdb --attribute-walk
# to access properties.
#
# FIXME - other rules have SUBSYSTEM= but this has SUBSYSTEMS= so at least
# one variant is probably bogus and both are likely redundant.
#
if ! [ -f /etc/udev/rules.d/21-stick.rules ]; then
echo "SUBSYSTEMS==\"usb\", ATTRS{product}==\"USB Flash Memory\",
KERNEL==\"sd?1\", SYMLINK=\"stick\", MODE=\"0660\""
>/etc/udev/rules.d/21-stick.rules
fi
# repeat the rule for a stick that thinks it's a 'DISK 2.0'
if ! [ -f /etc/udev/rules.d/22-stick.rules ]; then
echo "SUBSYSTEMS==\"usb\", ATTRS{product}==\"DISK 2.0\",
KERNEL==\"sd?1\", SYMLINK=\"stick\", MODE=\"0660\""
>/etc/udev/rules.d/22-stick.rules
fi
# repeat the rule for a TDK stick that thinks it's an 'EHCI Host Controller'
if ! [ -f /etc/udev/rules.d/25-stick.rules ]; then
echo "SUBSYSTEMS==\"usb\", ATTRS{product}==\"EHCI Host Controller\",
KERNEL==\"sd?1\", SYMLINK=\"stick\", MODE=\"0660\""
>/etc/udev/rules.d/25-stick.rules
fi
# and create the mount point if needed
if ! [ -d /media/stick ]; then
mkdir /media/stick
chgrp $UGRP /media/stick # as before
fi
# and add it to fstab for users
grep '/media/stick' /etc/fstab >/dev/null && NEEDSTICK=false || NEEDSTICK=true
if [ "$NEEDSTICK" = "true" ]; then
echo "/dev/stick /media/stick vfat shortname=lower,noauto,user,rw
0 0" >>/etc/fstab
fi
ĸen
--
Nanny Ogg usually went to bed early. After all, she was an old lady.
Sometimes she went to bed as early as 6 a.m.
--
http://lists.linuxfromscratch.org/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page
Do not top post on this list.
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
http://en.wikipedia.org/wiki/Posting_style