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