public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] Automount under mdev; looking for testers
@ 2012-05-28 22:18 Walter Dnes
  2012-05-29  2:13 ` Pandu Poluan
  0 siblings, 1 reply; 3+ messages in thread
From: Walter Dnes @ 2012-05-28 22:18 UTC (permalink / raw
  To: Gentoo Users List

  More beta-testing, and some "shiney" for mdev users... yes, we now
have automount.  I have no problem with manually mounting usb
drives/keys/cameras/etc, but some people insist on automount.  I've
worked out how to implement automounting under mdev.  I've got it
working on a machine at home, but we should have more testing before
posting this in the Gentoo mdev wiki.

  There are a few preliminary setup steps required first.  Everything
except part 4) b) is done as root.  4) b) is done by each regular user
that needs to unmount USB-plugable devices.

1) If you haven't already done so, install programs "pmount" and "sudo"
emerge pmount sudo


2) Create directory /media (It *MUST* be "/media").


3) Regular user accounts that need to access FAT-formatted USB keys need
to be added to group "plugdev".


4) a) In /etc/sudoers.d create a file (if it doesn't exist).  To the file
add a line like...

USERID  HOSTNAME = (root) NOPASSWD: /bin/umount /media/*

Replace "USERID" and "HOSTNAME" with the actual regular userid and the
actual hostname.  If you have 2 or more users that need to automount USB
devices, add a separate line for each one.

4) b) Yanking out a USB key or external drive, after writing, without
unmounting it first, "is not a good thing".  Since the USB device is
automounted by root, a regular user needs to use sudo to unmount it.
That's why we installed sudo.  E.g...
sudo /bin/umount /media/sdb1

To make things easy for lazy typists, create a 2-line executable
script "~/bin/um" in the regular user's home bin directory like so...

#/bin/bash
sudo /bin/umount /media/${1}

It can be executed as "um sdb1" to unmount /media/sdb1


5) In case something goes drastically wrong, you should have a bootable
CD or USB stick handy, to recover with.


  When running with mdev instead of udev under Gentoo, device setup is
controlled by /etc/mdev.conf.  There is a brief intro to the syntax at
http://git.busybox.net/busybox/plain/docs/mdev.txt

  We will make one change to /etc/mdev.conf and add a script to /lib/mdev/

1) Make a backup copy of /etc/mdev.conf

cp /etc/mdev.conf /etc/mdev.conf.000

  If stuff goes terribly wrong, you can boot from recovery media and
revert to the previous version, i.e.

cp /etc/mdev.conf.000 /etc/mdev.conf


2) Change a line in /etc/mdev.conf from
sd[a-z].*       root:disk 660 */lib/mdev/usbdisk_link

to

sd[a-z].*       root:disk 660 */lib/mdev/usbdisk_automount


3) Take the file "usbdisk_automount" (listedbelow) and copy it to
/lib/mdev/usbdisk_automount and remember to set it executable, e.g.

chmod 744 /lib/mdev/usbdisk_automount

Automounting should work now; rebooting is not required.  Plug in USB
keys/hard-drives/card-readers/direct-connection-to-cameras and play
around with them.

NOTES
=====

1) Sorry, pmount is hard-coded to mount in /media, e.g. /media/sdb1, and
similar.  If you want it mounting elsewhere, please submit patches to
upstream.

2) If you connect a device (key or hard drive) formatted with a posix
filesystem (ext2/3/4, reiserfs, btrfs, etc) file permissions will apply
as usual.  I.e. a regular user won't be able to modify/delete files
owned by other users (including root).  The various FAT variants do not
support posix file permissions.  pmount arbitrarily assigns user:root
and group:plugdev to all files+directories on FAT-based filesystems.  By
using the "--umask 007" option in pmount, all files on FAT-based devices
can be read+written by root and members of the plugdev group.

3) For the beta testing, I've enabled debug logging to a temporary log
file /dev/shm/mdevlog.txt

4) Does anyone have a USB key or memory card that has the pathological
setup where the entire stick is a FAT partition, without a partition
table?  If so, can you please let me know if automounting works with it?
If not please...

* unplug the device
* delete the file /dev/shm/mdevlog.txt
* plug the device in
* wait a few seconds and unplug it
* email me the contents of /dev/shm/mdevlog.txt

5) usbdisk_automount begins below

#!/bin/bash
#
# At bootup, "mdev -s" is called.  It does not pass any environmental
# variables other than MDEV.  If no ACTION variable is passed, exit
# the script.
if [ "X${ACTION}" == "X" ] ; then exit 0 ; fi
#
# Execute only if the device already exists; otherwise exit
if [ ! -b ${MDEV} ] ; then exit 0 ; fi
#
# Also only execute for partitions, not the underlying disks.
if [ "X${DEVTYPE}" != "Xpartition" ] ; then exit 0 ; fi

# Debug data dump.
exec 3>> /dev/shm/mdevlog.txt
echo "=============== * ${SEQNUM}" >&3
/usr/bin/printenv >&3
exec 3>&-

#
# The "add" action.
if [ "X${ACTION}" == "Xadd" ] ; then
#
# Create the directory in /media
   mkdir -p /media/${MDEV}
#
# Mount the directory in /media
   pmount --umask 007 --noatime /dev/${MDEV}
#
# The "remove" action.
elif [ "X${ACTION}" == "Xremove" ] ; then
#
# Unmount the directory in /media
   umount /media/${MDEV}
#
# Delete the directory in /media
   rm -rf /media/${MDEV}
fi


-- 
Walter Dnes <waltdnes@waltdnes.org>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gentoo-user] Automount under mdev; looking for testers
  2012-05-28 22:18 [gentoo-user] Automount under mdev; looking for testers Walter Dnes
@ 2012-05-29  2:13 ` Pandu Poluan
  2012-05-29  6:32   ` Walter Dnes
  0 siblings, 1 reply; 3+ messages in thread
From: Pandu Poluan @ 2012-05-29  2:13 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 5425 bytes --]

On May 29, 2012 5:23 AM, "Walter Dnes" <waltdnes@waltdnes.org> wrote:
>
>  More beta-testing, and some "shiney" for mdev users... yes, we now
> have automount.  I have no problem with manually mounting usb
> drives/keys/cameras/etc, but some people insist on automount.  I've
> worked out how to implement automounting under mdev.  I've got it
> working on a machine at home, but we should have more testing before
> posting this in the Gentoo mdev wiki.
>
>  There are a few preliminary setup steps required first.  Everything
> except part 4) b) is done as root.  4) b) is done by each regular user
> that needs to unmount USB-plugable devices.
>
> 1) If you haven't already done so, install programs "pmount" and "sudo"
> emerge pmount sudo
>
>
> 2) Create directory /media (It *MUST* be "/media").
>
>
> 3) Regular user accounts that need to access FAT-formatted USB keys need
> to be added to group "plugdev".
>
>
> 4) a) In /etc/sudoers.d create a file (if it doesn't exist).  To the file
> add a line like...
>
> USERID  HOSTNAME = (root) NOPASSWD: /bin/umount /media/*
>
> Replace "USERID" and "HOSTNAME" with the actual regular userid and the
> actual hostname.  If you have 2 or more users that need to automount USB
> devices, add a separate line for each one.
>
> 4) b) Yanking out a USB key or external drive, after writing, without
> unmounting it first, "is not a good thing".  Since the USB device is
> automounted by root, a regular user needs to use sudo to unmount it.
> That's why we installed sudo.  E.g...
> sudo /bin/umount /media/sdb1
>
> To make things easy for lazy typists, create a 2-line executable
> script "~/bin/um" in the regular user's home bin directory like so...
>
> #/bin/bash
> sudo /bin/umount /media/${1}
>
> It can be executed as "um sdb1" to unmount /media/sdb1
>
>
> 5) In case something goes drastically wrong, you should have a bootable
> CD or USB stick handy, to recover with.
>
>
>  When running with mdev instead of udev under Gentoo, device setup is
> controlled by /etc/mdev.conf.  There is a brief intro to the syntax at
> http://git.busybox.net/busybox/plain/docs/mdev.txt
>
>  We will make one change to /etc/mdev.conf and add a script to /lib/mdev/
>
> 1) Make a backup copy of /etc/mdev.conf
>
> cp /etc/mdev.conf /etc/mdev.conf.000
>
>  If stuff goes terribly wrong, you can boot from recovery media and
> revert to the previous version, i.e.
>
> cp /etc/mdev.conf.000 /etc/mdev.conf
>
>
> 2) Change a line in /etc/mdev.conf from
> sd[a-z].*       root:disk 660 */lib/mdev/usbdisk_link
>
> to
>
> sd[a-z].*       root:disk 660 */lib/mdev/usbdisk_automount
>
>
> 3) Take the file "usbdisk_automount" (listedbelow) and copy it to
> /lib/mdev/usbdisk_automount and remember to set it executable, e.g.
>
> chmod 744 /lib/mdev/usbdisk_automount
>
> Automounting should work now; rebooting is not required.  Plug in USB
> keys/hard-drives/card-readers/direct-connection-to-cameras and play
> around with them.
>
> NOTES
> =====
>
> 1) Sorry, pmount is hard-coded to mount in /media, e.g. /media/sdb1, and
> similar.  If you want it mounting elsewhere, please submit patches to
> upstream.
>
> 2) If you connect a device (key or hard drive) formatted with a posix
> filesystem (ext2/3/4, reiserfs, btrfs, etc) file permissions will apply
> as usual.  I.e. a regular user won't be able to modify/delete files
> owned by other users (including root).  The various FAT variants do not
> support posix file permissions.  pmount arbitrarily assigns user:root
> and group:plugdev to all files+directories on FAT-based filesystems.  By
> using the "--umask 007" option in pmount, all files on FAT-based devices
> can be read+written by root and members of the plugdev group.
>
> 3) For the beta testing, I've enabled debug logging to a temporary log
> file /dev/shm/mdevlog.txt
>
> 4) Does anyone have a USB key or memory card that has the pathological
> setup where the entire stick is a FAT partition, without a partition
> table?  If so, can you please let me know if automounting works with it?
> If not please...
>
> * unplug the device
> * delete the file /dev/shm/mdevlog.txt
> * plug the device in
> * wait a few seconds and unplug it
> * email me the contents of /dev/shm/mdevlog.txt
>
> 5) usbdisk_automount begins below
>
> #!/bin/bash
> #
> # At bootup, "mdev -s" is called.  It does not pass any environmental
> # variables other than MDEV.  If no ACTION variable is passed, exit
> # the script.
> if [ "X${ACTION}" == "X" ] ; then exit 0 ; fi
> #
> # Execute only if the device already exists; otherwise exit
> if [ ! -b ${MDEV} ] ; then exit 0 ; fi
> #
> # Also only execute for partitions, not the underlying disks.
> if [ "X${DEVTYPE}" != "Xpartition" ] ; then exit 0 ; fi
>
> # Debug data dump.
> exec 3>> /dev/shm/mdevlog.txt
> echo "=============== * ${SEQNUM}" >&3
> /usr/bin/printenv >&3
> exec 3>&-
>
> #
> # The "add" action.
> if [ "X${ACTION}" == "Xadd" ] ; then
> #
> # Create the directory in /media
>   mkdir -p /media/${MDEV}
> #
> # Mount the directory in /media
>   pmount --umask 007 --noatime /dev/${MDEV}
> #
> # The "remove" action.
> elif [ "X${ACTION}" == "Xremove" ] ; then
> #
> # Unmount the directory in /media
>   umount /media/${MDEV}
> #
> # Delete the directory in /media
>   rm -rf /media/${MDEV}
> fi
>
>

A quick question : for automounting to work, do you need to do sysctl -w
kernel.hotplug=/sbin/mdev , or is it optional?

Rgds,

[-- Attachment #2: Type: text/html, Size: 7166 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gentoo-user] Automount under mdev; looking for testers
  2012-05-29  2:13 ` Pandu Poluan
