Skip to contentSkip to conversation

improve get_persistent_name function

PATCH Superseded Dave Young 1 participant 1 message Sep 28, 2012

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Dave Young

author
#0 lore raw

PATCH v2 1/1 improve get_persistent_name function

For devices with filesystem, udev /dev/disk/by-uuid/* links are usually reliable. So improve the get_persistent_dev() by using by-uuid/* firstly, and fallback to use by-id/*

An exception is multipath devices, child and top layer device may have same uuid. As dm devices maintain /dev/mapper/* as persistent names, just do not doing converting for them.

---
 dracut-functions.sh |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
dracut-functions.sh +4 -1
@@ -242,10 +242,13 @@ fi
 get_persistent_dev() {
     local i _tmp _dev
 
+    # /dev/mapper/* suppose to be persistent
+    [[ $1 =~ /dev/mapper ]] && echo $1 && return
+
     _dev=$(udevadm info --query=name --name="$1" 2>/dev/null)
     [ -z "$_dev" ] && return
 
-    for i in /dev/disk/by-id/*; do
+    for i in /dev/disk/by-uuid/* /dev/disk/by-id/*; do
         _tmp=$(udevadm info --query=name --name="$i" 2>/dev/null)
         if [ "$_tmp" = "$_dev" ]; then
             echo $i