[arch-projects] [mkinitcpio] [PATCH 1/2] init_functions: escape slashes in tag values

Dave Reisner dreisner at archlinux.org
Sat Nov 23 21:01:58 EST 2013


This allows booting from devices which have labels like LABEL=/.

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
 init_functions | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/init_functions b/init_functions
index 474d6fa..11ce3ca 100644
--- a/init_functions
+++ b/init_functions
@@ -252,6 +252,16 @@ fsck_root() {
     fi
 }
 
+# TODO: this really needs to follow the logic of systemd's encode_devnode_name
+# function more closely.
+tag_to_udev_path() {
+    awk -v "tag=$1" -v "value=$2" '
+    BEGIN {
+        gsub(/\//, "\\x2f", value)
+        printf "/dev/disk/by-%s/%s\n", tolower(tag), value
+    }'
+}
+
 resolve_device() {
     local major minor dev tag device=$1
 
@@ -264,8 +274,7 @@ resolve_device() {
         UUID=*|LABEL=*|PARTUUID=*|PARTLABEL=*)
             dev=$(blkid -lt "$device" -o device)
             if [ -z "$dev" -a "$udevd_running" -eq 1 ]; then
-                tag=$(awk -v t="${device%%=*}" 'BEGIN { print tolower(t) }')
-                dev=/dev/disk/by-$tag/${device#*=}
+                dev=$(tag_to_udev_path "${device%%=*}" "${device#*=}")
             fi
     esac
 
-- 
1.8.4.2



More information about the arch-projects mailing list