From 0647c552b92c4e1aad130285f80120a35efedfcb Mon Sep 17 00:00:00 2001 From: mudler Date: Fri, 27 May 2016 01:08:26 +0200 Subject: [PATCH] [rpi-mc] automount udev rules, thx to Arch guys --- rpi-mc/Dockerfile | 5 ++++- rpi-mc/automount-media.rules | 28 ++++++++++++++++++++++++++++ rpi-mc/automount-sd.rules | 11 +++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 rpi-mc/automount-media.rules create mode 100644 rpi-mc/automount-sd.rules diff --git a/rpi-mc/Dockerfile b/rpi-mc/Dockerfile index b193879..1061b0b 100644 --- a/rpi-mc/Dockerfile +++ b/rpi-mc/Dockerfile @@ -9,11 +9,14 @@ ENV LC_ALL=en_US.UTF-8 RUN rsync -av "rsync://rsync.at.gentoo.org/gentoo-portage/licenses/" "/usr/portage/licenses/" && \ ls /usr/portage/licenses -1 | xargs -0 > /etc/entropy/packages/license.accept && \ equo up && equo u && \ - equo i kodi-raspberrypi app-misc/sabayon-auto-updater && \ + equo i kodi-raspberrypi app-misc/sabayon-auto-updater sys-fs/ntfs3g && \ echo -5 | equo conf update && equo cleanup RUN systemctl enable kodi-raspberrypi && systemctl enable sabayon-auto-updater.timer ADD ./config.txt /boot/config.txt +ADD ./automount-media.rules /etc/udev/rules.d/10-my-media-automount.rules +ADD ./automount-sd.rules /etc/udev/rules.d/11-sd-cards-auto-mount.rules + # Set environment variables. ENV HOME /root diff --git a/rpi-mc/automount-media.rules b/rpi-mc/automount-media.rules new file mode 100644 index 0000000..c3dad48 --- /dev/null +++ b/rpi-mc/automount-media.rules @@ -0,0 +1,28 @@ +# Control starts from sdb, ignoring system one +KERNEL!="sd[b-z]*", GOTO="my_media_automount_end" +ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="my_media_automount_end" + +IMPORT{program}="/sbin/blkid -o udev -p %N" + +# detect label or create one +ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}" +ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k" + +# make the dirs in /media +ACTION=="add", RUN+="/bin/mkdir -p '/media/%E{dir_name}'" + +# mount options +ACTION=="add", ENV{mount_options}="relatime" +# ntfs vfat specific options +ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=100,dmask=000,fmask=111,utf8" + +# use ntfs-3g to mount ntfs filesystems +ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options} /dev/%k '/media/%E{dir_name}'" +# automatic mount for others +ACTION=="add", ENV{ID_FS_TYPE}!="ntfs", RUN+="/bin/mount -t auto -o %E{mount_options} /dev/%k '/media/%E{dir_name}'" + +# cleanup on remove +ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'", RUN+="/bin/rmdir '/media/%E{dir_name}'" + +# exit +LABEL="my_media_automount_end" diff --git a/rpi-mc/automount-sd.rules b/rpi-mc/automount-sd.rules new file mode 100644 index 0000000..50c9af3 --- /dev/null +++ b/rpi-mc/automount-sd.rules @@ -0,0 +1,11 @@ +KERNEL!="mmcblk[0-9]p[0-9]", GOTO="sd_cards_auto_mount_end" + +# global options +ACTION=="add", ENV{mount_options}="relatime" +# fs specific +ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N" +ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002" + +ACTION=="add", RUN+="/bin/mkdir -p /media/sd-%k", RUN+="/bin/ln -s /media/sd-%k /mnt/sd-%k", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/sd-%k" +ACTION=="remove", RUN+="/bin/umount -l /media/sd-%k", RUN+="/bin/rmdir /media/sd-%k" +LABEL="sd_cards_auto_mount_end"