]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
Allow running on a cross-compiled rootfs
authorBöszörményi Zoltán <zboszor@pr.hu>
Thu, 24 Oct 2019 09:28:55 +0000 (11:28 +0200)
committerHarald Hoyer <harald@hoyer.xyz>
Fri, 25 Oct 2019 09:58:58 +0000 (11:58 +0200)
For the shell scripts, new environment variables were introduced.

dracutsysrootdir is the root directory, file existence checks use it.

DRACUT_LDCONFIG can override ldconfig with a different one that works
on the sysroot with foreign binaries.

DRACUT_LDD can override ldd with a different one that works
with foreign binaries.

DRACUT_TESTBIN can override /bin/sh. A cross-compiled sysroot
may use symlinks that are valid only when running on the target
so a real file must be provided that exist in the sysroot.

DRACUT_INSTALL now supports debugging dracut-install in itself
when run by dracut but without debugging the dracut scripts.
E.g. DRACUT_INSTALL="valgrind dracut-install or
DRACUT_INSTALL="dracut-install --debug".

DRACUT_COMPRESS_BZIP2, DRACUT_COMPRESS_LBZIP2, DRACUT_COMPRESS_LZMA,
DRACUT_COMPRESS_XZ, DRACUT_COMPRESS_GZIP, DRACUT_COMPRESS_PIGZ,
DRACUT_COMPRESS_LZOP, DRACUT_COMPRESS_ZSTD, DRACUT_COMPRESS_LZ4,
DRACUT_COMPRESS_CAT: All of the compression utilities may be
overridden, to support the native binaries in non-standard places.

DRACUT_ARCH overrides "uname -m".

SYSTEMD_VERSION overrides "systemd --version".

The dracut-install utility was overhauled to support sysroot via
a new option -r and fixes for clang-analyze. It supports
cross-compiler-ldd from
https://gist.github.com/jerome-pouiller/c403786c1394f53f44a3b61214489e6f

DRACUT_INSTALL_PATH was introduced so dracut-install can work with
a different PATH. In a cross-compiled environment (e.g. Yocto), PATH
points to natively built binaries that are not in the host's /bin,
/usr/bin, etc. dracut-install still needs plain /bin and /usr/bin
that are relative to the cross-compiled sysroot.

The hashmap pool allocate_tile/deallocate_tile code was removed
because clang-analyze showed errors in it. hashmap_copy was removed
because it wasn't used and clang-analyze showed errors in it.

DRACUT_INSTALL_LOG_TARGET and DRACUT_INSTALL_LOG_LEVEL were
introduced so dracut-install can use different settings from
DRACUT_LOG_TARGET and DRACUT_LOG_LEVEL.

Signed-off-by: Böszörményi Zoltán <zboszor@pr.hu>
52 files changed:
dracut-functions.sh
dracut-init.sh
dracut.sh
install/dracut-install.c
install/hashmap.c
install/hashmap.h
install/log.c
mkinitrd-dracut.sh
mkinitrd-suse.sh
modules.d/00systemd/module-setup.sh
modules.d/00warpclock/module-setup.sh
modules.d/02systemd-networkd/module-setup.sh
modules.d/03modsign/module-setup.sh
modules.d/10i18n/module-setup.sh
modules.d/35network-legacy/module-setup.sh
modules.d/40network/module-setup.sh
modules.d/45ifcfg/module-setup.sh
modules.d/45url-lib/module-setup.sh
modules.d/50drm/module-setup.sh
modules.d/50gensplash/module-setup.sh
modules.d/50plymouth/module-setup.sh
modules.d/50plymouth/plymouth-populate-initrd.sh
modules.d/80cms/module-setup.sh
modules.d/81cio_ignore/module-setup.sh
modules.d/90crypt/module-setup.sh
modules.d/90kernel-modules/module-setup.sh
modules.d/90kernel-network-modules/module-setup.sh
modules.d/90lvm/module-setup.sh
modules.d/90mdraid/module-setup.sh
modules.d/90multipath/module-setup.sh
modules.d/91crypt-gpg/module-setup.sh
modules.d/91zipl/module-setup.sh
modules.d/95cifs/module-setup.sh
modules.d/95dasd/module-setup.sh
modules.d/95dasd_mod/module-setup.sh
modules.d/95dasd_rules/module-setup.sh
modules.d/95dcssblk/module-setup.sh
modules.d/95debug/module-setup.sh
modules.d/95fcoe/module-setup.sh
modules.d/95fstab-sys/module-setup.sh
modules.d/95iscsi/module-setup.sh
modules.d/95nfs/module-setup.sh
modules.d/95qeth_rules/module-setup.sh
modules.d/95resume/module-setup.sh
modules.d/95ssh-client/module-setup.sh
modules.d/95terminfo/module-setup.sh
modules.d/95udev-rules/module-setup.sh
modules.d/95zfcp/module-setup.sh
modules.d/95zfcp_rules/module-setup.sh
modules.d/95znet/module-setup.sh
modules.d/99base/module-setup.sh
modules.d/99fs-lib/module-setup.sh

