[arch-projects] [mkinitcpio][PATCH] implement --moduleroot option

Dave Reisner dreisner at archlinux.org
Fri Jul 27 23:55:16 EDT 2012


This might be useful for creating an initramfs image as part of a kernel
package.

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
 bash-completion    |  6 +++---
 functions          |  4 ++--
 install/autodetect |  2 +-
 mkinitcpio         | 10 +++++++---
 mkinitcpio.8.txt   |  3 +++
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/bash-completion b/bash-completion
index c37484c..6d21fd8 100644
--- a/bash-completion
+++ b/bash-completion
@@ -55,15 +55,15 @@ _files_from_dirs() {
 _mkinitcpio() {
     local action cur prev opts
     opts=(-A --add -c --config -g --generate -H --hookhelp -h --help -k --kernel
-          -L --listhooks -M --automods -n --nocolor -p --preset -S --skiphooks
-          -s --save -t --builddir -v --verbose -z --compress)
+          -L --listhooks -M --automods -n --nocolor -p --preset -r --moduleroot
+          -S --skiphooks -s --save -t --builddir -v --verbose -z --compress)
 
     _get_comp_words_by_ref cur prev
 
     case $prev in
         -[cg]|--config|--generate)
             _filedir ;;
-        -t|--builddir)
+        -r|--moduleroot|-t|--builddir)
             _filedir -d ;;
         -k|--kernel)
             _find_kernel_versions ;;
diff --git a/functions b/functions
index 9c577f0..b42daf7 100644
--- a/functions
+++ b/functions
@@ -212,7 +212,7 @@ auto_modules() {
     IFS=$'\n' read -rd '' -a mods < \
         <(find /sys/devices -name modalias -exec sort -u {} + |
         # delimit each input by a newline, expanded in place
-        xargs -d $'\n' modprobe -qaRS "$KERNELVERSION" |
+        xargs -d $'\n' modprobe -d "$MODULEROOT" -qaRS "$KERNELVERSION" |
         sort -u)
 
     printf "%s\n" "${mods[@]//-/_}"
@@ -332,7 +332,7 @@ add_module() {
                 fi
                 ;;
         esac
-    done < <(modinfo -k "$KERNELVERSION" -0 "$module" 2>/dev/null)
+    done < <(modinfo -b "$MODULEROOT" -k "$KERNELVERSION" -0 "$module" 2>/dev/null)
 
     if [[ -z $path ]]; then
         (( ign_errors )) && return 0
diff --git a/install/autodetect b/install/autodetect
index b2d3687..20648e4 100644
--- a/install/autodetect
+++ b/install/autodetect
@@ -10,7 +10,7 @@ build() {
 
         # treat this as an alias, since ext3 might be aliased to ext4.
         IFS=$'\n' read -rd '' -a resolved < \
-            <(modprobe -S "$KERNELVERSION" -R "$1" 2>/dev/null)
+            <(modprobe -M "$MODULEROOT" -S "$KERNELVERSION" -R "$1" 2>/dev/null)
 
         if (( ${#resolved[*]} )); then
             printf '%s\n' "${resolved[@]}" >>"$MODULE_FILE"
diff --git a/mkinitcpio b/mkinitcpio
index 5202e7f..b64fb67 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -45,6 +45,7 @@ usage: ${0##*/} [options]
    -M, --automods               Display modules found via autodetection
    -n, --nocolor                Disable colorized output messages
    -p, --preset <file>          Build specified preset from /etc/mkinitcpio.d
+   -r, --moduleroot <dir>       Root directory for modules (default: /)
    -S, --skiphooks <hooks>      Skip specified hooks, comma-separated, during build
    -s, --save                   Save build directory. (default: no)
    -t, --builddir <dir>         Use DIR as the temporary build directory
@@ -99,7 +100,7 @@ resolve_kernver() {
 find_moduledir() {
     local d
 
-    for d in {/usr,}/lib/modules; do
+    for d in "$MODULEROOT"{/usr,}/lib/modules; do
         if [[ -d $d/$1/ ]]; then
             printf '%s' "$d/$1/"
             return 0
@@ -123,9 +124,9 @@ compute_hookset() {
 trap 'cleanup 130' INT
 trap 'cleanup 143' TERM
 
-OPT_SHORT='A:c:g:H:hk:mnLMp:S:st:vz:'
+OPT_SHORT='A:c:g:H:hk:mnLMp:r:S:st:vz:'
 OPT_LONG=('add:' 'config:' 'generate:' 'hookhelp:' 'help' 'kernel:' 'listhooks' 'automods'
-          'nocolor' 'preset:' 'skiphooks:' 'save' 'builddir:' 'verbose' 'compress:')
+          'moduleroot' 'nocolor' 'preset:' 'skiphooks:' 'save' 'builddir:' 'verbose' 'compress:')
 
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
     exit 1
@@ -199,6 +200,9 @@ while :; do
         -z|--compress)
             shift
             optcompress=$1 ;;
+        -r|--moduleroot)
+            shift
+            MODULEROOT=$1 ;;
         --)
             shift
             break 2 ;;
diff --git a/mkinitcpio.8.txt b/mkinitcpio.8.txt
index 06957ac..fa30b30 100644
--- a/mkinitcpio.8.txt
+++ b/mkinitcpio.8.txt
@@ -62,6 +62,9 @@ Options
 	/etc/mkinitcpio.d (without the .preset extension) or a full, absolute path to a
 	file.
 
+*-r, \--moduleroot* 'root'::
+	Specifies the root directory to find modules in, defaulting to '/'.
+
 *-S, \--skiphooks* 'hooks'::
 	Skip 'hooks' when generating the image. Multiple hooks should be comma-separated.
 	This option can be specified multiple times.
-- 
1.7.11.3



More information about the arch-projects mailing list