Skip to contentSkip to conversation

udev-extraconf/mount.sh: add LABELs to mountpoints

PATCH Superseded Muhammad Hamza 2 participants 3 messages Jun 20, 2022 – Jun 21, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udev-extraconf/mount.sh: add LABELs to mountpoints

This alters the mountpoints such that if a device has a LABEL or a PARTLABEL, it will be mounted at e.g.:

/run/media/$LABEL-<device-node>
/run/media/$PARTLABEL-<device-node>
/run/media/rootfs-sda2

otherwise the device will be mounted at e.g.:

/run/media/<device-node>
/run/media/sda1

The <device-node> appended with LABEL or PARTLABEL makes sure that the mountpoint is unique, therefore, avoids overlapping mounts.

---
 .../recipes-core/udev/udev-extraconf/mount.sh | 20 +++++++++++++++++++
 meta/recipes-core/udev/udev-extraconf_1.1.bb  |  2 +-
 2 files changed, 21 insertions(+), 1 deletion(-)
meta/recipes-core/udev/udev-extraconf/mount.sh +20 -0
index c8b773bc07..12c6a5af22 100644
@@ -54,6 +54,16 @@ automount_systemd() {
         grep "^[[:space:]]*$tmp" /etc/fstab && return
     done
 
+    # Get the LABEL or PARTLABEL
+    LABEL=`/sbin/blkid | grep "${DEVNAME}:" | grep -o 'LABEL=".*"' | cut -d '"' -f2`
+    # If the $DEVNAME has a LABEL or a PARTLABEL
+    if [ -n "$LABEL" ]; then
+            # Set the mount location dir name to LABEL appended
+            # with $name e.g. label-sda. That would avoid overlapping
+            # mounts in case two devices have same LABEL
+            name="${LABEL}-${name}"
+    fi
+
     [ -d "$MOUNT_BASE/$name" ] || mkdir -p "$MOUNT_BASE/$name"
 
     MOUNT="$MOUNT -o silent"
@@ -94,6 +104,16 @@ automount() {
 	# configured in fstab
 	grep -q "^$DEVNAME " /proc/mounts && return
 
+        # Get the LABEL or PARTLABEL
+        LABEL=`/sbin/blkid | grep "${DEVNAME}:" | grep -o 'LABEL=".*"' | cut -d '"' -f2`
+        # If the $DEVNAME has a LABEL or a PARTLABEL
+        if [ -n "$LABEL" ]; then
+                # Set the mount location dir name to LABEL appended
+                # with $name e.g. label-sda. That would avoid overlapping
+                # mounts in case two devices have same LABEL
+                name="${LABEL}-${name}"
+        fi
+
 	! test -d "$MOUNT_BASE/$name" && mkdir -p "$MOUNT_BASE/$name"
 	# Silent util-linux's version of mounting auto
 	if [ "x`readlink $MOUNT`" = "x/bin/mount.util-linux" ] ;
meta/recipes-core/udev/udev-extraconf_1.1.bb +1 -1
index 2b908ac05b..8213c1a930 100644
@@ -38,7 +38,7 @@ do_install() {
 }
 
 FILES:${PN} = "${sysconfdir}/udev"
-RDEPENDS:${PN} = "udev"
+RDEPENDS:${PN} = "udev util-linux-blkid"
 CONFFILES:${PN} = "${sysconfdir}/udev/mount.ignorelist"
 
 # to replace udev-extra-rules from meta-oe
Signature · 1 line
2.25.1
#1 lore raw

Hi Muhammad,

Quoted 46 lines · On Mon, 20 Jun 2022 17:26:40 +0500 "Muhammad Hamza"…

This alters the mountpoints such that if a device has a LABEL or a PARTLABEL, it will be mounted at e.g.:

/run/media/$LABEL-<device-node>
/run/media/$PARTLABEL-<device-node>
/run/media/rootfs-sda2

otherwise the device will be mounted at e.g.:

/run/media/<device-node>
/run/media/sda1

The <device-node> appended with LABEL or PARTLABEL makes sure that the mountpoint is unique, therefore, avoids overlapping mounts.

---
 .../recipes-core/udev/udev-extraconf/mount.sh | 20 +++++++++++++++++++
 meta/recipes-core/udev/udev-extraconf_1.1.bb  |  2 +-
 2 files changed, 21 insertions(+), 1 deletion(-)
meta/recipes-core/udev/udev-extraconf/mount.sh +10 -0
index c8b773bc07..12c6a5af22 100644
@@ -54,6 +54,16 @@ automount_systemd() {
         grep "^[[:space:]]*$tmp" /etc/fstab && return
     done
 
+    # Get the LABEL or PARTLABEL
+    LABEL=`/sbin/blkid | grep "${DEVNAME}:" | grep -o 'LABEL=".*"' | cut -d '"' -f2`
+    # If the $DEVNAME has a LABEL or a PARTLABEL
+    if [ -n "$LABEL" ]; then
+            # Set the mount location dir name to LABEL appended
+            # with $name e.g. label-sda. That would avoid overlapping
+            # mounts in case two devices have same LABEL
+            name="${LABEL}-${name}"
+    fi
+
     [ -d "$MOUNT_BASE/$name" ] || mkdir -p "$MOUNT_BASE/$name"
 
     MOUNT="$MOUNT -o silent"
@@ -94,6 +104,16 @@ automount() {
 	# configured in fstab
 	grep -q "^$DEVNAME " /proc/mounts && return

meta/recipes-core/udev/udev-extraconf/mount.sh automount() { · line 115

Quoted 10 lines
meta/recipes-core/udev/udev-extraconf/mount.sh +9 -0
 
+        # Get the LABEL or PARTLABEL
+        LABEL=`/sbin/blkid | grep "${DEVNAME}:" | grep -o 'LABEL=".*"' | cut -d '"' -f2`
+        # If the $DEVNAME has a LABEL or a PARTLABEL
+        if [ -n "$LABEL" ]; then
+                # Set the mount location dir name to LABEL appended
+                # with $name e.g. label-sda. That would avoid overlapping
+                # mounts in case two devices have same LABEL
+                name="${LABEL}-${name}"
+        fi

This is exactly as above. Can you move the common code to a function?

Signature · 3 lines
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

Hi Luca,
I have sent updated patch v2 at mailing list.

Regards,
Hamza

-----Original Message-----
From: Luca Ceresoli <[email protected]>
Sent: Tuesday, June 21, 2022 1:21 PM
To: Hamza, Muhammad <[email protected]>
Cc: [email protected]; Awan, Arsalan <[email protected]>
Subject: Re: [OE-core] [PATCH] udev-extraconf/mount.sh: add LABELs to mountpoints

Hi Muhammad,

Quoted 48 lines · On Mon, 20 Jun 2022 17:26:40 +0500 "Muhammad Hamza"…

This alters the mountpoints such that if a device has a LABEL or a PARTLABEL, it will be mounted at e.g.:

/run/media/$LABEL-<device-node>
/run/media/$PARTLABEL-<device-node>
/run/media/rootfs-sda2

otherwise the device will be mounted at e.g.:

/run/media/<device-node>
/run/media/sda1

The <device-node> appended with LABEL or PARTLABEL makes sure that the mountpoint is unique, therefore, avoids overlapping mounts.

---
 .../recipes-core/udev/udev-extraconf/mount.sh | 20 
+++++++++++++++++++  meta/recipes-core/udev/udev-extraconf_1.1.bb  |  
2 +-
 2 files changed, 21 insertions(+), 1 deletion(-)
meta/recipes-core/udev/udev-extraconf/mount.sh +10 -0
index c8b773bc07..12c6a5af22 100644
@@ -54,6 +54,16 @@ automount_systemd() {
         grep "^[[:space:]]*$tmp" /etc/fstab && return
     done
 
+    # Get the LABEL or PARTLABEL
+    LABEL=`/sbin/blkid | grep "${DEVNAME}:" | grep -o 'LABEL=".*"' | cut -d '"' -f2`
+    # If the $DEVNAME has a LABEL or a PARTLABEL
+    if [ -n "$LABEL" ]; then
+            # Set the mount location dir name to LABEL appended
+            # with $name e.g. label-sda. That would avoid overlapping
+            # mounts in case two devices have same LABEL
+            name="${LABEL}-${name}"
+    fi
+
     [ -d "$MOUNT_BASE/$name" ] || mkdir -p "$MOUNT_BASE/$name"
 
     MOUNT="$MOUNT -o silent"
@@ -94,6 +104,16 @@ automount() {
 	# configured in fstab
 	grep -q "^$DEVNAME " /proc/mounts && return

meta/recipes-core/udev/udev-extraconf/mount.sh automount() { · line 115

Quoted 10 lines
meta/recipes-core/udev/udev-extraconf/mount.sh +9 -0
 
+        # Get the LABEL or PARTLABEL
+        LABEL=`/sbin/blkid | grep "${DEVNAME}:" | grep -o 'LABEL=".*"' | cut -d '"' -f2`
+        # If the $DEVNAME has a LABEL or a PARTLABEL
+        if [ -n "$LABEL" ]; then
+                # Set the mount location dir name to LABEL appended
+                # with $name e.g. label-sda. That would avoid overlapping
+                # mounts in case two devices have same LABEL
+                name="${LABEL}-${name}"
+        fi

This is exactly as above. Can you move the common code to a function?

--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com