Skip to contentSkip to conversation

udev-extraconf: Fix the automount malfunction when the systemd is used

PATCH New Kevin Hao 1 participant 4 messages Oct 22, 2018

lore
Share & tools
lore

Kevin Hao

author
#0 lore raw

cover udev-extraconf: Fix the automount malfunction when the systemd is used

When we use the systemd as the init manager, the automount function doesn't work at all. This patch series fixes this issue. The patch 2&3 have been posted by Hongzhi one month ago [1], but they aren't merged yet. I have rebased them on the latest oe-core and also fix the author info since it is me to scratch these patches originally. :-)

Kevin Hao (3):
udev-extraconf: Use the canonical file name of systemd
udev-extraconf: Fix the recursively dependency for the systemd-mount
udev-extraconf: Skip the entry in /etc/fstab when using the
systemd-mount

 meta/recipes-core/udev/udev-extraconf/mount.sh | 36 +++++++++++++++++---------
 1 file changed, 24 insertions(+), 12 deletions(-)

[1] http://lists.openembedded.org/pipermail/openembedded-core/2018-September/155724.html

Thanks,
Kevin

Signature · 1 line
2.14.4
author
#1 lore raw

PATCH 1/3 udev-extraconf: Use the canonical file name of systemd

The new version of systemd has changed the symbolic link between /sbin/init and /lib/systemd/systemd to relative. So the output of the command 'readlink /sbin/init' become:
../lib/systemd/systemd

Then it causes the following check of "/lib/systemd/systemd" to return false. Fix this issue by using the canonical file name of the systemd.

---
 meta/recipes-core/udev/udev-extraconf/mount.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-core/udev/udev-extraconf/mount.sh +1 -1
index 067d4e2a16fb..34ef98a6a882 100644
@@ -4,7 +4,7 @@
 #
 # Attempt to mount any added block devices and umount any removed devices
 
-BASE_INIT="`readlink "@base_sbindir@/init"`"
+BASE_INIT="`readlink -f "@base_sbindir@/init"`"
 INIT_SYSTEMD="@systemd_unitdir@/systemd"
 
 if [ "x$BASE_INIT" = "x$INIT_SYSTEMD" ];then
Signature · 1 line
2.14.4
author
#2 lore raw

PATCH 2/3 udev-extraconf: Fix the recursively dependency for the systemd-mount

In reply to Kevin Hao

The commit 4ca9402c3720 ("udev-extraconf: Add systemd-mount to udev-extraconf/mount.sh") uses the systemd-mount to mount the new added disk partitions if systemd is used. But it forgot to move the codes which tries to mount the partition by using the configuration in /etc/fstab to the non-systemd function. And it will cause the systemd-mount try to mount the partition synchronously and trigger a recursively dependency like the following:

    dev-sda1.device -> run-media-sda1.mount -> dev-sda1.device
---
 meta/recipes-core/udev/udev-extraconf/mount.sh | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
meta/recipes-core/udev/udev-extraconf/mount.sh +14 -11
index 34ef98a6a882..afb368dd6737 100644
@@ -66,6 +66,16 @@ automount_systemd() {
 automount() {
 	name="`basename "$DEVNAME"`"
 
+	if [ -x "$PMOUNT" ]; then
+		$PMOUNT $DEVNAME 2> /dev/null
+	elif [ -x $MOUNT ]; then
+		$MOUNT $DEVNAME 2> /dev/null
+	fi
+
+	# If the device isn't mounted at this point, it isn't
+	# configured in fstab
+	grep -q "^$DEVNAME " /proc/mounts && return
+
 	! test -d "/run/media/$name" && mkdir -p "/run/media/$name"
 	# Silent util-linux's version of mounting auto
 	if [ "x`readlink $MOUNT`" = "x/bin/mount.util-linux" ] ;
@@ -109,20 +119,13 @@ name="`basename "$DEVNAME"`"
 [ -e /sys/block/$name/device/media ] && media_type=`cat /sys/block/$name/device/media`
 
 if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && [ -n "$ID_FS_TYPE" -o "$media_type" = "cdrom" ]; then
-	if [ -x "$PMOUNT" ]; then
-		$PMOUNT $DEVNAME 2> /dev/null
-	elif [ -x $MOUNT ]; then
-    		$MOUNT $DEVNAME 2> /dev/null
-	fi
-
-	# If the device isn't mounted at this point, it isn't
-	# configured in fstab (note the root filesystem can show up as
-	# /dev/root in /proc/mounts, so check the device number too)
+    # Note the root filesystem can show up as /dev/root in /proc/mounts,
+    # so check the device number too
     if expr $MAJOR "*" 256 + $MINOR != `stat -c %d /`; then
         if [ "`basename $MOUNT`" = "systemd-mount" ];then
-            grep -q "^$DEVNAME " /proc/mounts || automount_systemd
+            automount_systemd
         else
-            grep -q "^$DEVNAME " /proc/mounts || automount
+            automount
         fi
     fi
 fi
Signature · 1 line
2.14.4
author
#3 lore raw

PATCH 3/3 udev-extraconf: Skip the entry in /etc/fstab when using the systemd-mount

In reply to Kevin Hao

When using systemd, the systemd-fstab-generator would parse the /etc/fstab and create the corresponding unit dynamically. So we don't need to handle the ADD action for the partitions in /etc/fstab.

---
 meta/recipes-core/udev/udev-extraconf/mount.sh | 9 +++++++++
 1 file changed, 9 insertions(+)
meta/recipes-core/udev/udev-extraconf/mount.sh +9 -0
index afb368dd6737..3ee67b13183a 100644
@@ -38,6 +38,15 @@ done
 automount_systemd() {
     name="`basename "$DEVNAME"`"
 
+    # Skip the partition which are already in /etc/fstab
+    grep "^[[:space:]]*$DEVNAME" /etc/fstab && return
+    for n in LABEL PARTLABEL UUID PARTUUID; do
+        tmp="$(lsblk -o $n $DEVNAME | sed -e '1d')"
+        test -z "$tmp" && continue
+        tmp="$n=$tmp"
+        grep "^[[:space:]]*$tmp" /etc/fstab && return
+    done
+
     [ -d "/run/media/$name" ] || mkdir -p "/run/media/$name"
 
     MOUNT="$MOUNT -o silent"
Signature · 1 line
2.14.4