@ 2012-05-29  6:32   ` Walter Dnes
  0 siblings, 0 replies; 3+ messages in thread
From: Walter Dnes @ 2012-05-29  6:32 UTC (permalink / raw
  To: gentoo-user

On Tue, May 29, 2012 at 09:13:24AM +0700, Pandu Poluan wrote

> A quick question : for automounting to work, do you need to do sysctl -w
> kernel.hotplug=/sbin/mdev , or is it optional?

  Thanks, I'll have to document that.  In .config, I think you need
"CONFIG_HOTPLUG=y".  I don't know if the kernel can even be built
without it.  What output do you get from the command

cat /proc/sys/kernel/hotplug

  I get...

/sbin/mdev

  That's what you need.  *IF THAT IS NOT THE CASE FOR YOU* the docs at
http://git.busybox.net/busybox/plain/docs/mdev.txt give 2 options...

1) If you have a proc file system (yes we do), the way to do it is

echo /sbin/mdev > /proc/sys/kernel/hotplug


2) For embedded systems without a proc filesystem, you can

sysctl -w kernel.hotplug=/sbin/mdev


  Option 2 would probably also work for Gentoo, but the proc filesystem
makes things a lot easier.


  In my case hotplug support was enabled and /sbin/mdev was already
listed in /proc/sys/kernel/hotplug.  Google turns up a lot of
documentation for mdev on stripped down embedded systems.  Trying to
apply it to a desktop PC is breaking new ground.

-- 
Walter Dnes <waltdnes@waltdnes.org>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-05-29  6:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-28 22:18 [gentoo-user] Automount under mdev; looking for testers Walter Dnes
2012-05-29  2:13 ` Pandu Poluan
2012-05-29  6:32   ` Walter Dnes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox