[Grml] RFC: handling of external usb devices
Michael Prokop
mika at grml.org
Sun Sep 3 18:14:01 CEST 2006
Hello,
I'd like to ask for your comments about handling of external usb
devices on grml.
As you might know mounting usb pens on grml is possible via running
'mount /mnt/external1' (corresponding to /dev/sda1) and 'mount
/mnt/external' (corresponding to /dev/sda).
As stated in a mail by Tong to the grml user mailinglist the
problems start with multiple devices or devices with several
partitions on it. I'd like to improve usability and handling of it
therefore.
Thanks for input goes to Tong and Alexander Steinboeck, please read
on for details about my solution.
################################################################################
/mnt/external[1] will be left without any changes, we will stay
completely backwards compatible. Additionally we will create
/dev/usb-sd* devices via udev rules like:
# cat /etc/udev/usbpen.rules
SUBSYSTEM=="block", BUS=="usb", KERNEL=="sd[a-z]*", ACTION=="add", SYMLINK+="usb-%k", GROUP="users", NAME="%k"
SUBSYSTEM=="block", BUS=="usb", KERNEL=="sd[a-z]*", ACTION=="add", RUN+="/bin/mkdir -p /mnt/usb-%k"
SUBSYSTEM=="block", BUS=="usb", KERNEL=="sd[a-z]*", ACTION=="add", RUN+="/bin/sleep 2"
SUBSYSTEM=="block", BUS=="usb", KERNEL=="sd[a-z]*", ACTION=="add", RUN+="/usr/sbin/create_mnt_labels"
SUBSYSTEM=="block", BUS=="usb", KERNEL=="sd[a-z]*", ACTION=="add", RUN+="/usr/sbin/rebuildfstab -r -u 1000 -g 1000"
ACTION=="remove", KERNEL=="sd[a-z]*", RUN+="/usr/sbin/rebuildfstab -r -u 1000 -g 1000"
ACTION=="remove", KERNEL=="sd[a-z]*", RUN+="/bin/rmdir /mnt/usb-%k", OPTIONS="last_rule"
So we have the following devices available when plugging in an usb
pen with 4 partitions on it:
# ls -la /dev/usb* /dev/external* /dev/sd*
lrwxrwxrwx 1 root root 3 2006-09-03 17:25 /dev/external -> sda
lrwxrwxrwx 1 root root 4 2006-09-03 17:25 /dev/external1 -> sda1
lrwxrwxrwx 1 root root 4 2006-09-03 17:25 /dev/external2 -> sda2
lrwxrwxrwx 1 root root 4 2006-09-03 17:25 /dev/external3 -> sda3
lrwxrwxrwx 1 root root 4 2006-09-03 17:25 /dev/external4 -> sda4
brw-rw---- 1 root users 8, 0 2006-09-03 17:25 /dev/sda
brw-rw---- 1 root users 8, 1 2006-09-03 17:25 /dev/sda1
brw-rw---- 1 root users 8, 2 2006-09-03 17:25 /dev/sda2
brw-rw---- 1 root users 8, 3 2006-09-03 17:25 /dev/sda3
brw-rw---- 1 root users 8, 4 2006-09-03 17:25 /dev/sda4
lrwxrwxrwx 1 root root 3 2006-09-03 17:25 /dev/usb-sda -> sda
lrwxrwxrwx 1 root root 4 2006-09-03 17:25 /dev/usb-sda1 -> sda1
lrwxrwxrwx 1 root root 4 2006-09-03 17:25 /dev/usb-sda2 -> sda2
lrwxrwxrwx 1 root root 4 2006-09-03 17:25 /dev/usb-sda3 -> sda3
lrwxrwxrwx 1 root root 4 2006-09-03 17:25 /dev/usb-sda4 -> sda4
According to that we will have the following directories available
in /mnt:
# ls -lad /mnt/[eu]*
drwxr-xr-x 2 root root 4096 2006-03-08 19:55 /mnt/external/
drwxr-xr-x 2 root root 4096 2006-03-08 19:55 /mnt/external1/
drwxr-xr-x 2 root root 4096 2006-09-03 17:25 /mnt/usb-sda/
drwxr-xr-x 2 root root 4096 2006-09-03 17:25 /mnt/usb-sda1/
drwxr-xr-x 2 root root 4096 2006-09-03 17:25 /mnt/usb-sda2/
drwxr-xr-x 2 root root 4096 2006-09-03 17:25 /mnt/usb-sda3/
drwxr-xr-x 2 root root 4096 2006-09-03 17:25 /mnt/usb-sda4/
As /dev/sda4 contains a labeled filesystem the script
/usr/sbin/create_mnt_labels will create a new directory in /mnt:
# vol_id /dev/sda4
ID_FS_USAGE=filesystem
ID_FS_TYPE=xfs
ID_FS_VERSION=
ID_FS_UUID=dc79eb17-9f98-49c7-9cfc-10d8fd279215
ID_FS_LABEL=foobar
ID_FS_LABEL_SAFE=foobar
# ls -la /mnt/foobar
total 8
drwxr-xr-x 2 root root 4096 2006-09-03 18:05 ./
drwxr-xr-x 24 root root 4096 2006-09-03 18:05 ../
So mounting via label is possible therefore too with
root-permissions:
# mount -L foobar /mnt/foobar
/etc/fstab will be updated as well (see the udev rule above, 2
seconds delay so we really catch all devices) and therefore will
look like:
# cat /etc/fstab
[...]
# Added by GRML
/dev/hda1 /mnt/hda1 ntfs noauto,nouser,dev,suid,exec,ro,umask=000,uid=1000,gid=1000 0 0
# Added by GRML
/dev/sda1 /mnt/sda1 vfat noauto,nouser,dev,suid,exec,umask=000,uid=1000,gid=1000 0 0
# Added by GRML
/dev/sda2 /mnt/sda2 vfat noauto,nouser,dev,suid,exec,umask=000,uid=1000,gid=1000 0 0
# Added by GRML
/dev/sda3 /mnt/sda3 vfat noauto,nouser,dev,suid,exec,umask=000,uid=1000,gid=1000 0 0
# Added by GRML
/dev/sda4 /mnt/sda4 vfat noauto,nouser,dev,suid,exec,umask=000,uid=1000,gid=1000 0 0
# Added by GRML
/dev/usb-sda /mnt/usb-sda auto users,noauto,nodev,noatime,nosuid,noexec,rw,uid=1000,gid=1000 0 0
# Added by GRML
/dev/usb-sda1 /mnt/usb-sda1 auto users,noauto,nodev,noatime,nosuid,noexec,rw,uid=1000,gid=1000 0 0
# Added by GRML
/dev/usb-sda2 /mnt/usb-sda2 auto users,noauto,nodev,noatime,nosuid,noexec,rw,uid=1000,gid=1000 0 0
# Added by GRML
/dev/usb-sda3 /mnt/usb-sda3 auto users,noauto,nodev,noatime,nosuid,noexec,rw,uid=1000,gid=1000 0 0
# Added by GRML
/dev/usb-sda4 /mnt/usb-sda4 auto users,noauto,nodev,noatime,nosuid,noexec,rw,uid=1000,gid=1000 0 0
So you have the old /dev/sd* entries as usual and additionally the
new, but more restricted ones meant for use as normal user.
Mounting as user with uid 1000 (= user grml on the live-cd) is possible
via running for example "mount /mnt/usb-sda2".
As soon as you unplug the usb device /etc/fstab will be updated
again so all invalid/not-anymore-existing entries will be removed
automatically. The /mnt/usb-sd* directories will be deleted as well.
The fs-label directories in /mnt won't be deleted automatically.
If you want to disable the above feature at all on your grml system
you would just have to remove the according udev rules file. This
will be documented of course.
################################################################################
Please let me know what you think about it. If you're happy with
this solutions I'd implement it so you can test it in real-live with
the upcoming grml 0.7-1 devel-release.
regards,
-mika-
--
http://grml.org/ # Linux for texttool-users and sysadmins
http://wiki.grml.org/ # share your knowledge
http://grml.supersized.org/ # the grml development weblog
#grml @ irc.freenode.org # meet us on irc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://ml.grml.org/pipermail/grml/attachments/20060903/dbe23241/attachment-0003.pgp>
More information about the Grml
mailing list