Gentoo Archives: gentoo-user

From: Walter Dnes <waltdnes@××××××××.org>
To: Gentoo Users List <gentoo-user@l.g.o>
Subject: [gentoo-user] Automount under mdev; looking for testers
Date: Mon, 28 May 2012 22:21:00
Message-Id: 20120528221802.GA4369@waltdnes.org
1 More beta-testing, and some "shiney" for mdev users... yes, we now
2 have automount. I have no problem with manually mounting usb
3 drives/keys/cameras/etc, but some people insist on automount. I've
4 worked out how to implement automounting under mdev. I've got it
5 working on a machine at home, but we should have more testing before
6 posting this in the Gentoo mdev wiki.
7
8 There are a few preliminary setup steps required first. Everything
9 except part 4) b) is done as root. 4) b) is done by each regular user
10 that needs to unmount USB-plugable devices.
11
12 1) If you haven't already done so, install programs "pmount" and "sudo"
13 emerge pmount sudo
14
15
16 2) Create directory /media (It *MUST* be "/media").
17
18
19 3) Regular user accounts that need to access FAT-formatted USB keys need
20 to be added to group "plugdev".
21
22
23 4) a) In /etc/sudoers.d create a file (if it doesn't exist). To the file
24 add a line like...
25
26 USERID HOSTNAME = (root) NOPASSWD: /bin/umount /media/*
27
28 Replace "USERID" and "HOSTNAME" with the actual regular userid and the
29 actual hostname. If you have 2 or more users that need to automount USB
30 devices, add a separate line for each one.
31
32 4) b) Yanking out a USB key or external drive, after writing, without
33 unmounting it first, "is not a good thing". Since the USB device is
34 automounted by root, a regular user needs to use sudo to unmount it.
35 That's why we installed sudo. E.g...
36 sudo /bin/umount /media/sdb1
37
38 To make things easy for lazy typists, create a 2-line executable
39 script "~/bin/um" in the regular user's home bin directory like so...
40
41 #/bin/bash
42 sudo /bin/umount /media/${1}
43
44 It can be executed as "um sdb1" to unmount /media/sdb1
45
46
47 5) In case something goes drastically wrong, you should have a bootable
48 CD or USB stick handy, to recover with.
49
50
51 When running with mdev instead of udev under Gentoo, device setup is
52 controlled by /etc/mdev.conf. There is a brief intro to the syntax at
53 http://git.busybox.net/busybox/plain/docs/mdev.txt
54
55 We will make one change to /etc/mdev.conf and add a script to /lib/mdev/
56
57 1) Make a backup copy of /etc/mdev.conf
58
59 cp /etc/mdev.conf /etc/mdev.conf.000
60
61 If stuff goes terribly wrong, you can boot from recovery media and
62 revert to the previous version, i.e.
63
64 cp /etc/mdev.conf.000 /etc/mdev.conf
65
66
67 2) Change a line in /etc/mdev.conf from
68 sd[a-z].* root:disk 660 */lib/mdev/usbdisk_link
69
70 to
71
72 sd[a-z].* root:disk 660 */lib/mdev/usbdisk_automount
73
74
75 3) Take the file "usbdisk_automount" (listedbelow) and copy it to
76 /lib/mdev/usbdisk_automount and remember to set it executable, e.g.
77
78 chmod 744 /lib/mdev/usbdisk_automount
79
80 Automounting should work now; rebooting is not required. Plug in USB
81 keys/hard-drives/card-readers/direct-connection-to-cameras and play
82 around with them.
83
84 NOTES
85 =====
86
87 1) Sorry, pmount is hard-coded to mount in /media, e.g. /media/sdb1, and
88 similar. If you want it mounting elsewhere, please submit patches to
89 upstream.
90
91 2) If you connect a device (key or hard drive) formatted with a posix
92 filesystem (ext2/3/4, reiserfs, btrfs, etc) file permissions will apply
93 as usual. I.e. a regular user won't be able to modify/delete files
94 owned by other users (including root). The various FAT variants do not
95 support posix file permissions. pmount arbitrarily assigns user:root
96 and group:plugdev to all files+directories on FAT-based filesystems. By
97 using the "--umask 007" option in pmount, all files on FAT-based devices
98 can be read+written by root and members of the plugdev group.
99
100 3) For the beta testing, I've enabled debug logging to a temporary log
101 file /dev/shm/mdevlog.txt
102
103 4) Does anyone have a USB key or memory card that has the pathological
104 setup where the entire stick is a FAT partition, without a partition
105 table? If so, can you please let me know if automounting works with it?
106 If not please...
107
108 * unplug the device
109 * delete the file /dev/shm/mdevlog.txt
110 * plug the device in
111 * wait a few seconds and unplug it
112 * email me the contents of /dev/shm/mdevlog.txt
113
114 5) usbdisk_automount begins below
115
116 #!/bin/bash
117 #
118 # At bootup, "mdev -s" is called. It does not pass any environmental
119 # variables other than MDEV. If no ACTION variable is passed, exit
120 # the script.
121 if [ "X${ACTION}" == "X" ] ; then exit 0 ; fi
122 #
123 # Execute only if the device already exists; otherwise exit
124 if [ ! -b ${MDEV} ] ; then exit 0 ; fi
125 #
126 # Also only execute for partitions, not the underlying disks.
127 if [ "X${DEVTYPE}" != "Xpartition" ] ; then exit 0 ; fi
128
129 # Debug data dump.
130 exec 3>> /dev/shm/mdevlog.txt
131 echo "=============== * ${SEQNUM}" >&3
132 /usr/bin/printenv >&3
133 exec 3>&-
134
135 #
136 # The "add" action.
137 if [ "X${ACTION}" == "Xadd" ] ; then
138 #
139 # Create the directory in /media
140 mkdir -p /media/${MDEV}
141 #
142 # Mount the directory in /media
143 pmount --umask 007 --noatime /dev/${MDEV}
144 #
145 # The "remove" action.
146 elif [ "X${ACTION}" == "Xremove" ] ; then
147 #
148 # Unmount the directory in /media
149 umount /media/${MDEV}
150 #
151 # Delete the directory in /media
152 rm -rf /media/${MDEV}
153 fi
154
155
156 --
157 Walter Dnes <waltdnes@××××××××.org>

Replies

Subject Author
Re: [gentoo-user] Automount under mdev; looking for testers Pandu Poluan <pandu@××××××.info>