Skip to contentSkip to conversation

dracut: info which module is sourced; updated dracut usage

PATCH In review Amadeusz Żołnowski 3 participants 9 messages Jul 5, 2010 – Jul 9, 2010 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 dracut: info which module is sourced; updated dracut usage

Added description for --confdir.

---
 dracut |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
dracut +3 -0
index 3be4989..6b590f5 100755
@@ -57,6 +57,8 @@ Creates initial ramdisk images for preloading modules
   -v, --verbose         Verbose output during the build process
   -c, --conf [FILE]     Specify configuration file to use.
                          Default: /etc/dracut.conf
+  --confdir [DIR]       Specify configuration directory to use *.conf files from.
+                         Default: /etc/dracut.conf.d
   -l, --local           Local mode. Use modules from the current working
                          directory instead of the system-wide installed in
                          /usr/share/dracut/modules.d.
@@ -243,6 +245,7 @@ check_modules
 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
     mod=${moddir##*/}; mod=${mod#[0-9][0-9]}
     if strstr "$mods_to_load" " $mod "; then
+	dinfo "*** Sourcing module $mod"
 	if [[ $kernel_only = yes ]]; then
 	    [[ -x $moddir/installkernel ]] && . "$moddir/installkernel"
 	else
Signature · 1 line
1.7.1
#1 lore raw

PATCH 2/3 dracut-functions: info which udev rules are skipped

I found it useful. Maybe help others debugging.

---
 dracut-functions |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
dracut-functions +3 -2
index 9c2999a..0caf0d6 100755
@@ -335,8 +335,9 @@ inst_rules() {
     inst_dir "/lib/udev/rules.d"
     inst_dir "$target"
     for rule in "$@"; do 
-	rule=$(find_rule "$rule") && \
-	    inst_simple "$rule" "$target/${rule##*/}"
+	rule1=$(find_rule "$rule") && \
+	    inst_simple "$rule1" "$target/${rule1##*/}" \
+	    || dinfo "Skipping udev rule: $rule"
     done
 }
 
Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH 3/3] dracut-functions: find_rule a bit smarter

btw cosmetic changes to inst_rules

---
 dracut-functions |   29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)
dracut-functions +23 -6
index 0caf0d6..6da36ad 100755
@@ -319,11 +319,27 @@ inst_symlink() {
     inst "$realsrc" && ln -s "$realsrc" "$target"
 }
 
-# find a udev rule in the usual places.
+# find a udev rule in the usual places and try to be smart (just a bit).
+# See example:
+#   find_rule default.rules
+#   find_rule udev-default.rules
+#   find_rule 50-udev-default.rules
+# All of them will return: /lib/udev/rules.d/50-udev-default.rules
 find_rule() {
+    local rule
+
     [[ -f $1 ]] && { echo "$1"; return 0; }
     for r in . /lib/udev/rules.d /etc/udev/rules.d $dracutbasedir/rules.d; do
-	[[ -f $r/$1 ]] && { echo "$r/$1"; return 0; }
+        if ls $r/*$1 &>/dev/null; then
+            if [[ -f $r/$1 ]]; then
+                echo "$r/$1"
+                return 0
+            else
+                rule=$(ls "$r"/??"-$1" 2>/dev/null || \
+                    ls "$r"/??"-udev-$1" 2>/dev/null)
+                [[ -f $rule ]] && echo $rule && return 0
+            fi
+        fi
     done
     return 1
 }
@@ -331,13 +347,14 @@ find_rule() {
 # udev rules always get installed in the same place, so
 # create a function to install them to make life simpler.
 inst_rules() { 
-    local target=/etc/udev/rules.d
+    local target=/etc/udev/rules.d rule found
+
     inst_dir "/lib/udev/rules.d"
     inst_dir "$target"
     for rule in "$@"; do 
-	rule1=$(find_rule "$rule") && \
-	    inst_simple "$rule1" "$target/${rule1##*/}" \
-	    || dinfo "Skipping udev rule: $rule"
+        found=$(find_rule "$rule") && \
+            inst_simple "$found" "$target/${found##*/}" \
+            || dinfo "Skipping udev rule: $rule"
     done
 }
 
Signature · 1 line
1.7.1
#3 lore raw

Re: [PATCH 3/3] dracut-functions: find_rule a bit smarter

Matches rules filename if it's specified without prefix number.

---
 dracut-functions |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)