index 22940540580109ff58a70140dbf812c698865e7a..3cb9c7afd410f7173dfe85574e44092bae58e45c 100755 (executable)
@@ -40,19 +40,43 @@ str_ends() { [ "${1%*"$2"}" != "$1" ]; }
 # find a binary.  If we were not passed the full path directly,
 # search in the usual places to find the binary.
 find_binary() {
-    if [[ -z ${1##/*} ]]; then
-        if [[ -x $1 ]] || { [[ "$1" == *.so* ]] && ldd "$1" &>/dev/null; };  then
+    local _delim
+    local l
+    local p
+    [[ -z ${1##/*} ]] || _delim="/"
+
+    if [[ "$1" == *.so* ]]; then
+        for l in libdirs ; do
+            if { $DRACUT_LDD "$dracutsysrootdir$l$_delim$1" &>/dev/null; };  then
+                printf "%s\n" "$1"
+                return 0
+            fi
+        done
+        if { $DRACUT_LDD "$dracutsysrootdir$_delim$1" &>/dev/null; }; then
             printf "%s\n" "$1"
             return 0
         fi
     fi
+    if [[ "$1" == */* ]]; then
+        if [[ -L $dracutsysrootdir$_delim$1 ]] || [[ -x $dracutsysrootdir$_delim$1 ]]; then
+            printf "%s\n" "$1"
+            return 0
+        fi
+    fi
+    for p in $DRACUT_PATH ; do
+        if [[ -L $dracutsysrootdir$p$_delim$1 ]] || [[ -x $dracutsysrootdir$p$_delim$1 ]];  then
+            printf "%s\n" "$1"
+            return 0
+        fi
+    done
 
+    [[ -n "$dracutsysrootdir" ]] && return 1
     type -P "${1##*/}"
 }
 
 ldconfig_paths()
 {
-    ldconfig -pN 2>/dev/null | grep -E -v '/(lib|lib64|usr/lib|usr/lib64)/[^/]*$' | sed -n 's,.* => \(.*\)/.*,\1,p' | sort | uniq
+    $DRACUT_LDCONFIG ${dracutsysrootdir:+-r ${dracutsysrootdir} -f /etc/ld.so.conf} -pN 2>/dev/null | grep -E -v '/(lib|lib64|usr/lib|usr/lib64)/[^/]*$' | sed -n 's,.* => \(.*\)/.*,\1,p' | sort | uniq
 }
 
 # Version comparision function.  Assumes Linux style version scheme.
@@ -633,9 +657,9 @@ check_kernel_config()
 {
     local _config_opt="$1"
     local _config_file
-    [[ -f /boot/config-$kernel ]] \
+    [[ -f $dracutsysrootdir/boot/config-$kernel ]] \
         && _config_file="/boot/config-$kernel"
-    [[ -f /lib/modules/$kernel/config ]] \
+    [[ -f $dracutsysrootdir/lib/modules/$kernel/config ]] \
         && _config_file="/lib/modules/$kernel/config"
 
     # no kernel config file, so return true
index e6a0ae2a4532688aa66ed6f26cbd20478ad9783d..aff04c89084b98c97c33d226a2b73abf1ca074a9 100644 (file)
@@ -57,7 +57,7 @@ if ! [[ $kernel ]]; then
     export kernel
 fi
 
-srcmods="/lib/modules/$kernel/"
+srcmods="$dracutsysrootdir/lib/modules/$kernel/"
 
 [[ $drivers_dir ]] && {
     if ! command -v kmod &>/dev/null && vercmp "$(modprobe --version | cut -d' ' -f3)" lt 3.7; then
@@ -79,17 +79,21 @@ export srcmods
     export hookdirs
 }
 
+DRACUT_LDD=${DRACUT_LDD:-ldd}
+DRACUT_TESTBIN=${DRACUT_TESTBIN:-/bin/sh}
+DRACUT_LDCONFIG=${DRACUT_LDCONFIG:-ldconfig}
+
 . $dracutbasedir/dracut-functions.sh
 
 # Detect lib paths
 if ! [[ $libdirs ]] ; then
-    if [[ "$(ldd /bin/sh)" == */lib64/* ]] &>/dev/null \
-        && [[ -d /lib64 ]]; then
+    if [[ "$($DRACUT_LDD $dracutsysrootdir$DRACUT_TESTBIN)" == */lib64/* ]] &>/dev/null \
+        && [[ -d $dracutsysrootdir/lib64 ]]; then
         libdirs+=" /lib64"
-        [[ -d /usr/lib64 ]] && libdirs+=" /usr/lib64"
+        [[ -d $dracutsysrootdir/usr/lib64 ]] && libdirs+=" /usr/lib64"
     else
         libdirs+=" /lib"
-        [[ -d /usr/lib ]] && libdirs+=" /usr/lib"
+        [[ -d $dracutsysrootdir/usr/lib ]] && libdirs+=" /usr/lib"
     fi
 
     libdirs+=" $(ldconfig_paths)"
@@ -168,7 +172,18 @@ elif ! [[ $DRACUT_INSTALL ]] && [[ -x $dracutbasedir/install/dracut-install ]];
     DRACUT_INSTALL=$dracutbasedir/install/dracut-install
 fi
 
-if ! [[ -x $DRACUT_INSTALL ]]; then
+# Test if dracut-install is a standalone executable with no options.
+# E.g. DRACUT_INSTALL may be set externally as:
+# DRACUT_INSTALL="valgrind dracut-install"
+# or
+# DRACUT_INSTALL="dracut-install --debug"
+# in which case the string cannot be tested for being executable.
+DRINSTALLPARTS=0
+for i in $DRACUT_INSTALL ; do
+    DRINSTALLPARTS=$(($DRINSTALLPARTS+1))
+done
+
+if [[ $DRINSTALLPARTS = 1 ]] && ! [[ -x $DRACUT_INSTALL ]]; then
     dfatal "dracut-install not found!"
     exit 10
 fi
@@ -176,15 +191,15 @@ fi
 if [[ $hostonly == "-h" ]]; then
     if ! [[ $DRACUT_KERNEL_MODALIASES ]] || ! [[ -f "$DRACUT_KERNEL_MODALIASES" ]]; then
         export DRACUT_KERNEL_MODALIASES="${DRACUT_TMPDIR}/modaliases"
-        $DRACUT_INSTALL ${srcmods:+--kerneldir "$srcmods"} --modalias > "$DRACUT_KERNEL_MODALIASES"
+        $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${srcmods:+--kerneldir "$srcmods"} --modalias > "$DRACUT_KERNEL_MODALIASES"
     fi
 fi
 
 [[ $DRACUT_RESOLVE_LAZY ]] || export DRACUT_RESOLVE_DEPS=1
 inst_dir() {
     [[ -e ${initdir}/"$1" ]] && return 0  # already there
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@"
-    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} -d "$@" || :
+    $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@" || :
 }
 
 inst() {
@@ -194,8 +209,8 @@ inst() {
         shift
     fi
     [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
-    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+    $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
 }
 
 inst_simple() {
@@ -206,8 +221,8 @@ inst_simple() {
     fi
     [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
     [[ -e $1 ]] || return 1  # no source
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
-    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" || :
+    $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" || :
 }
 
 inst_symlink() {
@@ -218,15 +233,15 @@ inst_symlink() {
     fi
     [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
     [[ -L $1 ]] || return 1
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
-    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+    $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
 }
 
 inst_multiple() {
     local _ret
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@"
+    $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@"
     _ret=$?
-    (($_ret != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+    (($_ret != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
     return $_ret
 }
 
@@ -243,8 +258,9 @@ dracut_instmods() {
     done
 
     $DRACUT_INSTALL \
+        ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
         ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@"
-    (($? != 0)) && (($_silent == 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@" || :
+    (($? != 0)) && (($_silent == 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${hostonly:+-H} ${omit_drivers:+-N "$omit_drivers"} ${srcmods:+--kerneldir "$srcmods"} -m "$@" || :
 }
 
 inst_library() {
@@ -255,24 +271,24 @@ inst_library() {
     fi
     [[ -e ${initdir}/"${2:-$1}" ]] && return 0  # already there
     [[ -e $1 ]] || return 1  # no source
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
-    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
+    $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
 }
 
 inst_binary() {
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@"
-    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@" || :
+    $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@"
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@" || :
 }
 
 inst_script() {
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
-    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@" || :
+    $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"
+    (($? != 0)) && derror FAILED: $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$@" || :
 }
 
 inst_fsck_help() {
     local _helper="/run/dracut/fsck/fsck_help_$1.txt"
-    $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" $_helper
-    (($? != 0)) && derror $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$2" $_helper || :
+    $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" $_helper
+    (($? != 0)) && derror $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l}  ${DRACUT_FIPS_MODE:+-f} "$2" $_helper || :
 }
 
 # Use with form hostonly="$(optional_hostonly)" inst_xxxx <args>
@@ -369,12 +385,12 @@ inst_rule_group_owner() {
 
     for i in $(sed -nr 's/.*OWNER=?"([^ "]+).*/\1/p' "$1"); do
         if ! grep -Eq "^$i:" "$initdir/etc/passwd" 2>/dev/null; then
-            grep -E "^$i:" /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
+            grep -E "^$i:" $dracutsysrootdir/etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
         fi
     done
     for i in $(sed -nr 's/.*GROUP=?"([^ "]+).*/\1/p' "$1"); do
         if ! grep -Eq "^$i:" "$initdir/etc/group" 2>/dev/null; then
-            grep -E "^$i:" /etc/group 2>/dev/null >> "$initdir/etc/group"
+            grep -E "^$i:" $dracutsysrootdir/etc/group 2>/dev/null >> "$initdir/etc/group"
         fi
     done
 }
@@ -394,7 +410,7 @@ inst_rules() {
     inst_dir "$_target"
     for _rule in "$@"; do
         if [ "${_rule#/}" = "$_rule" ]; then
-            for r in ${udevdir}/rules.d ${hostonly:+/etc/udev/rules.d}; do
+            for r in $dracutsysrootdir${udevdir}/rules.d ${hostonly:+$dracutsysrootdir/etc/udev/rules.d}; do
                 [[ -e $r/$_rule ]] || continue
                 _found="$r/$_rule"
                 inst_rule_programs "$_found"
@@ -403,7 +419,7 @@ inst_rules() {
                 inst_simple "$_found"
             done
         fi
-        for r in '' $dracutbasedir/rules.d/; do
+        for r in '' $dracutsysrootdir$dracutbasedir/rules.d/; do
             # skip rules without an absolute path
             [[ "${r}$_rule" != /* ]] && continue
             [[ -f ${r}$_rule ]] || continue
@@ -525,7 +541,7 @@ inst_libdir_file() {
             for _i in "$@"; do
                 for _f in "$_dir"/$_i; do
                     [[ "$_f" =~ $_pattern ]] || continue
-                    [[ -e "$_f" ]] && _files+="$_f "
+                    [[ -e "$dracutsysrootdir$_f" ]] && _files+="$_f "
                 done
             done
         done
@@ -533,7 +549,7 @@ inst_libdir_file() {
         for _dir in $libdirs; do
             for _i in "$@"; do
                 for _f in "$_dir"/$_i; do
-                    [[ -e "$_f" ]] && _files+="$_f "
+                    [[ -e "$dracutsysrootdir$_f" ]] && _files+="$_f "
                 done
             done
         done
@@ -947,6 +963,7 @@ instmods() {
 
     $DRACUT_INSTALL \
         ${initdir:+-D "$initdir"} \
+        ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
         ${loginstall:+-L "$loginstall"} \
         ${hostonly:+-H} \
         ${omit_drivers:+-N "$omit_drivers"} \
@@ -960,6 +977,7 @@ instmods() {
         derror "FAILED: " \
             $DRACUT_INSTALL \
                 ${initdir:+-D "$initdir"} \
+                ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
                 ${loginstall:+-L "$loginstall"} \
                 ${hostonly:+-H} \
                 ${omit_drivers:+-N "$omit_drivers"} \
index 8343ba4e36e2c903a2849576eb839c096e29c859..5777f83a65524054f3d74549ff3ff7b02b5eecba 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -37,7 +37,7 @@ readonly dracut_cmd="$(readlink -f $0)"
 set -o pipefail
 
 usage() {
-    [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
+    [[ $dracutbasedir ]] || dracutbasedir=$dracutsysrootdir/usr/lib/dracut
     if [[ -f $dracutbasedir/dracut-version.sh ]]; then
         . $dracutbasedir/dracut-version.sh
     fi
@@ -62,7 +62,7 @@ EOF
 }
 
 long_usage() {
-    [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
+    [[ $dracutbasedir ]] || dracutbasedir=$dracutsysrootdir/usr/lib/dracut
     if [[ -f $dracutbasedir/dracut-version.sh ]]; then
         . $dracutbasedir/dracut-version.sh
     fi
@@ -140,6 +140,7 @@ Creates initial ramdisk images for preloading modules
                          from. Default: /etc/dracut.conf.d
   --tmpdir [DIR]        Temporary directory to be used instead of default
                          /var/tmp.
+  -r, --sysroot [DIR]   Specify sysroot directory to collect files from.
   -l, --local           Local mode. Use modules from the current working
                          directory instead of the system-wide installed in
                          /usr/lib/dracut/modules.d.
@@ -635,7 +636,7 @@ if [[ $regenerate_all == "yes" ]]; then
             unset dracut_args[$i]
     done
 
-    cd /lib/modules
+    cd $dracutsysrootdir/lib/modules
     for i in *; do
         [[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
         "$dracut_cmd" --kver="$i" "${dracut_args[@]}"
@@ -669,14 +670,14 @@ export DRACUT_LOG_LEVEL=warning
     debug=yes
 }
 
-[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
+[[ $dracutbasedir ]] || dracutbasedir=$dracutsysrootdir/usr/lib/dracut
 
 # if we were not passed a config file, try the default one
 if [[ ! -f $conffile ]]; then
     if [[ $allowlocal ]]; then
         conffile="$dracutbasedir/dracut.conf"
     else
-        conffile="/etc/dracut.conf"
+        conffile="$dracutsysrootdir/etc/dracut.conf"
     fi
 fi
 
@@ -684,7 +685,7 @@ if [[ ! -d $confdir ]]; then
     if [[ $allowlocal ]]; then
         confdir="$dracutbasedir/dracut.conf.d"
     else
-        confdir="/etc/dracut.conf.d"
+        confdir="$dracutsysrootdir/etc/dracut.conf.d"
     fi
 fi
 
@@ -700,8 +701,8 @@ DRACUT_PATH=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
 
 for i in $DRACUT_PATH; do
     rl=$i
-    if [ -L "$i" ]; then
-        rl=$(readlink -f $i)
+    if [ -L "$dracutsysrootdir$i" ]; then
+        rl=$(readlink -f $dracutsysrootdir$i)
     fi
     if [[ "$NPATH" != *:$rl* ]] ; then
         NPATH+=":$rl"
@@ -748,10 +749,10 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
-[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
-[[ $fw_dir ]] || fw_dir="/lib/firmware/updates:/lib/firmware:/lib/firmware/$kernel"
+[[ $dracutbasedir ]] || dracutbasedir=$dracutsysrootdir/usr/lib/dracut
+[[ $fw_dir ]] || fw_dir="$dracutsysrootdir/lib/firmware/updates:$dracutsysrootdir/lib/firmware:$dracutsysrootdir/lib/firmware/$kernel"
 [[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
-[[ $tmpdir ]] || tmpdir=/var/tmp
+[[ $tmpdir ]] || tmpdir=$dracutsysrootdir/var/tmp
 [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
 [[ $compress_l ]] && compress=$compress_l
 [[ $show_modules_l ]] && show_modules=$show_modules_l
@@ -768,7 +769,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
 
 if ! [[ $outfile ]]; then
     if [[ $machine_id != "no" ]]; then
-        [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
+        [[ -f $dracutsysrootdir/etc/machine-id ]] && read MACHINE_ID < $dracutsysrootdir/etc/machine-id
     fi
 
     if [[ $uefi == "yes" ]]; then
@@ -782,27 +783,34 @@ if ! [[ $outfile ]]; then
             exit 1
         fi
 
-        BUILD_ID=$(cat /etc/os-release /usr/lib/os-release \
+        BUILD_ID=$(cat $dracutsysrootdir/etc/os-release $dracutsysrootdir/usr/lib/os-release \
                        | while read -r line || [[ $line ]]; do \
                        [[ $line =~ BUILD_ID\=* ]] && eval "$line" && echo "$BUILD_ID" && break; \
                    done)
-        if [[ -d /efi ]] && mountpoint -q /efi; then
-            efidir=/efi/EFI
+        if [[ -z $dracutsysrootdir ]]; then
+            if [[ -d /efi ]] && mountpoint -q /efi; then
+                efidir=/efi/EFI
+            else
+                efidir=/boot/EFI
+                if [[ -d $dracutsysrootdir/boot/efi/EFI ]]; then
+                    efidir=/boot/efi/EFI
+                fi
+            fi
         else
             efidir=/boot/EFI
-            if [[ -d /boot/efi/EFI ]] && mountpoint -q /boot/efi; then
+            if [[ -d $dracutsysrootdir/boot/efi/EFI ]]; then
                 efidir=/boot/efi/EFI
             fi
         fi
-        mkdir -p "$efidir/Linux"
-        outfile="$efidir/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi"
+        mkdir -p "$dracutsysrootdir$efidir/Linux"
+        outfile="$dracutsysrootdir$efidir/Linux/linux-$kernel${MACHINE_ID:+-${MACHINE_ID}}${BUILD_ID:+-${BUILD_ID}}.efi"
     else
-        if [[ -e "/boot/vmlinuz-$kernel" ]]; then
+        if [[ -e "$dracutsysrootdir/boot/vmlinuz-$kernel" ]]; then
             outfile="/boot/initramfs-$kernel.img"
-        elif [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then
-            outfile="/boot/${MACHINE_ID}/$kernel/initrd"
+        elif [[ $MACHINE_ID ]] && ( [[ -d $dracutsysrootdir/boot/${MACHINE_ID} ]] || [[ -L $dracutsysrootdir/boot/${MACHINE_ID} ]] ); then
+            outfile="$dracutsysrootdir/boot/${MACHINE_ID}/$kernel/initrd"
         else
-            outfile="/boot/initramfs-$kernel.img"
+            outfile="$dracutsysrootdir/boot/initramfs-$kernel.img"
         fi
     fi
 fi
@@ -822,13 +830,24 @@ if [[ -n "$logfile" ]];then
 fi
 
 # handle compression options.
-if [[ $_no_compress_l = "cat" ]]; then
-    compress="cat"
+DRACUT_COMPRESS_BZIP2=${DRACUT_COMPRESS_BZIP2:-bzip2}
+DRACUT_COMPRESS_LBZIP2=${DRACUT_COMPRESS_LBZIP2:-lbzip2}
+DRACUT_COMPRESS_LZMA=${DRACUT_COMPRESS_LZMA:-lzma}
+DRACUT_COMPRESS_XZ=${DRACUT_COMPRESS_XZ:-xz}
+DRACUT_COMPRESS_GZIP=${DRACUT_COMPRESS_GZIP:-gzip}
+DRACUT_COMPRESS_PIGZ=${DRACUT_COMPRESS_PIGZ:-pigz}
+DRACUT_COMPRESS_LZOP=${DRACUT_COMPRESS_LZOP:-lzop}
+DRACUT_COMPRESS_ZSTD=${DRACUT_COMPRESS_ZSTD:-zstd}
+DRACUT_COMPRESS_LZ4=${DRACUT_COMPRESS_LZ4:-lz4}
+DRACUT_COMPRESS_CAT=${DRACUT_COMPRESS_CAT:-cat}
+
+if [[ $_no_compress_l = "$DRACUT_COMPRESS_CAT" ]]; then
+    compress="$DRACUT_COMPRESS_CAT"
 fi
 
 if ! [[ $compress ]]; then
     # check all known compressors, if none specified
-    for i in pigz gzip lz4 lzop zstd lzma xz lbzip2 bzip2 cat; do
+    for i in $DRACUT_COMPRESS_PIGZ $DRACUT_COMPRESS_GZIP $DRACUT_COMPRESS_LZ4 $DRACUT_COMPRESS_LZOP $ $DRACUT_COMPRESS_ZSTD $DRACUT_COMPRESS_LZMA $DRACUT_COMPRESS_XZ $DRACUT_COMPRESS_LBZIP2 $OMPRESS_BZIP2 $DRACUT_COMPRESS_CAT; do
         command -v "$i" &>/dev/null || continue
         compress="$i"
         break
@@ -841,35 +860,35 @@ fi
 # choose the right arguments for the compressor
 case $compress in
     bzip2|lbzip2)
-        if [[ "$compress" =  lbzip2 ]] || command -v lbzip2 &>/dev/null; then
-            compress="lbzip2 -9"
+        if [[ "$compress" =  lbzip2 ]] || command -v $DRACUT_COMPRESS_LBZIP2 &>/dev/null; then
+            compress="$DRACUT_COMPRESS_LBZIP2 -9"
         else
-            compress="bzip2 -9"
+            compress="$DRACUT_COMPRESS_BZIP2 -9"
         fi
         ;;
     lzma)
-        compress="lzma -9 -T0"
+        compress="$DRACUT_COMPRESS_LZMA -9 -T0"
         ;;
     xz)
-        compress="xz --check=crc32 --lzma2=dict=1MiB -T0"
+        compress="$DRACUT_COMPRESS_XZ --check=crc32 --lzma2=dict=1MiB -T0"
         ;;
     gzip|pigz)
-        if [[ "$compress" = pigz ]] || command -v pigz &>/dev/null; then
-            compress="pigz -9 -n -T -R"
-        elif command -v gzip &>/dev/null && gzip --help 2>&1 | grep -q rsyncable; then
-            compress="gzip -n -9 --rsyncable"
+        if [[ "$compress" = pigz ]] || command -v $DRACUT_COMPRESS_PIGZ &>/dev/null; then
+            compress="$DRACUT_COMPRESS_PIGZ -9 -n -T -R"
+        elif command -v gzip &>/dev/null && $DRACUT_COMPRESS_GZIP --help 2>&1 | grep -q rsyncable; then
+            compress="$DRACUT_COMPRESS_GZIP -n -9 --rsyncable"
         else
-            compress="gzip -n -9"
+            compress="$DRACUT_COMPRESS_GZIP -n -9"
         fi
         ;;
     lzo|lzop)
-        compress="lzop -9"
+        compress="$DRACUT_COMPRESS_LZOP -9"
         ;;
     lz4)
-        compress="lz4 -l -9"
+        compress="$DRACUT_COMPRESS_LZ4 -l -9"
         ;;
     zstd)
-       compress="zstd -15 -q -T0"
+       compress="$DRACUT_COMPRESS_ZSTD -15 -q -T0"
        ;;
 esac
 
@@ -920,7 +939,7 @@ if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_t
     mkdir "$early_cpio_dir"
 fi
 
-export DRACUT_RESOLVE_LAZY="1"
+[[ -n "$dracutsysrootdir" ]] || export DRACUT_RESOLVE_LAZY="1"
 
 if [[ $print_cmdline ]]; then
     stdloglvl=0
@@ -949,8 +968,8 @@ if [[ $no_kernel != yes ]] && ! [[ -d $srcmods ]]; then
 fi
 
 if ! [[ $print_cmdline ]]; then
-    inst /bin/sh
-    if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then
+    inst $DRACUT_TESTBIN
+    if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R "$DRACUT_TESTBIN" &>/dev/null; then
         unset DRACUT_RESOLVE_LAZY
         export DRACUT_RESOLVE_DEPS=1
     fi
@@ -1093,8 +1112,8 @@ if [[ ! $print_cmdline ]]; then
 
         if ! [[ -s $uefi_stub ]]; then
             for uefi_stub in \
-                "${systemdutildir}/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub" \
-                    "/usr/lib/gummiboot/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"; do
+                $dracutsysrootdir"${systemdutildir}/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub" \
+                    "$dracutsysrootdir/usr/lib/gummiboot/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"; do
                 [[ -s $uefi_stub ]] || continue
                 break
             done
@@ -1105,7 +1124,7 @@ if [[ ! $print_cmdline ]]; then
         fi
 
         if ! [[ $kernel_image ]]; then
-            for kernel_image in "/lib/modules/$kernel/vmlinuz" "/boot/vmlinuz-$kernel"; do
+            for kernel_image in "$dracutsysrootdir/lib/modules/$kernel/vmlinuz" "$dracutsysrootdir/boot/vmlinuz-$kernel"; do
                 [[ -s "$kernel_image" ]] || continue
                 break
             done
@@ -1218,7 +1237,7 @@ if [[ $hostonly ]] && [[ "$hostonly_default_device" != "no" ]]; then
         "/boot/zipl" \
         ;
     do
-        mp=$(readlink -f "$mp")
+        mp=$(readlink -f "$dracutsysrootdir$mp")
         mountpoint "$mp" >/dev/null 2>&1 || continue
         _dev=$(find_block_device "$mp")
         _bdev=$(readlink -f "/dev/block/$_dev")
@@ -1233,7 +1252,8 @@ if [[ $hostonly ]] && [[ "$hostonly_default_device" != "no" ]]; then
         fi
     done
 
-    if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then
+    # TODO - with sysroot, /proc/swaps is not relevant
+    if [[ -f /proc/swaps ]] && [[ -f $dracutsysrootdir/etc/fstab ]]; then
         while read dev type rest || [ -n "$dev" ]; do
             [[ -b $dev ]] || continue
             [[ "$type" == "partition" ]] || continue
@@ -1247,7 +1267,7 @@ if [[ $hostonly ]] && [[ "$hostonly_default_device" != "no" ]]; then
                 _d=$(expand_persistent_dev "$_d")
                 [[ "$_d" -ef "$dev" ]] || continue
 
-                if [[ -f /etc/crypttab ]]; then
+                if [[ -f $dracutsysrootdir/etc/crypttab ]]; then
                     while read _mapper _a _p _o || [ -n "$_mapper" ]; do
                         [[ $_mapper = \#* ]] && continue
                         [[ "$_d" -ef /dev/mapper/"$_mapper" ]] || continue
@@ -1256,19 +1276,19 @@ if [[ $hostonly ]] && [[ "$hostonly_default_device" != "no" ]]; then
                         [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2
                         # skip mkswap swap
                         [[ $_o == *swap* ]] && continue 2
-                    done < /etc/crypttab
+                    done < $dracutsysrootdir/etc/crypttab
                 fi
 
                 _dev="$(readlink -f "$dev")"
                 push_host_devs "$_dev"
                 swap_devs+=("$_dev")
                 break
-            done < /etc/fstab
+            done < $dracutsysrootdir/etc/fstab
         done < /proc/swaps
     fi
 
     # collect all "x-initrd.mount" entries from /etc/fstab
-    if [[ -f /etc/fstab ]]; then
+    if [[ -f $dracutsysrootdir/etc/fstab ]]; then
         while read _d _m _t _o _r || [ -n "$_d" ]; do
             [[ "$_d" == \#* ]] && continue
             [[ $_d ]] || continue
@@ -1283,7 +1303,7 @@ if [[ $hostonly ]] && [[ "$hostonly_default_device" != "no" ]]; then
                     push_host_devs "$i"
                 done
             fi
-        done < /etc/fstab
+        done < $dracutsysrootdir/etc/fstab
     fi
 fi
 
@@ -1328,29 +1348,29 @@ for dev in "${!host_fs_types[@]}"; do
     fi
 done
 
-[[ -d $udevdir ]] \
+[[ -d $dracutsysrootdir$udevdir ]] \
     || udevdir="$(pkg-config udev --variable=udevdir 2>/dev/null)"
-if ! [[ -d "$udevdir" ]]; then
-    [[ -e /lib/udev/ata_id ]] && udevdir=/lib/udev
-    [[ -e /usr/lib/udev/ata_id ]] && udevdir=/usr/lib/udev
+if ! [[ -d "$dracutsysrootdir$udevdir" ]]; then
+    [[ -e $dracutsysrootdir/lib/udev/ata_id ]] && udevdir=/lib/udev
+    [[ -e $dracutsysrootdir/usr/lib/udev/ata_id ]] && udevdir=/usr/lib/udev
 fi
 
-[[ -d $systemdsystemunitdir ]] \
+[[ -d $dracutsysrootdir$systemdsystemunitdir ]] \
     || systemdsystemunitdir=$(pkg-config systemd --variable=systemdsystemunitdir 2>/dev/null)
 
-[[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system
+[[ -d "$dracutsysrootdir$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system
 
-[[ -d $systemdsystemconfdir ]] \
+[[ -d $dracutsysrootdir$systemdsystemconfdir ]] \
     || systemdsystemconfdir=$(pkg-config systemd --variable=systemdsystemconfdir 2>/dev/null)
 
-[[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir=/etc/systemd/system
+[[ -d "$dracutsysrootdir$systemdsystemconfdir" ]] || systemdsystemconfdir=/etc/systemd/system
 
-[[ -d $tmpfilesdir ]] \
+[[ -d $dracutsysrootdir$tmpfilesdir ]] \
     || tmpfilesdir=$(pkg-config systemd --variable=tmpfilesdir 2>/dev/null)
 
-if ! [[ -d "$tmpfilesdir" ]]; then
-    [[ -d /lib/tmpfiles.d ]] && tmpfilesdir=/lib/tmpfiles.d
-    [[ -d /usr/lib/tmpfiles.d ]] && tmpfilesdir=/usr/lib/tmpfiles.d
+if ! [[ -d "$dracutsysrootdir$tmpfilesdir" ]]; then
+    [[ -d $dracutsysrootdir/lib/tmpfiles.d ]] && tmpfilesdir=/lib/tmpfiles.d
+    [[ -d $dracutsysrootdir/usr/lib/tmpfiles.d ]] && tmpfilesdir=/usr/lib/tmpfiles.d
 fi
 
 export initdir dracutbasedir \
@@ -1399,7 +1419,7 @@ fi
 # Create some directory structure first
 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
 
-[[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
+[[ -h $dracutsysrootdir/lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
 
 if [[ $prefix ]]; then
@@ -1569,7 +1589,7 @@ if [[ $kernel_only != yes ]]; then
         cat "$f" >> "${initdir}/etc/fstab"
     done
 
-    if [[ $systemdutildir ]]; then
+    if [[ $dracutsysrootdir$systemdutildir ]]; then
         if [ -d ${initdir}/$systemdutildir ]; then
             mkdir -p ${initdir}/etc/conf.d
             {
@@ -1583,7 +1603,7 @@ if [[ $kernel_only != yes ]]; then
     if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
         dinfo "*** Resolving executable dependencies ***"
         find "$initdir" -type f -perm /0111 -not -path '*.ko' -print0 \
-        | xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R ${DRACUT_FIPS_MODE:+-f} --
+        | xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} ${dracutsysrootdir:+-r "$dracutsysrootdir"} -R ${DRACUT_FIPS_MODE:+-f} --
         dinfo "*** Resolving executable dependencies done ***"
     fi
 
@@ -1593,7 +1613,7 @@ if [[ $kernel_only != yes ]]; then
 
     # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
     for _dir in $libdirs; do
-        for _f in "$_dir/libpthread.so"*; do
+        for _f in "$dracutsysrootdir$_dir/libpthread.so"*; do
             [[ -e "$_f" ]] || continue
             inst_libdir_file "libgcc_s.so*"
             break 2
@@ -1623,9 +1643,9 @@ for ((i=0; i < ${#include_src[@]}; i++)); do
                         mkdir -m 0755 -p "$object_destdir"
                         chmod --reference="$objectname" "$object_destdir"
                     fi
-                    $DRACUT_CP -t "$object_destdir" "$objectname"/*
+                    $DRACUT_CP -t "$object_destdir" "$dracutsysrootdir$objectname"/*
                 else
-                    $DRACUT_CP -t "$destdir" "$objectname"
+                    $DRACUT_CP -t "$destdir" "$dracutsysrootdir$objectname"
                 fi
             done
         elif [[ -e $src ]]; then
@@ -1638,10 +1658,10 @@ done
 
 if [[ $kernel_only != yes ]]; then
     # make sure that library links are correct and up to date
-    for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
-        [[ -f $f ]] && inst_simple "$f"
+    for f in $dracutsysrootdir/etc/ld.so.conf $dracutsysrootdir/etc/ld.so.conf.d/*; do
+        [[ -f $f ]] && inst_simple "${f#$dracutsysrootdir}"
     done
-    if ! ldconfig -r "$initdir"; then
+    if ! $DRACUT_LDCONFIG -r "$initdir" -f /etc/ld.so.conf; then
         if [[ $EUID = 0 ]]; then
             derror "ldconfig exited ungracefully"
         else
@@ -1958,8 +1978,8 @@ if [[ $uefi = yes ]]; then
     dinfo "Using UEFI kernel cmdline:"
     dinfo $(tr -d '\000' < "$uefi_outdir/cmdline.txt")
 
-    [[ -s /usr/lib/os-release ]] && uefi_osrelease="/usr/lib/os-release"
-    [[ -s /etc/os-release ]] && uefi_osrelease="/etc/os-release"
+    [[ -s $dracutsysrootdir/usr/lib/os-release ]] && uefi_osrelease="$dracutsysrootdir/usr/lib/os-release"
+    [[ -s $dracutsysrootdir/etc/os-release ]] && uefi_osrelease="$dracutsysrootdir/etc/os-release"
 
     if objcopy \
            ${uefi_osrelease:+--add-section .osrel=$uefi_osrelease --change-section-vma .osrel=0x20000} \
@@ -2004,7 +2024,7 @@ command -v restorecon &>/dev/null && restorecon -- "$outfile"
 # and there's no reason to sync, and *definitely* no reason to fsfreeze.
 # Another case where this happens is rpm-ostree, which performs its own sync/fsfreeze
 # globally.  See e.g. https://github.com/ostreedev/ostree/commit/8642ef5ab3fec3ac8eb8f193054852f83a8bc4d0
-if test -d /run/systemd/system; then
+if test -d $dracutsysrootdir/run/systemd/system; then
     if ! sync "$outfile" 2> /dev/null; then
         dinfo "dracut: sync operation on newly created initramfs $outfile failed"
         exit 1
index 7cda499dce7ed26fb8f33bfa03e586bd88234be3..2e2643349d2afc2a0604548c4702db66ddd1de97 100644 (file)
@@ -60,10 +60,13 @@ static bool arg_resolvelazy = false;
 static bool arg_resolvedeps = false;
 static bool arg_hostonly = false;
 static char *destrootdir = NULL;
+static char *sysrootdir = NULL;
+static size_t sysrootdirlen = 0;
 static char *kerneldir = NULL;
 static size_t kerneldirlen = 0;
 static char **firmwaredirs = NULL;
 static char **pathdirs;
+static char *ldd = NULL;
 static char *logdir = NULL;
 static char *logfile = NULL;
 FILE *logfile_f = NULL;
@@ -398,6 +401,75 @@ static int library_install(const char *src, const char *lib)
         return ret;
 }
 
+static char *get_real_file(const char *src, bool fullyresolve)
+{
+        char linktarget[PATH_MAX + 1];
+        ssize_t linksz;
+        _cleanup_free_ char *fullsrcpath;
+        char *abspath = NULL;
+        struct stat sb;
+
+        if (sysrootdirlen) {
+                if (strncmp(src, sysrootdir, sysrootdirlen) == 0)
+                        fullsrcpath = strdup(src);
+                else if (asprintf(&fullsrcpath, "%s/%s", (sysrootdirlen ? sysrootdir : ""), (src[0] == '/' ? src+1 : src)) < 0)
+                                       _exit(EXIT_FAILURE);
+        } else
+                fullsrcpath = strdup(src);
+
+        log_debug("get_real_file('%s')", fullsrcpath);
+
+        if (lstat(fullsrcpath, &sb) < 0)
+            return NULL;
+
+        switch (sb.st_mode & S_IFMT) {
+        case S_IFDIR:
+        case S_IFREG:
+            return strdup(fullsrcpath);
+        case S_IFLNK:
+            break;
+        default:
+            return NULL;
+        }
+
+        linksz = readlink(fullsrcpath, linktarget, sizeof(linktarget));
+        if (linksz < 0)
+                return NULL;
+        linktarget[linksz] = '\0';
+
+        log_debug("get_real_file: readlink('%s') returns '%s'", fullsrcpath, linktarget);
+
+        if (linktarget[0] == '/') {
+                if (asprintf(&abspath, "%s%s", (sysrootdirlen ? sysrootdir : ""), linktarget) < 0)
+                        return NULL;
+        } else {
+                _cleanup_free_ char *fullsrcdir = strdup(fullsrcpath);
+
+                if (!fullsrcdir) {
+                        log_error("Out of memory!");
+                        return NULL;
+                }
+
+                fullsrcdir[dir_len(fullsrcdir)] = '\0';
+
+                if (asprintf(&abspath, "%s/%s", fullsrcdir, linktarget) < 0)
+                        return NULL;
+        }
+
+        if (fullyresolve) {
+                struct stat st;
+                if (lstat(abspath, &st) < 0) {
+                        if (errno != ENOENT)
+                                return NULL;
+                }
+                if (S_ISLNK(st.st_mode))
+                        return get_real_file(abspath, fullyresolve);
+        }
+
+        log_debug("get_real_file('%s') => '%s'", src, abspath);
+        return abspath;
+}
+
 static int resolve_deps(const char *src)
 {
         int ret = 0;
@@ -406,6 +478,12 @@ static int resolve_deps(const char *src)
         size_t linesize = LINE_MAX;
         _cleanup_pclose_ FILE *fptr = NULL;
         _cleanup_free_ char *cmd = NULL;
+        _cleanup_free_ char *fullsrcpath = NULL;
+
+        fullsrcpath = get_real_file(src, true);
+        log_debug("resolve_deps('%s') -> get_real_file('%s', true) = '%s'", src, src, fullsrcpath);
+        if (!fullsrcpath)
+                return 0;
 
         buf = malloc(LINE_MAX);
         if (buf == NULL)
@@ -413,7 +491,7 @@ static int resolve_deps(const char *src)
 
         if (strstr(src, ".so") == 0) {
                 _cleanup_close_ int fd = -1;
-                fd = open(src, O_RDONLY | O_CLOEXEC);
+                fd = open(fullsrcpath, O_RDONLY | O_CLOEXEC);
                 if (fd < 0)
                         return -errno;
 
@@ -437,12 +515,14 @@ static int resolve_deps(const char *src)
         }
 
         /* run ldd */
-        ret = asprintf(&cmd, "ldd %s 2>&1", src);
+        ret = asprintf(&cmd, "%s %s 2>&1", ldd, fullsrcpath);
         if (ret < 0) {
                 log_error("Out of memory!");
                 exit(EXIT_FAILURE);
         }
 
+        log_debug("%s", cmd);
+
         ret = 0;
 
         fptr = popen(cmd, "r");
@@ -461,6 +541,13 @@ static int resolve_deps(const char *src)
                         break;
                 }
 
+                /* errors from cross-compiler-ldd */
+                if (strstr(buf, "unable to find sysroot") || strstr(buf, "command not found")) {
+                        log_error("%s", buf);
+                        ret += 1;
+                        break;
+                }
+
                 /* musl ldd */
                 if (strstr(buf, "Not a valid dynamic program"))
                         break;
@@ -597,16 +684,68 @@ static bool check_hashmap(Hashmap *hm, const char *item)
         return false;
 }
 
-static int dracut_install(const char *src, const char *dst, bool isdir, bool resolvedeps, bool hashdst)
+static int dracut_mkdir(const char *src) {
+        _cleanup_free_ char *parent = NULL;
+        struct stat sb;
+
+        parent = strdup(src);
+        if (!parent)
+                return 1;
+
+        parent[dir_len(parent)] = '\0';
+
+        if (stat(parent, &sb) == 0) {
+                if (!S_ISDIR(sb.st_mode)) {
+                        log_error("%s exists but is not a directory!", parent);
+                        return 1;
+                }
+
+                return mkdir(src, 0755);
+        }
+
+        if (errno != ENOENT) {
+                log_error("ERROR: stat '%s': %m", src);
+                return 1;
+        }
+
+        return dracut_mkdir(parent);
+}
+
+static int dracut_install(const char *orig_src, const char *orig_dst, bool isdir, bool resolvedeps, bool hashdst)
 {
         struct stat sb, db;
+        _cleanup_free_ char *fullsrcpath = NULL;
         _cleanup_free_ char *fulldstpath = NULL;
         _cleanup_free_ char *fulldstdir = NULL;
         int ret;
-        bool src_exists = true;
+        bool src_islink = false;
+        bool src_isdir = false;
+        mode_t src_mode = 0;
+        bool dst_exists = true;
         char *i = NULL;
+        _cleanup_free_ char *src;
+        _cleanup_free_ char *dst;
+
+        if (sysrootdirlen) {
+                if (strncmp(orig_src, sysrootdir, sysrootdirlen) == 0) {
+                        src = strdup(orig_src + sysrootdirlen);
+                        fullsrcpath = strdup(orig_src);
+                } else {
+                        src = strdup(orig_src);
+                        if (asprintf(&fullsrcpath, "%s%s", sysrootdir, src) < 0)
+                                _exit(EXIT_FAILURE);
+                }
+                if (strncmp(orig_dst, sysrootdir, sysrootdirlen) == 0)
+                        dst = strdup(orig_dst + sysrootdirlen);
+                else
+                        dst = strdup(orig_dst);
+        } else {
+                src = strdup(orig_src);
+                fullsrcpath = strdup(src);
+                dst = strdup(orig_dst);
+        }
 
-        log_debug("dracut_install('%s', '%s')", src, dst);
+        log_debug("dracut_install('%s', '%s', %d, %d, %d)", src, dst, isdir, resolvedeps, hashdst);
 
         if (check_hashmap(items_failed, src)) {
                 log_debug("hash hit items_failed for '%s'", src);
@@ -618,22 +757,19 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
                 return 0;
         }
 
-        if (lstat(src, &sb) < 0) {
-                src_exists = false;
+        if (lstat(fullsrcpath, &sb) < 0) {
                 if (!isdir) {
                         i = strdup(src);
                         hashmap_put(items_failed, i, i);
                         /* src does not exist */
                         return 1;
                 }
+        } else {
+                src_islink = S_ISLNK(sb.st_mode);
+                src_isdir = S_ISDIR(sb.st_mode);
+                src_mode = sb.st_mode;
         }
 
-        i = strdup(dst);
-        if (!i)
-                return -ENOMEM;
-
-        hashmap_put(items, i, i);
-
         ret = asprintf(&fulldstpath, "%s/%s", destrootdir, (dst[0]=='/' ? (dst+1) : dst));
         if (ret < 0) {
                 log_error("Out of memory!");
@@ -642,15 +778,18 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
 
         ret = stat(fulldstpath, &sb);
 
-        if (ret != 0 && (errno != ENOENT)) {
-                log_error("ERROR: stat '%s': %m", fulldstpath);
-                return 1;
+        if (ret != 0) {
+                dst_exists = false;
+                if (errno != ENOENT) {
+                        log_error("ERROR: stat '%s': %m", fulldstpath);
+                        return 1;
+                }
         }
 
         if (ret == 0) {
                 if (resolvedeps && S_ISREG(sb.st_mode) && (sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) {
                         log_debug("'%s' already exists, but checking for any deps", fulldstpath);
-                        ret = resolve_deps(src);
+                        ret = resolve_deps(fullsrcpath + sysrootdirlen);
                 } else
                         log_debug("'%s' already exists", fulldstpath);
 
@@ -660,6 +799,10 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
 
         /* check destination directory */
         fulldstdir = strdup(fulldstpath);
+        if (!fulldstdir) {
+                log_error("Out of memory!");
+                return 1;
+        }
         fulldstdir[dir_len(fulldstdir)] = '\0';
 
         ret = stat(fulldstdir, &db);
@@ -686,24 +829,34 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
                 }
         }
 
-        if (isdir && !src_exists) {
+        if (src_isdir) {
+                if (dst_exists) {
+                        if (S_ISDIR(sb.st_mode)) {
+                                log_debug("dest dir '%s' already exists", fulldstpath);
+                                return 0;
+                        }
+                        log_error("dest dir '%s' already exists but is not a directory", fulldstpath);
+                        return 1;
+                }
+
                 log_info("mkdir '%s'", fulldstpath);
-                ret = mkdir(fulldstpath, 0755);
+                ret = dracut_mkdir(fulldstpath);
+                if (ret == 0) {
+                        i = strdup(dst);
+                        if (!i)
+                                return -ENOMEM;
+
+                        hashmap_put(items, i, i);
+                }
                 return ret;
         }
 
         /* ready to install src */
 
-        if (S_ISDIR(sb.st_mode)) {
-                log_info("mkdir '%s'", fulldstpath);
-                ret = mkdir(fulldstpath, sb.st_mode | S_IWUSR);
-                return ret;
-        }
-
-        if (S_ISLNK(sb.st_mode)) {
+        if (src_islink) {
                 _cleanup_free_ char *abspath = NULL;
 
-                abspath = realpath(src, NULL);
+                abspath = get_real_file(src, false);
 
                 if (abspath == NULL)
                         return 1;
@@ -721,7 +874,7 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
                 if (lstat(fulldstpath, &sb) != 0) {
                         _cleanup_free_ char *absdestpath = NULL;
 
-                        ret = asprintf(&absdestpath, "%s/%s", destrootdir, (abspath[0]=='/' ? (abspath+1) : abspath));
+                        ret = asprintf(&absdestpath, "%s/%s", destrootdir, (abspath[0]=='/' ? (abspath+1) : abspath) + sysrootdirlen);
                         if (ret < 0) {
                                 log_error("Out of memory!");
                                 exit(EXIT_FAILURE);
@@ -738,9 +891,9 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
                 return 0;
         }
 
-        if (sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
+        if (src_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
                 if (resolvedeps)
-                        ret += resolve_deps(src);
+                        ret += resolve_deps(fullsrcpath + sysrootdirlen);
                 if (arg_hmac) {
                         /* copy .hmac files also */
                         hmac_install(src, dst, NULL);
@@ -748,14 +901,28 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
         }
 
         log_debug("dracut_install ret = %d", ret);
-        log_info("cp '%s' '%s'", src, fulldstpath);
 
         if (arg_hostonly && !arg_module)
                 mark_hostonly(dst);
 
-        ret += cp(src, fulldstpath);
-        if (ret == 0 && logfile_f)
-                dracut_log_cp(src);
+        if (isdir) {
+                log_info("mkdir '%s'", fulldstpath);
+                ret += dracut_mkdir(fulldstpath);
+        } else {
+                log_info("cp '%s' '%s'", fullsrcpath, fulldstpath);
+                ret += cp(fullsrcpath, fulldstpath);
+        }
+
+        if (ret == 0) {
+                i = strdup(dst);
+                if (!i)
+                        return -ENOMEM;
+
+                hashmap_put(items, i, i);
+
+                if (logfile_f)
+                        dracut_log_cp(src);
+        }
 
         log_debug("dracut_install ret = %d", ret);
 
@@ -771,11 +938,11 @@ static void item_free(char *i)
 static void usage(int status)
 {
               /*                                                                                */
-        printf("Usage: %s -D DESTROOTDIR [OPTION]... -a SOURCE...\n"
-               "or: %s -D DESTROOTDIR [OPTION]... SOURCE DEST\n"
-               "or: %s -D DESTROOTDIR [OPTION]... -m KERNELMODULE [KERNELMODULE …]\n"
+        printf("Usage: %s -D DESTROOTDIR [-r SYSROOTDIR] [OPTION]... -a SOURCE...\n"
+               "or: %s -D DESTROOTDIR [-r SYSROOTDIR] [OPTION]... SOURCE DEST\n"
+               "or: %s -D DESTROOTDIR [-r SYSROOTDIR] [OPTION]... -m KERNELMODULE [KERNELMODULE …]\n"
                "\n"
-               "Install SOURCE to DEST in DESTROOTDIR with all needed dependencies.\n"
+               "Install SOURCE (from rootfs or SYSROOTDIR) to DEST in DESTROOTDIR with all needed dependencies.\n"
                "\n"
                "  KERNELMODULE can have the format:\n"
                "     <absolute path> with a leading /\n"
@@ -783,6 +950,7 @@ static void usage(int status)
                "     <module name>\n"
                "\n"
                "  -D --destrootdir  Install all files to DESTROOTDIR as the root\n"
+               "  -r --sysrootdir   Install all files from SYSROOTDIR\n"
                "  -a --all          Install all SOURCE arguments to DESTROOTDIR\n"
                "  -o --optional     If SOURCE does not exist, do not fail\n"
                "  -d --dir          SOURCE is a directory\n"
@@ -842,6 +1010,7 @@ static int parse_argv(int argc, char *argv[])
                 {"module", no_argument, NULL, 'm'},
                 {"fips", no_argument, NULL, 'f'},
                 {"destrootdir", required_argument, NULL, 'D'},
+                {"sysrootdir", required_argument, NULL, 'r'},
                 {"logdir", required_argument, NULL, 'L'},
                 {"mod-filter-path", required_argument, NULL, 'p'},
                 {"mod-filter-nopath", required_argument, NULL, 'P'},
@@ -855,7 +1024,7 @@ static int parse_argv(int argc, char *argv[])
                 {NULL, 0, NULL, 0}
         };
 
-        while ((c = getopt_long(argc, argv, "madfhlL:oD:HRp:P:s:S:N:", options, NULL)) != -1) {
+        while ((c = getopt_long(argc, argv, "madfhlL:oD:Hr:Rp:P:s:S:N:v", options, NULL)) != -1) {
                 switch (c) {
                 case ARG_VERSION:
                         puts(PROGRAM_VERSION_STRING);
@@ -894,6 +1063,10 @@ static int parse_argv(int argc, char *argv[])
                 case 'D':
                         destrootdir = strdup(optarg);
                         break;
+                case 'r':
+                        sysrootdir = strdup(optarg);
+                        sysrootdirlen = strlen(sysrootdir);
+                        break;
                 case 'p':
                         if (regcomp(&mod_filter_path, optarg, REG_NOSUB|REG_EXTENDED) != 0) {
                                 log_error("Module path filter %s is not a regular expression", optarg);
@@ -1022,6 +1195,7 @@ static char **find_binary(const char *src)
 {
         char **ret = NULL;
         char **q;
+        char *fullsrcpath;
         char *newsrc = NULL;
 
         STRV_FOREACH(q, pathdirs) {
@@ -1034,15 +1208,28 @@ static char **find_binary(const char *src)
                         exit(EXIT_FAILURE);
                 }
 
-                if (stat(newsrc, &sb) != 0) {
-                        log_debug("stat(%s) != 0", newsrc);
+                fullsrcpath = get_real_file(newsrc, false);
+
+                if (!fullsrcpath) {
+                        log_debug("get_real_file(%s) not found", newsrc);
+                        free(newsrc);
+                        newsrc = NULL;
+                        continue;
+                }
+
+                if (lstat(fullsrcpath, &sb) != 0) {
+                        log_debug("stat(%s) != 0", fullsrcpath);
                         free(newsrc);
                         newsrc = NULL;
+                        free(fullsrcpath);
+                        fullsrcpath = NULL;
                         continue;
                 }
 
                 strv_push(&ret, newsrc);
 
+                free(fullsrcpath);
+                fullsrcpath = NULL;
         };
 
         if (ret) {
@@ -1271,12 +1458,12 @@ static int install_dependent_modules(struct kmod_list *modlist)
                         continue;
                 }
 
-                ret = dracut_install(path, &path[kerneldirlen], false, false, true);
+                ret = dracut_install(&path[kerneldirlen], &path[kerneldirlen], false, false, true);
                 if (ret == 0) {
                        _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
                        _cleanup_kmod_module_unref_list_ struct kmod_list *modpre = NULL;
                        _cleanup_kmod_module_unref_list_ struct kmod_list *modpost = NULL;
-                        log_debug("dracut_install '%s' '%s' OK", path, &path[kerneldirlen]);
+                        log_debug("dracut_install '%s' '%s' OK", &path[kerneldirlen], &path[kerneldirlen]);
                         install_firmware(mod);
                        modlist = kmod_module_get_dependencies(mod);
                        ret = install_dependent_modules(modlist);
@@ -1286,7 +1473,7 @@ static int install_dependent_modules(struct kmod_list *modlist)
                                        ret = install_dependent_modules(modpre);
                        }
                 } else {
-                        log_error("dracut_install '%s' '%s' ERROR", path, &path[kerneldirlen]);
+                        log_error("dracut_install '%s' '%s' ERROR", &path[kerneldirlen], &path[kerneldirlen]);
                 }
         }
 
@@ -1328,9 +1515,9 @@ static int install_module(struct kmod_module *mod)
                 return 1;
         }
 
-        log_debug("dracut_install '%s' '%s'", path, &path[kerneldirlen]);
+        log_debug("dracut_install '%s' '%s'", &path[kerneldirlen], &path[kerneldirlen]);
 
-        ret = dracut_install(path, &path[kerneldirlen], false, false, true);
+        ret = dracut_install(&path[kerneldirlen], &path[kerneldirlen], false, false, true);
         if (ret == 0) {
                 log_debug("dracut_install '%s' OK", kmod_module_get_name(mod));
         } else if (!arg_optional) {
@@ -1738,7 +1925,13 @@ int main(int argc, char **argv)
                 exit(0);
         }
 
-        path = getenv("PATH");
+        log_debug("Program arguments:");
+        for (r = 0; r < argc; r++)
+                log_debug("%s", argv[r]);
+
+        path = getenv("DRACUT_INSTALL_PATH");
+        if (path == NULL)
+                path = getenv("PATH");
 
         if (path == NULL) {
                 log_error("PATH is not set");
@@ -1747,6 +1940,11 @@ int main(int argc, char **argv)
 
         log_debug("PATH=%s", path);
 
+        ldd = getenv("DRACUT_LDD");
+        if (ldd == NULL)
+                ldd = "ldd";
+        log_debug("LDD=%s", ldd);
+
         pathdirs = strv_split(path, ":");
 
         umask(0022);
index 8845815282d4fd332bf861ccb7923318eaa8eabe..7e77f9a61281c3952d55e3d5ddc9be5a1cba9923 100644 (file)
@@ -41,86 +41,10 @@ struct Hashmap {
 
         struct hashmap_entry *iterate_list_head, *iterate_list_tail;
         unsigned n_entries;
-
-        bool from_pool;
 };
 
 #define BY_HASH(h) ((struct hashmap_entry**) ((uint8_t*) (h) + ALIGN(sizeof(Hashmap))))
 
-struct pool {
-        struct pool *next;
-        unsigned n_tiles;
-        unsigned n_used;
-};
-
-static struct pool *first_hashmap_pool = NULL;
-static void *first_hashmap_tile = NULL;
-
-static struct pool *first_entry_pool = NULL;
-static void *first_entry_tile = NULL;
-
-static void* allocate_tile(struct pool **first_pool, void **first_tile, size_t tile_size) {
-        unsigned i;
-
-        if (*first_tile) {
-                void *r;
-
-                r = *first_tile;
-                *first_tile = * (void**) (*first_tile);
-                return r;
-        }
-
-        if (_unlikely_(!*first_pool) || _unlikely_((*first_pool)->n_used >= (*first_pool)->n_tiles)) {
-                unsigned n;
-                size_t size;
-                struct pool *p;
-
-                n = *first_pool ? (*first_pool)->n_tiles : 0;
-                n = MAX(512U, n * 2);
-                size = PAGE_ALIGN(ALIGN(sizeof(struct pool)) + n*tile_size);
-                n = (size - ALIGN(sizeof(struct pool))) / tile_size;
-
-                p = malloc(size);
-                if (!p)
-                        return NULL;
-
-                p->next = *first_pool;
-                p->n_tiles = n;
-                p->n_used = 0;
-
-                *first_pool = p;
-        }
-
-        i = (*first_pool)->n_used++;
-
-        return ((uint8_t*) (*first_pool)) + ALIGN(sizeof(struct pool)) + i*tile_size;
-}
-
-static void deallocate_tile(void **first_tile, void *p) {
-        * (void**) p = *first_tile;
-        *first_tile = p;
-}
-
-#ifndef __OPTIMIZE__
-
-static void drop_pool(struct pool *p) {
-        while (p) {
-                struct pool *n;
-                n = p->next;
-                free(p);
-                p = n;
-        }
-}
-
-__attribute__((destructor)) static void cleanup_pool(void) {
-        /* Be nice to valgrind */
-
-        drop_pool(first_hashmap_pool);
-        drop_pool(first_entry_pool);
-}
-
-#endif
-
 unsigned string_hash_func(const void *p) {
         unsigned hash = 5381;
         const signed char *c;
@@ -146,26 +70,15 @@ int trivial_compare_func(const void *a, const void *b) {
 }
 
 Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func) {
-        bool b;
         Hashmap *h;
         size_t size;
 
-        b = is_main_thread();
-
         size = ALIGN(sizeof(Hashmap)) + NBUCKETS * sizeof(struct hashmap_entry*);
 
-        if (b) {
-                h = allocate_tile(&first_hashmap_pool, &first_hashmap_tile, size);
-                if (!h)
-                        return NULL;
+        h = malloc0(size);
 
-                memset(h, 0, size);
-        } else {
-                h = malloc0(size);
-
-                if (!h)
-                        return NULL;
-        }
+        if (!h)
+                return NULL;
 
         h->hash_func = hash_func ? hash_func : trivial_hash_func;
         h->compare_func = compare_func ? compare_func : trivial_compare_func;
@@ -173,8 +86,6 @@ Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func) {
         h->n_entries = 0;
         h->iterate_list_head = h->iterate_list_tail = NULL;
 
-        h->from_pool = b;
-
         return h;
 }
 
@@ -245,7 +156,8 @@ static void unlink_entry(Hashmap *h, struct hashmap_entry *e, unsigned hash) {
         h->n_entries--;
 }
 
-static void remove_entry(Hashmap *h, struct hashmap_entry *e) {
+static void remove_entry(Hashmap *h, struct hashmap_entry **ep) {
+        struct hashmap_entry *e = *ep;
         unsigned hash;
 
         assert(h);
@@ -255,10 +167,8 @@ static void remove_entry(Hashmap *h, struct hashmap_entry *e) {
 
         unlink_entry(h, e, hash);
 
-        if (h->from_pool)
-                deallocate_tile(&first_entry_tile, e);
-        else
-                free(e);
+        free(e);
+        *ep = NULL;
 }
 
 void hashmap_free(Hashmap*h) {
@@ -268,10 +178,7 @@ void hashmap_free(Hashmap*h) {
 
         hashmap_clear(h);
 
-        if (h->from_pool)
-                deallocate_tile(&first_hashmap_tile, h);
-        else
-                free(h);
+        free(h);
 }
 
 void hashmap_free_free(Hashmap *h) {
@@ -287,8 +194,10 @@ void hashmap_clear(Hashmap *h) {
         if (!h)
                 return;
 
-        while (h->iterate_list_head)
-                remove_entry(h, h->iterate_list_head);
+        while (h->iterate_list_head) {
+                struct hashmap_entry *e = h->iterate_list_head;
+                remove_entry(h, &e);
+        }
 }
 
 static struct hashmap_entry *hash_scan(Hashmap *h, unsigned hash, const void *key) {
@@ -319,10 +228,7 @@ int hashmap_put(Hashmap *h, const void *key, void *value) {
                 return -EEXIST;
         }
 
-        if (h->from_pool)
-                e = allocate_tile(&first_entry_pool, &first_entry_tile, sizeof(struct hashmap_entry));
-        else
-                e = new(struct hashmap_entry, 1);
+        e = new(struct hashmap_entry, 1);
 
         if (!e)
                 return -ENOMEM;
@@ -381,7 +287,7 @@ void* hashmap_remove(Hashmap *h, const void *key) {
                 return NULL;
 
         data = e->value;
-        remove_entry(h, e);
+        remove_entry(h, &e);
 
         return data;
 }
@@ -426,7 +332,7 @@ int hashmap_remove_and_replace(Hashmap *h, const void *old_key, const void *new_
 
         if ((k = hash_scan(h, new_hash, new_key)))
                 if (e != k)
-                        remove_entry(h, k);
+                        remove_entry(h, &k);
 
         unlink_entry(h, e, old_hash);
 
@@ -453,7 +359,7 @@ void* hashmap_remove_value(Hashmap *h, const void *key, void *value) {
         if (e->value != value)
                 return NULL;
 
-        remove_entry(h, e);
+        remove_entry(h, &e);
 
         return value;
 }
@@ -579,6 +485,7 @@ void* hashmap_last(Hashmap *h) {
 }
 
 void* hashmap_steal_first(Hashmap *h) {
+        struct hashmap_entry *e;
         void *data;
 
         if (!h)
@@ -587,13 +494,15 @@ void* hashmap_steal_first(Hashmap *h) {
         if (!h->iterate_list_head)
                 return NULL;
 
-        data = h->iterate_list_head->value;
-        remove_entry(h, h->iterate_list_head);
+        e = h->iterate_list_head;
+        data = e->value;
+        remove_entry(h, &e);
 
         return data;
 }
 
 void* hashmap_steal_first_key(Hashmap *h) {
+        struct hashmap_entry *e;
         void *key;
 
         if (!h)
@@ -602,8 +511,9 @@ void* hashmap_steal_first_key(Hashmap *h) {
         if (!h->iterate_list_head)
                 return NULL;
 
-        key = (void*) h->iterate_list_head->key;
-        remove_entry(h, h->iterate_list_head);
+        e = h->iterate_list_head;
+        key = (void*) e->key;
+        remove_entry(h, &e);
 
         return key;
 }
@@ -694,22 +604,6 @@ int hashmap_move_one(Hashmap *h, Hashmap *other, const void *key) {
         return 0;
 }
 
-Hashmap *hashmap_copy(Hashmap *h) {
-        Hashmap *copy;
-
-        assert(h);
-
-        if (!(copy = hashmap_new(h->hash_func, h->compare_func)))
-                return NULL;
-
-        if (hashmap_merge(copy, h) < 0) {
-                hashmap_free(copy);
-                return NULL;
-        }
-
-        return copy;
-}
-
 char **hashmap_get_strv(Hashmap *h) {
         char **sv;
         Iterator it;
index b6c25d9bb4bf0f8d18b44e5416a085c680b69639..d5e45fd5f17762f3a421b6c95ab4dd0c7adc5315 100644 (file)
@@ -46,7 +46,6 @@ int trivial_compare_func(const void *a, const void *b);
 Hashmap *hashmap_new(hash_func_t hash_func, compare_func_t compare_func);
 void hashmap_free(Hashmap *h);
 void hashmap_free_free(Hashmap *h);
-Hashmap *hashmap_copy(Hashmap *h);
 int hashmap_ensure_allocated(Hashmap **h, hash_func_t hash_func, compare_func_t compare_func);
 
 int hashmap_put(Hashmap *h, const void *key, void *value);
index cf05945ba55a8253b19ec63c7fa076472d03988a..1afd5289eba8d9a03d909add44a7beb6d4697f09 100644 (file)
@@ -264,14 +264,21 @@ int log_set_max_level_from_string(const char *e) {
 void log_parse_environment(void) {
         const char *e;
 
-        if ((e = getenv("DRACUT_LOG_TARGET")))
+        if ((e = getenv("DRACUT_INSTALL_LOG_TARGET"))) {
                 if (log_set_target_from_string(e) < 0)
                         log_warning("Failed to parse log target %s. Ignoring.", e);
+        } else if ((e = getenv("DRACUT_LOG_TARGET"))) {
+                if (log_set_target_from_string(e) < 0)
+                        log_warning("Failed to parse log target %s. Ignoring.", e);
+        }
 
-        if ((e = getenv("DRACUT_LOG_LEVEL")))
+        if ((e = getenv("DRACUT_INSTALL_LOG_LEVEL"))) {
                 if (log_set_max_level_from_string(e) < 0)
                         log_warning("Failed to parse log level %s. Ignoring.", e);
-
+        } else if ((e = getenv("DRACUT_LOG_LEVEL"))) {
+                if (log_set_max_level_from_string(e) < 0)
+                        log_warning("Failed to parse log level %s. Ignoring.", e);
+        }
 }
 
 LogTarget log_get_target(void) {
index 169e95f0b2de7400aa6d10e050a9bbb602514bb6..82d90684eddf337a692b0471b2b1fb2884482ad1 100755 (executable)
@@ -53,7 +53,7 @@ default_kernel_images() {
     local regex kernel_image kernel_version version_version initrd_image
     local qf='%{NAME}-%{VERSION}-%{RELEASE}\n'
 
-    case "$(uname -m)" in
+    case "${DRACUT_ARCH:-$(uname -m)}" in
         s390|s390x)
             regex='image'
             ;;
index fd852e7177451b52750da35a98bce5683802b376..db2eb188684d2b9379a322f2c7079d6f7fbfd715 100755 (executable)
@@ -164,7 +164,7 @@ default_kernel_images() {
     local regex kernel_image kernel_version version_version initrd_image
     local qf='%{NAME}-%{VERSION}-%{RELEASE}\n'
 
-    case "$(uname -m)" in
+    case "${DRACUT_ARCH:-$(uname -m)}" in
         s390|s390x)
             regex='image'
             ;;
index f931d0ab5252660542a8c813afce5106ecf152e6..469f196db4b1076f4180d8272a8af5de1923722f 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 
 getSystemdVersion() {
-    SYSTEMD_VERSION=$($systemdutildir/systemd --version | { read a b a; echo $b; })
+    [ -z "$SYSTEMD_VERSION" ] && SYSTEMD_VERSION=$($systemdutildir/systemd --version | { read a b a; echo $b; })
     # Check if the systemd version is a valid number
     if ! [[ $SYSTEMD_VERSION =~ ^[0-9]+$ ]]; then
         dfatal "systemd version is not a number ($SYSTEMD_VERSION)"
@@ -163,7 +163,7 @@ install() {
 
     modules_load_get() {
         local _line i
-        for i in "$1"/*.conf; do
+        for i in "$dracutsysrootdir$1"/*.conf; do
             [[ -f $i ]] || continue
             while read _line || [ -n "$_line" ]; do
                 case $_line in
@@ -208,17 +208,17 @@ install() {
 
     # install adm user/group for journald
     inst_multiple nologin
-    grep '^systemd-journal:' /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
-    grep '^adm:' /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
-    grep '^systemd-journal:' /etc/group >> "$initdir/etc/group"
-    grep '^wheel:' /etc/group >> "$initdir/etc/group"
-    grep '^adm:' /etc/group >> "$initdir/etc/group"
-    grep '^utmp:' /etc/group >> "$initdir/etc/group"
-    grep '^root:' /etc/group >> "$initdir/etc/group"
+    grep '^systemd-journal:' $dracutsysrootdir/etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
+    grep '^adm:' $dracutsysrootdir/etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
+    grep '^systemd-journal:' $dracutsysrootdir/etc/group >> "$initdir/etc/group"
+    grep '^wheel:' $dracutsysrootdir/etc/group >> "$initdir/etc/group"
+    grep '^adm:' $dracutsysrootdir/etc/group >> "$initdir/etc/group"
+    grep '^utmp:' $dracutsysrootdir/etc/group >> "$initdir/etc/group"
+    grep '^root:' $dracutsysrootdir/etc/group >> "$initdir/etc/group"
 
     # we don't use systemd-networkd, but the user is in systemd.conf tmpfiles snippet
-    grep '^systemd-network:' /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
-    grep '^systemd-network:' /etc/group >> "$initdir/etc/group"
+    grep '^systemd-network:' $dracutsysrootdir/etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
+    grep '^systemd-network:' $dracutsysrootdir/etc/group >> "$initdir/etc/group"
 
     ln_r $systemdutildir/systemd "/init"
     ln_r $systemdutildir/systemd "/sbin/init"
index ea1348ed9b021ea260c56506f553f22146bd28dd..e6fc47119558b6754f1a28e45f311e63e9635670 100644 (file)
@@ -5,7 +5,7 @@
 # called by dracut
 check() {
     # hwclock does not exist on S390(x), bail out silently then
-    local _arch=$(uname -m)
+    local _arch=${DRACUT_ARCH:-$(uname -m)}
     [ "$_arch" = "s390" -o "$_arch" = "s390x" ] && return 1
 
     [ -e /etc/localtime -a -e /etc/adjtime ] || return 1
index b86751eaa1d6db1b5ac2db7f087bcf1406b12298..1ab5902991a5d1b01a4f46c6f55e7a3c47b93cdd 100755 (executable)
@@ -48,12 +48,12 @@ install() {
 
     # inst_dir /var/lib/systemd/clock
 
-    grep '^systemd-network:' /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
-    grep '^systemd-network:' /etc/group >> "$initdir/etc/group"
-    # grep '^systemd-timesync:' /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
-    # grep '^systemd-timesync:' /etc/group >> "$initdir/etc/group"
+    grep '^systemd-network:' $dracutsysrootdir/etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
+    grep '^systemd-network:' $dracutsysrootdir/etc/group >> "$initdir/etc/group"
+    # grep '^systemd-timesync:' $dracutsysrootdir/etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
+    # grep '^systemd-timesync:' $dracutsysrootdir/etc/group >> "$initdir/etc/group"
 
-    _arch=$(uname -m)
+    _arch=${DRACUT_ARCH:-$(uname -m)}
     inst_libdir_file {"tls/$_arch/",tls/,"$_arch/",}"libnss_dns.so.*" \
                      {"tls/$_arch/",tls/,"$_arch/",}"libnss_mdns4_minimal.so.*" \
                      {"tls/$_arch/",tls/,"$_arch/",}"libnss_myhostname.so.*" \
index 4b449b910e0c530749021da0602b4478594f955b..4c5b46413dcff49eb8212fe466c24e7c2023d9f0 100755 (executable)
@@ -12,8 +12,8 @@ check() {
     # do not include module in hostonly mode,
     # if no keys are present
     if [[ $hostonly ]]; then
-        x=$(echo /lib/modules/keys/*)
-        [[ "${x}" = "/lib/modules/keys/*" ]] && return 255
+        x=$(echo $dracutsysrootdir/lib/modules/keys/*)
+        [[ "${x}" = "$dracutsysrootdir/lib/modules/keys/*" ]] && return 255
     fi
 
     return 0
@@ -31,8 +31,8 @@ install() {
 
     inst_hook pre-trigger 01 "$moddir/load-modsign-keys.sh"
 
-    for x in /lib/modules/keys/* ; do
-        [[ "${x}" = "/lib/modules/keys/*" ]] && break
-        inst_simple "${x}"
+    for x in $dracutsysrootdir/lib/modules/keys/* ; do
+        [[ "${x}" = "$dracutsysrootdir/lib/modules/keys/*" ]] && break
+        inst_simple "${x#$dracutsysrootdir}"
     done
 }
index fc0c5b3ab441ea92024f68fe1665f03df07e756e..ba17e4771e495d8e440a75790507c9ac4e02d0b4 100755 (executable)
@@ -19,7 +19,7 @@ install() {
     if dracut_module_included "systemd"; then
         unset FONT
         unset KEYMAP
-        [[ -f /etc/vconsole.conf ]] && . /etc/vconsole.conf
+        [[ -f $dracutsysrootdir/etc/vconsole.conf ]] && . $dracutsysrootdir/etc/vconsole.conf
     fi
 
     KBDSUBDIRS=consolefonts,consoletrans,keymaps,unimaps
@@ -32,8 +32,8 @@ install() {
         local MAPS=$1
         local MAPNAME=${1%.map*}
         local map
-        [[ ! -f $MAPS ]] && \
-            MAPS=$(find ${kbddir}/keymaps -type f -name ${MAPNAME} -o -name ${MAPNAME}.map -o -name ${MAPNAME}.map.\*)
+        [[ ! -f $dracutsysrootdir$MAPS ]] && \
+            MAPS=$(find $dracutsysrootdir${kbddir}/keymaps -type f -name ${MAPNAME} -o -name ${MAPNAME}.map -o -name ${MAPNAME}.map.\*)
 
         for map in $MAPS; do
             KEYMAPS="$KEYMAPS $map "
@@ -44,7 +44,7 @@ install() {
             esac
 
             for INCL in $($cmd "^include " $map | while read a a b || [ -n "$a" ]; do echo ${a//\"/}; done); do
-                for FN in $(find ${kbddir}/keymaps -type f -name $INCL\*); do
+                for FN in $(find $dracutsysrootdir${kbddir}/keymaps -type f -name $INCL\*); do
                     strstr "$KEYMAPS" " $FN " || findkeymap $FN
                 done
             done
@@ -87,8 +87,8 @@ install() {
             for map in ${item[1]//,/ }
             do
                 map=(${map//-/ })
-                if [[ -f "${item[0]}" ]]; then
-                    value=$(grep "^${map[0]}=" "${item[0]}")
+                if [[ -f "$dracutsysrootdir${item[0]}" ]]; then
+                    value=$(grep "^${map[0]}=" "$dracutsysrootdir${item[0]}")
                     value=${value#*=}
                     echo "${map[1]:-${map[0]}}=${value}"
                 fi
@@ -116,9 +116,10 @@ install() {
     install_all_kbd() {
         local rel f
 
-        for _src in $(eval echo ${kbddir}/{${KBDSUBDIRS}}); do
+        for __src in $(eval echo $dracutsysrootdir${kbddir}/{${KBDSUBDIRS}}); do
+            _src=${__src#$dracutsysrootdir}
             inst_dir "$_src"
-            $DRACUT_CP -L -t "${initdir}/${_src}" "$_src"/*
+            $DRACUT_CP -L -t "${initdir}/${_src}" "$__src"/*
         done
 
         # remove unnecessary files
@@ -139,8 +140,8 @@ install() {
         local map
 
         eval $(gather_vars ${i18n_vars})
-        [ -f $I18N_CONF ] && . $I18N_CONF
-        [ -f $VCONFIG_CONF ] && . $VCONFIG_CONF
+        [ -f $dracutsysrootdir$I18N_CONF ] && . $dracutsysrootdir$I18N_CONF
+        [ -f $dracutsysrootdir$VCONFIG_CONF ] && . $dracutsysrootdir$VCONFIG_CONF
 
         shopt -q -s nocasematch
         if [[ ${UNICODE} ]]
@@ -222,14 +223,14 @@ install() {
             inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
         fi
 
-        if dracut_module_included "systemd" && [[ -f ${I18N_CONF} ]]; then
+        if dracut_module_included "systemd" && [[ -f $dracutsysrootdir${I18N_CONF} ]]; then
             inst_simple ${I18N_CONF}
         else
             mksubdirs ${initdir}${I18N_CONF}
             print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
         fi
 
-        if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
+        if dracut_module_included "systemd" && [[ -f $dracutsysrootdir${VCONFIG_CONF} ]]; then
             inst_simple ${VCONFIG_CONF}
         else
             mksubdirs ${initdir}${VCONFIG_CONF}
@@ -242,16 +243,16 @@ install() {
     checks() {
         for kbddir in ${kbddir} /usr/lib/kbd /lib/kbd /usr/share /usr/share/kbd
         do
-            [[ -d "${kbddir}" ]] && \
+            [[ -d "$dracutsysrootdir${kbddir}" ]] && \
                 for dir in ${KBDSUBDIRS//,/ }
             do
-                [[ -d "${kbddir}/${dir}" ]] && continue
+                [[ -d "$dracutsysrootdir${kbddir}/${dir}" ]] && continue
                 false
             done && break
             kbddir=''
         done
 
-        [[ -f $I18N_CONF && -f $VCONFIG_CONF ]] || \
+        [[ -f $dracutsysrootdir$I18N_CONF && -f $dracutsysrootdir$VCONFIG_CONF ]] || \
             [[ ! ${hostonly} || ${i18n_vars} ]] || {
             derror 'i18n_vars not set!  Please set up i18n_vars in ' \
                 'configuration file.'
index 5a82e998cb938feba14990dd4f75762db49885b0..f7984c1aa051f1d335e76817ec3b0928cf488563 100755 (executable)
@@ -82,7 +82,7 @@ install() {
         )
     done
 
-    _arch=$(uname -m)
+    _arch=${DRACUT_ARCH:-$(uname -m)}
 
     inst_libdir_file {"tls/$_arch/",tls/,"$_arch/",}"libnss_dns.so.*" \
         {"tls/$_arch/",tls/,"$_arch/",}"libnss_mdns4_minimal.so.*"
index 8e2a74a344c54790eb4b5cf518c2871bea7bf043..3ba2f1901aed90e5e40e0bbe5f705adf7c0cdd02 100755 (executable)
@@ -8,7 +8,7 @@ check() {
 # called by dracut
 depends() {
     echo -n "kernel-network-modules "
-    if ! dracut_module_included "network-legacy" && [ -x "/usr/libexec/nm-initrd-generator" ] ; then
+    if ! dracut_module_included "network-legacy" && [ -x "$dracutsysrootdir/usr/libexec/nm-initrd-generator" ] ; then
         echo "network-manager"
     else
         echo "network-legacy"
index 85e7f992a5a75c53672b9966b79dd3a8c39a3403..7fe05a89933287a76e82fab890c10a6bf795131c 100755 (executable)
@@ -2,7 +2,7 @@
 
 # called by dracut
 check() {
-    [[ -d /etc/sysconfig/network-scripts ]] && return 0
+    [[ -d $dracutsysrootdir/etc/sysconfig/network-scripts ]] && return 0
     return 255
 }
 
index b3fe55a6d6aeaa5c97824b0c1f905a4215a95f86..a99e0c5635f6a72d2c0d3aa1c3b20ec494765075 100755 (executable)
@@ -26,14 +26,14 @@ install() {
     inst_libdir_file "libsqlite3.so*"
 
     for _dir in $libdirs; do
-       [[ -d $_dir ]] || continue
-        for _lib in $_dir/libcurl.so.*; do
+       [[ -d $dracutsysrootdir$_dir ]] || continue
+        for _lib in $dracutsysrootdir$_dir/libcurl.so.*; do
            [[ -e $_lib ]] || continue
             [[ $_nssckbi ]] || _nssckbi=$(grep -F --binary-files=text -z libnssckbi $_lib)
             _crt=$(grep -F --binary-files=text -z .crt $_lib)
             [[ $_crt ]] || continue
             [[ $_crt == /*/* ]] || continue
-            if ! inst "$_crt"; then
+            if ! inst "${_crt#$dracutsysrootdir}"; then
                 dwarn "Couldn't install '$_crt' SSL CA cert bundle; HTTPS might not work."
                 continue
             fi
@@ -49,23 +49,23 @@ install() {
         _found=1
         inst_libdir_file "libnssckbi.so*" || _found=
         for _dir in $libdirs; do
-            [[ -e $_dir/libnssckbi.so ]] || continue
+            [[ -e $dracutsysrootdir$_dir/libnssckbi.so ]] || continue
             # this looks for directory-ish strings in the file
-            for _p11roots in $(grep -o --binary-files=text "/[[:alpha:]][[:print:]]*" $_dir/libnssckbi.so) ; do
+            for _p11roots in $(grep -o --binary-files=text "/[[:alpha:]][[:print:]]*" $dracutsysrootdir$_dir/libnssckbi.so) ; do
                 # the string can be a :-separated list of dirs
                 for _p11root in $(echo "$_p11roots" | tr ':' '\n') ; do
                     # check if it's actually a directory (there are
                     # several false positives in the results)
-                    [[ -d "$_p11root" ]] || continue
+                    [[ -d "$dracutsysrootdir$_p11root" ]] || continue
                     # check if it has some specific subdirs that all
                     # p11-kit trust dirs have
-                    [[ -d "${_p11root}/anchors" ]] || continue
-                    [[ -d "${_p11root}/blacklist" ]] || continue
+                    [[ -d "$dracutsysrootdir${_p11root}/anchors" ]] || continue
+                    [[ -d "$dracutsysrootdir${_p11root}/blacklist" ]] || continue
                     # so now we know it's really a p11-kit trust dir;
                     # install everything in it
-                    for _p11item in $(find "$_p11root") ; do
-                        if ! inst "$_p11item" ; then
-                            dwarn "Couldn't install '$_p11item' from p11-kit trust dir '$_p11root'; HTTPS might not work."
+                    for _p11item in $(find "$dracutsysrootdir$_p11root") ; do
+                        if ! inst "${_p11item#$dracutsysrootdir}" ; then
+                            dwarn "Couldn't install '${_p11item#$dracutsysrootdir}' from p11-kit trust dir '${_p11root#$dracutsysrootdir}'; HTTPS might not work."
                             continue
                         fi
                     done
index 23545e34c66fd700292858e68cec5fffbf984b9d..dd9c026d2ee930300800dffd67e0575aab7bd816 100755 (executable)
@@ -15,7 +15,7 @@ installkernel() {
     local _modname
     # Include KMS capable drm drivers
 
-    if [[ "$(uname -m)" == arm* || "$(uname -m)" == aarch64 ]]; then
+    if [[ "${DRACUT_ARCH:-$(uname -m)}" == arm* || "${DRACUT_ARCH:-$(uname -m)}" == aarch64 ]]; then
         # arm/aarch64 specific modules needed by drm
         instmods \
             "=drivers/gpu/drm/i2c" \
index d2fccc26bb2225b0b98a316b959f419af5affd69..67faff12ca2288ff67ce597d99693331b30722c7 100755 (executable)
@@ -52,7 +52,7 @@ install() {
         _splash_res=${DRACUT_GENSPLASH_RES}
     elif [[ ${hostonly} ]]; then
         # Settings from config only in hostonly
-        [[ -e /etc/conf.d/splash ]] && source /etc/conf.d/splash
+        [[ -e $dracutsysrootdir/etc/conf.d/splash ]] && source $dracutsysrootdir/etc/conf.d/splash
         [[ ! ${_splash_theme} ]] && _splash_theme=default
         [[ ${_splash_res} ]] && _opts+=" -r ${_splash_res}"
     else
index b51913e821e4f6f171d69728b47659ad860ae21d..081d24e0b8d295d148afb4c65711a9eccff9e53b 100755 (executable)
@@ -6,7 +6,7 @@ pkglib_dir() {
         _dirs+=" /usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/plymouth"
     fi
     for _dir in $_dirs; do
-        if [ -x $_dir/plymouth-populate-initrd ]; then
+        if [ -x $dracutsysrootdir$_dir/plymouth-populate-initrd ]; then
             echo $_dir
             return
         fi
@@ -29,12 +29,12 @@ depends() {
 # called by dracut
 install() {
     PKGLIBDIR=$(pkglib_dir)
-    if grep -q nash ${PKGLIBDIR}/plymouth-populate-initrd \
-        || [ ! -x ${PKGLIBDIR}/plymouth-populate-initrd ]; then
+    if grep -q nash $dracutsysrootdir${PKGLIBDIR}/plymouth-populate-initrd \
+        || [ ! -x $dracutsysrootdir${PKGLIBDIR}/plymouth-populate-initrd ]; then
         . "$moddir"/plymouth-populate-initrd.sh
     else
         PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$dracutfunctions" \
-            ${PKGLIBDIR}/plymouth-populate-initrd -t "$initdir"
+            $dracutsysrootdir${PKGLIBDIR}/plymouth-populate-initrd -t "$initdir"
     fi
 
     inst_hook emergency 50 "$moddir"/plymouth-emergency.sh
index e3e0155f6daa94618fc43401110949727da17241..9ced85fdf65b9d31c7f49f0366204c63b961cab7 100755 (executable)
@@ -17,25 +17,25 @@ if [[ $hostonly ]]; then
         "/usr/share/plymouth/themes/details/details.plymouth" \
         "/usr/share/plymouth/themes/text/text.plymouth" \
 
-    if [[ -d /usr/share/plymouth/themes/${PLYMOUTH_THEME} ]]; then
+    if [[ -d $dracutsysrootdir/usr/share/plymouth/themes/${PLYMOUTH_THEME} ]]; then
         for x in "/usr/share/plymouth/themes/${PLYMOUTH_THEME}"/* ; do
-            [[ -f "$x" ]] || break
+            [[ -f "$dracutsysrootdir$x" ]] || break
             inst $x
         done
     fi
 
-    if [ -L /usr/share/plymouth/themes/default.plymouth ]; then
+    if [ -L $dracutsysrootdir/usr/share/plymouth/themes/default.plymouth ]; then
         inst /usr/share/plymouth/themes/default.plymouth
         # Install plugin for this theme
-        PLYMOUTH_PLUGIN=$(grep "^ModuleName=" /usr/share/plymouth/themes/default.plymouth | while read a b c || [ -n "$b" ]; do echo $b; done;)
+        PLYMOUTH_PLUGIN=$(grep "^ModuleName=" $dracutsysrootdir/usr/share/plymouth/themes/default.plymouth | while read a b c || [ -n "$b" ]; do echo $b; done;)
         inst_libdir_file "plymouth/${PLYMOUTH_PLUGIN}.so"
     fi
 else
-    for x in /usr/share/plymouth/themes/{text,details}/* ; do
+    for x in $dracutsysrootdir/usr/share/plymouth/themes/{text,details}/* ; do
         [[ -f "$x" ]] || continue
-        THEME_DIR=$(dirname "$x")
+        THEME_DIR=$(dirname "${x#$dracutsysrootdir}")
         mkdir -m 0755 -p "${initdir}/$THEME_DIR"
-        inst_multiple "$x"
+        inst_multiple "${x#$dracutsysrootdir}"
     done
     (
         cd ${initdir}/usr/share/plymouth/themes;
index 05c93e5a050fbc46fddcabe003d8251dbad22744..780d0c49a0bbbc220f0547dabe2f2b01fc13e902 100755 (executable)
@@ -2,14 +2,14 @@
 
 # called by dracut
 check() {
-    arch=$(uname -m)
+    arch=${DRACUT_ARCH:-$(uname -m)}
     [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1
     return 255
 }
 
 # called by dracut
 depends() {
-    arch=$(uname -m)
+    arch=${DRACUT_ARCH:-$(uname -m)}
     [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1
     echo znet zfcp dasd dasd_mod
     return 0
index 37b414bfcc63b587a79491da79a5d6bc85a67572..b4ab95a0835d2c5efa3285a759642a22e17b8f3d 100755 (executable)
@@ -5,7 +5,7 @@
 # called by dracut
 check() {
 # do not add this module by default
-    local arch=$(uname -m)
+    local arch=${DRACUT_ARCH:-$(uname -m)}
     [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1
     return 0
 }
index bd5bb6a06ef0fe6b8bf811f19184e50a28249718..254e2a5f925e886bea75e29e35acafa227bc9d1f 100755 (executable)
@@ -67,7 +67,7 @@ install() {
         inst_hook cleanup 30 "$moddir/crypt-cleanup.sh"
     fi
 
-    if [[ $hostonly ]] && [[ -f /etc/crypttab ]]; then
+    if [[ $hostonly ]] && [[ -f $dracutsysrootdir/etc/crypttab ]]; then
         # filter /etc/crypttab for the devices we need
         while read _mapper _dev _luksfile _luksoptions || [ -n "$_mapper" ]; do
             [[ $_mapper = \#* ]] && continue
@@ -113,7 +113,7 @@ install() {
                     fi
                 done
             fi
-        done < /etc/crypttab > $initdir/etc/crypttab
+        done < $dracutsysrootdir/etc/crypttab > $initdir/etc/crypttab
         mark_hostonly /etc/crypttab
     fi
 
index 3dfceff077d5c3fe6682e7451e1d56eebe231cee..c376fac35027db1b0a1623de86e650a75c686497 100755 (executable)
@@ -43,7 +43,7 @@ installkernel() {
             virtio virtio_blk virtio_ring virtio_pci virtio_scsi \
             "=drivers/pcmcia" =ide nvme vmd nfit
 
-        if [[ "$(uname -m)" == arm* || "$(uname -m)" == aarch64 ]]; then
+        if [[ "${DRACUT_ARCH:-$(uname -m)}" == arm* || "${DRACUT_ARCH:-$(uname -m)}" == aarch64 ]]; then
             # arm/aarch64 specific modules
             _blockfuncs+='|dw_mc_probe|dw_mci_pltfm_register'
             instmods \
index 600ef1125cf3bb31bd92dc72f0a936ee156123ef..6e4069319f2db1076708be02f15cd8920b07593a 100755 (executable)
@@ -13,7 +13,7 @@ depends() {
 # called by dracut
 installkernel() {
     # Include wired net drivers, excluding wireless
-    local _arch=$(uname -m)
+    local _arch=${DRACUT_ARCH:-$(uname -m)}
     local _net_drivers='eth_type_trans|register_virtio_device|usbnet_open'
     local _unwanted_drivers='/(wireless|isdn|uwb|net/ethernet|net/phy|net/team)/'
 
index 6ca4ee44882984917beb9b0332391e698c8293bf..d6d2c1857932a1df72b9f57081207337add487bc 100755 (executable)
@@ -60,7 +60,7 @@ install() {
     inst_rules "$moddir/64-lvm.rules"
 
     if [[ $hostonly ]] || [[ $lvmconf = "yes" ]]; then
-        if [ -f /etc/lvm/lvm.conf ]; then
+        if [ -f $dracutsysrootdir/etc/lvm/lvm.conf ]; then
             inst_simple -H /etc/lvm/lvm.conf
             # FIXME: near-term hack to establish read-only locking;
             # use command-line lvm.conf editor once it is available
@@ -70,7 +70,7 @@ install() {
 
         export LVM_SUPPRESS_FD_WARNINGS=1
         # Also install any files needed for LVM system id support.
-        if [ -f /etc/lvm/lvmlocal.conf ]; then
+        if [ -f $dracutsysrootdir/etc/lvm/lvmlocal.conf ]; then
             inst_simple -H /etc/lvm/lvmlocal.conf
         fi
         eval $(lvm dumpconfig global/system_id_source &>/dev/null)
index 98a4ef5d522ee1a7d596e9648a3693d28e98310e..f59d84a800e9b824fe69110de5a4a53ca8bc2a2b 100755 (executable)
@@ -104,16 +104,16 @@ install() {
     fi
 
     if [[ $hostonly ]] || [[ $mdadmconf = "yes" ]]; then
-        if [ -f /etc/mdadm.conf ]; then
+        if [ -f $dracutsysrootdir/etc/mdadm.conf ]; then
             inst -H /etc/mdadm.conf
         else
-            [ -f /etc/mdadm/mdadm.conf ] && inst -H /etc/mdadm/mdadm.conf /etc/mdadm.conf
+            [ -f $dracutsysrootdir/etc/mdadm/mdadm.conf ] && inst -H /etc/mdadm/mdadm.conf /etc/mdadm.conf
         fi
-        if [ -d /etc/mdadm.conf.d ]; then
+        if [ -d $dracutsysrootdir/etc/mdadm.conf.d ]; then
             local f
             inst_dir /etc/mdadm.conf.d
             for f in /etc/mdadm.conf.d/*.conf; do
-                [ -f "$f" ] || continue
+                [ -f "$dracutsysrootdir$f" ] || continue
                 inst -H "$f"
             done
         fi
@@ -127,13 +127,13 @@ install() {
     inst_script "$moddir/mdraid-cleanup.sh" /sbin/mdraid-cleanup
     inst_script "$moddir/mdraid_start.sh" /sbin/mdraid_start
     if dracut_module_included "systemd"; then
-        if [ -e $systemdsystemunitdir/mdmon@.service ]; then
+        if [ -e $dracutsysrootdir$systemdsystemunitdir/mdmon@.service ]; then
             inst_simple $systemdsystemunitdir/mdmon@.service
         fi
-        if [ -e $systemdsystemunitdir/mdadm-last-resort@.service ]; then
+        if [ -e $dracutsysrootdir$systemdsystemunitdir/mdadm-last-resort@.service ]; then
             inst_simple $systemdsystemunitdir/mdadm-last-resort@.service
         fi
-        if [ -e $systemdsystemunitdir/mdadm-last-resort@.timer ]; then
+        if [ -e $dracutsysrootdir$systemdsystemunitdir/mdadm-last-resort@.timer ]; then
             inst_simple $systemdsystemunitdir/mdadm-last-resort@.timer
         fi
     fi
index f825c00cd6c9e8ec8a5c1f636b67a7308f82ad46..1f6a55ec3706f8ae43fef52e313be8c00255e5c8 100755 (executable)
@@ -52,7 +52,7 @@ cmdline() {
 # called by dracut
 installkernel() {
     local _ret
-    local _arch=$(uname -m)
+    local _arch=${DRACUT_ARCH:-$(uname -m)}
     local _funcs='scsi_register_device_handler|dm_dirty_log_type_register|dm_register_path_selector|dm_register_target'
     local _s390
 
index f1c6a34bc715f8d91c0045a57499230803e4cdf9..0d99c8a60f4d54dd6c9af8f79e46c9a8ad79634d 100755 (executable)
@@ -30,7 +30,7 @@ install() {
         inst_multiple gpg-agent
         inst_multiple gpg-connect-agent
         inst_multiple /usr/libexec/scdaemon
-        cp "$(sc_public_key)" "${initdir}/root/"
+        cp "$dracutsysrootdir$(sc_public_key)" "${initdir}/root/"
     fi
 }
 
@@ -46,7 +46,7 @@ sc_supported() {
        require_binaries gpg-agent &&
        require_binaries gpg-connect-agent &&
        require_binaries /usr/libexec/scdaemon &&
-       (ldd /usr/libexec/scdaemon | grep libusb > /dev/null); then
+       ($DRACUT_LDD $dracutsysrootdir/usr/libexec/scdaemon | grep libusb > /dev/null); then
         return 0
     else
         return 1
@@ -54,7 +54,7 @@ sc_supported() {
 }
 
 sc_requested() {
-    if [ -f "$(sc_public_key)" ]; then
+    if [ -f "$dracutsysrootdir$(sc_public_key)" ]; then
         return 0
     else
         return 1
index 2f95fd55967465f09c5b47efaff6d7f629f8be2b..f8e912e5ae3d5bc7b2bbef72aac306acb7df568d 100755 (executable)
@@ -4,7 +4,7 @@
 
 # called by dracut
 check() {
-    local _arch=$(uname -m)
+    local _arch=${DRACUT_ARCH:-$(uname -m)}
     # Only for systems on s390 using indirect booting via userland grub
     [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
     # /boot/zipl contains a first stage kernel used to launch grub in initrd
index b6f69846cd0561d8e484e0eee4ad128e9b8966f2..b3747dcc8cef43f6d32a54f8e0d8b4b6a9b4a548 100755 (executable)
@@ -41,7 +41,7 @@ install() {
 
     inst_libdir_file 'libcap-ng.so*'
 
-    _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \
+    _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' $dracutsysrootdir/etc/nsswitch.conf \
         |  tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|')
     _nsslibs=${_nsslibs#|}
     _nsslibs=${_nsslibs%|}
index 0da613091ffabbc4ef5789242e422263bad3b7d8..2c49cd26f8d72fc10ec0fc8a97ff42ada171de37 100755 (executable)
@@ -2,7 +2,7 @@
 
 # called by dracut
 check() {
-    local _arch=$(uname -m)
+    local _arch=${DRACUT_ARCH:-$(uname -m)}
     [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
     require_binaries normalize_dasd_arg || return 1
     return 0
index 1118b79ed39a78aa3e073c1595fc0b9ca79344e4..cf0d858ca73e727a0cba4505e49d8d5f047692f6 100755 (executable)
@@ -2,7 +2,7 @@
 
 # called by dracut
 check() {
-    local _arch=$(uname -m)
+    local _arch=${DRACUT_ARCH:-$(uname -m)}
     [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
     require_binaries grep sed seq
 
index 124dbad979b043cea39e8aed90ba3606db13a746..a9ab7fc1486136abda1be998baf23d31dafa92c8 100755 (executable)
@@ -18,7 +18,7 @@ cmdline() {
 
 # called by dracut
 check() {
-    local _arch=$(uname -m)
+    local _arch=${DRACUT_ARCH:-$(uname -m)}
     local found=0
     local bdev
     [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
index 11e38490867b52ddf2d034b47afdfccae6093365..05c7f5c73424583713032698ff4afa940de4b8eb 100644 (file)
@@ -4,7 +4,7 @@
 
 # called by dracut
 check() {
-    local _arch=$(uname -m)
+    local _arch=${DRACUT_ARCH:-$(uname -m)}
     [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
     return 0
 }
index 6241e59510c0515bbad3a5caa6457d370d9bb06a..93216758a7b716319cfe78240a5745c435224111 100755 (executable)
@@ -18,6 +18,6 @@ install() {
                   tcpdump cp dd less hostname mkdir systemd-analyze \
                   fsck fsck.ext2 fsck.ext4 fsck.ext3 fsck.ext4dev fsck.f2fs fsck.vfat e2fsck
 
-    grep '^tcpdump:' /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
+    grep '^tcpdump:' $dracutsysrootdir/etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
 }
 
index 63f45b527fdb6fdd3bf2b0dcb8cadfbadd1aa52a..73927b4b81709944d72a931d13d6e7ae8f930127 100755 (executable)
@@ -92,7 +92,7 @@ cmdline() {
 # called by dracut
 install() {
     inst_multiple ip dcbtool fipvlan lldpad readlink lldptool fcoemon fcoeadm
-    if [ -e "/etc/hba.conf" ]; then
+    if [ -e "$dracutsysrootdir/etc/hba.conf" ]; then
         inst_libdir_file 'libhbalinux.so*'
         inst_simple "/etc/hba.conf"
     fi
index e588d18f710accc2ab37c4fe6c96523d60d57a4f..d3c1e45778ef5e1e2f09942a64d8f8cd980ed9fe 100755 (executable)
@@ -2,7 +2,7 @@
 
 # called by dracut
 check() {
-    test -f /etc/fstab.sys || [[ -n $add_fstab  ||  -n $fstab_lines ]]
+    test -f $dracutsysrootdir/etc/fstab.sys || [[ -n $add_fstab  ||  -n $fstab_lines ]]
 }
 
 # called by dracut
@@ -12,6 +12,6 @@ depends() {
 
 # called by dracut
 install() {
-    [ -f /etc/fstab.sys ] && inst_simple /etc/fstab.sys
+    [ -f $dracutsysrootdir/etc/fstab.sys ] && inst_simple /etc/fstab.sys
     inst_hook pre-pivot 00 "$moddir/mount-sys.sh"
 }
index 686ed570af50e25907166538b465543e06ea5ab4..b7f07d042577bd4af2ac27693cf6e595acae0b41 100755 (executable)
@@ -188,7 +188,7 @@ depends() {
 
 # called by dracut
 installkernel() {
-    local _arch=$(uname -m)
+    local _arch=${DRACUT_ARCH:-$(uname -m)}
     local _funcs='iscsi_register_transport'
 
     instmods bnx2i qla4xxx cxgb3i cxgb4i be2iscsi qedi
index dce457f4198a99f34359f10e1f1ff9ccdbf34a98..f9bcedd1f221449c5c5f43bc89ceea0952deab15 100755 (executable)
@@ -86,7 +86,7 @@ install() {
         [[ $_netconf ]] && printf "%s\n" "$_netconf" >> "${initdir}/etc/cmdline.d/95nfs.conf"
     fi
 
-    if [ -f /lib/modprobe.d/nfs.conf ]; then
+    if [ -f $dracutsysrootdir/lib/modprobe.d/nfs.conf ]; then
         inst_multiple /lib/modprobe.d/nfs.conf
     else
         [ -d $initdir/etc/modprobe.d/ ] || mkdir $initdir/etc/modprobe.d
@@ -95,7 +95,7 @@ install() {
 
     inst_libdir_file 'libnfsidmap_nsswitch.so*' 'libnfsidmap/*.so' 'libnfsidmap*.so*'
 
-    _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \
+    _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' $dracutsysrootdir/etc/nsswitch.conf \
         |  tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|')
     _nsslibs=${_nsslibs#|}
     _nsslibs=${_nsslibs%|}
@@ -113,13 +113,13 @@ install() {
 
     # Rather than copy the passwd file in, just set a user for rpcbind
     # We'll save the state and restart the daemon from the root anyway
-    grep -E '^nfsnobody:|^rpc:|^rpcuser:' /etc/passwd >> "$initdir/etc/passwd"
-    grep -E '^nogroup:|^rpc:|^nobody:' /etc/group >> "$initdir/etc/group"
+    grep -E '^nfsnobody:|^rpc:|^rpcuser:' $dracutsysrootdir/etc/passwd >> "$initdir/etc/passwd"
+    grep -E '^nogroup:|^rpc:|^nobody:' $dracutsysrootdir/etc/group >> "$initdir/etc/group"
 
     # rpc user needs to be able to write to this directory to save the warmstart
     # file
     chmod 770 "$initdir/var/lib/rpcbind"
-    grep -q '^rpc:' /etc/passwd \
-        && grep -q '^rpc:' /etc/group
+    grep -q '^rpc:' $dracutsysrootdir/etc/passwd \
+        && grep -q '^rpc:' $dracutsysrootdir/etc/group
     dracut_need_initqueue
 }
index d4d15118339cc7ec874b666c6844bc996adb31b3..543dd239dd677175839e089140554b6752a386c0 100755 (executable)
@@ -2,7 +2,7 @@
 
 # called by dracut
 check() {
-    local _arch=$(uname -m)
+    local _arch=${DRACUT_ARCH:-$(uname -m)}
     local _online=0
     [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
     require_binaries /usr/lib/udev/collect || return 1
index 7fe6df3a3ee20acd361c44f8bcbb72cbed595902..6ddc7259b623d571eaf43724392a2f3fce72d444 100755 (executable)
@@ -34,7 +34,7 @@ install() {
     fi
 
     # if systemd is included and has the hibernate-resume tool, use it and nothing else
-    if dracut_module_included "systemd" && [[ -x $systemdutildir/systemd-hibernate-resume ]]; then
+    if dracut_module_included "systemd" && [[ -x $dracutsysrootdir$systemdutildir/systemd-hibernate-resume ]]; then
         inst_multiple -o \
                       $systemdutildir/system-generators/systemd-hibernate-resume-generator \
                       $systemdsystemunitdir/systemd-hibernate-resume@.service \
@@ -45,9 +45,9 @@ install() {
     # Optional uswsusp support
     for _bin in /usr/sbin/resume /usr/lib/suspend/resume /usr/lib/uswsusp/resume
     do
-        [[ -x "${_bin}" ]] && {
+        [[ -x "$dracutsysrootdir${_bin}" ]] && {
             inst "${_bin}" /usr/sbin/resume
-            [[ $hostonly ]] && [[ -f /etc/suspend.conf ]] && inst -H /etc/suspend.conf
+            [[ $hostonly ]] && [[ -f $dracutsysrootdir/etc/suspend.conf ]] && inst -H /etc/suspend.conf
             break
         }
     done
index 672de5023ed8e707e8ba0da3687f542418e5b047..c6d26d9db77cc6b41e8c2e70af22124e6a0b04b0 100755 (executable)
@@ -10,7 +10,7 @@ check() {
     require_binaries ssh scp  || return 1
 
     if [[ $sshkey ]]; then
-        [ ! -f $sshkey ] && {
+        [ ! -f $dracutsysrootdir$sshkey ] && {
             derror "ssh key: $sshkey is not found!"
             return 1
         }
@@ -27,7 +27,7 @@ depends() {
 
 inst_sshenv()
 {
-    if [ -d /root/.ssh ]; then
+    if [ -d $dracutsysrootdir/root/.ssh ]; then
         inst_dir /root/.ssh
         chmod 700 ${initdir}/root/.ssh
     fi
@@ -35,13 +35,13 @@ inst_sshenv()
     # Copy over ssh key and knowhosts if needed
     [[ $sshkey ]] && {
         inst_simple $sshkey
-        [[ -f /root/.ssh/known_hosts ]] && inst_simple /root/.ssh/known_hosts
-        [[ -f /etc/ssh/ssh_known_hosts ]] && inst_simple /etc/ssh/ssh_known_hosts
+        [[ -f $dracutsysrootdir/root/.ssh/known_hosts ]] && inst_simple /root/.ssh/known_hosts
+        [[ -f $dracutsysrootdir/etc/ssh/ssh_known_hosts ]] && inst_simple /etc/ssh/ssh_known_hosts
     }
 
     # Copy over root and system-wide ssh configs.
-    [[ -f /root/.ssh/config ]] && inst_simple /root/.ssh/config
-    if [[ -f /etc/ssh/ssh_config ]]; then
+    [[ -f $dracutsysrootdir/root/.ssh/config ]] && inst_simple /root/.ssh/config
+    if [[ -f $dracutsysrootdir/etc/ssh/ssh_config ]]; then
         inst_simple /etc/ssh/ssh_config
         sed -i -e 's/\(^[[:space:]]*\)ProxyCommand/\1# ProxyCommand/' ${initdir}/etc/ssh/ssh_config
         while read key val || [ -n "$key" ]; do
@@ -55,7 +55,7 @@ inst_sshenv()
                 fi
                 inst_simple "$val"
             fi
-        done < /etc/ssh/ssh_config
+        done < $dracutsysrootdir/etc/ssh/ssh_config
     fi
 
     return 0
@@ -68,7 +68,7 @@ install() {
     inst_multiple ssh scp
     inst_sshenv
 
-    _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \
+    _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' $dracutsysrootdir/etc/nsswitch.conf \
         |  tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|')
     _nsslibs=${_nsslibs#|}
     _nsslibs=${_nsslibs%|}
index 1b572fab7808457d9d097c357ea0be73317b9420..532f5bde3675f876f85399004fe9ed136d33f295 100755 (executable)
@@ -5,13 +5,13 @@ install() {
     local _terminfodir
     # terminfo bits make things work better if you fall into interactive mode
     for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
-        [ -f ${_terminfodir}/l/linux ] && break
+        [ -f $dracutsysrootdir${_terminfodir}/l/linux ] && break
     done
 
-    if [ -d ${_terminfodir} ]; then
+    if [ -d $dracutsysrootdir${_terminfodir} ]; then
         for i in "l/linux" "v/vt100" "v/vt102" "v/vt220"; do
             inst_dir "$_terminfodir/${i%/*}"
-            $DRACUT_CP -L -t "${initdir}/${_terminfodir}/${i%/*}" "$_terminfodir/$i"
+            $DRACUT_CP -L -t "${initdir}/${_terminfodir}/${i%/*}" "$dracutsysrootdir$_terminfodir/$i"
         done
     fi
 }
index a59eca2a1cf2e26304a9f21841ddb05f48dd970d..4e8237bd0714b8b5d1eeebdb248fc3f3d6f64b50 100755 (executable)
@@ -13,7 +13,7 @@ install() {
 
     [ -d ${initdir}/$systemdutildir ] || mkdir -p ${initdir}/$systemdutildir
     for _i in ${systemdutildir}/systemd-udevd ${udevdir}/udevd /sbin/udevd; do
-        [ -x "$_i" ] || continue
+        [ -x "$dracutsysrootdir$_i" ] || continue
         inst "$_i"
 
         if ! [[ -f  ${initdir}${systemdutildir}/systemd-udevd ]]; then
@@ -64,7 +64,7 @@ install() {
     {
         for i in cdrom tape dialout floppy; do
             if ! grep -q "^$i:" "$initdir/etc/group" 2>/dev/null; then
-                if ! grep "^$i:" /etc/group 2>/dev/null; then
+                if ! grep "^$i:" $dracutsysrootdir/etc/group 2>/dev/null; then
                         case $i in
                             cdrom)   echo "$i:x:11:";;
                             dialout) echo "$i:x:18:";;
@@ -96,7 +96,7 @@ install() {
 
     inst_multiple -o /etc/pcmcia/config.opts
 
-    [ -f /etc/arch-release ] && \
+    [ -f $dracutsysrootdir/etc/arch-release ] && \
         inst_script "$moddir/load-modules.sh" /lib/udev/load-modules.sh
 
     inst_libdir_file "libnss_files*"
index cfbf48a1a0d241b6f6cd7ae7535812eafa56d97e..e1f3aa35a01335f1cc5d52d7fa00aee16221e620 100755 (executable)
@@ -2,7 +2,7 @@
 
 # called by dracut
 check() {
-    arch=$(uname -m)
+    arch=${DRACUT_ARCH:-$(uname -m)}
     [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1
 
     require_binaries zfcp_cio_free grep sed seq || return 1
index fc55e69ac267018010ca919c4cfeef58c69df9c2..5ffc9e4011acad814bb17377074d6715215ea531 100755 (executable)
@@ -38,7 +38,7 @@ cmdline() {
 
 # called by dracut
 check() {
-    local _arch=$(uname -m)
+    local _arch=${DRACUT_ARCH:-$(uname -m)}
     local _ccw
     [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
     require_binaries /usr/lib/udev/collect || return 1
index ebe740e326adf05939964a3d87e00bcaea51804d..89341c02cc65f7c132d4aec681cda7b0e753ca35 100755 (executable)
@@ -2,7 +2,7 @@
 
 # called by dracut
 check() {
-    arch=$(uname -m)
+    arch=${DRACUT_ARCH:-$(uname -m)}
     [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1
 
     require_binaries znet_cio_free grep sed seq readlink || return 1
index 36793ce3d848cd03326e1f4d4e8db11c2dba2a82..3a2246b400c9953cd22def3de4159c6dbc07b642 100755 (executable)
@@ -16,8 +16,8 @@ install() {
     local _d
 
     inst_multiple mount mknod mkdir sleep chroot chown \
-        sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink setsid
-    inst $(command -v modprobe) /sbin/modprobe
+        sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink setsid \
+        modprobe
 
     inst_multiple -o findmnt less kmod
 
@@ -30,9 +30,9 @@ install() {
     # use password for hostonly images to facilitate secure sulogin in emergency console
     [[ $hostonly ]] && pwshadow='x'
     grep '^root:' "$initdir/etc/passwd" 2>/dev/null || echo  "root:$pwshadow:0:0::/root:/bin/sh" >> "$initdir/etc/passwd"
-    grep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
+    grep '^nobody:' $dracutsysrootdir/etc/passwd >> "$initdir/etc/passwd"
 
-    [[ $hostonly ]] && grep '^root:' /etc/shadow >> "$initdir/etc/shadow"
+    [[ $hostonly ]] && grep '^root:' $dracutsysrootdir/etc/shadow >> "$initdir/etc/shadow"
 
     # install our scripts and hooks
     inst_script "$moddir/init.sh" "/init"
@@ -72,9 +72,9 @@ install() {
     local VERSION=""
     local PRETTY_NAME=""
     # Derive an os-release file from the host, if it exists
-    if [ -e /etc/os-release ]; then
-        . /etc/os-release
-        grep -hE -ve '^VERSION=' -ve '^PRETTY_NAME' /etc/os-release >${initdir}/usr/lib/initrd-release
+    if [ -e $dracutsysrootdir/etc/os-release ]; then
+        . $dracutsysrootdir/etc/os-release
+        grep -hE -ve '^VERSION=' -ve '^PRETTY_NAME' $dracutsysrootdir/etc/os-release >${initdir}/usr/lib/initrd-release
         [[ -n ${VERSION} ]] && VERSION+=" "
         [[ -n ${PRETTY_NAME} ]] && PRETTY_NAME+=" "
     else
index 22888847136cbd417b649185559b4c49758fdf71..8b4fe040078c5cac3d6836d1509507e2abbab729 100755 (executable)
@@ -81,7 +81,7 @@ install() {
         _helpers="$fscks"
     fi
 
-    if [[ "$_helpers" == *e2fsck* ]] && [ -e /etc/e2fsck.conf ]; then
+    if [[ "$_helpers" == *e2fsck* ]] && [ -e $dracutsysrootdir/etc/e2fsck.conf ]; then
         inst_simple /etc/e2fsck.conf
     fi