dracut-functions +23 -2
index be6b2e9..1f2528e 100755
@@ -319,11 +319,32 @@ inst_symlink() {
     inst "$realsrc" && ln -s "$realsrc" "$target"
 }
 
-# find a udev rule in the usual places.
+# find a udev rule in the usual places and try to be smart (just a bit).
+# See example:
+#   find_rule default.rules
+#   find_rule 50-default.rules
+# All of them will return: /lib/udev/rules.d/50-udev-default.rules
+# If there are few matching files, error message is printed.
 find_rule() {
+    local rule t
+
     [[ -f $1 ]] && { echo "$1"; return 0; }
     for r in . /lib/udev/rules.d /etc/udev/rules.d $dracutbasedir/rules.d; do
-	[[ -f $r/$1 ]] && { echo "$r/$1"; return 0; }
+        if ls $r/*$1 &>/dev/null; then
+            if [[ -f $r/$1 ]]; then
+                echo "$r/$1"
+                return 0
+            else
+                rule=$(ls "$r"/??"-$1" 2>/dev/null)
+                t=($rule)
+                if (( ${#t[@]} > 1 )); then
+                    derror "Ambigous rules filename.  Matches: ${t[@]}"
+                elif [[ -f "$rule" ]]; then
+                    echo $rule
+                    return 0
+                fi
+            fi
+        fi
     done
     return 1
 }
Signature · 1 line
1.7.1
#4 lore raw

Re: [PATCH 3/3] dracut-functions: find_rule a bit smarter

Quoted 15 lines · Amadeusz Żołnowski

Matches rules filename if it's specified without prefix number.

---
 dracut-functions |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)
dracut-functions +1 -1
index be6b2e9..1f2528e 100755
@@ -319,11 +319,32 @@ inst_symlink() {
     inst "$realsrc" && ln -s "$realsrc" "$target"
 }
 
-# find a udev rule in the usual places.
+# find a udev rule in the usual places and try to be smart (just a bit).

dracut-functions inst_symlink() { · line 332

Quoted 10 lines
dracut-functions +7 -0
+# See example:
+#   find_rule default.rules
+#   find_rule 50-default.rules
+# All of them will return: /lib/udev/rules.d/50-udev-default.rules
+# If there are few matching files, error message is printed.
 find_rule() {
+    local rule t
+
     [[ -f $1 ]] && { echo "$1"; return 0; }
     for r in . /lib/udev/rules.d /etc/udev/rules.d $dracutbasedir/rules.d; do

# Parsing the output of ls can lead to strange and subtle bugs. # Use globbing and parameter expansion instead, and go with the first

# matching file.
	local f
	for f in "$r/$1" "$r/${1%%-*}-udev-%{1##*-}" "$r/"*"$1"; do
		[[ -f $f ]] || continue
		echo "$f"
		return 0
Quoted 3 lines
dracut-functions +0 -0
     done
     return 1
 }
Signature · 2 lines
Victor Lowther
LPIC2 UCP RHCE 

A message that is not in the archive (sent off-list or not yet received): 1278341637.4056.17.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#6 lore raw

Re: [PATCH 3/3] dracut-functions: find_rule a bit smarter

Victor Lowther <[email protected]>:

Quoted 8 lines

# Parsing the output of ls can lead to strange and subtle bugs. # Use globbing and parameter expansion instead, and go with the first

# matching file.
	local f
	for f in "$r/$1" "$r/${1%%-*}-udev-%{1##*-}" "$r/"*"$1"; do
		[[ -f $f ]] || continue
		echo "$f"
		return 0

Thank you for advice! I've modified function to the following form:

# Final efect the same as previous, but in addition detects ambiguousness

# among multiple directories.  If it's not desired uncomment the line with
# "break" statement.
find_rule() {
    local rd f files=()
    [[ -f $1 ]] && { echo "$1"; return 0; }

    for rd in . /lib/udev/rules.d /etc/udev/rules.d $dracutbasedir/rules.d; do
        for f in "$rd/$1" "$rd"/*-"$1"
        do
            [[ -f $f ]] || continue
            [[ ${f##*/} =~ [0-9][0-9]-.*\.rules ]] || continue
            files+=($f)
        done
        # (( ${#files[@]} >= 1 )) && break
    done

    (( ${#files[@]} < 1 )) && return 1
    (( ${#files[@]} > 1 )) && {
        derror "Ambigous rules filename.  Matches: ${files[@]}"
        return 1
    }

    echo "$files"
}
Signature · 1 line
PGP key: 1024D/C284750D
#7 lore raw

PATCH 1/1 dracut-functions: find_rule a bit smarter; thanks to V. Lowther

Matches rules filename if it's specified without prefix number.

Thanks to Victor Lowther for advice of not using ls command. Use globbing and parameter expansion instead.

---
 dracut-functions |   31 +++++++++++++++++++++++++++----
 1 files changed, 27 insertions(+), 4 deletions(-)
dracut-functions +27 -4
index 0caf0d6..7a1d82f 100755
@@ -319,13 +319,36 @@ inst_symlink() {
     inst "$realsrc" && ln -s "$realsrc" "$target"
 }
 
-# find a udev rule in the usual places.
+# find a udev rule in the usual places and try to be smart (just a bit).
+# See example:
+#   find_rule default.rules
+#   find_rule 50-default.rules
+# All of them will return: /lib/udev/rules.d/50-udev-default.rules
+# If there are few matching files, error message is printed.
 find_rule() {
+    local rd f files=()
+
     [[ -f $1 ]] && { echo "$1"; return 0; }
-    for r in . /lib/udev/rules.d /etc/udev/rules.d $dracutbasedir/rules.d; do
-	[[ -f $r/$1 ]] && { echo "$r/$1"; return 0; }
+
+    for rd in . /lib/udev/rules.d /etc/udev/rules.d $dracutbasedir/rules.d; do
+        for f in "$rd/$1" "$rd"/*-"$1"
+        do
+            [[ -f $f ]] || continue
+            [[ ${f##*/} =~ [0-9][0-9]-.*\.rules ]] || continue
+            files+=($f)
+        done
+        # If detecting ambiguousness among different directories isn't desired,
+        # uncomment this:
+        # (( ${#files[@]} >= 1 )) && break
     done
-    return 1
+
+    (( ${#files[@]} < 1 )) && return 1
+    (( ${#files[@]} > 1 )) && {
+        derror "Ambigous rules filename.  Matches: ${files[@]}"
+        return 1
+    }
+
+    echo "$files"
 }
 
 # udev rules always get installed in the same place, so
Signature · 1 line
1.7.1
#8 lore raw

Re: [PATCH 2/3] dracut-functions: info which udev rules are skipped

In reply to Amadeusz Żołnowski
Quoted 11 lines · Amadeusz Å»oÅ‚nowski

I found it useful. Maybe help others debugging.

---
  dracut-functions |    5 +++--
  1 files changed, 3 insertions(+), 2 deletions(-)
dracut-functions +0 -0
index 9c2999a..0caf0d6 100755
@@ -335,8 +335,9 @@ inst_rules() {
      inst_dir "/lib/udev/rules.d"

dracut-functions inst_rules() { · line 343

Quoted 10 lines
dracut-functions +3 -2
      inst_dir "$target"
      for rule in "$@"; do
-	rule=$(find_rule "$rule")&&  \
-	    inst_simple "$rule" "$target/${rule##*/}"
+	rule1=$(find_rule "$rule")&&  \
+	    inst_simple "$rule1" "$target/${rule1##*/}" \
+	    || dinfo "Skipping udev rule: $rule"
      done
  }
 

pushed

#9 lore raw
In reply to Amadeusz Żołnowski
Quoted 19 lines · Amadeusz Å»oÅ‚nowski

Added description for --confdir.

---
  dracut |    3 +++
  1 files changed, 3 insertions(+), 0 deletions(-)
dracut +2 -0
index 3be4989..6b590f5 100755
@@ -57,6 +57,8 @@ Creates initial ramdisk images for preloading modules
    -v, --verbose         Verbose output during the build process
    -c, --conf [FILE]     Specify configuration file to use.
                           Default: /etc/dracut.conf
+  --confdir [DIR]       Specify configuration directory to use *.conf files from.
+                         Default: /etc/dracut.conf.d
    -l, --local           Local mode. Use modules from the current working
                           directory instead of the system-wide installed in
                           /usr/share/dracut/modules.d.

dracut check_modules · line 251

Quoted 7 lines
dracut +1 -0
@@ -243,6 +245,7 @@ check_modules
  for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
      mod=${moddir##*/}; mod=${mod#[0-9][0-9]}
      if strstr "$mods_to_load" " $mod "; then
+	dinfo "*** Sourcing module $mod"
  	if [[ $kernel_only = yes ]]; then
  	    [[ -x $moddir/installkernel ]]&&  . "$moddir/installkernel"
  	else

pushed