Browse Source

style: shfmt reformat

reproducible with:

```
$ shfmt_version=3.0.1
$ wget "https://github.com/mvdan/sh/releases/download/v${shfmt_version}/shfmt_v${shfmt_version}_linux_amd64" -O shfmt
$ chmod u+x shfmt
$ ./shfmt -w .
```
master
Harald Hoyer 3 years ago committed by Harald Hoyer
parent
commit
9a52c3fdb0
  1. 70
      configure
  2. 122
      dracut-bash-completion.sh
  3. 54
      dracut-catimages.sh
  4. 251
      dracut-functions.sh
  5. 148
      dracut-init.sh
  6. 18
      dracut-initramfs-restore.sh
  7. 127
      dracut-logger.sh
  8. 978
      dracut.sh
  9. 14
      examples/yocto/postinst-intercepts/execute_dracut
  10. 14
      fedora-test-github.sh
  11. 14
      fedora-test.sh
  12. 80
      lsinitrd-bash-completion.sh
  13. 137
      lsinitrd.sh
  14. 176
      mkinitrd-dracut.sh
  15. 253
      mkinitrd-suse.sh
  16. 1
      modules.d/00bash/module-setup.sh
  17. 1
      modules.d/00dash/module-setup.sh
  18. 1
      modules.d/00mksh/module-setup.sh
  19. 30
      modules.d/00systemd/module-setup.sh
  20. 10
      modules.d/00warpclock/warpclock.sh
  21. 4
      modules.d/01fips/fips-boot.sh
  22. 2
      modules.d/01fips/fips-load-crypto.sh
  23. 2
      modules.d/01fips/fips-noboot.sh
  24. 44
      modules.d/01fips/fips.sh
  25. 44
      modules.d/01systemd-ask-password/module-setup.sh
  26. 5
      modules.d/01systemd-coredump/module-setup.sh
  27. 30
      modules.d/01systemd-modules-load/module-setup.sh
  28. 12
      modules.d/01systemd-sysusers/module-setup.sh
  29. 3
      modules.d/02caps/caps.sh
  30. 3
      modules.d/02caps/module-setup.sh
  31. 36
      modules.d/02systemd-networkd/module-setup.sh
  32. 2
      modules.d/03modsign/load-modsign-keys.sh
  33. 2
      modules.d/03modsign/module-setup.sh
  34. 1
      modules.d/03rescue/module-setup.sh
  35. 14
      modules.d/04watchdog/module-setup.sh
  36. 16
      modules.d/04watchdog/watchdog.sh
  37. 1
      modules.d/05busybox/module-setup.sh
  38. 1
      modules.d/06dbus-broker/module-setup.sh
  39. 4
      modules.d/06dbus-daemon/module-setup.sh
  40. 6
      modules.d/09dbus/module-setup.sh
  41. 9
      modules.d/10i18n/console_init.sh
  42. 118
      modules.d/10i18n/module-setup.sh
  43. 25
      modules.d/10i18n/parse-i18n.sh
  44. 9
      modules.d/30convertfs/convertfs.sh
  45. 1
      modules.d/30convertfs/module-setup.sh
  46. 64
      modules.d/35network-legacy/dhclient-script.sh
  47. 40
      modules.d/35network-legacy/dhcp-multi.sh
  48. 153
      modules.d/35network-legacy/ifup.sh
  49. 8
      modules.d/35network-legacy/kill-dhclient.sh
  50. 3
      modules.d/35network-legacy/module-setup.sh
  51. 18
      modules.d/35network-legacy/net-genrules.sh
  52. 30
      modules.d/35network-legacy/parse-bond.sh
  53. 14
      modules.d/35network-legacy/parse-bridge.sh
  54. 6
      modules.d/35network-legacy/parse-ibft.sh
  55. 4
      modules.d/35network-legacy/parse-ifname.sh
  56. 69
      modules.d/35network-legacy/parse-ip-opts.sh
  57. 27
      modules.d/35network-legacy/parse-team.sh
  58. 7
      modules.d/35network-legacy/parse-vlan.sh
  59. 2
      modules.d/35network-manager/nm-config.sh
  60. 13
      modules.d/35network-manager/nm-lib.sh
  61. 27
      modules.d/35network-manager/nm-run.sh
  62. 2
      modules.d/35network-wicked/module-setup.sh
  63. 4
      modules.d/40network/ifname-genrules.sh
  64. 30
      modules.d/40network/module-setup.sh
  65. 289
      modules.d/40network/net-lib.sh
  66. 14
      modules.d/40network/netroot.sh
  67. 1
      modules.d/45ifcfg/module-setup.sh
  68. 23
      modules.d/45ifcfg/write-ifcfg.sh
  69. 15
      modules.d/45url-lib/module-setup.sh
  70. 29
      modules.d/45url-lib/url-lib.sh
  71. 6
      modules.d/50drm/module-setup.sh
  72. 8
      modules.d/50gensplash/module-setup.sh
  73. 3
      modules.d/50plymouth/module-setup.sh
  74. 2
      modules.d/50plymouth/plymouth-emergency.sh
  75. 2
      modules.d/50plymouth/plymouth-newroot.sh
  76. 12
      modules.d/50plymouth/plymouth-populate-initrd.sh
  77. 6
      modules.d/50plymouth/plymouth-pretrigger.sh
  78. 59
      modules.d/80cms/cms-write-ifcfg.sh
  79. 26
      modules.d/80cms/cmsifup.sh
  80. 56
      modules.d/80cms/cmssetup.sh
  81. 13
      modules.d/80lvmmerge/lvmmerge.sh
  82. 16
      modules.d/81cio_ignore/module-setup.sh
  83. 6
      modules.d/81cio_ignore/parse-cio_accept.sh
  84. 6
      modules.d/90btrfs/btrfs_device_ready.sh
  85. 8
      modules.d/90btrfs/btrfs_finished.sh
  86. 4
      modules.d/90btrfs/btrfs_timeout.sh
  87. 6
      modules.d/90btrfs/module-setup.sh
  88. 6
      modules.d/90crypt/crypt-cleanup.sh
  89. 96
      modules.d/90crypt/crypt-lib.sh
  90. 4
      modules.d/90crypt/crypt-run-generator.sh
  91. 2
      modules.d/90crypt/cryptroot-ask.sh
  92. 40
      modules.d/90crypt/module-setup.sh
  93. 9
      modules.d/90crypt/parse-crypt.sh
  94. 6
      modules.d/90crypt/parse-keydev.sh
  95. 5
      modules.d/90crypt/probe-keydev.sh
  96. 2
      modules.d/90dm/dm-pre-udev.sh
  97. 10
      modules.d/90dm/dm-shutdown.sh
  98. 5
      modules.d/90dm/module-setup.sh
  99. 10
      modules.d/90dmraid/dmraid.sh
  100. 2
      modules.d/90dmraid/module-setup.sh
  101. Some files were not shown because too many files have changed in this diff Show More

70
configure vendored

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash


# We don't support srcdir != builddir # We don't support srcdir != builddir
echo \#buildapi-variable-no-builddir >/dev/null echo \#buildapi-variable-no-builddir > /dev/null


prefix=/usr prefix=/usr


@ -31,24 +31,24 @@ read_arg() {


while (($# > 0)); do while (($# > 0)); do
case "${1%%=*}" in case "${1%%=*}" in
--prefix) read_arg prefix "$@" || shift;; --prefix) read_arg prefix "$@" || shift ;;
--libdir) read_arg libdir "$@" || shift;; --libdir) read_arg libdir "$@" || shift ;;
--datadir) read_arg datadir "$@" || shift;; --datadir) read_arg datadir "$@" || shift ;;
--sysconfdir) read_arg sysconfdir "$@" || shift;; --sysconfdir) read_arg sysconfdir "$@" || shift ;;
--sbindir) read_arg sbindir "$@" || shift;; --sbindir) read_arg sbindir "$@" || shift ;;
--mandir) read_arg mandir "$@" || shift;; --mandir) read_arg mandir "$@" || shift ;;
--disable-documentation) enable_documentation=no;; --disable-documentation) enable_documentation=no ;;
--program-prefix) read_arg programprefix "$@" || shift;; --program-prefix) read_arg programprefix "$@" || shift ;;
--exec-prefix) read_arg execprefix "$@" || shift;; --exec-prefix) read_arg execprefix "$@" || shift ;;
--bindir) read_arg bindir "$@" || shift;; --bindir) read_arg bindir "$@" || shift ;;
--includedir) read_arg includedir "$@" || shift;; --includedir) read_arg includedir "$@" || shift ;;
--libexecdir) read_arg libexecdir "$@" || shift;; --libexecdir) read_arg libexecdir "$@" || shift ;;
--localstatedir) read_arg localstatedir "$@" || shift;; --localstatedir) read_arg localstatedir "$@" || shift ;;
--sharedstatedir) read_arg sharedstatedir "$@" || shift;; --sharedstatedir) read_arg sharedstatedir "$@" || shift ;;
--infodir) read_arg infodir "$@" || shift;; --infodir) read_arg infodir "$@" || shift ;;
--systemdsystemunitdir) read_arg systemdsystemunitdir "$@" || shift;; --systemdsystemunitdir) read_arg systemdsystemunitdir "$@" || shift ;;
--bashcompletiondir) read_arg bashcompletiondir "$@" || shift;; --bashcompletiondir) read_arg bashcompletiondir "$@" || shift ;;
*) echo "Ignoring unknown option '$1'";; *) echo "Ignoring unknown option '$1'" ;;
esac esac
shift shift
done done
@ -58,7 +58,7 @@ if ! ${PKG_CONFIG} --exists --print-errors " libkmod >= 23 "; then
exit 1 exit 1
fi fi


cat <<EOF >conftest.c cat << EOF > conftest.c
#include <fts.h> #include <fts.h>
int main() { int main() {
return 0; return 0;
@ -66,17 +66,17 @@ int main() {
EOF EOF


# shellcheck disable=SC2086 # shellcheck disable=SC2086
${CC} $CFLAGS $LDFLAGS conftest.c >/dev/null 2>&1 ${CC} $CFLAGS $LDFLAGS conftest.c > /dev/null 2>&1
ret=$? ret=$?
rm -f conftest.c a.out rm -f conftest.c a.out


# musl doesn't have fts.h included # musl doesn't have fts.h included
if test $ret -ne 0; then if test $ret -ne 0; then
echo "dracut needs fts development files." >&2 echo "dracut needs fts development files." >&2
exit 1 exit 1
fi fi


cat <<EOF >conftest.c cat << EOF > conftest.c
#include <fts.h> #include <fts.h>
int main(void) { int main(void) {
fts_open(0, 0, 0); fts_open(0, 0, 0);
@ -86,23 +86,23 @@ EOF


found=no found=no
for lib in "-lc" "-lfts"; do for lib in "-lc" "-lfts"; do
# shellcheck disable=SC2086 # shellcheck disable=SC2086
${CC} $CFLAGS $LDFLAGS conftest.c -Wl,$lib >/dev/null 2>&1 ${CC} $CFLAGS $LDFLAGS conftest.c -Wl,$lib > /dev/null 2>&1
ret=$? ret=$?
if test $ret -eq 0; then if test $ret -eq 0; then
FTS_LIBS="$lib" FTS_LIBS="$lib"
found=yes found=yes
break; break
fi fi
done done
rm -f conftest.c a.out rm -f conftest.c a.out


if test $found = no; then if test $found = no; then
echo "dracut couldn't find usable fts library" >&2 echo "dracut couldn't find usable fts library" >&2
exit 1 exit 1
fi fi


cat > Makefile.inc.$$ <<EOF cat > Makefile.inc.$$ << EOF
prefix ?= ${prefix} prefix ?= ${prefix}
libdir ?= ${libdir:-${prefix}/lib} libdir ?= ${libdir:-${prefix}/lib}
datadir ?= ${datadir:-${prefix}/share} datadir ?= ${datadir:-${prefix}/share}

122
dracut-bash-completion.sh

@ -15,16 +15,17 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #


__contains_word () { __contains_word() {
local word="$1"; shift local word="$1"
for w in "$@"; do [[ $w = "$word" ]] && return 0; done shift
return 1 for w in "$@"; do [[ $w = "$word" ]] && return 0; done
return 1
} }


_dracut() { _dracut() {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD - 1]}
local -A OPTS=( local -A OPTS=(
[STANDALONE]='-f -v -q -l -H -h -M -N [STANDALONE]='-f -v -q -l -H -h -M -N
--ro-mnt --force --kernel-only --no-kernel --strip --nostrip --ro-mnt --force --kernel-only --no-kernel --strip --nostrip
--hardlink --nohardlink --noprefix --mdadmconf --nomdadmconf --hardlink --nohardlink --noprefix --mdadmconf --nomdadmconf
--lvmconf --nolvmconf --debug --profile --verbose --quiet --lvmconf --nolvmconf --debug --profile --verbose --quiet
@ -32,65 +33,74 @@ _dracut() {
--xz --zstd --no-compress --gzip --list-modules --show-modules --keep --xz --zstd --no-compress --gzip --list-modules --show-modules --keep
--printsize --regenerate-all --noimageifnotneeded --early-microcode --printsize --regenerate-all --noimageifnotneeded --early-microcode
--no-early-microcode --print-cmdline --reproducible --uefi' --no-early-microcode --print-cmdline --reproducible --uefi'
[ARG]='-a -m -o -d -I -k -c -L --kver --add --force-add --add-drivers [ARG]='-a -m -o -d -I -k -c -L --kver --add --force-add --add-drivers
--omit-drivers --modules --omit --drivers --filesystems --install --omit-drivers --modules --omit --drivers --filesystems --install
--fwdir --libdirs --fscks --add-fstab --mount --device --nofscks --fwdir --libdirs --fscks --add-fstab --mount --device --nofscks
--kmoddir --conf --confdir --tmpdir --stdlog --compress --prefix --kmoddir --conf --confdir --tmpdir --stdlog --compress --prefix
--kernel-cmdline --sshkey --persistent-policy --install-optional --kernel-cmdline --sshkey --persistent-policy --install-optional
--loginstall --uefi-stub --kernel-image --loginstall --uefi-stub --kernel-image
' '
) )


# shellcheck disable=SC2086 # shellcheck disable=SC2086
if __contains_word "$prev" ${OPTS[ARG]}; then if __contains_word "$prev" ${OPTS[ARG]}; then
case $prev in case $prev in
--kmoddir|-k|--fwdir|--confdir|--tmpdir) --kmoddir | -k | --fwdir | --confdir | --tmpdir)
comps=$(compgen -d -- "$cur") comps=$(compgen -d -- "$cur")
compopt -o filenames compopt -o filenames
;; ;;
-c|--conf|--sshkey|--add-fstab|--add-device|-I|--install|--install-optional) -c | --conf | --sshkey | --add-fstab | --add-device | -I | --install | --install-optional)
comps=$(compgen -f -- "$cur") comps=$(compgen -f -- "$cur")
compopt -o filenames compopt -o filenames
;; ;;
-a|-m|-o|--add|--modules|--omit) -a | -m | -o | --add | --modules | --omit)
comps=$(dracut --list-modules 2>/dev/null) comps=$(dracut --list-modules 2> /dev/null)
;; ;;
--persistent-policy) --persistent-policy)
comps=$(cd /dev/disk/ || return 0; printf -- "%s " *) comps=$(
;; cd /dev/disk/ || return 0
--kver) printf -- "%s " *
comps=$(cd /lib/modules || return 0; echo [0-9]*) )
;; ;;
*) --kver)
return 0 comps=$(
;; cd /lib/modules || return 0
esac echo [0-9]*
# shellcheck disable=SC2207 )
# shellcheck disable=SC2016 ;;
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) *)
return 0 return 0
fi ;;
esac
# shellcheck disable=SC2207
# shellcheck disable=SC2016
COMPREPLY=($(compgen -W '$comps' -- "$cur"))
return 0
fi


if [[ $cur = -* ]]; then if [[ $cur = -* ]]; then
# shellcheck disable=SC2207 # shellcheck disable=SC2207
# shellcheck disable=SC2016 # shellcheck disable=SC2016
COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) COMPREPLY=($(compgen -W '${OPTS[*]}' -- "$cur"))
return 0 return 0
fi fi


local args local args
_count_args _count_args
if [[ $args -eq 1 ]]; then if [[ $args -eq 1 ]]; then
_filedir _filedir
return 0 return 0
elif [[ $args -eq 2 ]]; then elif [[ $args -eq 2 ]]; then
# shellcheck disable=SC2034 # shellcheck disable=SC2034
comps=$(cd /lib/modules || return 0; echo [0-9]*) comps=$(
# shellcheck disable=SC2207 cd /lib/modules || return 0
# shellcheck disable=SC2016 echo [0-9]*
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) )
return 0 # shellcheck disable=SC2207
fi # shellcheck disable=SC2016
COMPREPLY=($(compgen -W '$comps' -- "$cur"))
return 0
fi
} }


complete -F _dracut dracut complete -F _dracut dracut

54
dracut-catimages.sh

@ -16,7 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #



dwarning() { dwarning() {
echo "Warning: $*" >&2 echo "Warning: $*" >&2
} }
@ -49,27 +48,46 @@ line and /boot/dracut/
EOF EOF
} }



imagedir=/boot/dracut/ imagedir=/boot/dracut/
overlay=/var/lib/dracut/overlay overlay=/var/lib/dracut/overlay


while (($# > 0)); do while (($# > 0)); do
case $1 in case $1 in
-f|--force) force=yes;; -f | --force) force=yes ;;
-i|--imagedir) imagedir=$2;shift;; -i | --imagedir)
-o|--overlaydir) overlay=$2;shift;; imagedir=$2
--nooverlay) no_overlay=yes;shift;; shift
--noimagedir) no_imagedir=yes;shift;; ;;
-h|--help) usage; exit 1 ;; -o | --overlaydir)
--debug) export debug="yes";; overlay=$2
-v|--verbose) beverbose="yes";; shift
-*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage; exit 1;; ;;
--nooverlay)
no_overlay=yes
shift
;;
--noimagedir)
no_imagedir=yes
shift
;;
-h | --help)
usage
exit 1
;;
--debug) export debug="yes" ;;
-v | --verbose) beverbose="yes" ;;
-*)
printf "\nUnknown option: %s\n\n" "$1" >&2
usage
exit 1
;;
*) break ;; *) break ;;
esac esac
shift shift
done done


outfile=$1; shift outfile=$1
shift


if [[ -z $outfile ]]; then if [[ -z $outfile ]]; then
derror "No output file specified." derror "No output file specified."
@ -77,7 +95,8 @@ if [[ -z $outfile ]]; then
exit 1 exit 1
fi fi


baseimage=$1; shift baseimage=$1
shift


if [[ -z $baseimage ]]; then if [[ -z $baseimage ]]; then
derror "No base image specified." derror "No base image specified."
@ -103,8 +122,11 @@ fi
if [[ ! $no_overlay ]]; then if [[ ! $no_overlay ]]; then
ofile="$imagedir/90-overlay.img" ofile="$imagedir/90-overlay.img"
dinfo "Creating image $ofile from directory $overlay" dinfo "Creating image $ofile from directory $overlay"
type pigz &>/dev/null && gzip=pigz || gzip=gzip type pigz &> /dev/null && gzip=pigz || gzip=gzip
( cd "$overlay" || return 1 ; find . |cpio --quiet -H newc -o |$gzip -9 > "$ofile"; ) (
cd "$overlay" || return 1
find . | cpio --quiet -H newc -o | $gzip -9 > "$ofile"
)
fi fi


if [[ ! $no_imagedir ]]; then if [[ ! $no_imagedir ]]; then
@ -113,7 +135,7 @@ if [[ ! $no_imagedir ]]; then
done done
fi fi


images+=( "$@" ) images+=("$@")


dinfo "Using base image $baseimage" dinfo "Using base image $baseimage"
cat -- "$baseimage" > "$outfile" cat -- "$baseimage" > "$outfile"

251
dracut-functions.sh

@ -25,7 +25,6 @@ is_func() {
[[ "$(type -t "$1")" = "function" ]] [[ "$(type -t "$1")" = "function" ]]
} }



# Generic substring function. If $2 is in $1, return 0. # Generic substring function. If $2 is in $1, return 0.
strstr() { [[ $1 = *"$2"* ]]; } strstr() { [[ $1 = *"$2"* ]]; }
# Generic glob matching function. If glob pattern $2 matches anywhere in $1, OK # Generic glob matching function. If glob pattern $2 matches anywhere in $1, OK
@ -49,15 +48,15 @@ find_binary() {


if [[ "$1" == *.so* ]]; then if [[ "$1" == *.so* ]]; then
# shellcheck disable=SC2154 # shellcheck disable=SC2154
for l in $libdirs ; do for l in $libdirs; do
_path="${l}${_delim}${1}" _path="${l}${_delim}${1}"
if { $DRACUT_LDD "${dracutsysrootdir}${_path}" &>/dev/null; }; then if { $DRACUT_LDD "${dracutsysrootdir}${_path}" &> /dev/null; }; then
printf "%s\n" "${_path}" printf "%s\n" "${_path}"
return 0 return 0
fi fi
done done
_path="${_delim}${1}" _path="${_delim}${1}"
if { $DRACUT_LDD "${dracutsysrootdir}${_path}" &>/dev/null; }; then if { $DRACUT_LDD "${dracutsysrootdir}${_path}" &> /dev/null; }; then
printf "%s\n" "${_path}" printf "%s\n" "${_path}"
return 0 return 0
fi fi
@ -69,9 +68,9 @@ find_binary() {
return 0 return 0
fi fi
fi fi
for p in $DRACUT_PATH ; do for p in $DRACUT_PATH; do
_path="${p}${_delim}${1}" _path="${p}${_delim}${1}"
if [[ -L ${dracutsysrootdir}${_path} ]] || [[ -x ${dracutsysrootdir}${_path} ]]; then if [[ -L ${dracutsysrootdir}${_path} ]] || [[ -x ${dracutsysrootdir}${_path} ]]; then
printf "%s\n" "${_path}" printf "%s\n" "${_path}"
return 0 return 0
fi fi
@ -81,9 +80,8 @@ find_binary() {
type -P "${1##*/}" type -P "${1##*/}"
} }


ldconfig_paths() ldconfig_paths() {
{ $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
$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. # Version comparision function. Assumes Linux style version scheme.
@ -98,23 +96,26 @@ vercmp() {
read -a _n2 <<< "${3//./ }" read -a _n2 <<< "${3//./ }"
local _i _res local _i _res


for ((_i=0; ; _i++)) for ((_i = 0; ; _i++)); do
do if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then
if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then _res=0 _res=0
elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then _res=1 elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then
elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then _res=2 _res=1
else continue elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then
_res=2
else
continue
fi fi
break break
done done


case $_op in case $_op in
gt) ((_res == 1));; gt) ((_res == 1)) ;;
ge) ((_res != 2));; ge) ((_res != 2)) ;;
eq) ((_res == 0));; eq) ((_res == 0)) ;;
le) ((_res != 1));; le) ((_res != 1)) ;;
lt) ((_res == 2));; lt) ((_res == 2)) ;;
ne) ((_res != 0));; ne) ((_res != 0)) ;;
esac esac
} }


@ -130,8 +131,7 @@ mksubdirs() {
print_vars() { print_vars() {
local _var _value local _var _value


for _var in "$@" for _var in "$@"; do
do
eval printf -v _value "%s" \""\$$_var"\" eval printf -v _value "%s" \""\$$_var"\"
[[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value" [[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
done done
@ -163,10 +163,16 @@ convert_abs_rel() {
set -- "$(normalize_path "$1")" "$(normalize_path "$2")" set -- "$(normalize_path "$1")" "$(normalize_path "$2")"


# corner case #1 - self looping link # corner case #1 - self looping link
[[ "$1" == "$2" ]] && { printf "%s\n" "${1##*/}"; return; } [[ "$1" == "$2" ]] && {
printf "%s\n" "${1##*/}"
return
}


# corner case #2 - own dir link # corner case #2 - own dir link
[[ "${1%/*}" == "$2" ]] && { printf ".\n"; return; } [[ "${1%/*}" == "$2" ]] && {
printf ".\n"
return
}


read -d '/' -r -a __current <<< "$1" read -d '/' -r -a __current <<< "$1"
read -d '/' -a __absolute <<< "$2" read -d '/' -a __absolute <<< "$2"
@ -174,28 +180,22 @@ convert_abs_rel() {
__abssize=${#__absolute[@]} __abssize=${#__absolute[@]}
__cursize=${#__current[@]} __cursize=${#__current[@]}


while [[ "${__absolute[__level]}" == "${__current[__level]}" ]] while [[ "${__absolute[__level]}" == "${__current[__level]}" ]]; do
do ((__level++))
(( __level++ )) if ((__level > __abssize || __level > __cursize)); then
if (( __level > __abssize || __level > __cursize ))
then
break break
fi fi
done done


for ((__i = __level; __i < __cursize-1; __i++)) for ((__i = __level; __i < __cursize - 1; __i++)); do
do if ((__i > __level)); then
if ((__i > __level))
then
__newpath=$__newpath"/" __newpath=$__newpath"/"
fi fi
__newpath=$__newpath".." __newpath=$__newpath".."
done done


for ((__i = __level; __i < __abssize; __i++)) for ((__i = __level; __i < __abssize; __i++)); do
do if [[ -n $__newpath ]]; then
if [[ -n $__newpath ]]
then
__newpath=$__newpath"/" __newpath=$__newpath"/"
fi fi
__newpath=$__newpath${__absolute[__i]} __newpath=$__newpath${__absolute[__i]}
@ -204,7 +204,6 @@ convert_abs_rel() {
printf -- "%s\n" "$__newpath" printf -- "%s\n" "$__newpath"
} }



# get_fs_env <device> # get_fs_env <device>
# Get and the ID_FS_TYPE variable from udev for a device. # Get and the ID_FS_TYPE variable from udev for a device.
# Example: # Example:
@ -216,10 +215,10 @@ get_fs_env() {
ID_FS_TYPE=$(blkid -u filesystem -o export -- "$1" \ ID_FS_TYPE=$(blkid -u filesystem -o export -- "$1" \
| while read line || [ -n "$line" ]; do | while read line || [ -n "$line" ]; do
if [[ "$line" == TYPE\=* ]]; then if [[ "$line" == TYPE\=* ]]; then
printf "%s" "${line#TYPE=}"; printf "%s" "${line#TYPE=}"
exit 0; exit 0
fi fi
done) done)
if [[ $ID_FS_TYPE ]]; then if [[ $ID_FS_TYPE ]]; then
printf "%s" "$ID_FS_TYPE" printf "%s" "$ID_FS_TYPE"
return 0 return 0
@ -234,11 +233,10 @@ get_fs_env() {
# 8:2 # 8:2
get_maj_min() { get_maj_min() {
local _majmin local _majmin
_majmin="$(stat -L -c '%t:%T' "$1" 2>/dev/null)" _majmin="$(stat -L -c '%t:%T' "$1" 2> /dev/null)"
printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))" printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))"
} }



# get_devpath_block <device> # get_devpath_block <device>
# get the DEVPATH in /sys of a block device # get the DEVPATH in /sys of a block device
get_devpath_block() { get_devpath_block() {
@ -247,7 +245,7 @@ get_devpath_block() {


for _i in /sys/block/*/dev /sys/block/*/*/dev; do for _i in /sys/block/*/dev /sys/block/*/*/dev; do
[[ -e "$_i" ]] || continue [[ -e "$_i" ]] || continue
if [[ "$_majmin" == "$(<"$_i")" ]]; then if [[ "$_majmin" == "$(< "$_i")" ]]; then
printf "%s" "${_i%/dev}" printf "%s" "${_i%/dev}"
return 0 return 0
fi fi
@ -263,9 +261,9 @@ get_persistent_dev() {
[ -z "$_dev" ] && return [ -z "$_dev" ] && return


if [[ -n "$persistent_policy" ]]; then if [[ -n "$persistent_policy" ]]; then
_pol="/dev/disk/${persistent_policy}/*" _pol="/dev/disk/${persistent_policy}/*"
else else
_pol= _pol=
fi fi


for i in \ for i in \
@ -276,8 +274,7 @@ get_persistent_dev() {
/dev/disk/by-partuuid/* \ /dev/disk/by-partuuid/* \
/dev/disk/by-partlabel/* \ /dev/disk/by-partlabel/* \
/dev/disk/by-id/* \ /dev/disk/by-id/* \
/dev/disk/by-path/* \ /dev/disk/by-path/*; do
; do
[[ -e "$i" ]] || continue [[ -e "$i" ]] || continue
[[ $i == /dev/mapper/control ]] && continue [[ $i == /dev/mapper/control ]] && continue
[[ $i == /dev/mapper/mpath* ]] && continue [[ $i == /dev/mapper/mpath* ]] && continue
@ -318,15 +315,20 @@ shorten_persistent_dev() {
local _dev="$1" local _dev="$1"
case "$_dev" in case "$_dev" in
/dev/disk/by-uuid/*) /dev/disk/by-uuid/*)
printf "%s" "UUID=${_dev##*/}";; printf "%s" "UUID=${_dev##*/}"
;;
/dev/disk/by-label/*) /dev/disk/by-label/*)
printf "%s" "LABEL=${_dev##*/}";; printf "%s" "LABEL=${_dev##*/}"
;;
/dev/disk/by-partuuid/*) /dev/disk/by-partuuid/*)
printf "%s" "PARTUUID=${_dev##*/}";; printf "%s" "PARTUUID=${_dev##*/}"
;;
/dev/disk/by-partlabel/*) /dev/disk/by-partlabel/*)
printf "%s" "PARTLABEL=${_dev##*/}";; printf "%s" "PARTLABEL=${_dev##*/}"
;;
*) *)
printf "%s" "$_dev";; printf "%s" "$_dev"
;;
esac esac
} }


@ -346,7 +348,7 @@ find_block_device() {


if [[ $use_fstab != yes ]]; then if [[ $use_fstab != yes ]]; then
[[ -d $_find_mpt/. ]] [[ -d $_find_mpt/. ]]
findmnt -e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | { \ findmnt -e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | {
while read _majmin _dev || [ -n "$_dev" ]; do while read _majmin _dev || [ -n "$_dev" ]; do
if [[ -b $_dev ]]; then if [[ -b $_dev ]]; then
if ! [[ $_majmin ]] || [[ $_majmin == 0:* ]]; then if ! [[ $_majmin ]] || [[ $_majmin == 0:* ]]; then
@ -363,11 +365,13 @@ find_block_device() {
printf "%s\n" "$_dev" printf "%s\n" "$_dev"
return 0 return 0
fi fi
done; return 1; } && return 0 done
return 1
} && return 0
fi fi
# fall back to /etc/fstab # fall back to /etc/fstab


findmnt -e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | { \ findmnt -e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | {
while read _majmin _dev || [ -n "$_dev" ]; do while read _majmin _dev || [ -n "$_dev" ]; do
if ! [[ $_dev ]]; then if ! [[ $_dev ]]; then
_dev="$_majmin" _dev="$_majmin"
@ -386,7 +390,9 @@ find_block_device() {
printf "%s\n" "$_dev" printf "%s\n" "$_dev"
return 0 return 0
fi fi
done; return 1; } && return 0 done
return 1
} && return 0


return 1 return 1
} }
@ -403,22 +409,26 @@ find_mp_fstype() {
local _fs local _fs


if [[ $use_fstab != yes ]]; then if [[ $use_fstab != yes ]]; then
findmnt -e -v -n -o 'FSTYPE' --target "$1" | { \ findmnt -e -v -n -o 'FSTYPE' --target "$1" | {
while read _fs || [ -n "$_fs" ]; do while read _fs || [ -n "$_fs" ]; do
[[ $_fs ]] || continue [[ $_fs ]] || continue
[[ $_fs = "autofs" ]] && continue [[ $_fs = "autofs" ]] && continue
printf "%s" "$_fs" printf "%s" "$_fs"
return 0 return 0
done; return 1; } && return 0 done
return 1
} && return 0
fi fi


findmnt --fstab -e -v -n -o 'FSTYPE' --target "$1" | { \ findmnt --fstab -e -v -n -o 'FSTYPE' --target "$1" | {
while read _fs || [ -n "$_fs" ]; do while read _fs || [ -n "$_fs" ]; do
[[ $_fs ]] || continue [[ $_fs ]] || continue
[[ $_fs = "autofs" ]] && continue [[ $_fs = "autofs" ]] && continue
printf "%s" "$_fs" printf "%s" "$_fs"
return 0 return 0
done; return 1; } && return 0 done
return 1
} && return 0


return 1 return 1
} }
@ -439,22 +449,26 @@ find_dev_fstype() {
fi fi


if [[ $use_fstab != yes ]]; then if [[ $use_fstab != yes ]]; then
findmnt -e -v -n -o 'FSTYPE' --source "$_find_dev" | { \ findmnt -e -v -n -o 'FSTYPE' --source "$_find_dev" | {
while read _fs || [ -n "$_fs" ]; do while read _fs || [ -n "$_fs" ]; do
[[ $_fs ]] || continue [[ $_fs ]] || continue
[[ $_fs = "autofs" ]] && continue [[ $_fs = "autofs" ]] && continue
printf "%s" "$_fs" printf "%s" "$_fs"
return 0 return 0
done; return 1; } && return 0 done
return 1
} && return 0
fi fi


findmnt --fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" | { \ findmnt --fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" | {
while read _fs || [ -n "$_fs" ]; do while read _fs || [ -n "$_fs" ]; do
[[ $_fs ]] || continue [[ $_fs ]] || continue
[[ $_fs = "autofs" ]] && continue [[ $_fs = "autofs" ]] && continue
printf "%s" "$_fs" printf "%s" "$_fs"
return 0 return 0
done; return 1; } && return 0 done
return 1
} && return 0


return 1 return 1
} }
@ -469,7 +483,7 @@ find_dev_fstype() {
# rw,relatime,discard,data=ordered # rw,relatime,discard,data=ordered
find_mp_fsopts() { find_mp_fsopts() {
if [[ $use_fstab != yes ]]; then if [[ $use_fstab != yes ]]; then
findmnt -e -v -n -o 'OPTIONS' --target "$1" 2>/dev/null && return 0 findmnt -e -v -n -o 'OPTIONS' --target "$1" 2> /dev/null && return 0
fi fi


findmnt --fstab -e -v -n -o 'OPTIONS' --target "$1" findmnt --fstab -e -v -n -o 'OPTIONS' --target "$1"
@ -492,36 +506,32 @@ find_dev_fsopts() {
fi fi


if [[ $use_fstab != yes ]]; then if [[ $use_fstab != yes ]]; then
findmnt -e -v -n -o 'OPTIONS' --source "$_find_dev" 2>/dev/null && return 0 findmnt -e -v -n -o 'OPTIONS' --source "$_find_dev" 2> /dev/null && return 0
fi fi


findmnt --fstab -e -v -n -o 'OPTIONS' --source "$_find_dev" findmnt --fstab -e -v -n -o 'OPTIONS' --source "$_find_dev"
} }



# finds the major:minor of the block device backing the root filesystem. # finds the major:minor of the block device backing the root filesystem.
find_root_block_device() { find_block_device /; } find_root_block_device() { find_block_device /; }


# for_each_host_dev_fs <func> # for_each_host_dev_fs <func>
# Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found # Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
# in ${host_fs_types[@]} # in ${host_fs_types[@]}
for_each_host_dev_fs() for_each_host_dev_fs() {
{
local _func="$1" local _func="$1"
local _dev local _dev
local _ret=1 local _ret=1


[[ "${#host_fs_types[@]}" ]] || return 2 [[ "${#host_fs_types[@]}" ]] || return 2



for _dev in "${!host_fs_types[@]}"; do for _dev in "${!host_fs_types[@]}"; do
$_func "$_dev" "${host_fs_types[$_dev]}" && _ret=0 $_func "$_dev" "${host_fs_types[$_dev]}" && _ret=0
done done
return $_ret return $_ret
} }


host_fs_all() host_fs_all() {
{
printf "%s\n" "${host_fs_types[@]}" printf "%s\n" "${host_fs_types[@]}"
} }


@ -535,12 +545,12 @@ check_block_and_slaves() {
if ! lvm_internal_dev $2; then "$1" $2 && return; fi if ! lvm_internal_dev $2; then "$1" $2 && return; fi
check_vol_slaves "$@" && return 0 check_vol_slaves "$@" && return 0
if [[ -f /sys/dev/block/$2/../dev ]] && [[ /sys/dev/block/$2/../subsystem -ef /sys/class/block ]]; then if [[ -f /sys/dev/block/$2/../dev ]] && [[ /sys/dev/block/$2/../subsystem -ef /sys/class/block ]]; then
check_block_and_slaves $1 $(<"/sys/dev/block/$2/../dev") && return 0 check_block_and_slaves $1 $(< "/sys/dev/block/$2/../dev") && return 0
fi fi
for _x in /sys/dev/block/$2/slaves/*; do for _x in /sys/dev/block/$2/slaves/*; do
[[ -f $_x/dev ]] || continue [[ -f $_x/dev ]] || continue
[[ $_x/subsystem -ef /sys/class/block ]] || continue [[ $_x/subsystem -ef /sys/class/block ]] || continue
check_block_and_slaves $1 $(<"$_x/dev") && return 0 check_block_and_slaves $1 $(< "$_x/dev") && return 0
done done
return 1 return 1
} }
@ -553,20 +563,19 @@ check_block_and_slaves_all() {
fi fi
check_vol_slaves_all "$@" && return 0 check_vol_slaves_all "$@" && return 0
if [[ -f /sys/dev/block/$2/../dev ]] && [[ /sys/dev/block/$2/../subsystem -ef /sys/class/block ]]; then if [[ -f /sys/dev/block/$2/../dev ]] && [[ /sys/dev/block/$2/../subsystem -ef /sys/class/block ]]; then
check_block_and_slaves_all $1 $(<"/sys/dev/block/$2/../dev") && _ret=0 check_block_and_slaves_all $1 $(< "/sys/dev/block/$2/../dev") && _ret=0
fi fi
for _x in /sys/dev/block/$2/slaves/*; do for _x in /sys/dev/block/$2/slaves/*; do
[[ -f $_x/dev ]] || continue [[ -f $_x/dev ]] || continue
[[ $_x/subsystem -ef /sys/class/block ]] || continue [[ $_x/subsystem -ef /sys/class/block ]] || continue
check_block_and_slaves_all $1 $(<"$_x/dev") && _ret=0 check_block_and_slaves_all $1 $(< "$_x/dev") && _ret=0
done done
return $_ret return $_ret
} }
# for_each_host_dev_and_slaves <func> # for_each_host_dev_and_slaves <func>
# Execute "<func> <dev>" for every "<dev>" found # Execute "<func> <dev>" for every "<dev>" found
# in ${host_devs[@]} and their slaves # in ${host_devs[@]} and their slaves
for_each_host_dev_and_slaves_all() for_each_host_dev_and_slaves_all() {
{
local _func="$1" local _func="$1"
local _dev local _dev
local _ret=1 local _ret=1
@ -582,8 +591,7 @@ for_each_host_dev_and_slaves_all()
return $_ret return $_ret
} }


for_each_host_dev_and_slaves() for_each_host_dev_and_slaves() {
{
local _func="$1" local _func="$1"
local _dev local _dev


@ -607,13 +615,12 @@ check_vol_slaves() {
_majmin="$2" _majmin="$2"
_lv="/dev/block/$_majmin" _lv="/dev/block/$_majmin"
_dm=/sys/dev/block/$_majmin/dm _dm=/sys/dev/block/$_majmin/dm
[[ -f $_dm/uuid && $(<$_dm/uuid) =~ LVM-* ]] || return 1 [[ -f $_dm/uuid && $(< $_dm/uuid) =~ LVM-* ]] || return 1
_vg=$(dmsetup splitname --noheadings -o vg_name $(<"$_dm/name") ) _vg=$(dmsetup splitname --noheadings -o vg_name $(< "$_dm/name"))
# strip space # strip space
_vg="${_vg//[[:space:]]/}" _vg="${_vg//[[:space:]]/}"
if [[ $_vg ]]; then if [[ $_vg ]]; then
for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null) for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2> /dev/null); do
do
check_block_and_slaves $1 $(get_maj_min $_pv) && return 0 check_block_and_slaves $1 $(get_maj_min $_pv) && return 0
done done
fi fi
@ -625,19 +632,18 @@ check_vol_slaves_all() {
_majmin="$2" _majmin="$2"
_lv="/dev/block/$_majmin" _lv="/dev/block/$_majmin"
_dm="/sys/dev/block/$_majmin/dm" _dm="/sys/dev/block/$_majmin/dm"
[[ -f $_dm/uuid && $(<$_dm/uuid) =~ LVM-* ]] || return 1 [[ -f $_dm/uuid && $(< $_dm/uuid) =~ LVM-* ]] || return 1
_vg=$(dmsetup splitname --noheadings -o vg_name $(<"$_dm/name") ) _vg=$(dmsetup splitname --noheadings -o vg_name $(< "$_dm/name"))
# strip space # strip space
_vg="${_vg//[[:space:]]/}" _vg="${_vg//[[:space:]]/}"
if [[ $_vg ]]; then if [[ $_vg ]]; then
# when filter/global_filter is set, lvm may be failed # when filter/global_filter is set, lvm may be failed
lvm lvs --noheadings -o vg_name $_vg 2>/dev/null 1>/dev/null lvm lvs --noheadings -o vg_name $_vg 2> /dev/null 1> /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
return 1 return 1
fi fi


for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2>/dev/null) for _pv in $(lvm vgs --noheadings -o pv_name "$_vg" 2> /dev/null); do
do
check_block_and_slaves_all $1 $(get_maj_min $_pv) check_block_and_slaves_all $1 $(get_maj_min $_pv)
done done
return 0 return 0
@ -645,8 +651,6 @@ check_vol_slaves_all() {
return 1 return 1
} }




# fs_get_option <filesystem options> <search for option> # fs_get_option <filesystem options> <search for option>
# search for a specific option in a bunch of filesystem options # search for a specific option in a bunch of filesystem options
# and return the value # and return the value
@ -662,13 +666,13 @@ fs_get_option() {
$_option=*) $_option=*)
echo ${1#${_option}=} echo ${1#${_option}=}
break break
;;
esac esac
shift shift
done done
} }


check_kernel_config() check_kernel_config() {
{
local _config_opt="$1" local _config_opt="$1"
local _config_file local _config_file
[[ -f $dracutsysrootdir/boot/config-$kernel ]] \ [[ -f $dracutsysrootdir/boot/config-$kernel ]] \
@ -686,13 +690,12 @@ check_kernel_config()
# 0 if the kernel module is either built-in or available # 0 if the kernel module is either built-in or available
# 1 if the kernel module is not enabled # 1 if the kernel module is not enabled
check_kernel_module() { check_kernel_module() {
modprobe -S $kernel --dry-run $1 &>/dev/null || return 1 modprobe -S $kernel --dry-run $1 &> /dev/null || return 1
} }


# get_cpu_vendor # get_cpu_vendor
# Only two values are returned: AMD or Intel # Only two values are returned: AMD or Intel
get_cpu_vendor () get_cpu_vendor() {
{
if grep -qE AMD /proc/cpuinfo; then if grep -qE AMD /proc/cpuinfo; then
printf "AMD" printf "AMD"
fi fi
@ -703,11 +706,10 @@ get_cpu_vendor ()


# get_host_ucode # get_host_ucode
# Get the hosts' ucode file based on the /proc/cpuinfo # Get the hosts' ucode file based on the /proc/cpuinfo
get_ucode_file () get_ucode_file() {
{ local family=$(grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //)
local family=`grep -E "cpu family" /proc/cpuinfo | head -1 | sed s/.*:\ //` local model=$(grep -E "model" /proc/cpuinfo | grep -v name | head -1 | sed s/.*:\ //)
local model=`grep -E "model" /proc/cpuinfo |grep -v name | head -1 | sed s/.*:\ //` local stepping=$(grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //)
local stepping=`grep -E "stepping" /proc/cpuinfo | head -1 | sed s/.*:\ //`


if [[ "$(get_cpu_vendor)" == "AMD" ]]; then if [[ "$(get_cpu_vendor)" == "AMD" ]]; then
if [[ $family -ge 21 ]]; then if [[ $family -ge 21 ]]; then
@ -726,9 +728,9 @@ get_ucode_file ()
# If it is an LVM device, touch only devices which have /dev/VG/LV symlink. # If it is an LVM device, touch only devices which have /dev/VG/LV symlink.
lvm_internal_dev() { lvm_internal_dev() {
local dev_dm_dir=/sys/dev/block/$1/dm local dev_dm_dir=/sys/dev/block/$1/dm
[[ ! -f $dev_dm_dir/uuid || $(<$dev_dm_dir/uuid) != LVM-* ]] && return 1 # Not an LVM device [[ ! -f $dev_dm_dir/uuid || $(< $dev_dm_dir/uuid) != LVM-* ]] && return 1 # Not an LVM device
local DM_VG_NAME DM_LV_NAME DM_LV_LAYER local DM_VG_NAME DM_LV_NAME DM_LV_LAYER
eval $(dmsetup splitname --nameprefixes --noheadings --rows "$(<$dev_dm_dir/name)" 2>/dev/null) eval $(dmsetup splitname --nameprefixes --noheadings --rows "$(< $dev_dm_dir/name)" 2> /dev/null)
[[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] || return 0 # Better skip this! [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] || return 0 # Better skip this!
[[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]] [[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]]
} }
@ -737,9 +739,9 @@ btrfs_devs() {
local _mp="$1" local _mp="$1"
btrfs device usage "$_mp" \ btrfs device usage "$_mp" \
| while read _dev _rest; do | while read _dev _rest; do
str_starts "$_dev" "/" || continue str_starts "$_dev" "/" || continue
_dev=${_dev%,} _dev=${_dev%,}
printf -- "%s\n" "$_dev" printf -- "%s\n" "$_dev"
done done
} }


@ -759,8 +761,8 @@ peer_for_addr() {


# quote periods in IPv4 address # quote periods in IPv4 address
qtd=${addr//./\\.} qtd=${addr//./\\.}
ip -o addr show | \ ip -o addr show \
sed -n 's%^.* '"$qtd"' peer \([0-9a-f.:]\{1,\}\(/[0-9]*\)\?\).*$%\1%p' | sed -n 's%^.* '"$qtd"' peer \([0-9a-f.:]\{1,\}\(/[0-9]*\)\?\).*$%\1%p'
} }


netmask_for_addr() { netmask_for_addr() {
@ -776,12 +778,12 @@ gateway_for_iface() {
local ifname=$1 addr=$2 local ifname=$1 addr=$2


case $addr in case $addr in
*.*) proto=4;; *.*) proto=4 ;;
*:*) proto=6;; *:*) proto=6 ;;
*) return;; *) return ;;
esac esac
ip -o -$proto route show | \ ip -o -$proto route show \
sed -n "s/^default via \([0-9a-z.:]\{1,\}\) dev $ifname .*\$/\1/p" | sed -n "s/^default via \([0-9a-z.:]\{1,\}\) dev $ifname .*\$/\1/p"
} }


# This works only for ifcfg-style network configuration! # This works only for ifcfg-style network configuration!
@ -819,21 +821,24 @@ ip_params_for_remote_addr() {
# ifname clause to bind the interface name to a MAC address # ifname clause to bind the interface name to a MAC address
if [ -d "/sys/class/net/$ifname/bonding" ]; then if [ -d "/sys/class/net/$ifname/bonding" ]; then
dinfo "Found bonded interface '${ifname}'. Make sure to provide an appropriate 'bond=' cmdline." dinfo "Found bonded interface '${ifname}'. Make sure to provide an appropriate 'bond=' cmdline."
elif [ -e "/sys/class/net/$ifname/address" ] ; then elif [ -e "/sys/class/net/$ifname/address" ]; then
ifmac=$(cat "/sys/class/net/$ifname/address") ifmac=$(cat "/sys/class/net/$ifname/address")
[[ $ifmac ]] && printf 'ifname=%s:%s ' "${ifname}" "${ifmac}" [[ $ifmac ]] && printf 'ifname=%s:%s ' "${ifname}" "${ifmac}"
fi fi


bootproto=$(bootproto_for_iface "$ifname") bootproto=$(bootproto_for_iface "$ifname")
case $bootproto in case $bootproto in
dhcp|dhcp6|auto6) ;; dhcp | dhcp6 | auto6) ;;
dhcp4) dhcp4)
bootproto=dhcp;; bootproto=dhcp
static*|"") ;;
bootproto=;; static* | "")
bootproto=
;;
*) *)
derror "bootproto \"$bootproto\" is unsupported by dracut, trying static configuration" derror "bootproto \"$bootproto\" is unsupported by dracut, trying static configuration"
bootproto=;; bootproto=
;;
esac esac
if [[ $bootproto ]]; then if [[ $bootproto ]]; then
printf 'ip=%s:%s ' "${ifname}" "${bootproto}" printf 'ip=%s:%s ' "${ifname}" "${bootproto}"
@ -852,7 +857,7 @@ ip_params_for_remote_addr() {
is_unbracketed_ipv6_address "$peer" && peer="[$peer]" is_unbracketed_ipv6_address "$peer" && peer="[$peer]"
is_unbracketed_ipv6_address "$gateway" && gateway="[$gateway]" is_unbracketed_ipv6_address "$gateway" && gateway="[$gateway]"
printf 'ip=%s:%s:%s:%s::%s:none ' \ printf 'ip=%s:%s:%s:%s::%s:none ' \
"${local_addr}" "${peer}" "${gateway}" "${netmask}" "${ifname}" "${local_addr}" "${peer}" "${gateway}" "${netmask}" "${ifname}"
fi fi


} }

148
dracut-init.sh

@ -38,7 +38,7 @@ if ! [[ $dracutbasedir ]]; then
dracutbasedir="$(readlink -f $dracutbasedir)" dracutbasedir="$(readlink -f $dracutbasedir)"
fi fi


if ! is_func dinfo >/dev/null 2>&1; then if ! is_func dinfo > /dev/null 2>&1; then
# shellcheck source=./dracut-logger.sh # shellcheck source=./dracut-logger.sh
. "$dracutbasedir/dracut-logger.sh" . "$dracutbasedir/dracut-logger.sh"
dlog_init dlog_init
@ -64,7 +64,7 @@ srcmods="$dracutsysrootdir/lib/modules/$kernel/"


# shellcheck disable=SC2154 # shellcheck disable=SC2154
[[ $drivers_dir ]] && { [[ $drivers_dir ]] && {
if ! command -v kmod &>/dev/null && vercmp "$(modprobe --version | cut -d' ' -f3)" lt 3.7; then if ! command -v kmod &> /dev/null && vercmp "$(modprobe --version | cut -d' ' -f3)" lt 3.7; then
dfatal 'To use --kmoddir option module-init-tools >= 3.7 is required.' dfatal 'To use --kmoddir option module-init-tools >= 3.7 is required.'
exit 1 exit 1
fi fi
@ -91,8 +91,8 @@ DRACUT_LDCONFIG=${DRACUT_LDCONFIG:-ldconfig}
. "$dracutbasedir"/dracut-functions.sh . "$dracutbasedir"/dracut-functions.sh


# Detect lib paths # Detect lib paths
if ! [[ $libdirs ]] ; then if ! [[ $libdirs ]]; then
if [[ $("$DRACUT_LDD" "$dracutsysrootdir$DRACUT_TESTBIN") == */lib64/* ]] &>/dev/null \ if [[ $("$DRACUT_LDD" "$dracutsysrootdir$DRACUT_TESTBIN") == */lib64/* ]] &> /dev/null \
&& [[ -d $dracutsysrootdir/lib64 ]]; then && [[ -d $dracutsysrootdir/lib64 ]]; then
libdirs+=" /lib64" libdirs+=" /lib64"
[[ -d $dracutsysrootdir/usr/lib64 ]] && libdirs+=" /usr/lib64" [[ -d $dracutsysrootdir/usr/lib64 ]] && libdirs+=" /usr/lib64"
@ -120,7 +120,7 @@ require_binaries() {
fi fi


for cmd in "$@"; do for cmd in "$@"; do
if ! find_binary "$cmd" &>/dev/null; then if ! find_binary "$cmd" &> /dev/null; then
dinfo "dracut module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!" dinfo "dracut module '${_module_name#[0-9][0-9]}' will not be installed, because command '$cmd' could not be found!"
((_ret++)) ((_ret++))
fi fi
@ -138,13 +138,13 @@ require_any_binary() {
fi fi


for cmd in "$@"; do for cmd in "$@"; do
if find_binary "$cmd" &>/dev/null; then if find_binary "$cmd" &> /dev/null; then
_ret=0 _ret=0
break break
fi fi
done done


if (( _ret != 0 )); then if ((_ret != 0)); then
dinfo "$_module_name: Could not find any command of '$*'!" dinfo "$_module_name: Could not find any command of '$*'!"
return 1 return 1
fi fi
@ -153,7 +153,7 @@ require_any_binary() {
} }


dracut_need_initqueue() { dracut_need_initqueue() {
: >"$initdir/lib/dracut/need-initqueue" : > "$initdir/lib/dracut/need-initqueue"
} }


dracut_module_included() { dracut_module_included() {
@ -162,7 +162,7 @@ dracut_module_included() {
} }


dracut_no_switch_root() { dracut_no_switch_root() {
: >"$initdir/lib/dracut/no-switch-root" : > "$initdir/lib/dracut/no-switch-root"
} }


dracut_module_path() { dracut_module_path() {
@ -193,11 +193,11 @@ fi
# DRACUT_INSTALL="dracut-install --debug" # DRACUT_INSTALL="dracut-install --debug"
# in which case the string cannot be tested for being executable. # in which case the string cannot be tested for being executable.
DRINSTALLPARTS=0 DRINSTALLPARTS=0
for i in $DRACUT_INSTALL ; do for i in $DRACUT_INSTALL; do
DRINSTALLPARTS=$((DRINSTALLPARTS+1)) DRINSTALLPARTS=$((DRINSTALLPARTS + 1))
done done


if [[ $DRINSTALLPARTS = 1 ]] && ! command -v "$DRACUT_INSTALL" > /dev/null 2>&1 ; then if [[ $DRINSTALLPARTS = 1 ]] && ! command -v "$DRACUT_INSTALL" > /dev/null 2>&1; then
dfatal "dracut-install not found!" dfatal "dracut-install not found!"
exit 10 exit 10
fi fi
@ -211,7 +211,7 @@ fi


[[ $DRACUT_RESOLVE_LAZY ]] || export DRACUT_RESOLVE_DEPS=1 [[ $DRACUT_RESOLVE_LAZY ]] || export DRACUT_RESOLVE_DEPS=1
inst_dir() { inst_dir() {
[[ -e ${initdir}/"$1" ]] && return 0 # already there [[ -e ${initdir}/"$1" ]] && return 0 # already there
if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"; then if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"; then
derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@" derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -d "$@"
fi fi
@ -223,7 +223,7 @@ inst() {
_hostonly_install="-H" _hostonly_install="-H"
shift shift
fi fi
[[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
# shellcheck disable=SC2154 # shellcheck disable=SC2154
if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
@ -236,8 +236,8 @@ inst_simple() {
_hostonly_install="-H" _hostonly_install="-H"
shift shift
fi fi
[[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
[[ -e $1 ]] || return 1 # no source [[ -e $1 ]] || return 1 # no source
if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"; then if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@"; then
derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" || : derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${_hostonly_install:+-H} "$@" || :
fi fi
@ -249,20 +249,20 @@ inst_symlink() {
_hostonly_install="-H" _hostonly_install="-H"
shift shift
fi fi
[[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
[[ -L $1 ]] || return 1 [[ -L $1 ]] || return 1
if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || : derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
fi fi
} }


inst_multiple() { inst_multiple() {
local _ret local _ret
if "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then if "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then
return 0 return 0
else else
_ret=$? _ret=$?
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} "$@" || : 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 return $_ret
fi fi
} }
@ -272,8 +272,8 @@ dracut_install() {
} }


dracut_instmods() { dracut_instmods() {
local _silent=0; local _silent=0
local i; local i
# shellcheck disable=SC2154 # shellcheck disable=SC2154
[[ $no_kernel = yes ]] && return [[ $no_kernel = yes ]] && return
for i in "$@"; do for i in "$@"; do
@ -296,29 +296,29 @@ inst_library() {
_hostonly_install="-H" _hostonly_install="-H"
shift shift
fi fi
[[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there [[ -e ${initdir}/"${2:-$1}" ]] && return 0 # already there
[[ -e $1 ]] || return 1 # no source [[ -e $1 ]] || return 1 # no source
if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"; then
derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || : derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@" || :
fi fi
} }


inst_binary() { inst_binary() {
if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then
derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || : derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
fi fi
} }


inst_script() { inst_script() {
if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@"; then
derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || : derror FAILED: "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$@" || :
fi fi
} }


inst_fsck_help() { inst_fsck_help() {
local _helper="/run/dracut/fsck/fsck_help_$1.txt" local _helper="/run/dracut/fsck/fsck_help_$1.txt"
if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" "$_helper"; then if ! "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" "$_helper"; then
derror "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" "$_helper" || : derror "$DRACUT_INSTALL" ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} "$2" "$_helper" || :
fi fi
} }


@ -366,7 +366,7 @@ rev_lib_symlinks() {


until [[ ${_fn##*.} == so ]]; do until [[ ${_fn##*.} == so ]]; do
_fn="${_fn%.*}" _fn="${_fn%.*}"
[[ -L ${_fn} ]] && [[ $(readlink -f "${_fn}") == "${_orig}" ]] && _links+=( "${_fn}" ) [[ -L ${_fn} ]] && [[ $(readlink -f "${_fn}") == "${_orig}" ]] && _links+=("${_fn}")
done done


echo "${_links[*]}}" echo "${_links[*]}}"
@ -385,7 +385,7 @@ inst_rule_programs() {
elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
_bin=$(find_binary "$_prog") || { _bin=$(find_binary "$_prog") || {
dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found" dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
continue; continue
} }
fi fi


@ -400,7 +400,7 @@ inst_rule_programs() {
elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin/initqueue" ]]; then elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin/initqueue" ]]; then
_bin=$(find_binary "$_prog") || { _bin=$(find_binary "$_prog") || {
dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found" dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
continue; continue
} }
fi fi


@ -415,7 +415,7 @@ inst_rule_programs() {
elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
_bin=$(find_binary "$_prog") || { _bin=$(find_binary "$_prog") || {
dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found" dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
continue; continue
} }
fi fi


@ -429,15 +429,15 @@ inst_rule_group_owner() {


# shellcheck disable=SC2013 # shellcheck disable=SC2013
for i in $(sed -nr 's/.*OWNER=?"([^ "]+).*/\1/p' "$1"); do for i in $(sed -nr 's/.*OWNER=?"([^ "]+).*/\1/p' "$1"); do
if ! grep -Eq "^$i:" "$initdir/etc/passwd" 2>/dev/null; then if ! grep -Eq "^$i:" "$initdir/etc/passwd" 2> /dev/null; then
grep -E "^$i:" "$dracutsysrootdir"/etc/passwd 2>/dev/null >> "$initdir/etc/passwd" grep -E "^$i:" "$dracutsysrootdir"/etc/passwd 2> /dev/null >> "$initdir/etc/passwd"
fi fi
done done


# shellcheck disable=SC2013 # shellcheck disable=SC2013
for i in $(sed -nr 's/.*GROUP=?"([^ "]+).*/\1/p' "$1"); do for i in $(sed -nr 's/.*GROUP=?"([^ "]+).*/\1/p' "$1"); do
if ! grep -Eq "^$i:" "$initdir/etc/group" 2>/dev/null; then if ! grep -Eq "^$i:" "$initdir/etc/group" 2> /dev/null; then
grep -E "^$i:" "$dracutsysrootdir"/etc/group 2>/dev/null >> "$initdir/etc/group" grep -E "^$i:" "$dracutsysrootdir"/etc/group 2> /dev/null >> "$initdir/etc/group"
fi fi
done done
} }
@ -485,7 +485,7 @@ inst_rules_wildcard() {


inst_dir "${udevdir}/rules.d" inst_dir "${udevdir}/rules.d"
inst_dir "$_target" inst_dir "$_target"
for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1 ; do for _rule in ${udevdir}/rules.d/$1 ${dracutbasedir}/rules.d/$1; do
[[ -e $_rule ]] || continue [[ -e $_rule ]] || continue
inst_rule_programs "$_rule" inst_rule_programs "$_rule"
inst_rule_group_owner "$_rule" inst_rule_group_owner "$_rule"
@ -493,8 +493,8 @@ inst_rules_wildcard() {
inst_simple "$_rule" inst_simple "$_rule"
_found=$_rule _found=$_rule
done done
if [[ -n ${hostonly} ]] ; then if [[ -n ${hostonly} ]]; then
for _rule in ${_target}/$1 ; do for _rule in ${_target}/$1; do
[[ -f $_rule ]] || continue [[ -f $_rule ]] || continue
inst_rule_programs "$_rule" inst_rule_programs "$_rule"
inst_rule_group_owner "$_rule" inst_rule_group_owner "$_rule"
@ -526,13 +526,13 @@ prepare_udev_rules() {
[ -e "$f" ] || continue [ -e "$f" ] || continue
while read -r line || [ -n "$line" ]; do while read -r line || [ -n "$line" ]; do
if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then if [ "${line%%IMPORT PATH_ID}" != "$line" ]; then
if (( UDEVVERSION >= 174 )); then if ((UDEVVERSION >= 174)); then
printf '%sIMPORT{builtin}="path_id"\n' "${line%%IMPORT PATH_ID}" printf '%sIMPORT{builtin}="path_id"\n' "${line%%IMPORT PATH_ID}"
else else
printf '%sIMPORT{program}="path_id %%p"\n' "${line%%IMPORT PATH_ID}" printf '%sIMPORT{program}="path_id %%p"\n' "${line%%IMPORT PATH_ID}"
fi fi
elif [ "${line%%IMPORT BLKID}" != "$line" ]; then elif [ "${line%%IMPORT BLKID}" != "$line" ]; then
if (( UDEVVERSION >= 176 )); then if ((UDEVVERSION >= 176)); then
printf '%sIMPORT{builtin}="blkid"\n' "${line%%IMPORT BLKID}" printf '%sIMPORT{builtin}="blkid"\n' "${line%%IMPORT BLKID}"
else else
# shellcheck disable=SC2016 # shellcheck disable=SC2016
@ -588,7 +588,6 @@ inst_any() {
return 1 return 1
} }



# inst_libdir_file [-n <pattern>] <file> [<file>...] # inst_libdir_file [-n <pattern>] <file> [<file>...]
# Install a <file> located on a lib directory to the initramfs image # Install a <file> located on a lib directory to the initramfs image
# -n <pattern> install matching files # -n <pattern> install matching files
@ -836,7 +835,8 @@ check_mount() {
fi fi


if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
module_check_mount "$_mod" "$_moddir"; ret=$? module_check_mount "$_mod" "$_moddir"
ret=$?


# explicit module, so also accept ret=255 # explicit module, so also accept ret=255
[[ $ret = 0 || $ret = 255 ]] || return 1 [[ $ret = 0 || $ret = 255 ]] || return 1
@ -869,8 +869,8 @@ check_mount() {
fi fi
done done


[[ " $mods_to_load " == *\ $_mod\ * ]] || \ [[ " $mods_to_load " == *\ $_mod\ * ]] \
mods_to_load+=" $_mod " || mods_to_load+=" $_mod "


return 0 return 0
} }
@ -902,9 +902,11 @@ check_module() {


if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then if [[ " $dracutmodules $add_dracutmodules $force_add_dracutmodules" == *\ $_mod\ * ]]; then
if [[ " $dracutmodules $force_add_dracutmodules " == *\ $_mod\ * ]]; then if [[ " $dracutmodules $force_add_dracutmodules " == *\ $_mod\ * ]]; then
module_check "$_mod" 1 "$_moddir"; ret=$? module_check "$_mod" 1 "$_moddir"
ret=$?
else else
module_check "$_mod" 0 "$_moddir"; ret=$? module_check "$_mod" 0 "$_moddir"
ret=$?
fi fi
# explicit module, so also accept ret=255 # explicit module, so also accept ret=255
[[ $ret = 0 || $ret = 255 ]] || return 1 [[ $ret = 0 || $ret = 255 ]] || return 1
@ -912,7 +914,8 @@ check_module() {
# module not in our list # module not in our list
if [[ $dracutmodules = all ]]; then if [[ $dracutmodules = all ]]; then
# check, if we can and should install this module # check, if we can and should install this module
module_check "$_mod" 0 "$_moddir"; ret=$? module_check "$_mod" 0 "$_moddir"
ret=$?
if [[ $ret != 0 ]]; then if [[ $ret != 0 ]]; then
[[ $2 ]] && return 1 [[ $2 ]] && return 1
[[ $ret != 255 ]] && return 1 [[ $ret != 255 ]] && return 1
@ -941,8 +944,8 @@ check_module() {
fi fi
done done


[[ " $mods_to_load " == *\ $_mod\ * ]] || \ [[ " $mods_to_load " == *\ $_mod\ * ]] \
mods_to_load+=" $_mod " || mods_to_load+=" $_mod "


return 0 return 0
} }
@ -956,10 +959,11 @@ for_each_module_dir() {
local _func local _func
_func=$1 _func=$1
for _moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do for _moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
[[ -d $_moddir ]] || continue; [[ -d $_moddir ]] || continue
[[ -e $_moddir/install || -e $_moddir/installkernel || \ [[ -e $_moddir/install || -e $_moddir/installkernel || -e \
-e $_moddir/module-setup.sh ]] || continue $_moddir/module-setup.sh ]] || continue
_mod=${_moddir##*/}; _mod=${_mod#[0-9][0-9]} _mod=${_moddir##*/}
_mod=${_mod#[0-9][0-9]}
$_func "$_mod" 1 "$_moddir" $_func "$_mod" 1 "$_moddir"
done done


@ -987,8 +991,8 @@ dracut_kernel_post() {
done done


# generate module dependencies for the initrd # generate module dependencies for the initrd
if [[ -d $initdir/lib/modules/$kernel ]] && \ if [[ -d $initdir/lib/modules/$kernel ]] \
! depmod -a -b "$initdir" "$kernel"; then && ! depmod -a -b "$initdir" "$kernel"; then
dfatal "\"depmod -a $kernel\" failed." dfatal "\"depmod -a $kernel\" failed."
exit 1 exit 1
fi fi
@ -1041,15 +1045,15 @@ instmods() {
if ((_ret != 0)) && [[ -z "$_silent" ]]; then if ((_ret != 0)) && [[ -z "$_silent" ]]; then
derror "FAILED: " \ derror "FAILED: " \
"$DRACUT_INSTALL" \ "$DRACUT_INSTALL" \
${initdir:+-D "$initdir"} \ ${initdir:+-D "$initdir"} \
${dracutsysrootdir:+-r "$dracutsysrootdir"} \ ${dracutsysrootdir:+-r "$dracutsysrootdir"} \
${loginstall:+-L "$loginstall"} \ ${loginstall:+-L "$loginstall"} \
${hostonly:+-H} \ ${hostonly:+-H} \
${omit_drivers:+-N "$omit_drivers"} \ ${omit_drivers:+-N "$omit_drivers"} \
${srcmods:+--kerneldir "$srcmods"} \ ${srcmods:+--kerneldir "$srcmods"} \
${_optional:+-o} \ ${_optional:+-o} \
${_silent:+--silent} \ ${_silent:+--silent} \
-m "$@" -m "$@"
fi fi


[[ "$optional" ]] && return 0 [[ "$optional" ]] && return 0
@ -1073,8 +1077,8 @@ is_qemu_virtualized() {
# 0 if a virt environment was detected # 0 if a virt environment was detected
# 1 if a virt environment could not be detected # 1 if a virt environment could not be detected
# 255 if any error was encountered # 255 if any error was encountered
if type -P systemd-detect-virt >/dev/null 2>&1; then if type -P systemd-detect-virt > /dev/null 2>&1; then
if ! vm=$(systemd-detect-virt --vm >/dev/null 2>&1); then if ! vm=$(systemd-detect-virt --vm > /dev/null 2>&1); then
return 255 return 255
fi fi
[[ $vm = "qemu" ]] && return 0 [[ $vm = "qemu" ]] && return 0
@ -1085,9 +1089,9 @@ is_qemu_virtualized() {
for i in /sys/class/dmi/id/*_vendor; do for i in /sys/class/dmi/id/*_vendor; do
[[ -f $i ]] || continue [[ -f $i ]] || continue
read -r vendor < "$i" read -r vendor < "$i"
[[ "$vendor" == "QEMU" ]] && return 0 [[ "$vendor" == "QEMU" ]] && return 0
[[ "$vendor" == "Red Hat" ]] && return 0 [[ "$vendor" == "Red Hat" ]] && return 0
[[ "$vendor" == "Bochs" ]] && return 0 [[ "$vendor" == "Bochs" ]] && return 0
done done
return 1 return 1
} }

18
dracut-initramfs-restore.sh

@ -14,15 +14,15 @@ SKIP="$dracutbasedir/skipcpio"


[[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id


mount -o ro /boot &>/dev/null || true mount -o ro /boot &> /dev/null || true


if [[ -d /efi/loader/entries || -L /efi/loader/entries ]] \ if [[ -d /efi/loader/entries || -L /efi/loader/entries ]] \
&& [[ $MACHINE_ID ]] \ && [[ $MACHINE_ID ]] \
&& [[ -d /efi/${MACHINE_ID} || -L /efi/${MACHINE_ID} ]] ; then && [[ -d /efi/${MACHINE_ID} || -L /efi/${MACHINE_ID} ]]; then
IMG="/efi/${MACHINE_ID}/${KERNEL_VERSION}/initrd" IMG="/efi/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
elif [[ -d /boot/loader/entries || -L /boot/loader/entries ]] \ elif [[ -d /boot/loader/entries || -L /boot/loader/entries ]] \
&& [[ $MACHINE_ID ]] \ && [[ $MACHINE_ID ]] \
&& [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]] ; then && [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]]; then
IMG="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd" IMG="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
else else
IMG="/boot/initramfs-${KERNEL_VERSION}.img" IMG="/boot/initramfs-${KERNEL_VERSION}.img"
@ -32,13 +32,13 @@ cd /run/initramfs


[ -f .need_shutdown -a -f "$IMG" ] || exit 1 [ -f .need_shutdown -a -f "$IMG" ] || exit 1


if $SKIP "$IMG" | zcat | cpio -id --no-absolute-filenames --quiet >/dev/null; then if $SKIP "$IMG" | zcat | cpio -id --no-absolute-filenames --quiet > /dev/null; then
rm -f -- .need_shutdown rm -f -- .need_shutdown
elif $SKIP "$IMG" | xzcat | cpio -id --no-absolute-filenames --quiet >/dev/null; then elif $SKIP "$IMG" | xzcat | cpio -id --no-absolute-filenames --quiet > /dev/null; then
rm -f -- .need_shutdown rm -f -- .need_shutdown
elif $SKIP "$IMG" | lz4 -d -c | cpio -id --no-absolute-filenames --quiet >/dev/null; then elif $SKIP "$IMG" | lz4 -d -c | cpio -id --no-absolute-filenames --quiet > /dev/null; then
rm -f -- .need_shutdown rm -f -- .need_shutdown
elif $SKIP "$IMG" | zstd -d -c | cpio -id --no-absolute-filenames --quiet >/dev/null; then elif $SKIP "$IMG" | zstd -d -c | cpio -id --no-absolute-filenames --quiet > /dev/null; then
rm -f -- .need_shutdown rm -f -- .need_shutdown
else else
# something failed, so we clean up # something failed, so we clean up
@ -48,7 +48,7 @@ else
fi fi


if [[ -d squash ]]; then if [[ -d squash ]]; then
unsquashfs -no-xattrs -f -d . squash-root.img >/dev/null unsquashfs -no-xattrs -f -d . squash-root.img > /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Squash module is enabled for this initramfs but failed to unpack squash-root.img" >&2 echo "Squash module is enabled for this initramfs but failed to unpack squash-root.img" >&2
rm -f -- /run/initramfs/shutdown rm -f -- /run/initramfs/shutdown
@ -56,7 +56,7 @@ if [[ -d squash ]]; then
fi fi
fi fi


if [ -e /etc/selinux/config -a -x /usr/sbin/setfiles ] ; then if [ -e /etc/selinux/config -a -x /usr/sbin/setfiles ]; then
. /etc/selinux/config . /etc/selinux/config
/usr/sbin/setfiles -v -r /run/initramfs /etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts /run/initramfs > /dev/null /usr/sbin/setfiles -v -r /run/initramfs /etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts /run/initramfs > /dev/null
fi fi

127
dracut-logger.sh

@ -17,10 +17,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.



export __DRACUT_LOGGER__=1 export __DRACUT_LOGGER__=1



## @brief Logging facility module for dracut both at build- and boot-time. ## @brief Logging facility module for dracut both at build- and boot-time.
# #
# @section intro Introduction # @section intro Introduction
@ -86,7 +84,6 @@ export __DRACUT_LOGGER__=1
# #
# @see dlog_init() # @see dlog_init()



## @brief Initializes dracut Logger. ## @brief Initializes dracut Logger.
# #
# @retval 1 if something has gone wrong # @retval 1 if something has gone wrong
@ -105,7 +102,8 @@ export __DRACUT_LOGGER__=1
# See file doc comment for details. # See file doc comment for details.
dlog_init() { dlog_init() {
local __oldumask local __oldumask
local ret=0; local errmsg local ret=0
local errmsg
[ -z "$stdloglvl" ] && stdloglvl=4 [ -z "$stdloglvl" ] && stdloglvl=4
[ -z "$sysloglvl" ] && sysloglvl=0 [ -z "$sysloglvl" ] && sysloglvl=0
[ -z "$kmsgloglvl" ] && kmsgloglvl=0 [ -z "$kmsgloglvl" ] && kmsgloglvl=0
@ -114,23 +112,23 @@ dlog_init() {


if [ -z "$fileloglvl" ]; then if [ -z "$fileloglvl" ]; then
[ -w "$logfile" ] && fileloglvl=4 || fileloglvl=0 [ -w "$logfile" ] && fileloglvl=4 || fileloglvl=0
elif (( fileloglvl > 0 )); then elif ((fileloglvl > 0)); then
if [[ $logfile ]]; then if [[ $logfile ]]; then
__oldumask=$(umask) __oldumask=$(umask)
umask 0377 umask 0377
! [ -e "$logfile" ] && : >"$logfile" ! [ -e "$logfile" ] && : > "$logfile"
umask "$__oldumask" umask "$__oldumask"
if [[ -w $logfile ]] && [[ -f $logfile ]]; then if [[ -w $logfile ]] && [[ -f $logfile ]]; then
# Mark new run in the log file # Mark new run in the log file
echo >>"$logfile" echo >> "$logfile"
if command -v date >/dev/null; then if command -v date > /dev/null; then
echo "=== $(date) ===" >>"$logfile" echo "=== $(date) ===" >> "$logfile"
else else
echo "===============================================" >>"$logfile" echo "===============================================" >> "$logfile"
fi fi
echo >>"$logfile" echo >> "$logfile"
else else
# We cannot log to file, so turn this facility off. # We cannot log to file, so turn this facility off.
fileloglvl=0 fileloglvl=0
ret=1 ret=1
errmsg="'$logfile' is not a writable file" errmsg="'$logfile' is not a writable file"
@ -138,22 +136,22 @@ dlog_init() {
fi fi
fi fi


if (( UID != 0 )); then if ((UID != 0)); then
kmsgloglvl=0 kmsgloglvl=0
sysloglvl=0 sysloglvl=0
fi fi


if (( sysloglvl > 0 )); then if ((sysloglvl > 0)); then
if [[ -d /run/systemd/journal ]] \ if [[ -d /run/systemd/journal ]] \
&& type -P systemd-cat &>/dev/null \ && type -P systemd-cat &> /dev/null \
&& systemctl --quiet is-active systemd-journald.socket &>/dev/null \ && systemctl --quiet is-active systemd-journald.socket &> /dev/null \
&& { echo "dracut-$DRACUT_VERSION" | systemd-cat -t 'dracut' &>/dev/null; } ; then && { echo "dracut-$DRACUT_VERSION" | systemd-cat -t 'dracut' &> /dev/null; }; then
readonly _systemdcatfile="$DRACUT_TMPDIR/systemd-cat" readonly _systemdcatfile="$DRACUT_TMPDIR/systemd-cat"
mkfifo "$_systemdcatfile" mkfifo "$_systemdcatfile"
readonly _dlogfd=15 readonly _dlogfd=15
systemd-cat -t 'dracut' --level-prefix=true <"$_systemdcatfile" & systemd-cat -t 'dracut' --level-prefix=true < "$_systemdcatfile" &
exec 15>"$_systemdcatfile" exec 15> "$_systemdcatfile"
elif ! [[ -S /dev/log ]] && [[ -w /dev/log ]] || ! command -v logger >/dev/null; then elif ! [[ -S /dev/log ]] && [[ -w /dev/log ]] || ! command -v logger > /dev/null; then
# We cannot log to syslog, so turn this facility off. # We cannot log to syslog, so turn this facility off.
kmsgloglvl=$sysloglvl kmsgloglvl=$sysloglvl
sysloglvl=0 sysloglvl=0
@ -162,7 +160,7 @@ dlog_init() {
fi fi
fi fi


if (( sysloglvl > 0 )) || (( kmsgloglvl > 0 )); then if ((sysloglvl > 0)) || ((kmsgloglvl > 0)); then
if [ -n "$dracutbasedir" ]; then if [ -n "$dracutbasedir" ]; then
readonly syslogfacility=user readonly syslogfacility=user
else else
@ -171,44 +169,44 @@ dlog_init() {
export syslogfacility export syslogfacility
fi fi


local lvl; local maxloglvl_l=0 local lvl
local maxloglvl_l=0
for lvl in $stdloglvl $sysloglvl $fileloglvl $kmsgloglvl; do for lvl in $stdloglvl $sysloglvl $fileloglvl $kmsgloglvl; do
(( lvl > maxloglvl_l )) && maxloglvl_l=$lvl ((lvl > maxloglvl_l)) && maxloglvl_l=$lvl
done done
readonly maxloglvl=$maxloglvl_l readonly maxloglvl=$maxloglvl_l
export maxloglvl export maxloglvl



if ((stdloglvl < 6)) && ((kmsgloglvl < 6)) && ((fileloglvl < 6)) && ((sysloglvl < 6)); then
if (( stdloglvl < 6 )) && ((kmsgloglvl < 6)) && ((fileloglvl < 6)) && ((sysloglvl < 6)); then
unset dtrace unset dtrace
dtrace() { :; }; dtrace() { :; }
fi fi


if ((stdloglvl < 5)) && ((kmsgloglvl < 5)) && ((fileloglvl < 5)) && ((sysloglvl < 5)); then if ((stdloglvl < 5)) && ((kmsgloglvl < 5)) && ((fileloglvl < 5)) && ((sysloglvl < 5)); then
unset ddebug unset ddebug
ddebug() { :; }; ddebug() { :; }
fi fi


if ((stdloglvl < 4)) && ((kmsgloglvl < 4)) && ((fileloglvl < 4)) && ((sysloglvl < 4)); then if ((stdloglvl < 4)) && ((kmsgloglvl < 4)) && ((fileloglvl < 4)) && ((sysloglvl < 4)); then
unset dinfo unset dinfo
dinfo() { :; }; dinfo() { :; }
fi fi


if ((stdloglvl < 3)) && ((kmsgloglvl < 3)) && ((fileloglvl < 3)) && ((sysloglvl < 3)); then if ((stdloglvl < 3)) && ((kmsgloglvl < 3)) && ((fileloglvl < 3)) && ((sysloglvl < 3)); then
unset dwarn unset dwarn
dwarn() { :; }; dwarn() { :; }
unset dwarning unset dwarning
dwarning() { :; }; dwarning() { :; }
fi fi


if ((stdloglvl < 2)) && ((kmsgloglvl < 2)) && ((fileloglvl < 2)) && ((sysloglvl < 2)); then if ((stdloglvl < 2)) && ((kmsgloglvl < 2)) && ((fileloglvl < 2)) && ((sysloglvl < 2)); then
unset derror unset derror
derror() { :; }; derror() { :; }
fi fi


if ((stdloglvl < 1)) && ((kmsgloglvl < 1)) && ((fileloglvl < 1)) && ((sysloglvl < 1)); then if ((stdloglvl < 1)) && ((kmsgloglvl < 1)) && ((fileloglvl < 1)) && ((sysloglvl < 1)); then
unset dfatal unset dfatal
dfatal() { :; }; dfatal() { :; }
fi fi


[ -n "$errmsg" ] && derror "$errmsg" [ -n "$errmsg" ] && derror "$errmsg"
@ -224,13 +222,13 @@ dlog_init() {
# @result Echoes first letter of level name. # @result Echoes first letter of level name.
_lvl2char() { _lvl2char() {
case "$1" in case "$1" in
1) echo F;; 1) echo F ;;
2) echo E;; 2) echo E ;;
3) echo W;; 3) echo W ;;
4) echo I;; 4) echo I ;;
5) echo D;; 5) echo D ;;
6) echo T;; 6) echo T ;;
*) return 1;; *) return 1 ;;
esac esac
} }


@ -243,13 +241,13 @@ _lvl2char() {
_lvl2syspri() { _lvl2syspri() {
printf "%s" -- "$syslogfacility." printf "%s" -- "$syslogfacility."
case "$1" in case "$1" in
1) echo crit;; 1) echo crit ;;
2) echo error;; 2) echo error ;;
3) echo warning;; 3) echo warning ;;
4) echo info;; 4) echo info ;;
5) echo debug;; 5) echo debug ;;
6) echo debug;; 6) echo debug ;;
*) return 1;; *) return 1 ;;
esac esac
} }


@ -279,16 +277,16 @@ _dlvl2syslvl() {
local lvl local lvl


case "$1" in case "$1" in
1) lvl=2;; 1) lvl=2 ;;
2) lvl=3;; 2) lvl=3 ;;
3) lvl=4;; 3) lvl=4 ;;
4) lvl=6;; 4) lvl=6 ;;
5) lvl=7;; 5) lvl=7 ;;
6) lvl=7;; 6) lvl=7 ;;
*) return 1;; *) return 1 ;;
esac esac


[ "$syslogfacility" = user ] && echo $(( 8 + lvl )) || echo $(( 24 + lvl )) [ "$syslogfacility" = user ] && echo $((8 + lvl)) || echo $((24 + lvl))
} }


## @brief Prints to stderr and/or writes to file, to syslog and/or /dev/kmsg ## @brief Prints to stderr and/or writes to file, to syslog and/or /dev/kmsg
@ -318,14 +316,15 @@ _dlvl2syslvl() {
# - @c INFO to @c info # - @c INFO to @c info
# - @c DEBUG and @c TRACE both to @c debug # - @c DEBUG and @c TRACE both to @c debug
_do_dlog() { _do_dlog() {
local lvl="$1"; shift local lvl="$1"
shift
local lvlc=$(_lvl2char "$lvl") || return 0 local lvlc=$(_lvl2char "$lvl") || return 0
local msg="$*" local msg="$*"
local lmsg="$lvlc: $*" local lmsg="$lvlc: $*"


(( lvl <= stdloglvl )) && printf -- 'dracut: %s\n' "$msg" >&2 ((lvl <= stdloglvl)) && printf -- 'dracut: %s\n' "$msg" >&2


if (( lvl <= sysloglvl )); then if ((lvl <= sysloglvl)); then
if [[ "$_dlogfd" ]]; then if [[ "$_dlogfd" ]]; then
printf -- "<%s>%s\n" "$(($(_dlvl2syslvl "$lvl") & 7))" "$msg" >&$_dlogfd printf -- "<%s>%s\n" "$(($(_dlvl2syslvl "$lvl") & 7))" "$msg" >&$_dlogfd
else else
@ -333,12 +332,12 @@ _do_dlog() {
fi fi
fi fi


if (( lvl <= fileloglvl )) && [[ -w "$logfile" ]] && [[ -f "$logfile" ]]; then if ((lvl <= fileloglvl)) && [[ -w "$logfile" ]] && [[ -f "$logfile" ]]; then
echo "$lmsg" >>"$logfile" echo "$lmsg" >> "$logfile"
fi fi


(( lvl <= kmsgloglvl )) && \ ((lvl <= kmsgloglvl)) \
echo "<$(_dlvl2syslvl "$lvl")>dracut[$$] $msg" >/dev/kmsg && echo "<$(_dlvl2syslvl "$lvl")>dracut[$$] $msg" > /dev/kmsg
} }


## @brief Internal helper function for _do_dlog() ## @brief Internal helper function for _do_dlog()
@ -359,9 +358,9 @@ _do_dlog() {
# echo "This is a warning" | dwarn # echo "This is a warning" | dwarn
dlog() { dlog() {
[ -z "$maxloglvl" ] && return 0 [ -z "$maxloglvl" ] && return 0
(( $1 <= maxloglvl )) || return 0 (($1 <= maxloglvl)) || return 0


if (( $# > 1 )); then if (($# > 1)); then
_do_dlog "$@" _do_dlog "$@"
else else
while read -r line || [ -n "$line" ]; do while read -r line || [ -n "$line" ]; do

978
dracut.sh

File diff suppressed because it is too large Load Diff

14
examples/yocto/postinst-intercepts/execute_dracut

@ -3,8 +3,8 @@
set -e set -e


if [[ -z "$DRACUT_TMPDIR" ]]; then if [[ -z "$DRACUT_TMPDIR" ]]; then
echo "DRACUT_TMPDIR is unset, exiting" echo "DRACUT_TMPDIR is unset, exiting"
exit 0 exit 0
fi fi


# We have to unset "prefix" as dracut uses it to move files around. # We have to unset "prefix" as dracut uses it to move files around.
@ -21,11 +21,11 @@ export DRACUT_INSTALL_PATH="/usr/sbin:/usr/bin:/sbin:/bin"
export PLYMOUTH_SYSROOT=$D export PLYMOUTH_SYSROOT=$D


export \ export \
systemdutildir systemdsystemunitdir systemdsystemconfdir udevdir \ systemdutildir systemdsystemunitdir systemdsystemconfdir udevdir \
DRACUT_ARCH DRACUT_TESTBIN DRACUT_LDD DRACUT_LDCONFIG DRACUT_INSTALL \ DRACUT_ARCH DRACUT_TESTBIN DRACUT_LDD DRACUT_LDCONFIG DRACUT_INSTALL \
DRACUT_COMPRESS_GZIP DRACUT_COMPRESS_BZIP2 DRACUT_COMPRESS_LZMA \ DRACUT_COMPRESS_GZIP DRACUT_COMPRESS_BZIP2 DRACUT_COMPRESS_LZMA \
PLYMOUTH_LDD PLYMOUTH_LDD_PATH PLYMOUTH_PLUGIN_PATH \ PLYMOUTH_LDD PLYMOUTH_LDD_PATH PLYMOUTH_PLUGIN_PATH \
PLYMOUTH_THEME_NAME PLYMOUTH_THEME PLYMOUTH_THEME_NAME PLYMOUTH_THEME


# List environment for debugging # List environment for debugging
echo ROOTFS-POSTINST-ENVIRONMENT echo ROOTFS-POSTINST-ENVIRONMENT

14
fedora-test-github.sh

@ -35,11 +35,11 @@ else
cd test cd test


time LOGTEE_TIMEOUT_MS=590000 make \ time LOGTEE_TIMEOUT_MS=590000 make \
enable_documentation=$make_docs \ enable_documentation=$make_docs \
KVERSION="$(rpm -qa kernel --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' | sort -rn | head -1)" \ KVERSION="$(rpm -qa kernel --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' | sort -rn | head -1)" \
DRACUT_NO_XATTR=1 \ DRACUT_NO_XATTR=1 \
TEST_RUN_ID="$RUN_ID" \ TEST_RUN_ID="$RUN_ID" \
${TESTS:+TESTS="$TESTS"} \ ${TESTS:+TESTS="$TESTS"} \
-k V=1 \ -k V=1 \
check check
fi fi

14
fedora-test.sh

@ -20,11 +20,11 @@ else
cd test cd test


time sudo LOGTEE_TIMEOUT_MS=300000 make \ time sudo LOGTEE_TIMEOUT_MS=300000 make \
enable_documentation=$make_docs \ enable_documentation=$make_docs \
KVERSION=$(rpm -qa kernel --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' | sort -rn | head -1) \ KVERSION=$(rpm -qa kernel --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' | sort -rn | head -1) \
DRACUT_NO_XATTR=1 \ DRACUT_NO_XATTR=1 \
TEST_RUN_ID=$RUN_ID \ TEST_RUN_ID=$RUN_ID \
${TESTS:+TESTS="$TESTS"} \ ${TESTS:+TESTS="$TESTS"} \
-k V=2 \ -k V=2 \
check check
fi fi

80
lsinitrd-bash-completion.sh

@ -15,53 +15,57 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #


__contains_word () { __contains_word() {
local word="$1"; shift local word="$1"
for w in "$@"; do [[ $w = "$word" ]] && return 0; done shift
return 1 for w in "$@"; do [[ $w = "$word" ]] && return 0; done
return 1
} }


_lsinitrd() { _lsinitrd() {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD - 1]}
local -A OPTS=( local -A OPTS=(
[STANDALONE]='-s --size -h --help' [STANDALONE]='-s --size -h --help'
[ARG]='-f --file -k --kver' [ARG]='-f --file -k --kver'
) )


# shellcheck disable=SC2086 # shellcheck disable=SC2086
if __contains_word "$prev" ${OPTS[ARG]}; then if __contains_word "$prev" ${OPTS[ARG]}; then
case $prev in case $prev in
--file|-f) --file | -f)
comps=$(compgen -f -- "$cur") comps=$(compgen -f -- "$cur")
compopt -o filenames compopt -o filenames
;; ;;
--kver|-k) --kver | -k)
comps=$(cd /lib/modules || return 1; echo [0-9]*) comps=$(
;; cd /lib/modules || return 1
*) echo [0-9]*
return 0 )
;; ;;
esac *)
# shellcheck disable=SC2207
# shellcheck disable=SC2016
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0 return 0
fi ;;

esac
if [[ $cur = -* ]]; then # shellcheck disable=SC2207
# shellcheck disable=SC2207 # shellcheck disable=SC2016
# shellcheck disable=SC2016 COMPREPLY=($(compgen -W '$comps' -- "$cur"))
COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) return 0
return 0 fi
fi


# shellcheck disable=SC2034 if [[ $cur = -* ]]; then
comps=$(compgen -f -- "$cur")
compopt -o filenames
# shellcheck disable=SC2207 # shellcheck disable=SC2207
# shellcheck disable=SC2016 # shellcheck disable=SC2016
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) COMPREPLY=($(compgen -W '${OPTS[*]}' -- "$cur"))
return 0 return 0
fi

# shellcheck disable=SC2034
comps=$(compgen -f -- "$cur")
compopt -o filenames
# shellcheck disable=SC2207
# shellcheck disable=SC2016
COMPREPLY=($(compgen -W '$comps' -- "$cur"))
return 0
} }


complete -F _lsinitrd lsinitrd complete -F _lsinitrd lsinitrd

137
lsinitrd.sh

@ -17,8 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #


usage() usage() {
{
{ {
echo "Usage: ${0##*/} [options] [<initramfs file> [<filename> [<filename> [...] ]]]" echo "Usage: ${0##*/} [options] [<initramfs file> [<filename> [<filename> [...] ]]]"
echo "Usage: ${0##*/} [options] -k <kernel version>" echo "Usage: ${0##*/} [options] -k <kernel version>"
@ -38,7 +37,6 @@ usage()
} >&2 } >&2
} }



[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut


sorted=0 sorted=0
@ -59,7 +57,7 @@ TEMP=$(getopt \
--long verbose \ --long verbose \
-- "$@") -- "$@")


if (( $? != 0 )); then if (($? != 0)); then
usage usage
exit 1 exit 1
fi fi
@ -68,16 +66,31 @@ eval set -- "$TEMP"


while (($# > 0)); do while (($# > 0)); do
case $1 in case $1 in
-k|--kver) KERNEL_VERSION="$2"; shift;; -k | --kver)
-f|--file) filenames[${2#/}]=1; shift;; KERNEL_VERSION="$2"
-s|--size) sorted=1;; shift
-h|--help) usage; exit 0;; ;;
-m|--mod) modules=1;; -f | --file)
-v|--verbose) verbose="--verbose";; filenames[${2#/}]=1
--unpack) unpack=1;; shift
--unpackearly) unpackearly=1;; ;;
--) shift;break;; -s | --size) sorted=1 ;;
*) usage; exit 1;; -h | --help)
usage
exit 0
;;
-m | --mod) modules=1 ;;
-v | --verbose) verbose="--verbose" ;;
--unpack) unpack=1 ;;
--unpackearly) unpackearly=1 ;;
--)
shift
break
;;
*)
usage
exit 1
;;
esac esac
shift shift
done done
@ -99,11 +112,11 @@ else


if [[ -d /efi/loader/entries || -L /efi/loader/entries ]] \ if [[ -d /efi/loader/entries || -L /efi/loader/entries ]] \
&& [[ $MACHINE_ID ]] \ && [[ $MACHINE_ID ]] \
&& [[ -d /efi/${MACHINE_ID} || -L /efi/${MACHINE_ID} ]] ; then && [[ -d /efi/${MACHINE_ID} || -L /efi/${MACHINE_ID} ]]; then
image="/efi/${MACHINE_ID}/${KERNEL_VERSION}/initrd" image="/efi/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
elif [[ -d /boot/loader/entries || -L /boot/loader/entries ]] \ elif [[ -d /boot/loader/entries || -L /boot/loader/entries ]] \
&& [[ $MACHINE_ID ]] \ && [[ $MACHINE_ID ]] \
&& [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]] ; then && [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]]; then
image="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd" image="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
else else
image="/boot/initramfs-${KERNEL_VERSION}.img" image="/boot/initramfs-${KERNEL_VERSION}.img"
@ -112,7 +125,7 @@ fi


shift shift
while (($# > 0)); do while (($# > 0)); do
filenames[${1#/}]=1; filenames[${1#/}]=1
shift shift
done done


@ -134,46 +147,42 @@ dracutlibdirs() {
done done
} }


extract_files() extract_files() {
{ ((${#filenames[@]} == 1)) && nofileinfo=1
(( ${#filenames[@]} == 1 )) && nofileinfo=1
for f in "${!filenames[@]}"; do for f in "${!filenames[@]}"; do
[[ $nofileinfo ]] || echo "initramfs:/$f" [[ $nofileinfo ]] || echo "initramfs:/$f"
[[ $nofileinfo ]] || echo "========================================================================" [[ $nofileinfo ]] || echo "========================================================================"
$CAT "$image" 2>/dev/null | cpio --extract --verbose --quiet --to-stdout "$f" 2>/dev/null $CAT "$image" 2> /dev/null | cpio --extract --verbose --quiet --to-stdout "$f" 2> /dev/null
((ret+=$?)) ((ret += $?))
[[ $nofileinfo ]] || echo "========================================================================" [[ $nofileinfo ]] || echo "========================================================================"
[[ $nofileinfo ]] || echo [[ $nofileinfo ]] || echo
done done
} }


list_modules() list_modules() {
{
echo "dracut modules:" echo "dracut modules:"
$CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \ $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \
$(dracutlibdirs modules.txt) 2>/dev/null $(dracutlibdirs modules.txt) 2> /dev/null
((ret+=$?)) ((ret += $?))
} }


list_files() list_files() {
{
echo "========================================================================" echo "========================================================================"
if [ "$sorted" -eq 1 ]; then if [ "$sorted" -eq 1 ]; then
$CAT "$image" 2>/dev/null | cpio --extract --verbose --quiet --list | sort -n -k5 $CAT "$image" 2> /dev/null | cpio --extract --verbose --quiet --list | sort -n -k5
else else
$CAT "$image" 2>/dev/null | cpio --extract --verbose --quiet --list | sort -k9 $CAT "$image" 2> /dev/null | cpio --extract --verbose --quiet --list | sort -k9
fi fi
((ret+=$?)) ((ret += $?))
echo "========================================================================" echo "========================================================================"
} }


list_squash_content() list_squash_content() {
{
SQUASH_IMG="squash-root.img" SQUASH_IMG="squash-root.img"
SQUASH_TMPFILE="$TMPDIR/initrd.root.sqsh" SQUASH_TMPFILE="$TMPDIR/initrd.root.sqsh"


$CAT "$image" 2>/dev/null | cpio --extract --verbose --quiet --to-stdout -- \ $CAT "$image" 2> /dev/null | cpio --extract --verbose --quiet --to-stdout -- \
$SQUASH_IMG > "$SQUASH_TMPFILE" 2>/dev/null $SQUASH_IMG > "$SQUASH_TMPFILE" 2> /dev/null
if [[ -s $SQUASH_TMPFILE ]]; then if [[ -s $SQUASH_TMPFILE ]]; then
echo "Squashed content ($SQUASH_IMG):" echo "Squashed content ($SQUASH_IMG):"
echo "========================================================================" echo "========================================================================"
@ -182,22 +191,24 @@ list_squash_content()
fi fi
} }


unpack_files() unpack_files() {
{ if ((${#filenames[@]} > 0)); then
if (( ${#filenames[@]} > 0 )); then
for f in "${!filenames[@]}"; do for f in "${!filenames[@]}"; do
$CAT "$image" 2>/dev/null | cpio -id --quiet $verbose $f $CAT "$image" 2> /dev/null | cpio -id --quiet $verbose $f
((ret+=$?)) ((ret += $?))
done done
else else
$CAT "$image" 2>/dev/null | cpio -id --quiet $verbose $CAT "$image" 2> /dev/null | cpio -id --quiet $verbose
((ret+=$?)) ((ret += $?))
fi fi
} }


read -N 2 bin < "$image" read -N 2 bin < "$image"
if [ "$bin" = "MZ" ]; then if [ "$bin" = "MZ" ]; then
command -v objcopy > /dev/null || { echo "Need 'objcopy' to unpack an UEFI executable."; exit 1; } command -v objcopy > /dev/null || {
echo "Need 'objcopy' to unpack an UEFI executable."
exit 1
}
objcopy \ objcopy \
--dump-section .linux="$TMPDIR/vmlinuz" \ --dump-section .linux="$TMPDIR/vmlinuz" \
--dump-section .initrd="$TMPDIR/initrd.img" \ --dump-section .initrd="$TMPDIR/initrd.img" \
@ -209,10 +220,10 @@ if [ "$bin" = "MZ" ]; then
[ -f "$image" ] || exit 1 [ -f "$image" ] || exit 1
fi fi


if (( ${#filenames[@]} <= 0 )) && [[ -z "$unpack" ]] && [[ -z "$unpackearly" ]]; then if ((${#filenames[@]} <= 0)) && [[ -z "$unpack" ]] && [[ -z "$unpackearly" ]]; then
if [ -n "$uefi" ]; then if [ -n "$uefi" ]; then
echo -n "initrd in UEFI: $uefi: " echo -n "initrd in UEFI: $uefi: "
du -h $image | while read a b || [ -n "$a" ]; do echo $a;done du -h $image | while read a b || [ -n "$a" ]; do echo $a; done
if [ -f "$TMPDIR/osrel.txt" ]; then if [ -f "$TMPDIR/osrel.txt" ]; then
name=$(sed -En '/^PRETTY_NAME/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt") name=$(sed -En '/^PRETTY_NAME/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt")
id=$(sed -En '/^ID/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt") id=$(sed -En '/^ID/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt")
@ -229,7 +240,7 @@ if (( ${#filenames[@]} <= 0 )) && [[ -z "$unpack" ]] && [[ -z "$unpackearly" ]];
fi fi
else else
echo -n "Image: $image: " echo -n "Image: $image: "
du -h $image | while read a b || [ -n "$a" ]; do echo $a;done du -h $image | while read a b || [ -n "$a" ]; do echo $a; done
fi fi


echo "========================================================================" echo "========================================================================"
@ -237,18 +248,18 @@ fi


read -N 6 bin < "$image" read -N 6 bin < "$image"
case $bin in case $bin in
$'\x71\xc7'*|070701) $'\x71\xc7'* | 070701)
CAT="cat --" CAT="cat --"
is_early=$(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2>/dev/null) is_early=$(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2> /dev/null)
# Debian mkinitramfs does not create the file 'early_cpio', so let's check if firmware files exist # Debian mkinitramfs does not create the file 'early_cpio', so let's check if firmware files exist
[[ "$is_early" ]] || is_early=$(cpio --list --verbose --quiet --to-stdout -- 'kernel/*/microcode/*.bin' < "$image" 2>/dev/null) [[ "$is_early" ]] || is_early=$(cpio --list --verbose --quiet --to-stdout -- 'kernel/*/microcode/*.bin' < "$image" 2> /dev/null)
if [[ "$is_early" ]]; then if [[ "$is_early" ]]; then
if [[ -n "$unpack" ]]; then if [[ -n "$unpack" ]]; then
# should use --unpackearly for early CPIO # should use --unpackearly for early CPIO
: :
elif [[ -n "$unpackearly" ]]; then elif [[ -n "$unpackearly" ]]; then
unpack_files unpack_files
elif (( ${#filenames[@]} > 0 )); then elif ((${#filenames[@]} > 0)); then
extract_files extract_files
else else
echo "Early CPIO image" echo "Early CPIO image"
@ -269,8 +280,8 @@ case $bin in
;; ;;
esac esac


if [[ $SKIP ]] ; then if [[ $SKIP ]]; then
bin="$($SKIP "$image" | { read -N 6 bin && echo "$bin" ; })" bin="$($SKIP "$image" | { read -N 6 bin && echo "$bin"; })"
else else
read -N 6 bin < "$image" read -N 6 bin < "$image"
fi fi
@ -281,7 +292,7 @@ case $bin in
BZh*) BZh*)
CAT="bzcat --" CAT="bzcat --"
;; ;;
$'\x71\xc7'*|070701) $'\x71\xc7'* | 070701)
CAT="cat --" CAT="cat --"
;; ;;
$'\x02\x21'*) $'\x02\x21'*)
@ -294,7 +305,7 @@ case $bin in
CAT="zstd -d -c" CAT="zstd -d -c"
;; ;;
*) *)
if echo "test"|xz|xzcat --single-stream >/dev/null 2>&1; then if echo "test" | xz | xzcat --single-stream > /dev/null 2>&1; then
CAT="xzcat --single-stream --" CAT="xzcat --single-stream --"
else else
CAT="xzcat --" CAT="xzcat --"
@ -302,8 +313,7 @@ case $bin in
;; ;;
esac esac


skipcpio() skipcpio() {
{
$SKIP "$@" | $ORIG_CAT $SKIP "$@" | $ORIG_CAT
} }


@ -312,11 +322,10 @@ if [[ $SKIP ]]; then
CAT=skipcpio CAT=skipcpio
fi fi


if (( ${#filenames[@]} > 1 )); then if ((${#filenames[@]} > 1)); then
TMPFILE="$TMPDIR/initrd.cpio" TMPFILE="$TMPDIR/initrd.cpio"
$CAT "$image" 2>/dev/null > $TMPFILE $CAT "$image" 2> /dev/null > $TMPFILE
pre_decompress() pre_decompress() {
{
cat $TMPFILE cat $TMPFILE
} }
CAT=pre_decompress CAT=pre_decompress
@ -326,12 +335,12 @@ ret=0


if [[ -n "$unpack" ]]; then if [[ -n "$unpack" ]]; then
unpack_files unpack_files
elif (( ${#filenames[@]} > 0 )); then elif ((${#filenames[@]} > 0)); then
extract_files extract_files
else else
version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \ version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \
$(dracutlibdirs 'dracut-*') 2>/dev/null) $(dracutlibdirs 'dracut-*') 2> /dev/null)
((ret+=$?)) ((ret += $?))
echo "Version: $version" echo "Version: $version"
echo echo
if [ "$modules" -eq 1 ]; then if [ "$modules" -eq 1 ]; then
@ -340,7 +349,7 @@ else
else else
echo -n "Arguments: " echo -n "Arguments: "
$CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \ $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \
$(dracutlibdirs build-parameter.txt) 2>/dev/null $(dracutlibdirs build-parameter.txt) 2> /dev/null
echo echo
list_modules list_modules
list_files list_files

176
mkinitrd-dracut.sh

@ -8,7 +8,7 @@ force=0


error() { echo "$@" >&2; } error() { echo "$@" >&2; }


usage () { usage() {
[[ $1 = '-n' ]] && cmd=echo || cmd=error [[ $1 = '-n' ]] && cmd=echo || cmd=error


$cmd "usage: ${0##*/} [--version] [--help] [-v] [-f] [--preload <module>]" $cmd "usage: ${0##*/} [--version] [--help] [-v] [-f] [--preload <module>]"
@ -34,16 +34,16 @@ read_arg() {
if [[ $2 =~ $rematch ]]; then if [[ $2 =~ $rematch ]]; then
read "$param" <<< "${BASH_REMATCH[1]}" read "$param" <<< "${BASH_REMATCH[1]}"
else else
for ((i=3; $i <= $#; i++)); do for ((i = 3; $i <= $#; i++)); do
# Only read next arg if it not an arg itself. # Only read next arg if it not an arg itself.
if [[ ${*:$i:1} = -* ]];then if [[ ${*:$i:1} = -* ]]; then
break break
fi fi
result="$result ${@:$i:1}" result="$result ${@:$i:1}"
# There is no way to shift our callers args, so # There is no way to shift our callers args, so
# return "no of args" to indicate they should do it instead. # return "no of args" to indicate they should do it instead.
done done
read "$1" <<< "$result" read "$1" <<< "$result"
return $(($i - 3)) return $(($i - 3))
fi fi
} }
@ -54,35 +54,36 @@ default_kernel_images() {
local qf='%{NAME}-%{VERSION}-%{RELEASE}\n' local qf='%{NAME}-%{VERSION}-%{RELEASE}\n'


case "${DRACUT_ARCH:-$(uname -m)}" in case "${DRACUT_ARCH:-$(uname -m)}" in
s390|s390x) s390 | s390x)
regex='image' regex='image'
;; ;;
ppc*) ppc*)
regex='vmlinux' regex='vmlinux'
;; ;;
i?86|x86_64) i?86 | x86_64)
regex='vmlinuz' regex='vmlinuz'
;; ;;
arm*) arm*)
regex='[uz]Image' regex='[uz]Image'
;; ;;
aarch64|riscv64) aarch64 | riscv64)
regex='Image' regex='Image'
;; ;;
*) regex='vmlinu.' *)
regex='vmlinu.'
;; ;;
esac esac


# user mode linux # user mode linux
if grep -q UML /proc/cpuinfo; then if grep -q UML /proc/cpuinfo; then
regex='linux' regex='linux'
fi fi


kernel_images="" kernel_images=""
initrd_images="" initrd_images=""
for kernel_image in $(ls $boot_dir \ for kernel_image in $(ls $boot_dir \
| sed -ne "\|^$regex\(-[0-9.]\+-[0-9]\+-[a-z0-9]\+$\)\?|p" \ | sed -ne "\|^$regex\(-[0-9.]\+-[0-9]\+-[a-z0-9]\+$\)\?|p" \
| grep -v kdump$ ) ; do | grep -v kdump$); do


# Note that we cannot check the RPM database here -- this # Note that we cannot check the RPM database here -- this
# script is itself called from within the binary kernel # script is itself called from within the binary kernel
@ -91,20 +92,20 @@ default_kernel_images() {
[ -L "$boot_dir/$kernel_image" ] && continue [ -L "$boot_dir/$kernel_image" ] && continue
[ "${kernel_image%%.gz}" != "$kernel_image" ] && continue [ "${kernel_image%%.gz}" != "$kernel_image" ] && continue
kernel_version=$(/usr/bin/get_kernel_version \ kernel_version=$(/usr/bin/get_kernel_version \
$boot_dir/$kernel_image 2> /dev/null) $boot_dir/$kernel_image 2> /dev/null)
initrd_image=$(echo $kernel_image | sed -e "s|${regex}|initrd|") initrd_image=$(echo $kernel_image | sed -e "s|${regex}|initrd|")
if [ "$kernel_image" != "$initrd_image" -a \ if [ "$kernel_image" != "$initrd_image" -a \
-n "$kernel_version" -a \ -n "$kernel_version" -a \
-d "/lib/modules/$kernel_version" ]; then -d "/lib/modules/$kernel_version" ]; then
kernel_images="$kernel_images $boot_dir/$kernel_image" kernel_images="$kernel_images $boot_dir/$kernel_image"
initrd_images="$initrd_images $boot_dir/$initrd_image" initrd_images="$initrd_images $boot_dir/$initrd_image"
fi fi
done done
for kernel_image in $kernel_images;do for kernel_image in $kernel_images; do
kernels="$kernels ${kernel_image#*-}" kernels="$kernels ${kernel_image#*-}"
done done
for initrd_image in $initrd_images;do for initrd_image in $initrd_images; do
targets="$targets $initrd_image" targets="$targets $initrd_image"
done done
host_only=1 host_only=1
force=1 force=1
@ -112,25 +113,36 @@ default_kernel_images() {


while (($# > 0)); do while (($# > 0)); do
case ${1%%=*} in case ${1%%=*} in
--with-usb) read_arg usbmodule "$@" || shift $? --with-usb)
read_arg usbmodule "$@" || shift $?
basicmodules="$basicmodules ${usbmodule:-usb-storage}" basicmodules="$basicmodules ${usbmodule:-usb-storage}"
unset usbmodule;; unset usbmodule
--with-avail) read_arg modname "$@" || shift $? ;;
basicmodules="$basicmodules $modname";; --with-avail)
--with) read_arg modname "$@" || shift $? read_arg modname "$@" || shift $?
basicmodules="$basicmodules $modname";; basicmodules="$basicmodules $modname"
;;
--with)
read_arg modname "$@" || shift $?
basicmodules="$basicmodules $modname"
;;
--version) --version)
echo "mkinitrd: dracut compatibility wrapper" echo "mkinitrd: dracut compatibility wrapper"
exit 0;; exit 0
-v|--verbose) dracut_args="${dracut_args} -v";; ;;
-f|--force) force=1;; -v | --verbose) dracut_args="${dracut_args} -v" ;;
--preload) read_arg modname "$@" || shift $? -f | --force) force=1 ;;
basicmodules="$basicmodules $modname";; --preload)
--image-version) img_vers=yes;; read_arg modname "$@" || shift $?
--rootfs|-d) read_arg rootfs "$@" || shift $? basicmodules="$basicmodules $modname"
dracut_args="${dracut_args} --filesystems $rootfs";; ;;
--nocompress) dracut_args="$dracut_args --no-compress";; --image-version) img_vers=yes ;;
--help) usage -n;; --rootfs | -d)
read_arg rootfs "$@" || shift $?
dracut_args="${dracut_args} --filesystems $rootfs"
;;
--nocompress) dracut_args="$dracut_args --no-compress" ;;
--help) usage -n ;;
--builtin) ;; --builtin) ;;
--without*) ;; --without*) ;;
--without-usb) ;; --without-usb) ;;
@ -153,34 +165,36 @@ while (($# > 0)); do
--loopopts*) ;; --loopopts*) ;;
--looppath*) ;; --looppath*) ;;
--dsdt*) ;; --dsdt*) ;;
-s) ;; -s) ;;
--quiet|-q) quiet=1;; --quiet | -q) quiet=1 ;;
-b) read_arg boot_dir "$@" || shift $? -b)
if [ ! -d $boot_dir ];then read_arg boot_dir "$@" || shift $?
error "Boot directory $boot_dir does not exist" if [ ! -d $boot_dir ]; then
exit 1 error "Boot directory $boot_dir does not exist"
fi exit 1
;; fi
-k) # Would be nice to get a list of images here ;;
read_arg kernel_images "$@" || shift $? -k) # Would be nice to get a list of images here
for kernel_image in $kernel_images;do read_arg kernel_images "$@" || shift $?
kernels="$kernels ${kernel_image#*-}" for kernel_image in $kernel_images; do
done kernels="$kernels ${kernel_image#*-}"
host_only=1 done
force=1 host_only=1
;; force=1
-i) read_arg initrd_images "$@" || shift $? ;;
for initrd_image in $initrd_images;do -i)
targets="$targets $boot_dir/$initrd_image" read_arg initrd_images "$@" || shift $?
done for initrd_image in $initrd_images; do
;; targets="$targets $boot_dir/$initrd_image"
*) if [[ ! $targets ]]; then done
;;
*) if [[ ! $targets ]]; then
targets=$1 targets=$1
elif [[ ! $kernels ]]; then elif [[ ! $kernels ]]; then
kernels=$1 kernels=$1
else else
usage usage
fi;; fi ;;
esac esac
shift shift
done done
@ -189,37 +203,37 @@ done
[[ $targets && $kernels ]] || (error "No kernel found in $boot_dir" && usage) [[ $targets && $kernels ]] || (error "No kernel found in $boot_dir" && usage)


# We can have several targets/kernels, transform the list to an array # We can have several targets/kernels, transform the list to an array
targets=( $targets ) targets=($targets)
[[ $kernels ]] && kernels=( $kernels ) [[ $kernels ]] && kernels=($kernels)


[[ $host_only == 1 ]] && dracut_args="${dracut_args} -H" [[ $host_only == 1 ]] && dracut_args="${dracut_args} -H"
[[ $force == 1 ]] && dracut_args="${dracut_args} -f" [[ $force == 1 ]] && dracut_args="${dracut_args} -f"


echo "Creating: target|kernel|dracut args|basicmodules " echo "Creating: target|kernel|dracut args|basicmodules "
for ((i=0 ; $i<${#targets[@]} ; i++)); do for ((i = 0; $i < ${#targets[@]}; i++)); do


if [[ $img_vers ]];then if [[ $img_vers ]]; then
target="${targets[$i]}-${kernels[$i]}" target="${targets[$i]}-${kernels[$i]}"
else else
target="${targets[$i]}" target="${targets[$i]}"
fi fi
kernel="${kernels[$i]}" kernel="${kernels[$i]}"


# Duplicate code: No way found how to redirect output based on $quiet # Duplicate code: No way found how to redirect output based on $quiet
if [[ $quiet == 1 ]];then if [[ $quiet == 1 ]]; then
echo "$target|$kernel|$dracut_args|$basicmodules" echo "$target|$kernel|$dracut_args|$basicmodules"
if [[ $basicmodules ]]; then if [[ $basicmodules ]]; then
dracut $dracut_args --add-drivers "$basicmodules" "$target" \ dracut $dracut_args --add-drivers "$basicmodules" "$target" \
"$kernel" &>/dev/null "$kernel" &> /dev/null
else else
dracut $dracut_args "$target" "$kernel" &>/dev/null dracut $dracut_args "$target" "$kernel" &> /dev/null
fi fi
else else
if [[ $basicmodules ]]; then if [[ $basicmodules ]]; then
dracut $dracut_args --add-drivers "$basicmodules" "$target" \ dracut $dracut_args --add-drivers "$basicmodules" "$target" \
"$kernel" "$kernel"
else else
dracut $dracut_args "$target" "$kernel" dracut $dracut_args "$target" "$kernel"
fi fi
fi fi
done done

253
mkinitrd-suse.sh

@ -25,7 +25,7 @@ dracut_cmd=dracut


error() { echo "$@" >&2; } error() { echo "$@" >&2; }


usage () { usage() {
[[ $1 = '-n' ]] && cmd=echo || cmd=error [[ $1 = '-n' ]] && cmd=echo || cmd=error


$cmd "usage: ${0##*/} [options]" $cmd "usage: ${0##*/} [options]"
@ -85,16 +85,16 @@ read_arg() {
if [[ $2 =~ $rematch ]]; then if [[ $2 =~ $rematch ]]; then
read "$param" <<< "${BASH_REMATCH[1]}" read "$param" <<< "${BASH_REMATCH[1]}"
else else
for ((i=3; $i <= $#; i++)); do for ((i = 3; $i <= $#; i++)); do
# Only read next arg if it not an arg itself. # Only read next arg if it not an arg itself.
if [[ ${*:$i:1} = -* ]];then if [[ ${*:$i:1} = -* ]]; then
break break
fi fi
result="$result ${@:$i:1}" result="$result ${@:$i:1}"
# There is no way to shift our callers args, so # There is no way to shift our callers args, so
# return "no of args" to indicate they should do it instead. # return "no of args" to indicate they should do it instead.
done done
read "$1" <<< "$result" read "$1" <<< "$result"
return $(($i - 3)) return $(($i - 3))
fi fi
} }
@ -104,12 +104,12 @@ calc_netmask() {
local prefix=$1 local prefix=$1


[ -z "$prefix" ] && return [ -z "$prefix" ] && return
mask=$(( 0xffffffff << (32 - $prefix) )) mask=$((0xffffffff << (32 - $prefix)))
byte1=$(( mask >> 24 )) byte1=$((mask >> 24))
byte2=$(( mask >> 16 )) byte2=$((mask >> 16))
byte3=$(( mask >> 8 )) byte3=$((mask >> 8))
byte4=$(( mask & 0xff )) byte4=$((mask & 0xff))
netmask=$(printf "%d.%d.%d.%d" $(( byte1 & 0xff )) $(( byte2 & 0xff )) $(( byte3 & 0xff )) $byte4); netmask=$(printf "%d.%d.%d.%d" $((byte1 & 0xff)) $((byte2 & 0xff)) $((byte3 & 0xff)) $byte4)


echo $netmask echo $netmask
} }
@ -135,8 +135,7 @@ is_xen_kernel() {
local root_dir=$2 local root_dir=$2
local cfg local cfg


for cfg in ${root_dir}/boot/config-$kversion $root_dir/lib/modules/$kversion/build/.config for cfg in ${root_dir}/boot/config-$kversion $root_dir/lib/modules/$kversion/build/.config; do
do
test -r $cfg || continue test -r $cfg || continue
grep -q "^CONFIG_XEN=y\$" $cfg grep -q "^CONFIG_XEN=y\$" $cfg
return return
@ -151,12 +150,12 @@ kernel_version_from_image() {
local kernel_image="$1" kernel_image_gz="${dir}vmlinux-${1#*-}.gz" local kernel_image="$1" kernel_image_gz="${dir}vmlinux-${1#*-}.gz"
echo kernel_image_gz="'$kernel_image_gz'" >&2 echo kernel_image_gz="'$kernel_image_gz'" >&2


if get_kernel_version "$kernel_image" 2>/dev/null; then if get_kernel_version "$kernel_image" 2> /dev/null; then
return return
fi fi


# As a last resort, try vmlinux-$version.gz, which might be around # As a last resort, try vmlinux-$version.gz, which might be around
get_kernel_version "$kernel_image_gz" 2>/dev/null get_kernel_version "$kernel_image_gz" 2> /dev/null
} }


# Taken over from SUSE mkinitrd # Taken over from SUSE mkinitrd
@ -165,30 +164,31 @@ default_kernel_images() {
local qf='%{NAME}-%{VERSION}-%{RELEASE}\n' local qf='%{NAME}-%{VERSION}-%{RELEASE}\n'


case "${DRACUT_ARCH:-$(uname -m)}" in case "${DRACUT_ARCH:-$(uname -m)}" in
s390|s390x) s390 | s390x)
regex='image' regex='image'
;; ;;
ppc|ppc64) ppc | ppc64)
regex='vmlinux' regex='vmlinux'
;; ;;
i?86|x86_64) i?86 | x86_64)
regex='vmlinuz' regex='vmlinuz'
;; ;;
arm*) arm*)
regex='[uz]Image' regex='[uz]Image'
;; ;;
aarch64|riscv64) aarch64 | riscv64)
regex='Image' regex='Image'
;; ;;
*) regex='vmlinu.' *)
regex='vmlinu.'
;; ;;
esac esac


kernel_images="" kernel_images=""
initrd_images="" initrd_images=""
for kernel_image in $(ls $boot_dir \ for kernel_image in $(ls $boot_dir \
| sed -ne "\|^$regex\(-[0-9.]\+-[0-9]\+-[a-z0-9]\+$\)\?|p" \ | sed -ne "\|^$regex\(-[0-9.]\+-[0-9]\+-[a-z0-9]\+$\)\?|p" \
| grep -v kdump$ ) ; do | grep -v kdump$); do


# Note that we cannot check the RPM database here -- this # Note that we cannot check the RPM database here -- this
# script is itself called from within the binary kernel # script is itself called from within the binary kernel
@ -198,120 +198,137 @@ default_kernel_images() {
[ "${kernel_image%%.gz}" != "$kernel_image" ] && continue [ "${kernel_image%%.gz}" != "$kernel_image" ] && continue


kernel_version=$(kernel_version_from_image \ kernel_version=$(kernel_version_from_image \
$boot_dir/$kernel_image 2> /dev/null) $boot_dir/$kernel_image 2> /dev/null)
initrd_image=$(echo $kernel_image | sed -e "s|${regex}|initrd|") initrd_image=$(echo $kernel_image | sed -e "s|${regex}|initrd|")
if [ "$kernel_image" != "$initrd_image" -a \ if [ "$kernel_image" != "$initrd_image" -a \
-n "$kernel_version" -a \ -n "$kernel_version" -a \
-d "/lib/modules/$kernel_version" ]; then -d "/lib/modules/$kernel_version" ]; then
kernel_images="$kernel_images $boot_dir/$kernel_image" kernel_images="$kernel_images $boot_dir/$kernel_image"
initrd_images="$initrd_images $boot_dir/$initrd_image" initrd_images="$initrd_images $boot_dir/$initrd_image"
fi fi
done done
for kernel_image in $kernel_images;do for kernel_image in $kernel_images; do
kernels="$kernels ${kernel_image#*-}" kernels="$kernels ${kernel_image#*-}"
done done
for initrd_image in $initrd_images;do for initrd_image in $initrd_images; do
targets="$targets $initrd_image" targets="$targets $initrd_image"
done done
} }


while (($# > 0)); do while (($# > 0)); do
case ${1%%=*} in case ${1%%=*} in
-f) read_arg feature_list "$@" || shift $? -f)
# Could be several features read_arg feature_list "$@" || shift $?
;; # Could be several features
-k) # Would be nice to get a list of images here ;;
read_arg kernel_images "$@" || shift $? -k) # Would be nice to get a list of images here
for kernel_image in $kernel_images;do read_arg kernel_images "$@" || shift $?
[ -L "/boot/$kernel_image" ] && kernel_image="$(readlink "/boot/$kernel_image")" for kernel_image in $kernel_images; do
kernels="$kernels ${kernel_image#*-}" [ -L "/boot/$kernel_image" ] && kernel_image="$(readlink "/boot/$kernel_image")"
done kernels="$kernels ${kernel_image#*-}"
;; done
-i) read_arg initrd_images "$@" || shift $? ;;
for initrd_image in $initrd_images;do -i)
[ -L "/boot/$initrd_image" ] && initrd_image="$(readlink "/boot/$initrd_image")" read_arg initrd_images "$@" || shift $?
# Check if the initrd_image contains a path. for initrd_image in $initrd_images; do
# if not, then add the default boot_dir [ -L "/boot/$initrd_image" ] && initrd_image="$(readlink "/boot/$initrd_image")"
dname=`dirname $initrd_image` # Check if the initrd_image contains a path.
if [ "$dname" == "." ]; then # if not, then add the default boot_dir
targets="$targets $boot_dir/$initrd_image"; dname=$(dirname $initrd_image)
else if [ "$dname" == "." ]; then
targets="$targets $initrd_image"; targets="$targets $boot_dir/$initrd_image"
fi else
done targets="$targets $initrd_image"
;; fi
-b) read_arg boot_dir "$@" || shift $? done
if [ ! -d $boot_dir ];then ;;
error "Boot directory $boot_dir does not exist" -b)
exit 1 read_arg boot_dir "$@" || shift $?
fi if [ ! -d $boot_dir ]; then
;; error "Boot directory $boot_dir does not exist"
-t) read_arg tmp_dir "$@" || shift $? exit 1
dracut_args="${dracut_args} --tmpdir $tmp_dir" fi
;; ;;
-M) read_arg map_file "$@" || shift $? -t)
;; read_arg tmp_dir "$@" || shift $?
-A) dracut_args="${dracut_args} --no-host-only";; dracut_args="${dracut_args} --tmpdir $tmp_dir"
-B) skip_update_bootloader=1;; ;;
-v|--verbose) dracut_args="${dracut_args} -v";; -M)
-L) logfile=;; read_arg map_file "$@" || shift $?
-h|--help) usage -n;; ;;
-m) read_arg module_list "$@" || shift $? ;; -A) dracut_args="${dracut_args} --no-host-only" ;;
-u) read_arg domu_module_list "$@" || shift $? -B) skip_update_bootloader=1 ;;
echo "mkinitrd: DomU modules not yet supported" ;; -v | --verbose) dracut_args="${dracut_args} -v" ;;
-d) read_arg rootfs "$@" || shift $? -L) logfile= ;;
dracut_args="${dracut_args} --filesystems $rootfs" ;; -h | --help) usage -n ;;
-D) read_arg dhcp_if "$@" || shift $? -m) read_arg module_list "$@" || shift $? ;;
dracut_cmdline="${dracut_cmdline} ip=${dhcp_if}:dhcp" -u)
;; read_arg domu_module_list "$@" || shift $?
-I) read_arg static_if "$@" || shift $? echo "mkinitrd: DomU modules not yet supported"
dracut_cmdline="${dracut_cmdline} ip=$(ipconfig $static_if)": ;;
;; -d)
-a) read_arg acpi_dsdt "$@" || shift $? read_arg rootfs "$@" || shift $?
echo "Obsolete -a param, use acpi_table_dir= and acpi_override= variables in /etc/dracut.conf.d/" dracut_args="${dracut_args} --filesystems $rootfs"
exit 1 ;;
;; -D)
-s) read_arg boot_splash "$@" || shift $? read_arg dhcp_if "$@" || shift $?
echo "mkinitrd: boot splash not yet supported" dracut_cmdline="${dracut_cmdline} ip=${dhcp_if}:dhcp"
exit 1 ;;
;; -I)
-V) echo "mkinitrd: vendor scipts are no longer supported" read_arg static_if "$@" || shift $?
exit 1;; dracut_cmdline="${dracut_cmdline} ip=$(ipconfig $static_if)":
--dracut) ;;
read_arg dracut_cmd "$@" || shift $? ;; -a)
--version|-R) read_arg acpi_dsdt "$@" || shift $?
echo "Obsolete -a param, use acpi_table_dir= and acpi_override= variables in /etc/dracut.conf.d/"
exit 1
;;
-s)
read_arg boot_splash "$@" || shift $?
echo "mkinitrd: boot splash not yet supported"
exit 1
;;
-V)
echo "mkinitrd: vendor scipts are no longer supported"
exit 1
;;
--dracut)
read_arg dracut_cmd "$@" || shift $?
;;
--version | -R)
echo "mkinitrd: dracut compatibility wrapper" echo "mkinitrd: dracut compatibility wrapper"
exit 0;; exit 0
--quiet|-q) quiet=1;; ;;
*) if [[ ! $targets ]]; then --quiet | -q) quiet=1 ;;
*) if [[ ! $targets ]]; then
targets=$1 targets=$1
elif [[ ! $kernels ]]; then elif [[ ! $kernels ]]; then
kernels=$1 kernels=$1
else else
usage usage
fi;; fi ;;
esac esac
shift shift
done done


[[ $targets && $kernels ]] || default_kernel_images [[ $targets && $kernels ]] || default_kernel_images
if [[ ! $targets || ! $kernels ]];then if [[ ! $targets || ! $kernels ]]; then
error "No kernel found in $boot_dir or bad modules dir in /lib/modules" error "No kernel found in $boot_dir or bad modules dir in /lib/modules"
exit 1 exit 1
fi fi


# We can have several targets/kernels, transform the list to an array # We can have several targets/kernels, transform the list to an array
targets=( $targets ) targets=($targets)
[[ $kernels ]] && kernels=( $kernels ) [[ $kernels ]] && kernels=($kernels)


[[ $logfile ]] && dracut_args="${dracut_args} --logfile $logfile" [[ $logfile ]] && dracut_args="${dracut_args} --logfile $logfile"
dracut_args="${dracut_args} --force" dracut_args="${dracut_args} --force"


[[ $dracut_cmdline ]] && dracut_args="${dracut_args} --kernel-cmdline ${dracut_cmdline}" [[ $dracut_cmdline ]] && dracut_args="${dracut_args} --kernel-cmdline ${dracut_cmdline}"
[ -z "$(type -p update-bootloader)" ] && skip_update_bootloader=1 [ -z "$(type -p update-bootloader)" ] && skip_update_bootloader=1


# Update defaults from /etc/sysconfig/kernel # Update defaults from /etc/sysconfig/kernel
if [ -f /etc/sysconfig/kernel ] ; then if [ -f /etc/sysconfig/kernel ]; then
. /etc/sysconfig/kernel . /etc/sysconfig/kernel
fi fi
[[ $module_list ]] || module_list="${INITRD_MODULES}" [[ $module_list ]] || module_list="${INITRD_MODULES}"
@ -320,17 +337,17 @@ shopt -s extglob


failed="" failed=""


for ((i=0 ; $i<${#targets[@]} ; i++)); do for ((i = 0; $i < ${#targets[@]}; i++)); do


if [[ $img_vers ]];then if [[ $img_vers ]]; then
target="${targets[$i]}-${kernels[$i]}" target="${targets[$i]}-${kernels[$i]}"
else else
target="${targets[$i]}" target="${targets[$i]}"
fi fi
kernel="${kernels[$i]}" kernel="${kernels[$i]}"


if is_xen_kernel $kernel $rootfs ; then if is_xen_kernel $kernel $rootfs; then
modules_all="${module_list} ${domu_module_list}" modules_all="${module_list} ${domu_module_list}"
else else
modules_all="${module_list}" modules_all="${module_list}"
fi fi
@ -342,19 +359,19 @@ for ((i=0 ; $i<${#targets[@]} ; i++)); do
echo "Creating initrd: $target" echo "Creating initrd: $target"


# Duplicate code: No way found how to redirect output based on $quiet # Duplicate code: No way found how to redirect output based on $quiet
if [[ $quiet == 1 ]];then if [[ $quiet == 1 ]]; then
# Duplicate code: --force-drivers must not be called with empty string # Duplicate code: --force-drivers must not be called with empty string
# -> dracut bug workarounded ugly, because of complex whitespace # -> dracut bug workarounded ugly, because of complex whitespace
# expansion magics # expansion magics
if [ -n "${modules_all}" ];then if [ -n "${modules_all}" ]; then
$dracut_cmd $dracut_args --force-drivers "${modules_all}" "$target" "$kernel" &>/dev/null $dracut_cmd $dracut_args --force-drivers "${modules_all}" "$target" "$kernel" &> /dev/null
[ $? -ne 0 ] && failed="$failed $target" [ $? -ne 0 ] && failed="$failed $target"
else else
$dracut_cmd $dracut_args "$target" "$kernel" &>/dev/null $dracut_cmd $dracut_args "$target" "$kernel" &> /dev/null
[ $? -ne 0 ] && failed="$failed $target" [ $? -ne 0 ] && failed="$failed $target"
fi fi
else else
if [ -n "${modules_all}" ];then if [ -n "${modules_all}" ]; then
$dracut_cmd $dracut_args --force-drivers "${modules_all}" "$target" "$kernel" $dracut_cmd $dracut_args --force-drivers "${modules_all}" "$target" "$kernel"
[ $? -ne 0 ] && failed="$failed $target" [ $? -ne 0 ] && failed="$failed $target"
else else
@ -364,7 +381,7 @@ for ((i=0 ; $i<${#targets[@]} ; i++)); do
fi fi
done done


if [ "$skip_update_bootloader" ] ; then if [ "$skip_update_bootloader" ]; then
echo 2>&1 "Did not refresh the bootloader. You might need to refresh it manually." echo 2>&1 "Did not refresh the bootloader. You might need to refresh it manually."
else else
update-bootloader --refresh update-bootloader --refresh

1
modules.d/00bash/module-setup.sh

@ -18,4 +18,3 @@ install() {
# Prefer bash as /bin/sh if it is available. # Prefer bash as /bin/sh if it is available.
inst /bin/bash && ln -sf bash "${initdir}/bin/sh" inst /bin/bash && ln -sf bash "${initdir}/bin/sh"
} }


1
modules.d/00dash/module-setup.sh

@ -18,4 +18,3 @@ install() {
# Prefer dash as /bin/sh if it is available. # Prefer dash as /bin/sh if it is available.
inst /bin/dash && ln -sf dash "${initdir}/bin/sh" inst /bin/dash && ln -sf dash "${initdir}/bin/sh"
} }


1
modules.d/00mksh/module-setup.sh

@ -18,4 +18,3 @@ install() {
# Prefer mksh as /bin/sh if it is available. # Prefer mksh as /bin/sh if it is available.
inst /bin/mksh && ln -sf mksh "${initdir}/bin/sh" inst /bin/mksh && ln -sf mksh "${initdir}/bin/sh"
} }


30
modules.d/00systemd/module-setup.sh

@ -1,7 +1,10 @@
#!/bin/bash #!/bin/bash


getSystemdVersion() { getSystemdVersion() {
[ -z "$SYSTEMD_VERSION" ] && SYSTEMD_VERSION=$("$systemdutildir"/systemd --version | { read -r _ b _; echo "$b"; }) [ -z "$SYSTEMD_VERSION" ] && SYSTEMD_VERSION=$("$systemdutildir"/systemd --version | {
read -r _ b _
echo "$b"
})
# Check if the systemd version is a valid number # Check if the systemd version is a valid number
if ! [[ $SYSTEMD_VERSION =~ ^[0-9]+$ ]]; then if ! [[ $SYSTEMD_VERSION =~ ^[0-9]+$ ]]; then
dfatal "systemd version is not a number ($SYSTEMD_VERSION)" dfatal "systemd version is not a number ($SYSTEMD_VERSION)"
@ -16,8 +19,8 @@ check() {
[[ $mount_needs ]] && return 1 [[ $mount_needs ]] && return 1
if require_binaries "$systemdutildir"/systemd; then if require_binaries "$systemdutildir"/systemd; then
SYSTEMD_VERSION=$(getSystemdVersion) SYSTEMD_VERSION=$(getSystemdVersion)
(( SYSTEMD_VERSION >= 198 )) && return 0 ((SYSTEMD_VERSION >= 198)) && return 0
return 255 return 255
fi fi


return 1 return 1
@ -43,9 +46,9 @@ install() {
fi fi


if [[ $(getSystemdVersion) -ge 240 ]]; then if [[ $(getSystemdVersion) -ge 240 ]]; then
inst_multiple -o \ inst_multiple -o \
"$systemdutildir"/system-generators/systemd-debug-generator \ "$systemdutildir"/system-generators/systemd-debug-generator \
"$systemdsystemunitdir"/debug-shell.service "$systemdsystemunitdir"/debug-shell.service
fi fi


inst_multiple -o \ inst_multiple -o \
@ -170,12 +173,13 @@ install() {
[[ -f $i ]] || continue [[ -f $i ]] || continue
while read -r _line || [ -n "$_line" ]; do while read -r _line || [ -n "$_line" ]; do
case $_line in case $_line in
\#*) \#*) ;;
;;
\;*) \;*) ;;
;;
*) *)
echo "$_line" echo "$_line"
;;
esac esac
done < "$i" done < "$i"
done done
@ -211,8 +215,8 @@ install() {


# install adm user/group for journald # install adm user/group for journald
inst_multiple nologin inst_multiple nologin
grep '^systemd-journal:' "$dracutsysrootdir"/etc/passwd 2>/dev/null >> "$initdir/etc/passwd" grep '^systemd-journal:' "$dracutsysrootdir"/etc/passwd 2> /dev/null >> "$initdir/etc/passwd"
grep '^adm:' "$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 '^systemd-journal:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group"
grep '^wheel:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group" grep '^wheel:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group"
grep '^adm:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group" grep '^adm:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group"
@ -220,7 +224,7 @@ install() {
grep '^root:' "$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 # we don't use systemd-networkd, but the user is in systemd.conf tmpfiles snippet
grep '^systemd-network:' "$dracutsysrootdir"/etc/passwd 2>/dev/null >> "$initdir/etc/passwd" grep '^systemd-network:' "$dracutsysrootdir"/etc/passwd 2> /dev/null >> "$initdir/etc/passwd"
grep '^systemd-network:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group" grep '^systemd-network:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group"


ln_r "$systemdutildir"/systemd "/init" ln_r "$systemdutildir"/systemd "/init"

10
modules.d/00warpclock/warpclock.sh

@ -1,9 +1,9 @@
#!/bin/sh #!/bin/sh


if test -e /etc/adjtime ; then if test -e /etc/adjtime; then
while read line ; do while read line; do
if test "$line" = LOCAL ; then if test "$line" = LOCAL; then
hwclock --systz hwclock --systz
fi fi
done < /etc/adjtime done < /etc/adjtime
fi fi

4
modules.d/01fips/fips-boot.sh

@ -1,10 +1,10 @@
#!/bin/sh #!/bin/sh


if ! fipsmode=$(getarg fips) || [ "$fipsmode" = "0" ]; then if ! fipsmode=$(getarg fips) || [ "$fipsmode" = "0" ]; then
rm -f -- /etc/modprobe.d/fips.conf >/dev/null 2>&1 rm -f -- /etc/modprobe.d/fips.conf > /dev/null 2>&1
elif [ -z "$fipsmode" ]; then elif [ -z "$fipsmode" ]; then
die "FIPS mode have to be enabled by 'fips=1' not just 'fips'" die "FIPS mode have to be enabled by 'fips=1' not just 'fips'"
elif getarg boot= >/dev/null; then elif getarg boot= > /dev/null; then
. /sbin/fips.sh . /sbin/fips.sh
if mount_boot; then if mount_boot; then
do_fips || die "FIPS integrity test failed" do_fips || die "FIPS integrity test failed"

2
modules.d/01fips/fips-load-crypto.sh

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh


if ! fipsmode=$(getarg fips) || [ $fipsmode = "0" ]; then if ! fipsmode=$(getarg fips) || [ $fipsmode = "0" ]; then
rm -f -- /etc/modprobe.d/fips.conf >/dev/null 2>&1 rm -f -- /etc/modprobe.d/fips.conf > /dev/null 2>&1
else else
. /sbin/fips.sh . /sbin/fips.sh
fips_load_crypto || die "FIPS integrity test failed" fips_load_crypto || die "FIPS integrity test failed"

2
modules.d/01fips/fips-noboot.sh

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh


if ! fipsmode=$(getarg fips) || [ "$fipsmode" = "0" ]; then if ! fipsmode=$(getarg fips) || [ "$fipsmode" = "0" ]; then
rm -f -- /etc/modprobe.d/fips.conf >/dev/null 2>&1 rm -f -- /etc/modprobe.d/fips.conf > /dev/null 2>&1
elif [ -z "$fipsmode" ]; then elif [ -z "$fipsmode" ]; then
die "FIPS mode have to be enabled by 'fips=1' not just 'fips'" die "FIPS mode have to be enabled by 'fips=1' not just 'fips'"
elif ! [ -f /tmp/fipsdone ]; then elif ! [ -f /tmp/fipsdone ]; then

44
modules.d/01fips/fips.sh

@ -12,23 +12,23 @@ else
} }
fi fi


mount_boot() mount_boot() {
{
boot=$(getarg boot=) boot=$(getarg boot=)


if [ -n "$boot" ]; then if [ -n "$boot" ]; then
case "$boot" in case "$boot" in
LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*) LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*)
boot="$(label_uuid_to_dev "$boot")" boot="$(label_uuid_to_dev "$boot")"
;; ;;
/dev/*) /dev/*) ;;
;;
*) *)
die "You have to specify boot=<boot device> as a boot option for fips=1" ;; die "You have to specify boot=<boot device> as a boot option for fips=1"
;;
esac esac


if ! [ -e "$boot" ]; then if ! [ -e "$boot" ]; then
udevadm trigger --action=add >/dev/null 2>&1 udevadm trigger --action=add > /dev/null 2>&1
[ -z "$UDEVVERSION" ] && UDEVVERSION=$(udevadm --version) [ -z "$UDEVVERSION" ] && UDEVVERSION=$(udevadm --version)
i=0 i=0
while ! [ -e $boot ]; do while ! [ -e $boot ]; do
@ -39,7 +39,7 @@ mount_boot()
fi fi
[ -e $boot ] && break [ -e $boot ] && break
sleep 0.5 sleep 0.5
i=$(($i+1)) i=$(($i + 1))
[ $i -gt 40 ] && break [ $i -gt 40 ] && break
done done
fi fi
@ -55,8 +55,7 @@ mount_boot()
fi fi
} }


do_rhevh_check() do_rhevh_check() {
{
KERNEL=$(uname -r) KERNEL=$(uname -r)
kpath=${1} kpath=${1}


@ -71,23 +70,21 @@ do_rhevh_check()
return 0 return 0
} }


nonfatal_modprobe() nonfatal_modprobe() {
{ modprobe $1 2>&1 > /dev/stdout \
modprobe $1 2>&1 > /dev/stdout | | while read -r line || [ -n "$line" ]; do
while read -r line || [ -n "$line" ]; do
echo "${line#modprobe: FATAL: }" >&2 echo "${line#modprobe: FATAL: }" >&2
done done
} }


fips_load_crypto() fips_load_crypto() {
{
FIPSMODULES=$(cat /etc/fipsmodules) FIPSMODULES=$(cat /etc/fipsmodules)


fips_info "Loading and integrity checking all crypto modules" fips_info "Loading and integrity checking all crypto modules"
mv /etc/modprobe.d/fips.conf /etc/modprobe.d/fips.conf.bak mv /etc/modprobe.d/fips.conf /etc/modprobe.d/fips.conf.bak
for _module in $FIPSMODULES; do for _module in $FIPSMODULES; do
if [ "$_module" != "tcrypt" ]; then if [ "$_module" != "tcrypt" ]; then
if ! nonfatal_modprobe "${_module}" 2>/tmp/fips.modprobe_err; then if ! nonfatal_modprobe "${_module}" 2> /tmp/fips.modprobe_err; then
# check if kernel provides generic algo # check if kernel provides generic algo
_found=0 _found=0
while read _k _s _v || [ -n "$_k" ]; do while read _k _s _v || [ -n "$_k" ]; do
@ -95,7 +92,7 @@ fips_load_crypto()
[ "$_v" != "$_module" ] && continue [ "$_v" != "$_module" ] && continue
_found=1 _found=1
break break
done </proc/crypto done < /proc/crypto
[ "$_found" = "0" ] && cat /tmp/fips.modprobe_err >&2 && return 1 [ "$_found" = "0" ] && cat /tmp/fips.modprobe_err >&2 && return 1
fi fi
fi fi
@ -107,8 +104,7 @@ fips_load_crypto()
rmmod tcrypt rmmod tcrypt
} }


do_fips() do_fips() {
{
local _v local _v
local _s local _s
local _v local _v
@ -159,7 +155,7 @@ do_fips()


> /tmp/fipsdone > /tmp/fipsdone


umount /boot >/dev/null 2>&1 umount /boot > /dev/null 2>&1


return 0 return 0
} }

44
modules.d/01systemd-ask-password/module-setup.sh

@ -34,26 +34,26 @@ install() {
$systemdsystemunitdir/sysinit.target.wants/systemd-ask-password-console.path \ $systemdsystemunitdir/sysinit.target.wants/systemd-ask-password-console.path \
systemd-ask-password systemd-tty-ask-password-agent systemd-ask-password systemd-tty-ask-password-agent


# Enable the systemd type service unit for systemd-ask-password. # Enable the systemd type service unit for systemd-ask-password.
$SYSTEMCTL -q --root "$initdir" enable systemd-ask-password-console.service $SYSTEMCTL -q --root "$initdir" enable systemd-ask-password-console.service


# Install systemd-ask-password plymouth units if plymouth is enabled. # Install systemd-ask-password plymouth units if plymouth is enabled.
if dracut_module_included "plymouth"; then if dracut_module_included "plymouth"; then
inst_multiple -o \ inst_multiple -o \
$systemdsystemunitdir/systemd-ask-password-plymouth.path \ $systemdsystemunitdir/systemd-ask-password-plymouth.path \
$systemdsystemunitdir/systemd-ask-password-plymouth.service $systemdsystemunitdir/systemd-ask-password-plymouth.service


$SYSTEMCTL -q --root "$initdir" enable systemd-ask-password-plymouth.service $SYSTEMCTL -q --root "$initdir" enable systemd-ask-password-plymouth.service
fi fi


# Uncomment this section if the usecase for wall module in the initramfs arises. # Uncomment this section if the usecase for wall module in the initramfs arises.
# Install systemd-ask-password wall units if <wall module> is enabled. # Install systemd-ask-password wall units if <wall module> is enabled.
#if dracut_module_included "<wall module>"; then #if dracut_module_included "<wall module>"; then
# inst_multiple -o \ # inst_multiple -o \
# $systemdsystemunitdir/systemd-ask-password-wall.path \ # $systemdsystemunitdir/systemd-ask-password-wall.path \
# $systemdsystemunitdir/systemd-ask-password-wall.service \ # $systemdsystemunitdir/systemd-ask-password-wall.service \
# $systemdsystemunitdir/multi-user.target.wants/systemd-ask-password-wall.path # $systemdsystemunitdir/multi-user.target.wants/systemd-ask-password-wall.path
# #
# $SYSTEMCTL -q --root "$initdir" enable systemd-ask-password-wall.service # $SYSTEMCTL -q --root "$initdir" enable systemd-ask-password-wall.service
#fi #fi
} }

5
modules.d/01systemd-coredump/module-setup.sh

@ -27,14 +27,13 @@ depends() {
# Install the required file(s) and directories for the module in the initramfs. # Install the required file(s) and directories for the module in the initramfs.
install() { install() {


inst_dir /var/lib/systemd/coredump inst_dir /var/lib/systemd/coredump
inst_multiple -o \ inst_multiple -o \
$sysctld/50-coredump.conf \ $sysctld/50-coredump.conf \
$systemdutildir/coredump.conf \ $systemdutildir/coredump.conf \
$systemdsystemunitdir/systemd-coredump \ $systemdsystemunitdir/systemd-coredump \
$systemdsystemunitdir/systemd-coredump.socket \ $systemdsystemunitdir/systemd-coredump.socket \
$systemdsystemunitdir/systemd-coredump@.service\ $systemdsystemunitdir/systemd-coredump@.service $systemdsystemunitdir/sockets.target.wants/systemd-coredump.socket \
$systemdsystemunitdir/sockets.target.wants/systemd-coredump.socket \
coredumpctl coredumpctl


# Install the hosts local user configurations if enabled. # Install the hosts local user configurations if enabled.

30
modules.d/01systemd-modules-load/module-setup.sh

@ -26,24 +26,24 @@ depends() {
# Install the required file(s) for the module in the initramfs. # Install the required file(s) for the module in the initramfs.
install() { install() {


# Create systemd-modules-load related directories. # Create systemd-modules-load related directories.
inst_dir $modulesload inst_dir $modulesload
inst_dir $modulesloadconfdir inst_dir $modulesloadconfdir


# Install related files for systemd-modules-load # Install related files for systemd-modules-load
inst_multiple -o \ inst_multiple -o \
$systemdsystemunitdir/systemd-modules-load.service \ $systemdsystemunitdir/systemd-modules-load.service \
$systemdutildir/systemd-modules-load $systemdutildir/systemd-modules-load


# Install local user configurations if host only is enabled.. # Install local user configurations if host only is enabled..
if [[ $hostonly ]]; then if [[ $hostonly ]]; then
inst_multiple -H -o \ inst_multiple -H -o \
$systemdsystemconfdir/systemd-modules-load.service \ $systemdsystemconfdir/systemd-modules-load.service \
$systemdsystemconfdir/systemd-systemd-modules-load.d/*.conf \ $systemdsystemconfdir/systemd-systemd-modules-load.d/*.conf \
${NULL} ${NULL}
fi fi


# Enable the systemd type service unit for systemd-modules-load. # Enable the systemd type service unit for systemd-modules-load.
$SYSTEMCTL -q --root "$initdir" enable systemd-modules-load.service $SYSTEMCTL -q --root "$initdir" enable systemd-modules-load.service


} }

12
modules.d/01systemd-sysusers/module-setup.sh

@ -37,17 +37,17 @@ install() {
$systemdsystemunitdir/systemd-sysusers.service \ $systemdsystemunitdir/systemd-sysusers.service \
systemd-sysusers systemd-sysusers


# Install the hosts local user configurations if enabled. # Install the hosts local user configurations if enabled.
if [[ $hostonly ]]; then if [[ $hostonly ]]; then
inst_multiple -H -o \ inst_multiple -H -o \
$sysusersconfdir/basic.conf \ $sysusersconfdir/basic.conf \
$sysusersconfdir/systemd.conf \ $sysusersconfdir/systemd.conf \
$systemdsystemconfdir/systemd-sysusers.service \ $systemdsystemconfdir/systemd-sysusers.service \
$systemdsystemconfdir/systemd-sysusers.service.d/*.conf \ $systemdsystemconfdir/systemd-sysusers.service.d/*.conf \
${NULL} ${NULL}
fi fi


# Enable the systemd type service unit for sysusers. # Enable the systemd type service unit for sysusers.
$SYSTEMCTL -q --root "$initdir" enable systemd-sysusers.service $SYSTEMCTL -q --root "$initdir" enable systemd-sysusers.service


} }

3
modules.d/02caps/caps.sh

@ -10,7 +10,7 @@ if [ "$capsmode" = "1" ]; then
CAPS_KEXEC_DISABLED=$(getarg rd.caps.disablekexec=) CAPS_KEXEC_DISABLED=$(getarg rd.caps.disablekexec=)


info "Loading CAPS_MODULES $CAPS_MODULES" info "Loading CAPS_MODULES $CAPS_MODULES"
for i in $CAPS_MODULES;do modprobe "$i" 2>&1 >/dev/null | vinfo; done for i in $CAPS_MODULES; do modprobe "$i" 2>&1 > /dev/null | vinfo; done


if [ "$CAPS_MODULES_DISABLED" = "1" -a -e /proc/sys/kernel/modules_disabled ]; then if [ "$CAPS_MODULES_DISABLED" = "1" -a -e /proc/sys/kernel/modules_disabled ]; then
info "Disabling module loading." info "Disabling module loading."
@ -32,4 +32,3 @@ if [ "$capsmode" = "1" ]; then
echo "CAPS_INIT_DROP=\"$CAPS_INIT_DROP\"" > /etc/capsdrop echo "CAPS_INIT_DROP=\"$CAPS_INIT_DROP\"" > /etc/capsdrop
info "Will drop capabilities $CAPS_INIT_DROP from init." info "Will drop capabilities $CAPS_INIT_DROP from init."
fi fi


3
modules.d/02caps/module-setup.sh

@ -15,11 +15,10 @@ depends() {
install() { install() {
if ! dracut_module_included "systemd"; then if ! dracut_module_included "systemd"; then
inst_hook pre-pivot 00 "$moddir/caps.sh" inst_hook pre-pivot 00 "$moddir/caps.sh"
inst $(find_binary capsh 2>/dev/null) /usr/sbin/capsh inst $(find_binary capsh 2> /dev/null) /usr/sbin/capsh
# capsh wants bash and we need bash also # capsh wants bash and we need bash also
inst /bin/bash inst /bin/bash
else else
dwarning "caps: does not work with systemd in the initramfs" dwarning "caps: does not work with systemd in the initramfs"
fi fi
} }


36
modules.d/02systemd-networkd/module-setup.sh

@ -27,33 +27,32 @@ install() {
$systemdutildir/network/99-default.link \ $systemdutildir/network/99-default.link \
networkctl ip networkctl ip


#hostnamectl timedatectl #hostnamectl timedatectl
# $systemdutildir/systemd-timesyncd \ # $systemdutildir/systemd-timesyncd \
# $systemdutildir/systemd-timedated \ # $systemdutildir/systemd-timedated \
# $systemdutildir/systemd-hostnamed \ # $systemdutildir/systemd-hostnamed \
# $systemdutildir/systemd-resolvd \ # $systemdutildir/systemd-resolvd \
# $systemdutildir/systemd-resolve-host \ # $systemdutildir/systemd-resolve-host \
# $systemdsystemunitdir/systemd-resolved.service \ # $systemdsystemunitdir/systemd-resolved.service \
# $systemdsystemunitdir/systemd-hostnamed.service \ # $systemdsystemunitdir/systemd-hostnamed.service \
# $systemdsystemunitdir/systemd-timesyncd.service \ # $systemdsystemunitdir/systemd-timesyncd.service \
# $systemdsystemunitdir/systemd-timedated.service \ # $systemdsystemunitdir/systemd-timedated.service \
# $systemdsystemunitdir/time-sync.target \ # $systemdsystemunitdir/time-sync.target \
# /etc/systemd/resolved.conf \ # /etc/systemd/resolved.conf \



# inst_dir /var/lib/systemd/clock # inst_dir /var/lib/systemd/clock


grep '^systemd-network:' "$dracutsysrootdir"/etc/passwd 2>/dev/null >> "$initdir/etc/passwd" grep '^systemd-network:' "$dracutsysrootdir"/etc/passwd 2> /dev/null >> "$initdir/etc/passwd"
grep '^systemd-network:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group" 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/passwd 2>/dev/null >> "$initdir/etc/passwd"
# grep '^systemd-timesync:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group" # grep '^systemd-timesync:' "$dracutsysrootdir"/etc/group >> "$initdir/etc/group"


_arch=${DRACUT_ARCH:-$(uname -m)} _arch=${DRACUT_ARCH:-$(uname -m)}
inst_libdir_file \ inst_libdir_file \
{"tls/$_arch/",tls/,"$_arch/",}"libnss_dns.so.*" \ {"tls/$_arch/",tls/,"$_arch/",}"libnss_dns.so.*" \
{"tls/$_arch/",tls/,"$_arch/",}"libnss_mdns4_minimal.so.*" \ {"tls/$_arch/",tls/,"$_arch/",}"libnss_mdns4_minimal.so.*" \
{"tls/$_arch/",tls/,"$_arch/",}"libnss_myhostname.so.*" \ {"tls/$_arch/",tls/,"$_arch/",}"libnss_myhostname.so.*" \
{"tls/$_arch/",tls/,"$_arch/",}"libnss_resolve.so.*" {"tls/$_arch/",tls/,"$_arch/",}"libnss_resolve.so.*"


# systemd-timesyncd.service # systemd-timesyncd.service
for i in \ for i in \
@ -64,4 +63,3 @@ install() {
$SYSTEMCTL -q --root "$initdir" enable "$i" $SYSTEMCTL -q --root "$initdir" enable "$i"
done done
} }


2
modules.d/03modsign/load-modsign-keys.sh

@ -5,7 +5,7 @@
# Copyright 2013 Red Hat, Inc. # Copyright 2013 Red Hat, Inc.
# Peter Jones <pjones@redhat.com> # Peter Jones <pjones@redhat.com>


for x in /lib/modules/keys/* ; do for x in /lib/modules/keys/*; do
[ "${x}" = "/lib/modules/keys/*" ] && break [ "${x}" = "/lib/modules/keys/*" ] && break
keyctl padd asymmetric "" @s < ${x} keyctl padd asymmetric "" @s < ${x}
done done

2
modules.d/03modsign/module-setup.sh

@ -31,7 +31,7 @@ install() {


inst_hook pre-trigger 01 "$moddir/load-modsign-keys.sh" inst_hook pre-trigger 01 "$moddir/load-modsign-keys.sh"


for x in "$dracutsysrootdir"/lib/modules/keys/* ; do for x in "$dracutsysrootdir"/lib/modules/keys/*; do
[[ "${x}" = "$dracutsysrootdir/lib/modules/keys/*" ]] && break [[ "${x}" = "$dracutsysrootdir/lib/modules/keys/*" ]] && break
inst_simple "${x#$dracutsysrootdir}" inst_simple "${x#$dracutsysrootdir}"
done done

1
modules.d/03rescue/module-setup.sh

@ -17,4 +17,3 @@ install() {
ping netstat rpcinfo vi scp ping6 ssh \ ping netstat rpcinfo vi scp ping6 ssh \
fsck fsck.ext2 fsck.ext4 fsck.ext3 fsck.ext4dev fsck.f2fs fsck.vfat e2fsck fsck fsck.ext2 fsck.ext4 fsck.ext3 fsck.ext4dev fsck.f2fs fsck.vfat e2fsck
} }


14
modules.d/04watchdog/module-setup.sh

@ -16,17 +16,17 @@ install() {
# Do not add watchdog hooks if systemd module is included # Do not add watchdog hooks if systemd module is included
# In that case, systemd will manage watchdog kick # In that case, systemd will manage watchdog kick
if ! dracut_module_included "systemd"; then if ! dracut_module_included "systemd"; then
inst_hook cmdline 00 "$moddir/watchdog.sh" inst_hook cmdline 00 "$moddir/watchdog.sh"
inst_hook cmdline 50 "$moddir/watchdog.sh" inst_hook cmdline 50 "$moddir/watchdog.sh"
inst_hook pre-trigger 00 "$moddir/watchdog.sh" inst_hook pre-trigger 00 "$moddir/watchdog.sh"
inst_hook initqueue 00 "$moddir/watchdog.sh" inst_hook initqueue 00 "$moddir/watchdog.sh"
inst_hook mount 00 "$moddir/watchdog.sh" inst_hook mount 00 "$moddir/watchdog.sh"
inst_hook mount 50 "$moddir/watchdog.sh" inst_hook mount 50 "$moddir/watchdog.sh"
inst_hook mount 99 "$moddir/watchdog.sh" inst_hook mount 99 "$moddir/watchdog.sh"
inst_hook pre-pivot 00 "$moddir/watchdog.sh" inst_hook pre-pivot 00 "$moddir/watchdog.sh"
inst_hook pre-pivot 99 "$moddir/watchdog.sh" inst_hook pre-pivot 99 "$moddir/watchdog.sh"
inst_hook cleanup 00 "$moddir/watchdog.sh" inst_hook cleanup 00 "$moddir/watchdog.sh"
inst_hook cleanup 99 "$moddir/watchdog.sh" inst_hook cleanup 99 "$moddir/watchdog.sh"
fi fi


inst_hook emergency 02 "$moddir/watchdog-stop.sh" inst_hook emergency 02 "$moddir/watchdog-stop.sh"

16
modules.d/04watchdog/watchdog.sh

@ -1,12 +1,12 @@
#!/bin/sh #!/bin/sh
if [ -e /dev/watchdog ]; then if [ -e /dev/watchdog ]; then
if [ ! -e /tmp/watchdog_timeout ]; then if [ ! -e /tmp/watchdog_timeout ]; then
wdctl -s 60 /dev/watchdog >/dev/null 2>&1 wdctl -s 60 /dev/watchdog > /dev/null 2>&1
> /tmp/watchdog_timeout > /tmp/watchdog_timeout
fi fi
info "Triggering watchdog" info "Triggering watchdog"
>/dev/watchdog > /dev/watchdog
else else
modprobe ib700wdt modprobe ib700wdt
modprobe i6300esb modprobe i6300esb
fi fi

1
modules.d/05busybox/module-setup.sh

@ -29,4 +29,3 @@ install() {
ln_r /usr/bin/busybox $_path ln_r /usr/bin/busybox $_path
done done
} }


1
modules.d/06dbus-broker/module-setup.sh

@ -65,7 +65,6 @@ install() {
/^\[Socket\]/aRemoveOnStop=yes' \ /^\[Socket\]/aRemoveOnStop=yes' \
"$initdir$systemdsystemunitdir/dbus.socket" "$initdir$systemdsystemunitdir/dbus.socket"



# Install the hosts local user configurations if enabled. # Install the hosts local user configurations if enabled.
if [[ $hostonly ]]; then if [[ $hostonly ]]; then
inst_multiple -H -o \ inst_multiple -H -o \

4
modules.d/06dbus-daemon/module-setup.sh

@ -65,7 +65,7 @@ install() {


# Adjusting dependencies for initramfs in the dbus socket unit. # Adjusting dependencies for initramfs in the dbus socket unit.
sed -i -e \ sed -i -e \
'/^\[Unit\]/aDefaultDependencies=no\ '/^\[Unit\]/aDefaultDependencies=no\
Conflicts=shutdown.target\ Conflicts=shutdown.target\
Before=shutdown.target Before=shutdown.target
/^\[Socket\]/aRemoveOnStop=yes' \ /^\[Socket\]/aRemoveOnStop=yes' \
@ -84,7 +84,7 @@ install() {
$systemdsystemconfdir/dbus.service \ $systemdsystemconfdir/dbus.service \
$systemdsystemconfdir/dbus.service.d/*.conf \ $systemdsystemconfdir/dbus.service.d/*.conf \
${NULL} ${NULL}
fi fi


# We need to make sure that systemd-tmpfiles-setup.service->dbus.socket # We need to make sure that systemd-tmpfiles-setup.service->dbus.socket
# will not wait for local-fs.target to start if swap is encrypted, # will not wait for local-fs.target to start if swap is encrypted,

6
modules.d/09dbus/module-setup.sh

@ -13,13 +13,13 @@ depends() {
local _module local _module
# Add a dbus meta dependency based on the module in use. # Add a dbus meta dependency based on the module in use.
for _module in dbus-daemon dbus-broker; do for _module in dbus-daemon dbus-broker; do
if dracut_module_included "$_module" ; then if dracut_module_included "$_module"; then
echo "$_module" echo "$_module"
return 0 return 0
fi fi
done; done


if find_binary dbus-broker &> /dev/null ; then if find_binary dbus-broker &> /dev/null; then
echo "dbus-broker" echo "dbus-broker"
return 0 return 0
else else

9
modules.d/10i18n/console_init.sh

@ -45,7 +45,9 @@ set_keymap() {
} }


set_font() { set_font() {
local dev=$1; local trans=''; local uni='' local dev=$1
local trans=''
local uni=''


[ -z "${FONT}" ] && FONT=${DEFAULT_FONT} [ -z "${FONT}" ] && FONT=${DEFAULT_FONT}
[ -n "${FONT_MAP}" ] && trans="-m ${FONT_MAP}" [ -n "${FONT_MAP}" ] && trans="-m ${FONT_MAP}"
@ -62,8 +64,8 @@ dev_close() {
dev_open() { dev_open() {
local dev=$1 local dev=$1


exec 6<${dev} && \ exec 6< ${dev} \
exec 7>>${dev} && exec 7>> ${dev}
} }


dev=/dev/${1#/dev/} dev=/dev/${1#/dev/}
@ -90,4 +92,3 @@ set_font ${dev}
set_keymap set_keymap


dev_close dev_close


118
modules.d/10i18n/module-setup.sh

@ -28,19 +28,19 @@ install() {
VCONFIG_CONF="/etc/vconsole.conf" VCONFIG_CONF="/etc/vconsole.conf"


# This is from 10redhat-i18n. # This is from 10redhat-i18n.
findkeymap () { findkeymap() {
local MAPS=$1 local MAPS=$1
local MAPNAME=${1%.map*} local MAPNAME=${1%.map*}
local map local map
[[ ! -f $dracutsysrootdir$MAPS ]] && \ [[ ! -f $dracutsysrootdir$MAPS ]] \
MAPS=$(find $dracutsysrootdir${kbddir}/keymaps -type f -name ${MAPNAME} -o -name ${MAPNAME}.map -o -name ${MAPNAME}.map.\*) && MAPS=$(find $dracutsysrootdir${kbddir}/keymaps -type f -name ${MAPNAME} -o -name ${MAPNAME}.map -o -name ${MAPNAME}.map.\*)


for map in $MAPS; do for map in $MAPS; do
KEYMAPS="$KEYMAPS $map " KEYMAPS="$KEYMAPS $map "
case $map in case $map in
*.gz) cmd="zgrep";; *.gz) cmd="zgrep" ;;
*.bz2) cmd="bzgrep";; *.bz2) cmd="bzgrep" ;;
*) cmd="grep";; *) cmd="grep" ;;
esac esac


for INCL in $($cmd "^include " $map | while read _ a _ || [ -n "$a" ]; do echo ${a//\"/}; done); do for INCL in $($cmd "^include " $map | while read _ a _ || [ -n "$a" ]; do echo ${a//\"/}; done); do
@ -52,43 +52,41 @@ install() {
done done
} }


# Function gathers variables from distributed files among the tree, maps to # Function gathers variables from distributed files among the tree, maps to
# specified names and prints the result in format "new-name=value". # specified names and prints the result in format "new-name=value".
# #
# $@ = list in format specified below (BNF notation) # $@ = list in format specified below (BNF notation)
# #
# <list> ::= <element> | <element> " " <list> # <list> ::= <element> | <element> " " <list>
# <element> ::= <conf-file-name> ":" <map-list> # <element> ::= <conf-file-name> ":" <map-list>
# <map-list> ::= <mapping> | <mapping> "," <map-list> # <map-list> ::= <mapping> | <mapping> "," <map-list>
# <mapping> ::= <src-var> "-" <dst-var> | <src-var> # <mapping> ::= <src-var> "-" <dst-var> | <src-var>
# #
# We assume no whitespace are allowed between symbols. # We assume no whitespace are allowed between symbols.
# <conf-file-name> is a file holding <src-var> in your system. # <conf-file-name> is a file holding <src-var> in your system.
# <src-var> is a variable holding value of meaning the same as <dst-var>. # <src-var> is a variable holding value of meaning the same as <dst-var>.
# <dst-var> is a variable which will be set up inside initramfs. # <dst-var> is a variable which will be set up inside initramfs.
# If <dst-var> has the same name as <src-var> we can omit <dst-var>. # If <dst-var> has the same name as <src-var> we can omit <dst-var>.
# #
# Example: # Example:
# /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS # /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS
# <list> = /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS # <list> = /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS
# <element> = /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS # <element> = /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS
# <conf-file-name> = /etc/conf.d/keymaps # <conf-file-name> = /etc/conf.d/keymaps
# <map-list> = KEYMAP,extended_keymaps-EXT_KEYMAPS # <map-list> = KEYMAP,extended_keymaps-EXT_KEYMAPS
# <mapping> = KEYMAP # <mapping> = KEYMAP
# <src-var> = KEYMAP # <src-var> = KEYMAP
# <mapping> = extended_keymaps-EXT_KEYMAPS # <mapping> = extended_keymaps-EXT_KEYMAPS
# <src-var> = extended_keymaps # <src-var> = extended_keymaps
# <dst-var> = EXT_KEYMAPS # <dst-var> = EXT_KEYMAPS
gather_vars() { gather_vars() {
local item map value local item map value


# FIXME: double check # FIXME: double check
# shellcheck disable=SC2068 # shellcheck disable=SC2068
for item in $@ for item in $@; do
do
item=(${item/:/ }) item=(${item/:/ })
for map in ${item[1]//,/ } for map in ${item[1]//,/ }; do
do
map=(${map//-/ }) map=(${map//-/ })
if [[ -f "$dracutsysrootdir${item[0]}" ]]; then if [[ -f "$dracutsysrootdir${item[0]}" ]]; then
value=$(grep "^${map[0]}=" "$dracutsysrootdir${item[0]}") value=$(grep "^${map[0]}=" "$dracutsysrootdir${item[0]}")
@ -129,12 +127,12 @@ install() {
find "${initdir}${kbddir}/" -name README\* -delete find "${initdir}${kbddir}/" -name README\* -delete
find "${initdir}${kbddir}/" -name '*.gz' -print -quit \ find "${initdir}${kbddir}/" -name '*.gz' -print -quit \
| while read line || [ -n "$line" ]; do | while read line || [ -n "$line" ]; do
inst_multiple gzip inst_multiple gzip
done done


find "${initdir}${kbddir}/" -name '*.bz2' -print -quit \ find "${initdir}${kbddir}/" -name '*.bz2' -print -quit \
| while read line || [ -n "$line" ]; do | while read line || [ -n "$line" ]; do
inst_multiple bzip2 inst_multiple bzip2
done done
} }


@ -146,20 +144,16 @@ install() {
[ -f $dracutsysrootdir$VCONFIG_CONF ] && . $dracutsysrootdir$VCONFIG_CONF [ -f $dracutsysrootdir$VCONFIG_CONF ] && . $dracutsysrootdir$VCONFIG_CONF


shopt -q -s nocasematch shopt -q -s nocasematch
if [[ ${UNICODE} ]] if [[ ${UNICODE} ]]; then
then if [[ ${UNICODE} = YES || ${UNICODE} = 1 ]]; then
if [[ ${UNICODE} = YES || ${UNICODE} = 1 ]]
then
UNICODE=1 UNICODE=1
elif [[ ${UNICODE} = NO || ${UNICODE} = 0 ]] elif [[ ${UNICODE} = NO || ${UNICODE} = 0 ]]; then
then
UNICODE=0 UNICODE=0
else else
UNICODE='' UNICODE=''
fi fi
fi fi
if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]] if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]]; then
then
UNICODE=1 UNICODE=1
fi fi
shopt -q -u nocasematch shopt -q -u nocasematch
@ -174,10 +168,10 @@ install() {
# determines whether non-UNICODE or UNICODE version is used # determines whether non-UNICODE or UNICODE version is used


if [[ ${KEYTABLE} ]]; then if [[ ${KEYTABLE} ]]; then
if [[ ${UNICODE} == 1 ]]; then if [[ ${UNICODE} == 1 ]]; then
[[ ${KEYTABLE} =~ .*\.uni.* ]] || KEYTABLE=${KEYTABLE%.map*}.uni [[ ${KEYTABLE} =~ .*\.uni.* ]] || KEYTABLE=${KEYTABLE%.map*}.uni
fi fi
KEYMAP=${KEYTABLE} KEYMAP=${KEYTABLE}
fi fi


# I'm not sure of the purpose of UNIKEYMAP and GRP_TOGGLE. They were in # I'm not sure of the purpose of UNIKEYMAP and GRP_TOGGLE. They were in
@ -191,8 +185,7 @@ install() {


findkeymap ${KEYMAP} findkeymap ${KEYMAP}


for map in ${EXT_KEYMAPS} for map in ${EXT_KEYMAPS}; do
do
ddebug "Adding extra map: ${map}" ddebug "Adding extra map: ${map}"
findkeymap ${map} findkeymap ${map}
done done
@ -203,24 +196,21 @@ install() {


inst_opt_decompress ${kbddir}/consolefonts/${DEFAULT_FONT}.* inst_opt_decompress ${kbddir}/consolefonts/${DEFAULT_FONT}.*


if [[ ${FONT} ]] && [[ ${FONT} != ${DEFAULT_FONT} ]] if [[ ${FONT} ]] && [[ ${FONT} != ${DEFAULT_FONT} ]]; then
then
FONT=${FONT%.psf*} FONT=${FONT%.psf*}
inst_opt_decompress ${kbddir}/consolefonts/${FONT}.* inst_opt_decompress ${kbddir}/consolefonts/${FONT}.*
fi fi


if [[ ${FONT_MAP} ]] if [[ ${FONT_MAP} ]]; then
then
FONT_MAP=${FONT_MAP%.trans} FONT_MAP=${FONT_MAP%.trans}
# There are three different formats that setfont supports # There are three different formats that setfont supports
inst_simple ${kbddir}/consoletrans/${FONT_MAP} \ inst_simple ${kbddir}/consoletrans/${FONT_MAP} \
|| inst_simple ${kbddir}/consoletrans/${FONT_MAP}.trans \ || inst_simple ${kbddir}/consoletrans/${FONT_MAP}.trans \
|| inst_simple ${kbddir}/consoletrans/${FONT_MAP}_to_uni.trans \ || inst_simple ${kbddir}/consoletrans/${FONT_MAP}_to_uni.trans \
|| dwarn "Could not find FONT_MAP ${FONT_MAP}!" || dwarn "Could not find FONT_MAP ${FONT_MAP}!"
fi fi


if [[ ${FONT_UNIMAP} ]] if [[ ${FONT_UNIMAP} ]]; then
then
FONT_UNIMAP=${FONT_UNIMAP%.uni} FONT_UNIMAP=${FONT_UNIMAP%.uni}
inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
fi fi
@ -251,8 +241,8 @@ install() {
kbddir='' kbddir=''
done done


[[ -f $dracutsysrootdir$I18N_CONF && -f $dracutsysrootdir$VCONFIG_CONF ]] || \ [[ -f $dracutsysrootdir$I18N_CONF && -f $dracutsysrootdir$VCONFIG_CONF ]] \
[[ ! ${hostonly} || ${i18n_vars} ]] || { || [[ ! ${hostonly} || ${i18n_vars} ]] || {
derror 'i18n_vars not set! Please set up i18n_vars in ' \ derror 'i18n_vars not set! Please set up i18n_vars in ' \
'configuration file.' 'configuration file.'
} }

25
modules.d/10i18n/parse-i18n.sh

@ -4,9 +4,12 @@ inst_key_val() {
local _value local _value
local _file local _file
local _default local _default
_file="$1"; shift _file="$1"
_key="$1"; shift shift
_default="$1"; shift _key="$1"
shift
_default="$1"
shift
_value="$(getarg "$@")" _value="$(getarg "$@")"
[ -z "${_value}" ] && _value=$_default [ -z "${_value}" ] && _value=$_default
if [ -n "${_value}" ]; then if [ -n "${_value}" ]; then
@ -16,15 +19,15 @@ inst_key_val() {
unset _value unset _value
} }


inst_key_val /etc/vconsole.conf KEYMAP '' rd.vconsole.keymap KEYMAP -d KEYTABLE inst_key_val /etc/vconsole.conf KEYMAP '' rd.vconsole.keymap KEYMAP -d KEYTABLE
inst_key_val /etc/vconsole.conf FONT '' rd.vconsole.font FONT -d SYSFONT inst_key_val /etc/vconsole.conf FONT '' rd.vconsole.font FONT -d SYSFONT
inst_key_val /etc/vconsole.conf FONT_MAP '' rd.vconsole.font.map FONT_MAP -d CONTRANS inst_key_val /etc/vconsole.conf FONT_MAP '' rd.vconsole.font.map FONT_MAP -d CONTRANS
inst_key_val /etc/vconsole.conf FONT_UNIMAP '' rd.vconsole.font.unimap FONT_UNIMAP -d UNIMAP inst_key_val /etc/vconsole.conf FONT_UNIMAP '' rd.vconsole.font.unimap FONT_UNIMAP -d UNIMAP
inst_key_val /etc/vconsole.conf UNICODE 1 rd.vconsole.font.unicode UNICODE vconsole.unicode inst_key_val /etc/vconsole.conf UNICODE 1 rd.vconsole.font.unicode UNICODE vconsole.unicode
inst_key_val /etc/vconsole.conf EXT_KEYMAP '' rd.vconsole.keymap.ext EXT_KEYMAP inst_key_val /etc/vconsole.conf EXT_KEYMAP '' rd.vconsole.keymap.ext EXT_KEYMAP


inst_key_val /etc/locale.conf LANG '' rd.locale.LANG LANG inst_key_val /etc/locale.conf LANG '' rd.locale.LANG LANG
inst_key_val /etc/locale.conf LC_ALL '' rd.locale.LC_ALL LC_ALL inst_key_val /etc/locale.conf LC_ALL '' rd.locale.LC_ALL LC_ALL


if [ -f /etc/locale.conf ]; then if [ -f /etc/locale.conf ]; then
. /etc/locale.conf . /etc/locale.conf

9
modules.d/30convertfs/convertfs.sh

@ -47,7 +47,6 @@ if ! [ -e "$ROOT/usr/bin" ]; then
exit 1 exit 1
fi fi



if ! needconvert; then if ! needconvert; then
echo "Your system is already converted." echo "Your system is already converted."
exit 0 exit 0
@ -82,7 +81,7 @@ find_mount() {


# usage: ismounted <mountpoint> # usage: ismounted <mountpoint>
# usage: ismounted /dev/<device> # usage: ismounted /dev/<device>
if command -v findmnt >/dev/null; then if command -v findmnt > /dev/null; then
ismounted() { ismounted() {
findmnt "$1" > /dev/null 2>&1 findmnt "$1" > /dev/null 2>&1
} }
@ -104,7 +103,7 @@ fi
cleanup() { cleanup() {
echo "Something failed. Move back to the original state" echo "Something failed. Move back to the original state"
for dir in "$ROOT/bin" "$ROOT/sbin" "$ROOT/lib" "$ROOT/lib64" \ for dir in "$ROOT/bin" "$ROOT/sbin" "$ROOT/lib" "$ROOT/lib64" \
"$ROOT/usr/bin" "$ROOT/usr/sbin" "$ROOT/usr/lib" \ "$ROOT/usr/bin" "$ROOT/usr/sbin" "$ROOT/usr/lib" \
"$ROOT/usr/lib64"; do "$ROOT/usr/lib64"; do
[[ -d "${dir}.usrmove-new" ]] && rm -fr -- "${dir}.usrmove-new" [[ -d "${dir}.usrmove-new" ]] && rm -fr -- "${dir}.usrmove-new"
if [[ -d "${dir}.usrmove-old" ]]; then if [[ -d "${dir}.usrmove-old" ]]; then
@ -166,8 +165,8 @@ done
echo "Clean up backup files." echo "Clean up backup files."
# everything seems to work; cleanup # everything seems to work; cleanup
for dir in bin sbin lib lib64; do for dir in bin sbin lib lib64; do
# if we get killed in the middle of "rm -rf", ensure not to leave # if we get killed in the middle of "rm -rf", ensure not to leave
# an incomplete directory, which is moved back by cleanup() # an incomplete directory, which is moved back by cleanup()
[[ -d "$ROOT/usr/${dir}.usrmove-old" ]] \ [[ -d "$ROOT/usr/${dir}.usrmove-old" ]] \
&& mv "$ROOT/usr/${dir}.usrmove-old" "$ROOT/usr/${dir}.usrmove-old~" && mv "$ROOT/usr/${dir}.usrmove-old" "$ROOT/usr/${dir}.usrmove-old~"
[[ -d "$ROOT/${dir}.usrmove-old" ]] \ [[ -d "$ROOT/${dir}.usrmove-old" ]] \

1
modules.d/30convertfs/module-setup.sh

@ -17,4 +17,3 @@ install() {
inst_hook pre-pivot 99 "$moddir/do-convertfs.sh" inst_hook pre-pivot 99 "$moddir/do-convertfs.sh"
inst_script "$moddir/convertfs.sh" /usr/bin/convertfs inst_script "$moddir/convertfs.sh" /usr/bin/convertfs
} }


64
modules.d/35network-legacy/dhclient-script.sh

@ -2,8 +2,8 @@


PATH=/usr/sbin:/usr/bin:/sbin:/bin PATH=/usr/sbin:/usr/bin:/sbin:/bin


type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh type ip_to_var > /dev/null 2>&1 || . /lib/net-lib.sh


# We already need a set netif here # We already need a set netif here
netif=$interface netif=$interface
@ -31,8 +31,8 @@ setup_interface() {
# problems with UDP traffic, among other things. As such, # problems with UDP traffic, among other things. As such,
# disallow MTUs from 576 and below by default, so that broken # disallow MTUs from 576 and below by default, so that broken
# MTUs are ignored, but higher stuff is allowed (1492, 1500, etc). # MTUs are ignored, but higher stuff is allowed (1492, 1500, etc).
if [ -n "$mtu" ] && [ $mtu -gt 576 ] ; then if [ -n "$mtu" ] && [ $mtu -gt 576 ]; then
if ! ip link set $netif mtu $mtu ; then if ! ip link set $netif mtu $mtu; then
ip link set $netif down ip link set $netif down
ip link set $netif mtu $mtu ip link set $netif mtu $mtu
linkup $netif linkup $netif
@ -43,8 +43,8 @@ setup_interface() {
${lease_time:+valid_lft $lease_time} \ ${lease_time:+valid_lft $lease_time} \
${preferred_lft:+preferred_lft ${preferred_lft}} ${preferred_lft:+preferred_lft ${preferred_lft}}


if [ -n "$gw" ] ; then if [ -n "$gw" ]; then
if [ "$mask" = "255.255.255.255" ] ; then if [ "$mask" = "255.255.255.255" ]; then
# point-to-point connection => set explicit route to gateway # point-to-point connection => set explicit route to gateway
echo ip route add $gw dev $netif > /tmp/net.$netif.gw echo ip route add $gw dev $netif > /tmp/net.$netif.gw
fi fi
@ -52,7 +52,7 @@ setup_interface() {
echo "$gw" | { echo "$gw" | {
IFS=' ' read -r main_gw other_gw IFS=' ' read -r main_gw other_gw
echo ip route replace default via $main_gw dev $netif >> /tmp/net.$netif.gw echo ip route replace default via $main_gw dev $netif >> /tmp/net.$netif.gw
if [ -n "$other_gw" ] ; then if [ -n "$other_gw" ]; then
for g in $other_gw; do for g in $other_gw; do
echo ip route add default via $g dev $netif >> /tmp/net.$netif.gw echo ip route add default via $g dev $netif >> /tmp/net.$netif.gw
done done
@ -62,7 +62,7 @@ setup_interface() {


if getargbool 1 rd.peerdns; then if getargbool 1 rd.peerdns; then
[ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf
if [ -n "$namesrv" ] ; then if [ -n "$namesrv" ]; then
for s in $namesrv; do for s in $namesrv; do
echo nameserver $s echo nameserver $s
done done
@ -92,7 +92,7 @@ setup_interface6() {


if getargbool 1 rd.peerdns; then if getargbool 1 rd.peerdns; then
[ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf
if [ -n "$namesrv" ] ; then if [ -n "$namesrv" ]; then
for s in $namesrv; do for s in $namesrv; do
echo nameserver $s echo nameserver $s
done done
@ -119,13 +119,19 @@ parse_option_121() {
# Parse the arguments into a CIDR net/mask string # Parse the arguments into a CIDR net/mask string
if [ $mask -gt 24 ]; then if [ $mask -gt 24 ]; then
destination="$1.$2.$3.$4/$mask" destination="$1.$2.$3.$4/$mask"
shift; shift; shift; shift shift
shift
shift
shift
elif [ $mask -gt 16 ]; then elif [ $mask -gt 16 ]; then
destination="$1.$2.$3.0/$mask" destination="$1.$2.$3.0/$mask"
shift; shift; shift shift
shift
shift
elif [ $mask -gt 8 ]; then elif [ $mask -gt 8 ]; then
destination="$1.$2.0.0/$mask" destination="$1.$2.0.0/$mask"
shift; shift shift
shift
elif [ $mask -gt 0 ]; then elif [ $mask -gt 0 ]; then
destination="$1.0.0.0/$mask" destination="$1.0.0.0/$mask"
shift shift
@ -135,7 +141,10 @@ parse_option_121() {


# Read the gateway # Read the gateway
gateway="$1.$2.$3.$4" gateway="$1.$2.$3.$4"
shift; shift; shift; shift shift
shift
shift
shift


# Multicast routing on Linux # Multicast routing on Linux
# - If you set a next-hop address for a multicast group, this breaks with Cisco switches # - If you set a next-hop address for a multicast group, this breaks with Cisco switches
@ -150,7 +159,6 @@ parse_option_121() {
done done
} }



case $reason in case $reason in
PREINIT) PREINIT)
echo "dhcp: PREINIT $netif up" echo "dhcp: PREINIT $netif up"
@ -170,13 +178,13 @@ case $reason in
read layer2 < /sys/class/net/$netif/device/layer2 read layer2 < /sys/class/net/$netif/device/layer2
fi fi
if [ "$layer2" != "0" ]; then if [ "$layer2" != "0" ]; then
if command -v arping2 >/dev/null; then if command -v arping2 > /dev/null; then
if arping2 -q -C 1 -c 2 -I $netif -0 $new_ip_address ; then if arping2 -q -C 1 -c 2 -I $netif -0 $new_ip_address; then
warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying" warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
exit 1 exit 1
fi fi
else else
if ! arping -f -q -D -c 2 -I $netif $new_ip_address ; then if ! arping -f -q -D -c 2 -I $netif $new_ip_address; then
warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying" warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
exit 1 exit 1
fi fi
@ -187,7 +195,7 @@ case $reason in
set | while read line || [ -n "$line" ]; do set | while read line || [ -n "$line" ]; do
[ "${line#new_}" = "$line" ] && continue [ "${line#new_}" = "$line" ] && continue
echo "$line" echo "$line"
done >/tmp/dhclient.$netif.dhcpopts done > /tmp/dhclient.$netif.dhcpopts


{ {
echo '. /lib/net-lib.sh' echo '. /lib/net-lib.sh'
@ -204,22 +212,22 @@ case $reason in
} > $hookdir/initqueue/setup_net_$netif.sh } > $hookdir/initqueue/setup_net_$netif.sh


echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhclient-$netif.sh echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhclient-$netif.sh
>/tmp/net.$netif.up > /tmp/net.$netif.up
if [ -e /sys/class/net/${netif}/address ]; then if [ -e /sys/class/net/${netif}/address ]; then
> /tmp/net.$(cat /sys/class/net/${netif}/address).up > /tmp/net.$(cat /sys/class/net/${netif}/address).up
fi fi


;; ;;


RENEW|REBIND) RENEW | REBIND)
unset lease_time unset lease_time
[ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
[ -n "$new_max_life" ] && lease_time=$new_max_life [ -n "$new_max_life" ] && lease_time=$new_max_life
preferred_lft=$lease_time preferred_lft=$lease_time
[ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
ip -4 addr change ${new_ip_address}/${new_subnet_mask} broadcast ${new_broadcast_address} dev ${interface} \ ip -4 addr change ${new_ip_address}/${new_subnet_mask} broadcast ${new_broadcast_address} dev ${interface} \
${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \ ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \
>/dev/null 2>&1 > /dev/null 2>&1
;; ;;


BOUND6) BOUND6)
@ -229,7 +237,7 @@ case $reason in
set | while read line || [ -n "$line" ]; do set | while read line || [ -n "$line" ]; do
[ "${line#new_}" = "$line" ] && continue [ "${line#new_}" = "$line" ] && continue
echo "$line" echo "$line"
done >/tmp/dhclient.$netif.dhcpopts done > /tmp/dhclient.$netif.dhcpopts


{ {
echo '. /lib/net-lib.sh' echo '. /lib/net-lib.sh'
@ -240,24 +248,24 @@ case $reason in
} > $hookdir/initqueue/setup_net_$netif.sh } > $hookdir/initqueue/setup_net_$netif.sh


echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhclient-$netif.sh echo "[ -f /tmp/net.$netif.did-setup ]" > $hookdir/initqueue/finished/dhclient-$netif.sh
>/tmp/net.$netif.up > /tmp/net.$netif.up
if [ -e /sys/class/net/${netif}/address ]; then if [ -e /sys/class/net/${netif}/address ]; then
> /tmp/net.$(cat /sys/class/net/${netif}/address).up > /tmp/net.$(cat /sys/class/net/${netif}/address).up
fi fi
;; ;;


RENEW6|REBIND6) RENEW6 | REBIND6)
unset lease_time unset lease_time
[ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time
[ -n "$new_max_life" ] && lease_time=$new_max_life [ -n "$new_max_life" ] && lease_time=$new_max_life
preferred_lft=$lease_time preferred_lft=$lease_time
[ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life
ip -6 addr change ${new_ip6_address}/${new_ip6_prefixlen} dev ${interface} scope global \ ip -6 addr change ${new_ip6_address}/${new_ip6_prefixlen} dev ${interface} scope global \
${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \ ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \
>/dev/null 2>&1 > /dev/null 2>&1
;; ;;


*) echo "dhcp: $reason";; *) echo "dhcp: $reason" ;;
esac esac


exit 0 exit 0

40
modules.d/35network-legacy/dhcp-multi.sh

@ -23,14 +23,14 @@ do_dhclient() {
while [ $_COUNT -lt $_DHCPRETRY ]; do while [ $_COUNT -lt $_DHCPRETRY ]; do
info "Starting dhcp for interface $netif" info "Starting dhcp for interface $netif"
dhclient $arg \ dhclient $arg \
${_timeout:+--timeout $_timeout} \ ${_timeout:+--timeout $_timeout} \
-q \ -q \
-1 \ -1 \
-cf /etc/dhclient.conf \ -cf /etc/dhclient.conf \
-pf /tmp/dhclient.$netif.pid \ -pf /tmp/dhclient.$netif.pid \
-lf /tmp/dhclient.$netif.lease \ -lf /tmp/dhclient.$netif.lease \
$netif & $netif &
wait $! 2>/dev/null wait $! 2> /dev/null


# wait will return the return value of dhclient # wait will return the return value of dhclient
retv=$? retv=$?
@ -45,7 +45,7 @@ do_dhclient() {
# find the process with that pid and return error code 127. In that # find the process with that pid and return error code 127. In that
# case we need to check if /tmp/dhclient.$netif.lease exists. If it # case we need to check if /tmp/dhclient.$netif.lease exists. If it
# does, it means dhclient finished executing before wait was called, # does, it means dhclient finished executing before wait was called,
# and it was successful (return 0). If /tmp/dhclient.$netif.lease # and it was successful (return 0). If /tmp/dhclient.$netif.lease
# does not exist, then it means dhclient was killed by another thread # does not exist, then it means dhclient was killed by another thread
# or it finished execution but failed dhcp on that interface. # or it finished execution but failed dhcp on that interface.


@ -56,14 +56,14 @@ do_dhclient() {
info "PID $pid not found but DHCP successful on $netif" info "PID $pid not found but DHCP successful on $netif"
return 0 return 0
fi fi
fi fi


_COUNT=$(($_COUNT+1)) _COUNT=$(($_COUNT + 1))
[ $_COUNT -lt $_DHCPRETRY ] && sleep 1 [ $_COUNT -lt $_DHCPRETRY ] && sleep 1
done done
warn "dhcp for interface $netif failed" warn "dhcp for interface $netif failed"
# nuke those files since we failed; we might retry dhcp again if it's e.g. # nuke those files since we failed; we might retry dhcp again if it's e.g.
# `ip=dhcp,dhcp6` and we check for the PID file earlier # `ip=dhcp,dhcp6` and we check for the PID file earlier
rm -f /tmp/dhclient.$netif.{pid,lease} rm -f /tmp/dhclient.$netif.{pid,lease}
return 1 return 1
} }
@ -85,15 +85,15 @@ if [ $ret -eq 0 ]; then
fi fi


# Check if DHCP also suceeded on another interface before this one. # Check if DHCP also suceeded on another interface before this one.
# We will always use the first one on which DHCP succeeded, by using # We will always use the first one on which DHCP succeeded, by using
# a commom file $IFNETFILE, to synchronize between threads. # a commom file $IFNETFILE, to synchronize between threads.
# Consider the race condition in which multiple threads # Consider the race condition in which multiple threads
# corresponding to different interfaces may try to read $IFNETFILE # corresponding to different interfaces may try to read $IFNETFILE
# and find it does not exist; they may all end up thinking they are the # and find it does not exist; they may all end up thinking they are the
# first to succeed (hence more than one thread may end up writing to # first to succeed (hence more than one thread may end up writing to
# $IFNETFILE). To take care of this, instead of checking if $IFNETFILE # $IFNETFILE). To take care of this, instead of checking if $IFNETFILE
# exists to determine if we are the first, we create a symbolic link # exists to determine if we are the first, we create a symbolic link
# in $IFNETFILE, pointing to the interface name ($netif), thus storing # in $IFNETFILE, pointing to the interface name ($netif), thus storing
# the interface name in the link pointer. # the interface name in the link pointer.
# Creating a link will fail, if the link already exists, hence kernel # Creating a link will fail, if the link already exists, hence kernel
# will take care of allowing only first thread to create link, which # will take care of allowing only first thread to create link, which
@ -101,22 +101,22 @@ if [ $ret -eq 0 ]; then
# Also, the link points to the interface name, which will tell us which # Also, the link points to the interface name, which will tell us which
# interface succeeded. # interface succeeded.


if ln -s $netif $IFNETFILE 2>/dev/null; then if ln -s $netif $IFNETFILE 2> /dev/null; then
intf=$(readlink $IFNETFILE) intf=$(readlink $IFNETFILE)
if [ -e /tmp/dhclient.$intf.lease ]; then if [ -e /tmp/dhclient.$intf.lease ]; then
info "DHCP successful on interface $intf" info "DHCP successful on interface $intf"
# Kill all existing dhclient calls for other interfaces, since we # Kill all existing dhclient calls for other interfaces, since we
# already got one successful interface # already got one successful interface


npid=$(cat /tmp/dhclient.$netif.pid) npid=$(cat /tmp/dhclient.$netif.pid)
pidlist=$(pgrep dhclient) pidlist=$(pgrep dhclient)
for pid in $pidlist; do for pid in $pidlist; do
[ "$pid" -eq "$npid" ] && continue [ "$pid" -eq "$npid" ] && continue
kill -9 $pid >/dev/null 2>&1 kill -9 $pid > /dev/null 2>&1
done done
else else
echo "ERROR! $IFNETFILE exists but /tmp/dhclient.$intf.lease does not exist!!!" echo "ERROR! $IFNETFILE exists but /tmp/dhclient.$intf.lease does not exist!!!"
fi fi
else else
info "DHCP success on $netif, and also on $intf" info "DHCP success on $netif, and also on $intf"
exit 0 exit 0

153
modules.d/35network-legacy/ifup.sh

@ -7,8 +7,8 @@
# or it is for manually bring up network ie. for kdump scp vmcore # or it is for manually bring up network ie. for kdump scp vmcore
PATH=/usr/sbin:/usr/bin:/sbin:/bin PATH=/usr/sbin:/usr/bin:/sbin:/bin


type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh type ip_to_var > /dev/null 2>&1 || . /lib/net-lib.sh


# Huh? No $1? # Huh? No $1?
[ -z "$1" ] && exit 1 [ -z "$1" ] && exit 1
@ -17,7 +17,7 @@ type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh
netif=$1 netif=$1


# loopback is always handled the same way # loopback is always handled the same way
if [ "$netif" = "lo" ] ; then if [ "$netif" = "lo" ]; then
ip link set lo up ip link set lo up
ip addr add 127.0.0.1/8 dev lo ip addr add 127.0.0.1/8 dev lo
exit 0 exit 0
@ -36,15 +36,15 @@ do_dhcp_parallel() {
fi fi


bootintf=$(readlink $IFNETFILE) bootintf=$(readlink $IFNETFILE)
if [ ! -z $bootintf ] && [ -e /tmp/dhclient.$bootintf.lease ]; then if [ ! -z $bootintf ] && [ -e /tmp/dhclient.$bootintf.lease ]; then
info "DHCP already succeeded for $bootintf, exiting for $netif" info "DHCP already succeeded for $bootintf, exiting for $netif"
return 1; return 1
fi fi


if [ ! -e /run/NetworkManager/conf.d/10-dracut-dhclient.conf ]; then if [ ! -e /run/NetworkManager/conf.d/10-dracut-dhclient.conf ]; then
mkdir -p /run/NetworkManager/conf.d mkdir -p /run/NetworkManager/conf.d
echo '[main]' > /run/NetworkManager/conf.d/10-dracut-dhclient.conf echo '[main]' > /run/NetworkManager/conf.d/10-dracut-dhclient.conf
echo 'dhcp=dhclient' >>/run/NetworkManager/conf.d/10-dracut-dhclient.conf echo 'dhcp=dhclient' >> /run/NetworkManager/conf.d/10-dracut-dhclient.conf
fi fi


chmod +x /sbin/dhcp-multi.sh chmod +x /sbin/dhcp-multi.sh
@ -73,21 +73,21 @@ do_dhcp() {
if [ ! -e /run/NetworkManager/conf.d/10-dracut-dhclient.conf ]; then if [ ! -e /run/NetworkManager/conf.d/10-dracut-dhclient.conf ]; then
mkdir -p /run/NetworkManager/conf.d mkdir -p /run/NetworkManager/conf.d
echo '[main]' > /run/NetworkManager/conf.d/10-dracut-dhclient.conf echo '[main]' > /run/NetworkManager/conf.d/10-dracut-dhclient.conf
echo 'dhcp=dhclient' >>/run/NetworkManager/conf.d/10-dracut-dhclient.conf echo 'dhcp=dhclient' >> /run/NetworkManager/conf.d/10-dracut-dhclient.conf
fi fi


while [ $_COUNT -lt $_DHCPRETRY ]; do while [ $_COUNT -lt $_DHCPRETRY ]; do
info "Starting dhcp for interface $netif" info "Starting dhcp for interface $netif"
dhclient "$@" \ dhclient "$@" \
${_timeout:+--timeout $_timeout} \ ${_timeout:+--timeout $_timeout} \
-q \ -q \
-1 \ -1 \
-cf /etc/dhclient.conf \ -cf /etc/dhclient.conf \
-pf /tmp/dhclient.$netif.pid \ -pf /tmp/dhclient.$netif.pid \
-lf /tmp/dhclient.$netif.lease \ -lf /tmp/dhclient.$netif.lease \
$netif \ $netif \
&& return 0 && return 0
_COUNT=$(($_COUNT+1)) _COUNT=$(($_COUNT + 1))
[ $_COUNT -lt $_DHCPRETRY ] && sleep 1 [ $_COUNT -lt $_DHCPRETRY ] && sleep 1
done done
warn "dhcp for interface $netif failed" warn "dhcp for interface $netif failed"
@ -102,7 +102,7 @@ load_ipv6() {
modprobe ipv6 modprobe ipv6
i=0 i=0
while [ ! -d /proc/sys/net/ipv6 ]; do while [ ! -d /proc/sys/net/ipv6 ]; do
i=$(($i+1)) i=$(($i + 1))
[ $i -gt 10 ] && break [ $i -gt 10 ] && break
sleep 0.1 sleep 0.1
done done
@ -148,7 +148,7 @@ do_static() {
return 1 return 1
fi fi


ip route get "$ip" 2>/dev/null | { ip route get "$ip" 2> /dev/null | {
read a rest read a rest
if [ "$a" = "local" ]; then if [ "$a" = "local" ]; then
warn "Not assigning $ip to interface $netif, cause it is already assigned!" warn "Not assigning $ip to interface $netif, cause it is already assigned!"
@ -168,13 +168,13 @@ do_static() {
wait_for_ipv6_dad $netif wait_for_ipv6_dad $netif
else else
if [ -z "$srv" ]; then if [ -z "$srv" ]; then
if command -v arping2 >/dev/null; then if command -v arping2 > /dev/null; then
if arping2 -q -C 1 -c 2 -I $netif -0 $ip ; then if arping2 -q -C 1 -c 2 -I $netif -0 $ip; then
warn "Duplicate address detected for $ip for interface $netif." warn "Duplicate address detected for $ip for interface $netif."
return 1 return 1
fi fi
else else
if ! arping -f -q -D -c 2 -I $netif $ip ; then if ! arping -f -q -D -c 2 -I $netif $ip; then
warn "Duplicate address detected for $ip for interface $netif." warn "Duplicate address detected for $ip for interface $netif."
return 1 return 1
fi fi
@ -192,12 +192,12 @@ do_static() {


get_vid() { get_vid() {
case "$1" in case "$1" in
vlan*) vlan*)
echo ${1#vlan} echo ${1#vlan}
;; ;;
*.*) *.*)
echo ${1##*.} echo ${1##*.}
;; ;;
esac esac
} }


@ -230,7 +230,6 @@ if ! [ -e /tmp/vlan.${netif}.phy ]; then
done done
fi fi



# bridge this interface? # bridge this interface?
if [ -z "$NO_BRIDGE_MASTER" ]; then if [ -z "$NO_BRIDGE_MASTER" ]; then
for i in /tmp/bridge.*.info; do for i in /tmp/bridge.*.info; do
@ -238,7 +237,7 @@ if [ -z "$NO_BRIDGE_MASTER" ]; then
unset bridgeslaves unset bridgeslaves
unset bridgename unset bridgename
. "$i" . "$i"
for ethname in $bridgeslaves ; do for ethname in $bridgeslaves; do
[ "$netif" != "$ethname" ] && continue [ "$netif" != "$ethname" ] && continue


NO_BRIDGE_MASTER=yes NO_AUTO_DHCP=yes ifup $ethname NO_BRIDGE_MASTER=yes NO_AUTO_DHCP=yes ifup $ethname
@ -262,40 +261,40 @@ if [ -z "$NO_BOND_MASTER" ]; then
unset bondslaves unset bondslaves
unset bondname unset bondname
. "$i" . "$i"
for slave in $bondslaves ; do for slave in $bondslaves; do
[ "$netif" != "$slave" ] && continue [ "$netif" != "$slave" ] && continue


# already setup # already setup
[ -e /tmp/bond.$bondname.up ] && exit 0 [ -e /tmp/bond.$bondname.up ] && exit 0


# wait for all slaves to show up # wait for all slaves to show up
for slave in $bondslaves ; do for slave in $bondslaves; do
# try to create the slave (maybe vlan or bridge) # try to create the slave (maybe vlan or bridge)
NO_BOND_MASTER=yes NO_AUTO_DHCP=yes ifup $slave NO_BOND_MASTER=yes NO_AUTO_DHCP=yes ifup $slave


if ! ip link show dev $slave >/dev/null 2>&1; then if ! ip link show dev $slave > /dev/null 2>&1; then
# wait for the last slave to show up # wait for the last slave to show up
exit 0 exit 0
fi fi
done done


modprobe -q -b bonding modprobe -q -b bonding
echo "+$bondname" > /sys/class/net/bonding_masters 2>/dev/null echo "+$bondname" > /sys/class/net/bonding_masters 2> /dev/null
ip link set $bondname down ip link set $bondname down


# Stolen from ifup-eth # Stolen from ifup-eth
# add the bits to setup driver parameters here # add the bits to setup driver parameters here
for arg in $bondoptions ; do for arg in $bondoptions; do
key=${arg%%=*}; key=${arg%%=*}
value=${arg##*=}; value=${arg##*=}
# %{value:0:1} is replaced with non-bash specific construct # %{value:0:1} is replaced with non-bash specific construct
if [ "${key}" = "arp_ip_target" -a "${#value}" != "0" -a "+${value%%+*}" != "+" ]; then if [ "${key}" = "arp_ip_target" -a "${#value}" != "0" -a "+${value%%+*}" != "+" ]; then
OLDIFS=$IFS; OLDIFS=$IFS
IFS=','; IFS=','
for arp_ip in $value; do for arp_ip in $value; do
echo +$arp_ip > /sys/class/net/${bondname}/bonding/$key echo +$arp_ip > /sys/class/net/${bondname}/bonding/$key
done done
IFS=$OLDIFS; IFS=$OLDIFS
else else
echo $value > /sys/class/net/${bondname}/bonding/$key echo $value > /sys/class/net/${bondname}/bonding/$key
fi fi
@ -303,7 +302,7 @@ if [ -z "$NO_BOND_MASTER" ]; then


linkup $bondname linkup $bondname


for slave in $bondslaves ; do for slave in $bondslaves; do
cat /sys/class/net/$slave/address > /tmp/net.${bondname}.${slave}.hwaddr cat /sys/class/net/$slave/address > /tmp/net.${bondname}.${slave}.hwaddr
ip link set $slave down ip link set $slave down
echo "+$slave" > /sys/class/net/$bondname/bonding/slaves echo "+$slave" > /sys/class/net/$bondname/bonding/slaves
@ -314,9 +313,9 @@ if [ -z "$NO_BOND_MASTER" ]; then
[ -n "$bondmtu" ] && ip link set mtu $bondmtu dev $bondname [ -n "$bondmtu" ] && ip link set mtu $bondmtu dev $bondname


# add the bits to setup the needed post enslavement parameters # add the bits to setup the needed post enslavement parameters
for arg in $bondoptions ; do for arg in $bondoptions; do
key=${arg%%=*}; key=${arg%%=*}
value=${arg##*=}; value=${arg##*=}
if [ "${key}" = "primary" ]; then if [ "${key}" = "primary" ]; then
echo $value > /sys/class/net/${bondname}/bonding/$key echo $value > /sys/class/net/${bondname}/bonding/$key
fi fi
@ -336,30 +335,30 @@ if [ -z "$NO_TEAM_MASTER" ]; then
unset teammaster unset teammaster
unset teamslaves unset teamslaves
. "$i" . "$i"
for slave in $teamslaves ; do for slave in $teamslaves; do
[ "$netif" != "$slave" ] && continue [ "$netif" != "$slave" ] && continue


[ -e /tmp/team.$teammaster.up ] && exit 0 [ -e /tmp/team.$teammaster.up ] && exit 0


# wait for all slaves to show up # wait for all slaves to show up
for slave in $teamslaves ; do for slave in $teamslaves; do
# try to create the slave (maybe vlan or bridge) # try to create the slave (maybe vlan or bridge)
NO_TEAM_MASTER=yes NO_AUTO_DHCP=yes ifup $slave NO_TEAM_MASTER=yes NO_AUTO_DHCP=yes ifup $slave


if ! ip link show dev $slave >/dev/null 2>&1; then if ! ip link show dev $slave > /dev/null 2>&1; then
# wait for the last slave to show up # wait for the last slave to show up
exit 0 exit 0
fi fi
done done


if [ ! -e /tmp/team.$teammaster.up ] ; then if [ ! -e /tmp/team.$teammaster.up ]; then
# We shall only bring up those _can_ come up # We shall only bring up those _can_ come up
# in case of some slave is gone in active-backup mode # in case of some slave is gone in active-backup mode
working_slaves="" working_slaves=""
for slave in $teamslaves ; do for slave in $teamslaves; do
teamdctl ${teammaster} port present ${slave} 2>/dev/null \ teamdctl ${teammaster} port present ${slave} 2> /dev/null \
&& continue && continue
ip link set dev $slave up 2>/dev/null ip link set dev $slave up 2> /dev/null
if wait_for_if_up $slave; then if wait_for_if_up $slave; then
working_slaves="$working_slaves$slave " working_slaves="$working_slaves$slave "
fi fi
@ -399,7 +398,7 @@ if [ -z "$NO_TEAM_MASTER" ]; then
fi fi


# all synthetic interfaces done.. now check if the interface is available # all synthetic interfaces done.. now check if the interface is available
if ! ip link show dev $netif >/dev/null 2>&1; then if ! ip link show dev $netif > /dev/null 2>&1; then
exit 1 exit 1
fi fi


@ -408,16 +407,15 @@ fi
[ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2" [ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2"


if [ -n "$manualup" ]; then if [ -n "$manualup" ]; then
>/tmp/net.$netif.manualup > /tmp/net.$netif.manualup
rm -f /tmp/net.${netif}.did-setup rm -f /tmp/net.${netif}.did-setup
else else
[ -e /tmp/net.${netif}.did-setup ] && exit 0 [ -e /tmp/net.${netif}.did-setup ] && exit 0
[ -z "$DO_VLAN" ] && \ [ -z "$DO_VLAN" ] \
[ -e /sys/class/net/$netif/address ] && \ && [ -e /sys/class/net/$netif/address ] \
[ -e /tmp/net.$(cat /sys/class/net/$netif/address).did-setup ] && exit 0 && [ -e /tmp/net.$(cat /sys/class/net/$netif/address).did-setup ] && exit 0
fi fi



# Specific configuration, spin through the kernel command line # Specific configuration, spin through the kernel command line
# looking for ip= lines # looking for ip= lines
for p in $(getargs ip=); do for p in $(getargs ip=); do
@ -426,11 +424,11 @@ for p in $(getargs ip=); do
[ "$autoconf" = "ibft" ] && continue [ "$autoconf" = "ibft" ] && continue


case "$dev" in case "$dev" in
??:??:??:??:??:??) # MAC address ??:??:??:??:??:??) # MAC address
_dev=$(iface_for_mac $dev) _dev=$(iface_for_mac $dev)
[ -n "$_dev" ] && dev="$_dev" [ -n "$_dev" ] && dev="$_dev"
;; ;;
??-??-??-??-??-??) # MAC address in BOOTIF form ??-??-??-??-??-??) # MAC address in BOOTIF form
_dev=$(iface_for_mac $(fix_bootif $dev)) _dev=$(iface_for_mac $(fix_bootif $dev))
[ -n "$_dev" ] && dev="$_dev" [ -n "$_dev" ] && dev="$_dev"
;; ;;
@ -450,22 +448,29 @@ for p in $(getargs ip=); do


for autoopt in $(str_replace "$autoconf" "," " "); do for autoopt in $(str_replace "$autoconf" "," " "); do
case $autoopt in case $autoopt in
dhcp|on|any) dhcp | on | any)
do_dhcp -4 ;; do_dhcp -4
;;
single-dhcp) single-dhcp)
do_dhcp_parallel -4 do_dhcp_parallel -4
exit 0 ;; exit 0
;;
dhcp6) dhcp6)
load_ipv6 load_ipv6
do_dhcp -6 ;; do_dhcp -6
;;
auto6) auto6)
do_ipv6auto ;; do_ipv6auto
;;
either6) either6)
do_ipv6auto || do_dhcp -6 ;; do_ipv6auto || do_dhcp -6
;;
link6) link6)
do_ipv6link ;; do_ipv6link
;;
*) *)
do_static ;; do_static
;;
esac esac
done done
ret=$? ret=$?
@ -479,7 +484,7 @@ for p in $(getargs ip=); do
if [ $ret -eq 0 ]; then if [ $ret -eq 0 ]; then
> /tmp/net.${netif}.up > /tmp/net.${netif}.up


if [ -z "$DO_VLAN" ] && [ -e /sys/class/net/${netif}/address ]; then if [ -z "$DO_VLAN" ] && [ -e /sys/class/net/${netif}/address ]; then
> /tmp/net.$(cat /sys/class/net/${netif}/address).up > /tmp/net.$(cat /sys/class/net/${netif}/address).up
fi fi


@ -493,7 +498,7 @@ for p in $(getargs ip=); do
fi fi
fi fi


if command -v wicked >/dev/null && [ -z "$manualup" ]; then if command -v wicked > /dev/null && [ -z "$manualup" ]; then
/sbin/netroot $netif /sbin/netroot $netif
fi fi


@ -514,12 +519,12 @@ if [ -z "$NO_AUTO_DHCP" ] && [ ! -e /tmp/net.${netif}.up ]; then
# No ip lines, no bootdev -> default to dhcp # No ip lines, no bootdev -> default to dhcp
ip=$(getarg ip) ip=$(getarg ip)


if getargs 'ip=dhcp6' >/dev/null || [ -z "$ip" -a "$netroot" = "dhcp6" ]; then if getargs 'ip=dhcp6' > /dev/null || [ -z "$ip" -a "$netroot" = "dhcp6" ]; then
load_ipv6 load_ipv6
do_dhcp -6 do_dhcp -6
ret=$? ret=$?
fi fi
if getargs 'ip=dhcp' >/dev/null || [ -z "$ip" -a "$netroot" != "dhcp6" ]; then if getargs 'ip=dhcp' > /dev/null || [ -z "$ip" -a "$netroot" != "dhcp6" ]; then
do_dhcp -4 do_dhcp -4
ret=$? ret=$?
fi fi
@ -530,11 +535,11 @@ if [ -z "$NO_AUTO_DHCP" ] && [ ! -e /tmp/net.${netif}.up ]; then
echo nameserver $s >> /tmp/net.$netif.resolv.conf echo nameserver $s >> /tmp/net.$netif.resolv.conf
done done


if [ "$ret" -eq 0 ] && [ -n "$(ls /tmp/leaseinfo.${netif}* 2>/dev/null)" ]; then if [ "$ret" -eq 0 ] && [ -n "$(ls /tmp/leaseinfo.${netif}* 2> /dev/null)" ]; then
> /tmp/net.${netif}.did-setup > /tmp/net.${netif}.did-setup
if [ -e /sys/class/net/${netif}/address ]; then if [ -e /sys/class/net/${netif}/address ]; then
> /tmp/net.$(cat /sys/class/net/${netif}/address).did-setup > /tmp/net.$(cat /sys/class/net/${netif}/address).did-setup
fi fi
fi fi
fi fi



8
modules.d/35network-legacy/kill-dhclient.sh

@ -2,14 +2,14 @@


for f in /tmp/dhclient.*.pid; do for f in /tmp/dhclient.*.pid; do
[ -e $f ] || continue [ -e $f ] || continue
read PID < $f; read PID < $f
kill $PID >/dev/null 2>&1 kill $PID > /dev/null 2>&1
done done


sleep 0.1 sleep 0.1


for f in /tmp/dhclient.*.pid; do for f in /tmp/dhclient.*.pid; do
[ -e $f ] || continue [ -e $f ] || continue
read PID < $f; read PID < $f
kill -9 $PID >/dev/null 2>&1 kill -9 $PID > /dev/null 2>&1
done done

3
modules.d/35network-legacy/module-setup.sh

@ -62,7 +62,7 @@ install() {
( (
. "$i" . "$i"
if ! [ "${ONBOOT}" = "no" -o "${ONBOOT}" = "NO" ] \ if ! [ "${ONBOOT}" = "no" -o "${ONBOOT}" = "NO" ] \
&& [ -n "${TEAM_MASTER}${TEAM_CONFIG}${TEAM_PORT_CONFIG}" ]; then && [ -n "${TEAM_MASTER}${TEAM_CONFIG}${TEAM_PORT_CONFIG}" ]; then
if [ -n "$TEAM_CONFIG" ] && [ -n "$DEVICE" ]; then if [ -n "$TEAM_CONFIG" ] && [ -n "$DEVICE" ]; then
mkdir -p $initdir/etc/teamd mkdir -p $initdir/etc/teamd
printf -- "%s" "$TEAM_CONFIG" > "$initdir/etc/teamd/${DEVICE}.conf" printf -- "%s" "$TEAM_CONFIG" > "$initdir/etc/teamd/${DEVICE}.conf"
@ -90,4 +90,3 @@ install() {


dracut_need_initqueue dracut_need_initqueue
} }


18
modules.d/35network-legacy/net-genrules.sh

@ -7,7 +7,7 @@ if [ -z "$netroot" ] && [ ! -e "/tmp/net.ifaces" ] && [ "$NEEDNET" != "1" ]; the
return return
fi fi


command -v fix_bootif >/dev/null || . /lib/net-lib.sh command -v fix_bootif > /dev/null || . /lib/net-lib.sh


# Write udev rules # Write udev rules
{ {
@ -75,15 +75,15 @@ command -v fix_bootif >/dev/null || . /lib/net-lib.sh
echo 'ACTION!="add|change|move", GOTO="net_end"' echo 'ACTION!="add|change|move", GOTO="net_end"'
for iface in $IFACES $RAW_IFACES; do for iface in $IFACES $RAW_IFACES; do
case "$iface" in case "$iface" in
??:??:??:??:??:??) # MAC address ??:??:??:??:??:??) # MAC address
cond="ATTR{address}==\"$iface\"" cond="ATTR{address}==\"$iface\""
echo "$cond, $runcmd, GOTO=\"net_end\"" echo "$cond, $runcmd, GOTO=\"net_end\""
;; ;;
??-??-??-??-??-??) # MAC address in BOOTIF form ??-??-??-??-??-??) # MAC address in BOOTIF form
cond="ATTR{address}==\"$(fix_bootif $iface)\"" cond="ATTR{address}==\"$(fix_bootif $iface)\""
echo "$cond, $runcmd, GOTO=\"net_end\"" echo "$cond, $runcmd, GOTO=\"net_end\""
;; ;;
*) # an interface name *) # an interface name
cond="ENV{INTERFACE}==\"$iface\"" cond="ENV{INTERFACE}==\"$iface\""
echo "$cond, $runcmd, GOTO=\"net_end\"" echo "$cond, $runcmd, GOTO=\"net_end\""
cond="NAME==\"$iface\"" cond="NAME==\"$iface\""
@ -96,11 +96,11 @@ command -v fix_bootif >/dev/null || . /lib/net-lib.sh


for iface in $IFACES; do for iface in $IFACES; do
if [ "$bootdev" = "$iface" ] || [ "$NEEDNET" = "1" ]; then if [ "$bootdev" = "$iface" ] || [ "$NEEDNET" = "1" ]; then
if [ -n "$netroot" ] && [ -n "$DRACUT_SYSTEMD" ]; then if [ -n "$netroot" ] && [ -n "$DRACUT_SYSTEMD" ]; then
echo "systemctl is-active initrd-root-device.target || [ -f /tmp/net.${iface}.did-setup ]" echo "systemctl is-active initrd-root-device.target || [ -f /tmp/net.${iface}.did-setup ]"
else else
echo "[ -f /tmp/net.${iface}.did-setup ]" echo "[ -f /tmp/net.${iface}.did-setup ]"
fi >$hookdir/initqueue/finished/wait-$iface.sh fi > $hookdir/initqueue/finished/wait-$iface.sh
fi fi
done done
# Default: We don't know the interface to use, handle all # Default: We don't know the interface to use, handle all
@ -110,9 +110,9 @@ command -v fix_bootif >/dev/null || . /lib/net-lib.sh
# if you change the name of "91-default-net.rules", also change modules.d/80cms/cmssetup.sh # if you change the name of "91-default-net.rules", also change modules.d/80cms/cmssetup.sh
echo "$cond, $runcmd" > /etc/udev/rules.d/91-default-net.rules echo "$cond, $runcmd" > /etc/udev/rules.d/91-default-net.rules
if [ "$NEEDNET" = "1" ]; then if [ "$NEEDNET" = "1" ]; then
echo 'for i in /tmp/net.*.did-setup; do [ -f "$i" ] && exit 0; done; exit 1' >$hookdir/initqueue/finished/wait-network.sh echo 'for i in /tmp/net.*.did-setup; do [ -f "$i" ] && exit 0; done; exit 1' > $hookdir/initqueue/finished/wait-network.sh
fi fi
fi fi


# if you change the name of "90-net.rules", also change modules.d/80cms/cmssetup.sh # if you change the name of "90-net.rules", also change modules.d/80cms/cmssetup.sh
} > /etc/udev/rules.d/90-net.rules } > /etc/udev/rules.d/90-net.rules

30
modules.d/35network-legacy/parse-bond.sh

@ -23,12 +23,30 @@ parsebond() {
done done


case $# in case $# in
0) bondname=bond0; bondslaves="eth0 eth1" ;; 0)
1) bondname=$1; bondslaves="eth0 eth1" ;; bondname=bond0
2) bondname=$1; bondslaves=$(str_replace "$2" "," " ") ;; bondslaves="eth0 eth1"
3) bondname=$1; bondslaves=$(str_replace "$2" "," " "); bondoptions=$(str_replace "$3" "," " ") ;; ;;
4) bondname=$1; bondslaves=$(str_replace "$2" "," " "); bondoptions=$(str_replace "$3" "," " "); bondmtu=$4;; 1)
*) die "bond= requires zero to four parameters" ;; bondname=$1
bondslaves="eth0 eth1"
;;
2)
bondname=$1
bondslaves=$(str_replace "$2" "," " ")
;;
3)
bondname=$1
bondslaves=$(str_replace "$2" "," " ")
bondoptions=$(str_replace "$3" "," " ")
;;
4)
bondname=$1
bondslaves=$(str_replace "$2" "," " ")
bondoptions=$(str_replace "$3" "," " ")
bondmtu=$4
;;
*) die "bond= requires zero to four parameters" ;;
esac esac
} }



14
modules.d/35network-legacy/parse-bridge.sh

@ -15,10 +15,16 @@ parsebridge() {
v=${v#*:} v=${v#*:}
done done
case $# in case $# in
0) bridgename=br0; bridgeslaves=$iface ;; 0)
1) die "bridge= requires two parameters" ;; bridgename=br0
2) bridgename=$1; bridgeslaves=$(str_replace "$2" "," " ") ;; bridgeslaves=$iface
*) die "bridge= requires two parameters" ;; ;;
1) die "bridge= requires two parameters" ;;
2)
bridgename=$1
bridgeslaves=$(str_replace "$2" "," " ")
;;
*) die "bridge= requires two parameters" ;;
esac esac
} }



6
modules.d/35network-legacy/parse-ibft.sh

@ -1,10 +1,10 @@
#!/bin/sh #!/bin/sh


command -v getarg >/dev/null || . /lib/dracut-lib.sh command -v getarg > /dev/null || . /lib/dracut-lib.sh
command -v ibft_to_cmdline >/dev/null || . /lib/net-lib.sh command -v ibft_to_cmdline > /dev/null || . /lib/net-lib.sh


if getargbool 0 rd.iscsi.ibft -d "ip=ibft"; then if getargbool 0 rd.iscsi.ibft -d "ip=ibft"; then
modprobe -b -q iscsi_boot_sysfs 2>/dev/null modprobe -b -q iscsi_boot_sysfs 2> /dev/null
modprobe -b -q iscsi_ibft modprobe -b -q iscsi_ibft
ibft_to_cmdline ibft_to_cmdline
fi fi

4
modules.d/35network-legacy/parse-ifname.sh

@ -12,11 +12,11 @@
# an ifname= argument for each interface used in an ip= or fcoe= argument # an ifname= argument for each interface used in an ip= or fcoe= argument


# check if there are any ifname parameters # check if there are any ifname parameters
if ! getarg ifname= >/dev/null ; then if ! getarg ifname= > /dev/null; then
return return
fi fi


command -v parse_ifname_opts >/dev/null || . /lib/net-lib.sh command -v parse_ifname_opts > /dev/null || . /lib/net-lib.sh


# Check ifname= lines # Check ifname= lines
for p in $(getargs ifname=); do for p in $(getargs ifname=); do

69
modules.d/35network-legacy/parse-ip-opts.sh

@ -12,22 +12,23 @@
# routing,dns,dhcp-options,etc. # routing,dns,dhcp-options,etc.
# #


command -v getarg >/dev/null || . /lib/dracut-lib.sh command -v getarg > /dev/null || . /lib/dracut-lib.sh


if [ -n "$netroot" ] && [ -z "$(getarg ip=)" ] && [ -z "$(getarg BOOTIF=)" ]; then if [ -n "$netroot" ] && [ -z "$(getarg ip=)" ] && [ -z "$(getarg BOOTIF=)" ]; then
# No ip= argument(s) for netroot provided, defaulting to DHCP # No ip= argument(s) for netroot provided, defaulting to DHCP
return; return
fi fi


# Count ip= lines to decide whether we need bootdev= or not # Count ip= lines to decide whether we need bootdev= or not
if [ -z "$NEEDBOOTDEV" ] ; then if [ -z "$NEEDBOOTDEV" ]; then
count=0 count=0
for p in $(getargs ip=); do for p in $(getargs ip=); do
case "$p" in case "$p" in
ibft) ibft)
continue;; continue
;;
esac esac
count=$(( $count + 1 )) count=$(($count + 1))
done done
[ $count -gt 1 ] && NEEDBOOTDEV=1 [ $count -gt 1 ] && NEEDBOOTDEV=1
fi fi
@ -59,7 +60,7 @@ for p in $(getargs ip=); do
[ "$autoconf" = "ibft" ] && continue [ "$autoconf" = "ibft" ] && continue


# Empty autoconf defaults to 'dhcp' # Empty autoconf defaults to 'dhcp'
if [ -z "$autoconf" ] ; then if [ -z "$autoconf" ]; then
warn "Empty autoconf values default to dhcp" warn "Empty autoconf values default to dhcp"
autoconf="dhcp" autoconf="dhcp"
fi fi
@ -67,30 +68,30 @@ for p in $(getargs ip=); do
# Error checking for autoconf in combination with other values # Error checking for autoconf in combination with other values
for autoopt in $(str_replace "$autoconf" "," " "); do for autoopt in $(str_replace "$autoconf" "," " "); do
case $autoopt in case $autoopt in
error) die "Error parsing option 'ip=$p'";; error) die "Error parsing option 'ip=$p'" ;;
bootp|rarp|both) die "Sorry, ip=$autoopt is currenty unsupported";; bootp | rarp | both) die "Sorry, ip=$autoopt is currenty unsupported" ;;
none|off) none | off)
[ -z "$ip" ] && \ [ -z "$ip" ] \
die "For argument 'ip=$p'\nValue '$autoopt' without static configuration does not make sense" && die "For argument 'ip=$p'\nValue '$autoopt' without static configuration does not make sense"
[ -z "$mask" ] && \ [ -z "$mask" ] \
die "Sorry, automatic calculation of netmask is not yet supported" && die "Sorry, automatic calculation of netmask is not yet supported"
;; ;;
auto6|link6);; auto6 | link6) ;;
either6);; either6) ;;
dhcp|dhcp6|on|any|single-dhcp) \ dhcp | dhcp6 | on | any | single-dhcp)
[ -n "$NEEDBOOTDEV" ] && [ -z "$dev" ] && \ [ -n "$NEEDBOOTDEV" ] && [ -z "$dev" ] \
die "Sorry, 'ip=$p' does not make sense for multiple interface configurations" && die "Sorry, 'ip=$p' does not make sense for multiple interface configurations"
[ -n "$ip" ] && \ [ -n "$ip" ] \
die "For argument 'ip=$p'\nSorry, setting client-ip does not make sense for '$autoopt'" && die "For argument 'ip=$p'\nSorry, setting client-ip does not make sense for '$autoopt'"
;; ;;
*) die "For argument 'ip=$p'\nSorry, unknown value '$autoopt'";; *) die "For argument 'ip=$p'\nSorry, unknown value '$autoopt'" ;;
esac esac
done done


if [ -n "$dev" ] ; then if [ -n "$dev" ]; then
# We don't like duplicate device configs # We don't like duplicate device configs
if [ -n "$IFACES" ] ; then if [ -n "$IFACES" ]; then
for i in $IFACES ; do for i in $IFACES; do
[ "$dev" = "$i" ] && die "For argument 'ip=$p'\nDuplication configurations for '$dev'" [ "$dev" = "$i" ] && die "For argument 'ip=$p'\nDuplication configurations for '$dev'"
done done
fi fi
@ -99,7 +100,7 @@ for p in $(getargs ip=); do
fi fi


# Do we need to check for specific options? # Do we need to check for specific options?
if [ -n "$NEEDDHCP" ] || [ -n "$DHCPORSERVER" ] ; then if [ -n "$NEEDDHCP" ] || [ -n "$DHCPORSERVER" ]; then
# Correct device? (Empty is ok as well) # Correct device? (Empty is ok as well)
[ "$dev" = "$BOOTDEV" ] || continue [ "$dev" = "$BOOTDEV" ] || continue
# Server-ip is there? # Server-ip is there?
@ -113,13 +114,13 @@ for p in $(getargs ip=); do


if str_starts "$dev" "enx" && [ ${#dev} -eq 15 ]; then if str_starts "$dev" "enx" && [ ${#dev} -eq 15 ]; then
printf -- "ifname=%s:%s:%s:%s:%s:%s:%s\n" \ printf -- "ifname=%s:%s:%s:%s:%s:%s:%s\n" \
"$dev" \ "$dev" \
"${dev:3:2}" \ "${dev:3:2}" \
"${dev:5:2}" \ "${dev:5:2}" \
"${dev:7:2}" \ "${dev:7:2}" \
"${dev:9:2}" \ "${dev:9:2}" \
"${dev:11:2}" \ "${dev:11:2}" \
"${dev:13:2}" >> /etc/cmdline.d/80-enx.conf "${dev:13:2}" >> /etc/cmdline.d/80-enx.conf
fi fi
done done


@ -130,11 +131,11 @@ if getargbool 1 "rd.bootif" && BOOTIF="$(getarg BOOTIF=)"; then
fi fi


# This ensures that BOOTDEV is always first in IFACES # This ensures that BOOTDEV is always first in IFACES
if [ -n "$BOOTDEV" ] && [ -n "$IFACES" ] ; then if [ -n "$BOOTDEV" ] && [ -n "$IFACES" ]; then
IFACES="${IFACES%$BOOTDEV*} ${IFACES#*$BOOTDEV}" IFACES="${IFACES%$BOOTDEV*} ${IFACES#*$BOOTDEV}"
IFACES="$BOOTDEV $IFACES" IFACES="$BOOTDEV $IFACES"
fi fi


# Store BOOTDEV and IFACES for later use # Store BOOTDEV and IFACES for later use
[ -n "$BOOTDEV" ] && echo $BOOTDEV > /tmp/net.bootdev [ -n "$BOOTDEV" ] && echo $BOOTDEV > /tmp/net.bootdev
[ -n "$IFACES" ] && echo $IFACES > /tmp/net.ifaces [ -n "$IFACES" ] && echo $IFACES > /tmp/net.ifaces

27
modules.d/35network-legacy/parse-team.sh

@ -18,11 +18,27 @@ parseteam() {
done done


case $# in case $# in
0) teammaster=team0; teamslaves="eth0 eth1"; teamrunner="activebackup" ;; 0)
1) teammaster=$1; teamslaves="eth0 eth1"; teamrunner="activebackup" ;; teammaster=team0
2) teammaster=$1; teamslaves=$(str_replace "$2" "," " "); teamrunner="activebackup" ;; teamslaves="eth0 eth1"
3) teammaster=$1; teamslaves=$(str_replace "$2" "," " "); teamrunner=$3 ;; teamrunner="activebackup"
*) die "team= requires zero to three parameters" ;; ;;
1)
teammaster=$1
teamslaves="eth0 eth1"
teamrunner="activebackup"
;;
2)
teammaster=$1
teamslaves=$(str_replace "$2" "," " ")
teamrunner="activebackup"
;;
3)
teammaster=$1
teamslaves=$(str_replace "$2" "," " ")
teamrunner=$3
;;
*) die "team= requires zero to three parameters" ;;
esac esac
return 0 return 0
} }
@ -46,4 +62,3 @@ for team in $(getargs team); do
printf -- "%s" "{\"runner\": {\"name\": \"$teamrunner\"}, \"link_watch\": {\"name\": \"ethtool\"}}" > "/tmp/${teammaster}.conf" printf -- "%s" "{\"runner\": {\"name\": \"$teamrunner\"}, \"link_watch\": {\"name\": \"ethtool\"}}" > "/tmp/${teammaster}.conf"
fi fi
done done


7
modules.d/35network-legacy/parse-vlan.sh

@ -14,8 +14,11 @@ parsevlan() {


unset vlanname phydevice unset vlanname phydevice
case $# in case $# in
2) vlanname=$1; phydevice=$2 ;; 2)
*) die "vlan= requires two parameters" ;; vlanname=$1
phydevice=$2
;;
*) die "vlan= requires two parameters" ;;
esac esac
} }



2
modules.d/35network-manager/nm-config.sh

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh


type nm_generate_connections >/dev/null 2>&1 || . /lib/nm-lib.sh type nm_generate_connections > /dev/null 2>&1 || . /lib/nm-lib.sh


if [ -n "$netroot" ] || [ -e /tmp/net.ifaces ]; then if [ -n "$netroot" ] || [ -e /tmp/net.ifaces ]; then
echo rd.neednet >> /etc/cmdline.d/35-neednet.conf echo rd.neednet >> /etc/cmdline.d/35-neednet.conf

13
modules.d/35network-manager/nm-lib.sh

@ -1,19 +1,18 @@
#!/bin/bash #!/bin/bash


type getcmdline >/dev/null 2>&1 || . /lib/dracut-lib.sh type getcmdline > /dev/null 2>&1 || . /lib/dracut-lib.sh


nm_generate_connections() nm_generate_connections() {
{
rm -f /run/NetworkManager/system-connections/* rm -f /run/NetworkManager/system-connections/*
/usr/libexec/nm-initrd-generator -- $(getcmdline) /usr/libexec/nm-initrd-generator -- $(getcmdline)


if getargbool 0 rd.neednet; then if getargbool 0 rd.neednet; then
for i in /usr/lib/NetworkManager/system-connections/* \ for i in /usr/lib/NetworkManager/system-connections/* \
/run/NetworkManager/system-connections/* \ /run/NetworkManager/system-connections/* \
/etc/NetworkManager/system-connections/* \ /etc/NetworkManager/system-connections/* \
/etc/sysconfig/network-scripts/ifcfg-*; do /etc/sysconfig/network-scripts/ifcfg-*; do
[ -f "$i" ] || continue [ -f "$i" ] || continue
echo '[ -f /tmp/nm.done ]' >$hookdir/initqueue/finished/nm.sh echo '[ -f /tmp/nm.done ]' > $hookdir/initqueue/finished/nm.sh
break break
done done
fi fi

27
modules.d/35network-manager/nm-run.sh

@ -1,31 +1,30 @@
#!/bin/sh #!/bin/sh


type source_hook >/dev/null 2>&1 || . /lib/dracut-lib.sh type source_hook > /dev/null 2>&1 || . /lib/dracut-lib.sh


if [ -e /tmp/nm.done ]; then if [ -e /tmp/nm.done ]; then
return return
fi fi


[ -z "$DRACUT_SYSTEMD" ] && \ [ -z "$DRACUT_SYSTEMD" ] \
for i in /usr/lib/NetworkManager/system-connections/* \ && for i in /usr/lib/NetworkManager/system-connections/* \
/run/NetworkManager/system-connections/* \ /run/NetworkManager/system-connections/* \
/etc/NetworkManager/system-connections/* \ /etc/NetworkManager/system-connections/* \
/etc/sysconfig/network-scripts/ifcfg-*; do /etc/sysconfig/network-scripts/ifcfg-*; do
[ -f "$i" ] || continue [ -f "$i" ] || continue
/usr/sbin/NetworkManager --configure-and-quit=initrd --no-daemon /usr/sbin/NetworkManager --configure-and-quit=initrd --no-daemon
break break
done done


if [ -s /run/NetworkManager/initrd/hostname ]; then if [ -s /run/NetworkManager/initrd/hostname ]; then
cat /run/NetworkManager/initrd/hostname > /proc/sys/kernel/hostname cat /run/NetworkManager/initrd/hostname > /proc/sys/kernel/hostname
fi fi


for _i in /sys/class/net/* for _i in /sys/class/net/*; do
do
state=/run/NetworkManager/devices/$(cat $_i/ifindex) state=/run/NetworkManager/devices/$(cat $_i/ifindex)
grep -q connection-uuid= $state 2>/dev/null || continue grep -q connection-uuid= $state 2> /dev/null || continue
ifname=${_i##*/} ifname=${_i##*/}
sed -n 's/root-path/new_root_path/p;s/next-server/new_next_server/p' <$state >/tmp/dhclient.$ifname.dhcpopts sed -n 's/root-path/new_root_path/p;s/next-server/new_next_server/p' < $state > /tmp/dhclient.$ifname.dhcpopts
source_hook initqueue/online $ifname source_hook initqueue/online $ifname
/sbin/netroot $ifname /sbin/netroot $ifname
done done

2
modules.d/35network-wicked/module-setup.sh

@ -61,6 +61,6 @@ install() {
'/^\[Unit\]/aDefaultDependencies=no\ '/^\[Unit\]/aDefaultDependencies=no\
Conflicts=shutdown.target\ Conflicts=shutdown.target\
Before=shutdown.target' \ Before=shutdown.target' \
"$initdir"$unit "$initdir"$unit
done done
} }

4
modules.d/40network/ifname-genrules.sh

@ -1,11 +1,11 @@
#!/bin/sh #!/bin/sh


# if there are no ifname parameters, just use NAME=KERNEL # if there are no ifname parameters, just use NAME=KERNEL
if ! getarg ifname= >/dev/null ; then if ! getarg ifname= > /dev/null; then
return return
fi fi


command -v parse_ifname_opts >/dev/null || . /lib/net-lib.sh command -v parse_ifname_opts > /dev/null || . /lib/net-lib.sh


{ {
for p in $(getargs ifname=); do for p in $(getargs ifname=); do

30
modules.d/40network/module-setup.sh

@ -9,22 +9,22 @@ check() {
depends() { depends() {
is_qemu_virtualized && echo -n "qemu-net " is_qemu_virtualized && echo -n "qemu-net "


for module in network-wicked network-manager network-legacy ; do for module in network-wicked network-manager network-legacy; do
if dracut_module_included "$module" ; then if dracut_module_included "$module"; then
network_handler="$module" network_handler="$module"
break break
fi
done;

if [ -z "$network_handler" ]; then
if find_binary wicked &>/dev/null ; then
network_handler="network-wicked"
elif [[ -x $dracutsysrootdir/usr/libexec/nm-initrd-generator ]]; then
network_handler="network-manager"
else
network_handler="network-legacy"
fi
fi fi
done

if [ -z "$network_handler" ]; then
if find_binary wicked &> /dev/null; then
network_handler="network-wicked"
elif [[ -x $dracutsysrootdir/usr/libexec/nm-initrd-generator ]]; then
network_handler="network-manager"
else
network_handler="network-legacy"
fi
fi
echo "kernel-network-modules $network_handler" echo "kernel-network-modules $network_handler"
return 0 return 0
} }

289
modules.d/40network/net-lib.sh

@ -6,10 +6,10 @@ is_ip() {
echo "$1" | { echo "$1" | {
IFS=. read a b c d IFS=. read a b c d
test "$a" -ge 0 -a "$a" -le 255 \ test "$a" -ge 0 -a "$a" -le 255 \
-a "$b" -ge 0 -a "$b" -le 255 \ -a "$b" -ge 0 -a "$b" -le 255 \
-a "$c" -ge 0 -a "$c" -le 255 \ -a "$c" -ge 0 -a "$c" -le 255 \
-a "$d" -ge 0 -a "$d" -le 255 \ -a "$d" -ge 0 -a "$d" -le 255 \
2> /dev/null 2> /dev/null
} && return 0 } && return 0
return 1 return 1
} }
@ -23,7 +23,7 @@ get_ip() {
} }


iface_for_remote_addr() { iface_for_remote_addr() {
set -- $(ip route get to $1 | sed 's/.*\bdev\b//p;q') set -- $(ip route get to $1 | sed 's/.*\bdev\b//p;q')
echo $1 echo $1
} }


@ -44,8 +44,8 @@ iface_for_mac() {
# get the iface name for the given identifier - either a MAC, IP, or iface name # get the iface name for the given identifier - either a MAC, IP, or iface name
iface_name() { iface_name() {
case $1 in case $1 in
??:??:??:??:??:??|??-??-??-??-??-??) iface_for_mac $1 ;; ??:??:??:??:??:?? | ??-??-??-??-??-??) iface_for_mac $1 ;;
*:*:*|*.*.*.*) iface_for_ip $1 ;; *:*:* | *.*.*.*) iface_for_ip $1 ;;
*) echo $1 ;; *) echo $1 ;;
esac esac
} }
@ -87,13 +87,16 @@ get_netroot_ip() {
local prefix="" server="" rest="" local prefix="" server="" rest=""
splitsep "$1" ":" prefix server rest splitsep "$1" ":" prefix server rest
case $server in case $server in
[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*) echo "$server"; return 0 ;; [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)
echo "$server"
return 0
;;
esac esac
return 1 return 1
} }


ip_is_local() { ip_is_local() {
strstr "$(ip route get $1 2>/dev/null)" " via " strstr "$(ip route get $1 2> /dev/null)" " via "
} }


ifdown() { ifdown() {
@ -103,9 +106,9 @@ ifdown() {
ip addr flush dev $netif ip addr flush dev $netif
echo "#empty" > /etc/resolv.conf echo "#empty" > /etc/resolv.conf
rm -f -- /tmp/net.$netif.did-setup rm -f -- /tmp/net.$netif.did-setup
[ -z "$DO_VLAN" ] && \ [ -z "$DO_VLAN" ] \
[ -e /sys/class/net/$netif/address ] && \ && [ -e /sys/class/net/$netif/address ] \
rm -f -- /tmp/net.$(cat /sys/class/net/$netif/address).did-setup && rm -f -- /tmp/net.$(cat /sys/class/net/$netif/address).did-setup
# TODO: send "offline" uevent? # TODO: send "offline" uevent?
} }


@ -113,19 +116,19 @@ setup_net() {
local netif="$1" f="" gw_ip="" netroot_ip="" iface="" IFACES="" local netif="$1" f="" gw_ip="" netroot_ip="" iface="" IFACES=""
local _p local _p
[ -e /tmp/net.$netif.did-setup ] && return [ -e /tmp/net.$netif.did-setup ] && return
[ -z "$DO_VLAN" ] && \ [ -z "$DO_VLAN" ] \
[ -e /sys/class/net/$netif/address ] && \ && [ -e /sys/class/net/$netif/address ] \
[ -e /tmp/net.$(cat /sys/class/net/$netif/address).did-setup ] && return && [ -e /tmp/net.$(cat /sys/class/net/$netif/address).did-setup ] && return
[ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces
[ -z "$IFACES" ] && IFACES="$netif" [ -z "$IFACES" ] && IFACES="$netif"
# run the scripts written by ifup # run the scripts written by ifup
[ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname [ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname
[ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override
[ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts
# set up resolv.conf # set up resolv.conf
[ -e /tmp/net.$netif.resolv.conf ] && \ [ -e /tmp/net.$netif.resolv.conf ] \
awk '!array[$0]++' /tmp/net.$netif.resolv.conf > /etc/resolv.conf && awk '!array[$0]++' /tmp/net.$netif.resolv.conf > /etc/resolv.conf
[ -e /tmp/net.$netif.gw ] && . /tmp/net.$netif.gw [ -e /tmp/net.$netif.gw ] && . /tmp/net.$netif.gw


# add static route # add static route
for _p in $(getargs rd.route); do for _p in $(getargs rd.route); do
@ -146,7 +149,7 @@ setup_net() {
# RTNETLINK answers: Network is unreachable # RTNETLINK answers: Network is unreachable
# Replace the default route again after static routes to cover # Replace the default route again after static routes to cover
# this scenario. # this scenario.
[ -e /tmp/net.$netif.gw ] && . /tmp/net.$netif.gw [ -e /tmp/net.$netif.gw ] && . /tmp/net.$netif.gw


# Handle STP Timeout: arping the default gateway. # Handle STP Timeout: arping the default gateway.
# (or the root server, if a) it's local or b) there's no gateway.) # (or the root server, if a) it's local or b) there's no gateway.)
@ -173,7 +176,7 @@ setup_net() {
fi fi


if [ "$layer2" != "0" ] && [ -n "$dest" ] && ! strstr "$dest" ":"; then if [ "$layer2" != "0" ] && [ -n "$dest" ] && ! strstr "$dest" ":"; then
if command -v arping2 >/dev/null; then if command -v arping2 > /dev/null; then
arping2 -q -C 1 -c 60 -I $netif $dest || info "Resolving $dest via ARP on $netif failed" arping2 -q -C 1 -c 60 -I $netif $dest || info "Resolving $dest via ARP on $netif failed"
else else
arping -q -f -w 60 -I $netif $dest || info "Resolving $dest via ARP on $netif failed" arping -q -f -w 60 -I $netif $dest || info "Resolving $dest via ARP on $netif failed"
@ -182,9 +185,9 @@ setup_net() {
unset layer2 unset layer2


> /tmp/net.$netif.did-setup > /tmp/net.$netif.did-setup
[ -z "$DO_VLAN" ] && \ [ -z "$DO_VLAN" ] \
[ -e /sys/class/net/$netif/address ] && \ && [ -e /sys/class/net/$netif/address ] \
> /tmp/net.$(cat /sys/class/net/$netif/address).did-setup && > /tmp/net.$(cat /sys/class/net/$netif/address).did-setup
} }


save_netinfo() { save_netinfo() {
@ -211,7 +214,7 @@ set_ifname() {
done done
# otherwise, pick a new name and use that # otherwise, pick a new name and use that
while :; do while :; do
num=$(($num+1)); num=$(($num + 1))
[ -e /sys/class/net/$name$num ] && continue [ -e /sys/class/net/$name$num ] && continue
for n in $(getargs ifname=); do for n in $(getargs ifname=); do
[ "$name$num" = "${n%%:*}" ] && continue 2 [ "$name$num" = "${n%%:*}" ] && continue 2
@ -244,24 +247,39 @@ ibft_to_cmdline() {
local dns1 dns2 local dns1 dns2


[ -e ${iface}/mac ] || continue [ -e ${iface}/mac ] || continue
mac=$(read a < ${iface}/mac; echo $a) mac=$(
read a < ${iface}/mac
echo $a
)
[ -z "$mac" ] && continue [ -z "$mac" ] && continue
dev=$(set_ifname ibft $mac) dev=$(set_ifname ibft $mac)


[ -e /tmp/net.${dev}.has_ibft_config ] && continue [ -e /tmp/net.${dev}.has_ibft_config ] && continue


[ -e ${iface}/flags ] && flags=$(read a < ${iface}/flags; echo $a) [ -e ${iface}/flags ] && flags=$(
read a < ${iface}/flags
echo $a
)
# Skip invalid interfaces # Skip invalid interfaces
(( $flags & 1 )) || continue (($flags & 1)) || continue
# Skip interfaces not used for booting unless using multipath # Skip interfaces not used for booting unless using multipath
if ! getargbool 0 rd.iscsi.mp ; then if ! getargbool 0 rd.iscsi.mp; then
(( $flags & 2 )) || continue (($flags & 2)) || continue
fi fi
[ -e ${iface}/dhcp ] && dhcp=$(read a < ${iface}/dhcp; echo $a) [ -e ${iface}/dhcp ] && dhcp=$(
[ -e ${iface}/origin ] && origin=$(read a < ${iface}/origin; echo $a) read a < ${iface}/dhcp
[ -e ${iface}/ip-addr ] && ip=$(read a < ${iface}/ip-addr; echo $a) echo $a

)
if [ -n "$ip" ] ; then [ -e ${iface}/origin ] && origin=$(
read a < ${iface}/origin
echo $a
)
[ -e ${iface}/ip-addr ] && ip=$(
read a < ${iface}/ip-addr
echo $a
)

if [ -n "$ip" ]; then
case "$ip" in case "$ip" in
*.*.*.*) *.*.*.*)
family=ipv4 family=ipv4
@ -272,7 +290,7 @@ ibft_to_cmdline() {
esac esac
fi fi
if [ -n "$dhcp" ] || [ "$origin" -eq 3 ]; then if [ -n "$dhcp" ] || [ "$origin" -eq 3 ]; then
if [ "$family" = "ipv6" ] ; then if [ "$family" = "ipv6" ]; then
echo "ip=$dev:dhcp6" echo "ip=$dev:dhcp6"
else else
echo "ip=$dev:dhcp" echo "ip=$dev:dhcp"
@ -280,23 +298,41 @@ ibft_to_cmdline() {
elif [ -e ${iface}/ip-addr ]; then elif [ -e ${iface}/ip-addr ]; then
# skip not assigned ip adresses # skip not assigned ip adresses
[ "$ip" = "0.0.0.0" ] && continue [ "$ip" = "0.0.0.0" ] && continue
[ -e ${iface}/gateway ] && gw=$(read a < ${iface}/gateway; echo $a) [ -e ${iface}/gateway ] && gw=$(
read a < ${iface}/gateway
echo $a
)
[ "$gateway" = "0.0.0.0" ] && unset $gateway [ "$gateway" = "0.0.0.0" ] && unset $gateway
[ -e ${iface}/subnet-mask ] && mask=$(read a < ${iface}/subnet-mask; echo $a) [ -e ${iface}/subnet-mask ] && mask=$(
[ -e ${iface}/prefix-len ] && prefix=$(read a < ${iface}/prefix-len; echo $a) read a < ${iface}/subnet-mask
[ -e ${iface}/primary-dns ] && dns1=$(read a < ${iface}/primary-dns; echo $a) echo $a
)
[ -e ${iface}/prefix-len ] && prefix=$(
read a < ${iface}/prefix-len
echo $a
)
[ -e ${iface}/primary-dns ] && dns1=$(
read a < ${iface}/primary-dns
echo $a
)
[ "$dns1" = "0.0.0.0" ] && unset $dns1 [ "$dns1" = "0.0.0.0" ] && unset $dns1
[ -e ${iface}/secondary-dns ] && dns2=$(read a < ${iface}/secondary-dns; echo $a) [ -e ${iface}/secondary-dns ] && dns2=$(
read a < ${iface}/secondary-dns
echo $a
)
[ "$dns2" = "0.0.0.0" ] && unset $dns2 [ "$dns2" = "0.0.0.0" ] && unset $dns2
[ -e ${iface}/hostname ] && hostname=$(read a < ${iface}/hostname; echo $a) [ -e ${iface}/hostname ] && hostname=$(
if [ "$family" = "ipv6" ] ; then read a < ${iface}/hostname
if [ -n "$ip" ] ; then echo $a
)
if [ "$family" = "ipv6" ]; then
if [ -n "$ip" ]; then
ip="[$ip]" ip="[$ip]"
[ -n "$prefix" ] || prefix=64 [ -n "$prefix" ] || prefix=64
ip="[${ip}/${prefix}]" ip="[${ip}/${prefix}]"
mask= mask=
fi fi
if [ -n "$gw" ] ; then if [ -n "$gw" ]; then
gw="[${gw}]" gw="[${gw}]"
fi fi
fi fi
@ -315,7 +351,10 @@ ibft_to_cmdline() {
fi fi


if [ -e ${iface}/vlan ]; then if [ -e ${iface}/vlan ]; then
vlan=$(read a < ${iface}/vlan; echo $a) vlan=$(
read a < ${iface}/vlan
echo $a
)
if [ "$vlan" -ne "0" ]; then if [ "$vlan" -ne "0" ]; then
case "$vlan" in case "$vlan" in
[0-9]*) [0-9]*)
@ -338,8 +377,7 @@ ibft_to_cmdline() {
) >> /etc/cmdline.d/40-ibft.conf ) >> /etc/cmdline.d/40-ibft.conf
} }


parse_iscsi_root() parse_iscsi_root() {
{
local v local v
v=${1#iscsi:} v=${1#iscsi:}


@ -406,17 +444,22 @@ parse_iscsi_root()
set $v set $v
IFS="$OLDIFS" IFS="$OLDIFS"


iscsi_protocol=$1; shift # ignored iscsi_protocol=$1
iscsi_target_port=$1; shift shift # ignored
iscsi_target_port=$1
shift


if [ -n "$iscsi_target_name" ]; then if [ -n "$iscsi_target_name" ]; then
if [ $# -eq 3 ]; then if [ $# -eq 3 ]; then
iscsi_iface_name=$1; shift iscsi_iface_name=$1
shift
fi fi
if [ $# -eq 2 ]; then if [ $# -eq 2 ]; then
iscsi_netdev_name=$1; shift iscsi_netdev_name=$1
shift
fi fi
iscsi_lun=$1; shift iscsi_lun=$1
shift
if [ $# -ne 0 ]; then if [ $# -ne 0 ]; then
warn "Invalid parameter in iscsi: parameter!" warn "Invalid parameter in iscsi: parameter!"
return 1 return 1
@ -424,15 +467,17 @@ parse_iscsi_root()
return 0 return 0
fi fi



if [ $# -gt 3 ] && [ -n "$1$2" ]; then if [ $# -gt 3 ] && [ -n "$1$2" ]; then
if [ -z "$3" ] || [ "$3" -ge 0 ] 2>/dev/null ; then if [ -z "$3" ] || [ "$3" -ge 0 ] 2> /dev/null; then
iscsi_iface_name=$1; shift iscsi_iface_name=$1
iscsi_netdev_name=$1; shift shift
iscsi_netdev_name=$1
shift
fi fi
fi fi


iscsi_lun=$1; shift iscsi_lun=$1
shift


iscsi_target_name=$(printf "%s:" "$@") iscsi_target_name=$(printf "%s:" "$@")
iscsi_target_name=${iscsi_target_name%:} iscsi_target_name=${iscsi_target_name%:}
@ -482,7 +527,7 @@ ip_to_var() {


# handle special values for ksdevice # handle special values for ksdevice
case "$dev" in case "$dev" in
bootif|BOOTIF) dev=$(fix_bootif $(getarg BOOTIF=)) ;; bootif | BOOTIF) dev=$(fix_bootif $(getarg BOOTIF=)) ;;
link) dev="" ;; # FIXME: do something useful with this link) dev="" ;; # FIXME: do something useful with this
ibft) dev="" ;; # ignore - ibft is handled elsewhere ibft) dev="" ;; # ignore - ibft is handled elsewhere
esac esac
@ -513,7 +558,7 @@ ip_to_var() {
[ -n "$6" ] && dev=$6 [ -n "$6" ] && dev=$6
[ -n "$7" ] && autoconf=$7 [ -n "$7" ] && autoconf=$7
case "$8" in case "$8" in
[0-9a-fA-F]*:*|[0-9]*.[0-9]*.[0-9]*.[0-9]*) [0-9a-fA-F]*:* | [0-9]*.[0-9]*.[0-9]*.[0-9]*)
dns1="$8" dns1="$8"
[ -n "$9" ] && dns2="$9" [ -n "$9" ] && dns2="$9"
;; ;;
@ -531,7 +576,7 @@ ip_to_var() {
elif [ -n "${9}" -a -n "${10}" -a -n "${11}" -a -n "${12}" -a -n "${13}" -a -n "${14}" ]; then elif [ -n "${9}" -a -n "${10}" -a -n "${11}" -a -n "${12}" -a -n "${13}" -a -n "${14}" ]; then
macaddr="${9}:${10}:${11}:${12}:${13}:${14}" macaddr="${9}:${10}:${11}:${12}:${13}:${14}"
fi fi
;; ;;
esac esac
return 0 return 0
} }
@ -555,11 +600,18 @@ route_to_var() {


unset route_mask route_gw route_dev unset route_mask route_gw route_dev
case $# in case $# in
2) [ -n "$1" ] && route_mask="$1"; [ -n "$2" ] && route_gw="$2" 2)
return 0;; [ -n "$1" ] && route_mask="$1"
3) [ -n "$1" ] && route_mask="$1"; [ -n "$2" ] && route_gw="$2"; [ -n "$3" ] && route_dev="$3" [ -n "$2" ] && route_gw="$2"
return 0;; return 0
*) return 1;; ;;
3)
[ -n "$1" ] && route_mask="$1"
[ -n "$2" ] && route_gw="$2"
[ -n "$3" ] && route_dev="$3"
return 0
;;
*) return 1 ;;
esac esac
} }


@ -584,7 +636,7 @@ parse_ifname_opts() {
esac esac


case $ifname_if in case $ifname_if in
eth[0-9]|eth[0-9][0-9]|eth[0-9][0-9][0-9]|eth[0-9][0-9][0-9][0-9]) eth[0-9] | eth[0-9][0-9] | eth[0-9][0-9][0-9] | eth[0-9][0-9][0-9][0-9])
warn "ifname=$ifname_if uses the kernel name space for interfaces" warn "ifname=$ifname_if uses the kernel name space for interfaces"
warn "This can fail for multiple network interfaces and is discouraged!" warn "This can fail for multiple network interfaces and is discouraged!"
warn "Please use a custom name like \"netboot\" or \"bluesocket\"" warn "Please use a custom name like \"netboot\" or \"bluesocket\""
@ -600,13 +652,13 @@ wait_for_if_link() {
local li local li
local timeout="$(getargs rd.net.timeout.iflink=)" local timeout="$(getargs rd.net.timeout.iflink=)"
timeout=${timeout:-60} timeout=${timeout:-60}
timeout=$(($timeout*10)) timeout=$(($timeout * 10))


while [ $cnt -lt $timeout ]; do while [ $cnt -lt $timeout ]; do
li=$(ip link show dev $1 2>/dev/null) li=$(ip link show dev $1 2> /dev/null)
[ -n "$li" ] && return 0 [ -n "$li" ] && return 0
sleep 0.1 sleep 0.1
cnt=$(($cnt+1)) cnt=$(($cnt + 1))
done done
return 1 return 1
} }
@ -616,27 +668,30 @@ wait_for_if_up() {
local li local li
local timeout="$(getargs rd.net.timeout.ifup=)" local timeout="$(getargs rd.net.timeout.ifup=)"
timeout=${timeout:-20} timeout=${timeout:-20}
timeout=$(($timeout*10)) timeout=$(($timeout * 10))


while [ $cnt -lt $timeout ]; do while [ $cnt -lt $timeout ]; do
li=$(ip link show up dev $1) li=$(ip link show up dev $1)
if [ -n "$li" ]; then if [ -n "$li" ]; then
case "$li" in case "$li" in
*\<UP*) *\<UP*)
return 0;; return 0
;;
*\<*,UP\>*) *\<*,UP\>*)
return 0;; return 0
;;
*\<*,UP,*\>*) *\<*,UP,*\>*)
return 0;; return 0
;;
esac esac
fi fi
if strstr "$li" "LOWER_UP" \ if strstr "$li" "LOWER_UP" \
&& strstr "$li" "state UNKNOWN" \ && strstr "$li" "state UNKNOWN" \
&& ! strstr "$li" "DORMANT"; then && ! strstr "$li" "DORMANT"; then
return 0 return 0
fi fi
sleep 0.1 sleep 0.1
cnt=$(($cnt+1)) cnt=$(($cnt + 1))
done done
return 1 return 1
} }
@ -645,13 +700,13 @@ wait_for_route_ok() {
local cnt=0 local cnt=0
local timeout="$(getargs rd.net.timeout.route=)" local timeout="$(getargs rd.net.timeout.route=)"
timeout=${timeout:-20} timeout=${timeout:-20}
timeout=$(($timeout*10)) timeout=$(($timeout * 10))


while [ $cnt -lt $timeout ]; do while [ $cnt -lt $timeout ]; do
li=$(ip route show) li=$(ip route show)
[ -n "$li" ] && [ -z "${li##*$1*}" ] && return 0 [ -n "$li" ] && [ -z "${li##*$1*}" ] && return 0
sleep 0.1 sleep 0.1
cnt=$(($cnt+1)) cnt=$(($cnt + 1))
done done
return 1 return 1
} }
@ -660,7 +715,7 @@ wait_for_ipv6_dad_link() {
local cnt=0 local cnt=0
local timeout="$(getargs rd.net.timeout.ipv6dad=)" local timeout="$(getargs rd.net.timeout.ipv6dad=)"
timeout=${timeout:-50} timeout=${timeout:-50}
timeout=$(($timeout*10)) timeout=$(($timeout * 10))


while [ $cnt -lt $timeout ]; do while [ $cnt -lt $timeout ]; do
[ -n "$(ip -6 addr show dev "$1" scope link)" ] \ [ -n "$(ip -6 addr show dev "$1" scope link)" ] \
@ -669,7 +724,7 @@ wait_for_ipv6_dad_link() {
[ -n "$(ip -6 addr show dev "$1" scope link dadfailed)" ] \ [ -n "$(ip -6 addr show dev "$1" scope link dadfailed)" ] \
&& return 1 && return 1
sleep 0.1 sleep 0.1
cnt=$(($cnt+1)) cnt=$(($cnt + 1))
done done
return 1 return 1
} }
@ -678,7 +733,7 @@ wait_for_ipv6_dad() {
local cnt=0 local cnt=0
local timeout="$(getargs rd.net.timeout.ipv6dad=)" local timeout="$(getargs rd.net.timeout.ipv6dad=)"
timeout=${timeout:-50} timeout=${timeout:-50}
timeout=$(($timeout*10)) timeout=$(($timeout * 10))


while [ $cnt -lt $timeout ]; do while [ $cnt -lt $timeout ]; do
[ -n "$(ip -6 addr show dev "$1")" ] \ [ -n "$(ip -6 addr show dev "$1")" ] \
@ -688,7 +743,7 @@ wait_for_ipv6_dad() {
[ -n "$(ip -6 addr show dev "$1" dadfailed)" ] \ [ -n "$(ip -6 addr show dev "$1" dadfailed)" ] \
&& return 1 && return 1
sleep 0.1 sleep 0.1
cnt=$(($cnt+1)) cnt=$(($cnt + 1))
done done
return 1 return 1
} }
@ -697,28 +752,26 @@ wait_for_ipv6_auto() {
local cnt=0 local cnt=0
local timeout="$(getargs rd.net.timeout.ipv6auto=)" local timeout="$(getargs rd.net.timeout.ipv6auto=)"
timeout=${timeout:-40} timeout=${timeout:-40}
timeout=$(($timeout*10)) timeout=$(($timeout * 10))


while [ $cnt -lt $timeout ]; do while [ $cnt -lt $timeout ]; do
[ -z "$(ip -6 addr show dev "$1" tentative)" ] \ [ -z "$(ip -6 addr show dev "$1" tentative)" ] \
&& [ -n "$(ip -6 route list proto ra dev "$1" | grep ^default)" ] \ && [ -n "$(ip -6 route list proto ra dev "$1" | grep ^default)" ] \
&& return 0 && return 0
sleep 0.1 sleep 0.1
cnt=$(($cnt+1)) cnt=$(($cnt + 1))
done done
return 1 return 1
} }


linkup() { linkup() {
wait_for_if_link $1 2>/dev/null\ wait_for_if_link $1 2> /dev/null && ip link set $1 up 2> /dev/null && wait_for_if_up $1 2> /dev/null
&& ip link set $1 up 2>/dev/null\
&& wait_for_if_up $1 2>/dev/null
} }


type hostname >/dev/null 2>&1 || \ type hostname > /dev/null 2>&1 \
hostname() { || hostname() {
cat /proc/sys/kernel/hostname cat /proc/sys/kernel/hostname
} }


iface_has_carrier() { iface_has_carrier() {
local cnt=0 local cnt=0
@ -728,7 +781,7 @@ iface_has_carrier() {
[ -d "$interface" ] || return 2 [ -d "$interface" ] || return 2
local timeout="$(getargs rd.net.timeout.carrier=)" local timeout="$(getargs rd.net.timeout.carrier=)"
timeout=${timeout:-10} timeout=${timeout:-10}
timeout=$(($timeout*10)) timeout=$(($timeout * 10))


linkup "$1" linkup "$1"


@ -747,7 +800,7 @@ iface_has_carrier() {
# double check the syscfs carrier flag # double check the syscfs carrier flag
[ -e "$interface/carrier" ] && [ "$(cat $interface/carrier)" = 1 ] && return 0 [ -e "$interface/carrier" ] && [ "$(cat $interface/carrier)" = 1 ] && return 0
sleep 0.1 sleep 0.1
cnt=$(($cnt+1)) cnt=$(($cnt + 1))
done done
return 1 return 1
} }
@ -791,21 +844,22 @@ is_persistent_ethernet_name() {


case "$_netif" in case "$_netif" in
# udev persistent interface names # udev persistent interface names
eno[0-9]|eno[0-9][0-9]|eno[0-9][0-9][0-9]*) eno[0-9] | eno[0-9][0-9] | eno[0-9][0-9][0-9]*) ;;
;;
ens[0-9]|ens[0-9][0-9]|ens[0-9][0-9][0-9]*) ens[0-9] | ens[0-9][0-9] | ens[0-9][0-9][0-9]*) ;;
;;
enp[0-9]s[0-9]*|enp[0-9][0-9]s[0-9]*|enp[0-9][0-9][0-9]*s[0-9]*) enp[0-9]s[0-9]* | enp[0-9][0-9]s[0-9]* | enp[0-9][0-9][0-9]*s[0-9]*) ;;
;;
enP*p[0-9]s[0-9]*|enP*p[0-9][0-9]s[0-9]*|enP*p[0-9][0-9][0-9]*s[0-9]*) enP*p[0-9]s[0-9]* | enP*p[0-9][0-9]s[0-9]* | enP*p[0-9][0-9][0-9]*s[0-9]*) ;;
;;
# biosdevname # biosdevname
em[0-9]|em[0-9][0-9]|em[0-9][0-9][0-9]*) em[0-9] | em[0-9][0-9] | em[0-9][0-9][0-9]*) ;;
;;
p[0-9]p[0-9]*|p[0-9][0-9]p[0-9]*|p[0-9][0-9][0-9]*p[0-9]*) p[0-9]p[0-9]* | p[0-9][0-9]p[0-9]* | p[0-9][0-9][0-9]*p[0-9]*) ;;
;;
*) *)
return 1 return 1
;;
esac esac
return 0 return 0
} }
@ -818,13 +872,13 @@ is_kernel_ethernet_name() {
_name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type") _name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type")


case "$_name_assign_type" in case "$_name_assign_type" in
2|3|4) 2 | 3 | 4)
# NET_NAME_PREDICTABLE 2 # NET_NAME_PREDICTABLE 2
# NET_NAME_USER 3 # NET_NAME_USER 3
# NET_NAME_RENAMED 4 # NET_NAME_RENAMED 4
return 1 return 1
;; ;;
1|*) 1 | *)
# NET_NAME_ENUM 1 # NET_NAME_ENUM 1
return 0 return 0
;; ;;
@ -833,11 +887,12 @@ is_kernel_ethernet_name() {


# fallback to error prone manual name check # fallback to error prone manual name check
case "$_netif" in case "$_netif" in
eth[0-9]|eth[0-9][0-9]|eth[0-9][0-9][0-9]*) eth[0-9] | eth[0-9][0-9] | eth[0-9][0-9][0-9]*)
return 0 return 0
;; ;;
*) *)
return 1 return 1
;;
esac esac


} }
@ -849,12 +904,12 @@ iface_get_subchannels() {
_netif="$1" _netif="$1"


_subchannels=$({ _subchannels=$({
for i in /sys/class/net/$_netif/device/cdev[0-9]*; do for i in /sys/class/net/$_netif/device/cdev[0-9]*; do
[ -e $i ] || continue [ -e $i ] || continue
channel=$(readlink -f $i) channel=$(readlink -f $i)
printf -- "%s" "${channel##*/}," printf -- "%s" "${channel##*/},"
done done
}) })
[ -n "$_subchannels" ] || return 1 [ -n "$_subchannels" ] || return 1


printf -- "%s" ${_subchannels%,} printf -- "%s" ${_subchannels%,}

14
modules.d/40network/netroot.sh

@ -1,8 +1,8 @@
#!/bin/sh #!/bin/sh


PATH=/usr/sbin:/usr/bin:/sbin:/bin PATH=/usr/sbin:/usr/bin:/sbin:/bin
command -v getarg >/dev/null || . /lib/dracut-lib.sh command -v getarg > /dev/null || . /lib/dracut-lib.sh
command -v setup_net >/dev/null || . /lib/net-lib.sh command -v setup_net > /dev/null || . /lib/net-lib.sh


# Huh? Empty $1? # Huh? Empty $1?
[ -z "$1" ] && exit 1 [ -z "$1" ] && exit 1
@ -24,7 +24,7 @@ netif=$1
[ -e "/tmp/net.bootdev" ] && read netif < /tmp/net.bootdev [ -e "/tmp/net.bootdev" ] && read netif < /tmp/net.bootdev


case "$netif" in case "$netif" in
??:??:??:??:??:??) # MAC address ??:??:??:??:??:??) # MAC address
for i in /sys/class/net/*/address; do for i in /sys/class/net/*/address; do
mac=$(cat $i) mac=$(cat $i)
if [ "$mac" = "$netif" ]; then if [ "$mac" = "$netif" ]; then
@ -32,7 +32,7 @@ case "$netif" in
netif=${i##*/} netif=${i##*/}
break break
fi fi
done done ;;
esac esac


# Figure out the handler for root=dhcp by recalling all netroot cmdline # Figure out the handler for root=dhcp by recalling all netroot cmdline
@ -44,7 +44,7 @@ if [ -z "$2" ]; then


# If we have a specific bootdev with no dhcpoptions or empty root-path, # If we have a specific bootdev with no dhcpoptions or empty root-path,
# we die. Otherwise we just warn # we die. Otherwise we just warn
if [ -z "$new_root_path" ] ; then if [ -z "$new_root_path" ]; then
[ -n "$BOOTDEV" ] && die "No dhcp root-path received for '$BOOTDEV'" [ -n "$BOOTDEV" ] && die "No dhcp root-path received for '$BOOTDEV'"
warn "No dhcp root-path received for '$netif' trying other interfaces if available" warn "No dhcp root-path received for '$netif' trying other interfaces if available"
exit 1 exit 1
@ -58,7 +58,7 @@ if [ -z "$2" ]; then
# FIXME! # FIXME!
unset rootok unset rootok
for f in $hookdir/cmdline/90*.sh; do for f in $hookdir/cmdline/90*.sh; do
[ -f "$f" ] && . "$f"; [ -f "$f" ] && . "$f"
done done
else else
rootok="1" rootok="1"
@ -74,7 +74,7 @@ if [ -z "$2" ]; then
handler=${netroot%%:*} handler=${netroot%%:*}
handler=${handler%%4} handler=${handler%%4}
handler=$(command -v ${handler}root) handler=$(command -v ${handler}root)
if [ -z "$netroot" ] || [ ! -e "$handler" ] ; then if [ -z "$netroot" ] || [ ! -e "$handler" ]; then
die "No handler for netroot type '$netroot'" die "No handler for netroot type '$netroot'"
fi fi
fi fi

1
modules.d/45ifcfg/module-setup.sh

@ -17,4 +17,3 @@ install() {
inst_binary awk inst_binary awk
inst_hook pre-pivot 85 "$moddir/write-ifcfg.sh" inst_hook pre-pivot 85 "$moddir/write-ifcfg.sh"
} }


23
modules.d/45ifcfg/write-ifcfg.sh

@ -1,15 +1,14 @@
#!/bin/sh #!/bin/sh


# NFS root might have reached here before /tmp/net.ifaces was written # NFS root might have reached here before /tmp/net.ifaces was written
type is_persistent_ethernet_name >/dev/null 2>&1 || . /lib/net-lib.sh type is_persistent_ethernet_name > /dev/null 2>&1 || . /lib/net-lib.sh


udevadm settle --timeout=30 udevadm settle --timeout=30


mkdir -m 0755 -p /tmp/ifcfg/ mkdir -m 0755 -p /tmp/ifcfg/
mkdir -m 0755 -p /tmp/ifcfg-leases/ mkdir -m 0755 -p /tmp/ifcfg-leases/


get_config_line_by_subchannel() get_config_line_by_subchannel() {
{
local CHANNEL local CHANNEL
local line local line


@ -62,7 +61,7 @@ print_s390() {
shift shift
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case $1 in case $1 in
*=*) OPTIONS="$OPTIONS $1";; *=*) OPTIONS="$OPTIONS $1" ;;
esac esac
shift shift
done done
@ -109,7 +108,7 @@ interface_bind() {
echo "DEVICE=\"$_netif\"" echo "DEVICE=\"$_netif\""
} }


for netup in /tmp/net.*.did-setup ; do for netup in /tmp/net.*.did-setup; do
[ -f $netup ] || continue [ -f $netup ] || continue


netif=${netup%%.did-setup} netif=${netup%%.did-setup}
@ -211,7 +210,7 @@ for netup in /tmp/net.*.did-setup ; do
echo "TYPE=Ethernet" >> /tmp/ifcfg/ifcfg-$netif echo "TYPE=Ethernet" >> /tmp/ifcfg/ifcfg-$netif
fi fi


if [ -n "$vlan" ] ; then if [ -n "$vlan" ]; then
{ {
echo "TYPE=Vlan" echo "TYPE=Vlan"
echo "DEVICE=\"$netif\"" echo "DEVICE=\"$netif\""
@ -220,7 +219,7 @@ for netup in /tmp/net.*.did-setup ; do
} >> /tmp/ifcfg/ifcfg-$netif } >> /tmp/ifcfg/ifcfg-$netif
fi fi


if [ -n "$bond" ] ; then if [ -n "$bond" ]; then
# bond interface # bond interface
{ {
# This variable is an indicator of a bond interface for initscripts # This variable is an indicator of a bond interface for initscripts
@ -229,7 +228,7 @@ for netup in /tmp/net.*.did-setup ; do
echo "TYPE=Bond" echo "TYPE=Bond"
} >> /tmp/ifcfg/ifcfg-$netif } >> /tmp/ifcfg/ifcfg-$netif


for slave in $bondslaves ; do for slave in $bondslaves; do
# write separate ifcfg file for the raw eth interface # write separate ifcfg file for the raw eth interface
( (
echo "# Generated by dracut initrd" echo "# Generated by dracut initrd"
@ -247,13 +246,13 @@ for netup in /tmp/net.*.did-setup ; do
done done
fi fi


if [ -n "$bridge" ] ; then if [ -n "$bridge" ]; then
# bridge # bridge
{ {
echo "TYPE=Bridge" echo "TYPE=Bridge"
echo "NAME=\"$netif\"" echo "NAME=\"$netif\""
} >> /tmp/ifcfg/ifcfg-$netif } >> /tmp/ifcfg/ifcfg-$netif
for slave in $bridgeslaves ; do for slave in $bridgeslaves; do
# write separate ifcfg file for the raw eth interface # write separate ifcfg file for the raw eth interface
( (
echo "# Generated by dracut initrd" echo "# Generated by dracut initrd"
@ -272,7 +271,7 @@ for netup in /tmp/net.*.did-setup ; do
i=1 i=1
for ns in $(getargs nameserver) $dns1 $dns2; do for ns in $(getargs nameserver) $dns1 $dns2; do
echo "DNS${i}=\"${ns}\"" >> /tmp/ifcfg/ifcfg-$netif echo "DNS${i}=\"${ns}\"" >> /tmp/ifcfg/ifcfg-$netif
i=$((i+1)) i=$((i + 1))
done done


[ -f /tmp/net.route6."$netif" ] && cp /tmp/net.route6."$netif" /tmp/ifcfg/route6-"$netif" [ -f /tmp/net.route6."$netif" ] && cp /tmp/net.route6."$netif" /tmp/ifcfg/route6-"$netif"
@ -287,7 +286,7 @@ echo "files /var/lib/dhclient" >> /run/initramfs/rwtab
{ {
cp /tmp/net.* /run/initramfs/ cp /tmp/net.* /run/initramfs/
for i in /tmp/net.*.resolv.conf; do for i in /tmp/net.*.resolv.conf; do
[ -f "$i" ] && cat "$i" [ -f "$i" ] && cat "$i"
done | awk '!($0 in a) { a[$0]; print }' > /run/initramfs/state/etc/resolv.conf done | awk '!($0 in a) { a[$0]; print }' > /run/initramfs/state/etc/resolv.conf
[ -s /run/initramfs/state/etc/resolv.conf ] || rm -f /run/initramfs/state/etc/resolv.conf [ -s /run/initramfs/state/etc/resolv.conf ] || rm -f /run/initramfs/state/etc/resolv.conf
copytree /tmp/ifcfg /run/initramfs/state/etc/sysconfig/network-scripts copytree /tmp/ifcfg /run/initramfs/state/etc/sysconfig/network-scripts

15
modules.d/45url-lib/module-setup.sh

@ -28,9 +28,9 @@ install() {
fi fi


for _dir in $libdirs; do for _dir in $libdirs; do
[[ -d $dracutsysrootdir$_dir ]] || continue [[ -d $dracutsysrootdir$_dir ]] || continue
for _lib in $dracutsysrootdir$_dir/libcurl.so.*; do for _lib in $dracutsysrootdir$_dir/libcurl.so.*; do
[[ -e $_lib ]] || continue [[ -e $_lib ]] || continue
[[ $_nssckbi ]] || _nssckbi=$(grep -F --binary-files=text -z libnssckbi $_lib) [[ $_nssckbi ]] || _nssckbi=$(grep -F --binary-files=text -z libnssckbi $_lib)
_crt=$(grep -F --binary-files=text -z .crt $_lib) _crt=$(grep -F --binary-files=text -z .crt $_lib)
[[ $_crt ]] || continue [[ $_crt ]] || continue
@ -47,15 +47,15 @@ install() {
# If its truly NSS libnssckbi, it includes its own trust bundle, # If its truly NSS libnssckbi, it includes its own trust bundle,
# but if it's really p11-kit-trust.so, we need to find the dirs # but if it's really p11-kit-trust.so, we need to find the dirs
# where it will look for a trust bundle and install them too. # where it will look for a trust bundle and install them too.
if ! [[ $_found ]] && [[ $_nssckbi ]] ; then if ! [[ $_found ]] && [[ $_nssckbi ]]; then
_found=1 _found=1
inst_libdir_file "libnssckbi.so*" || _found= inst_libdir_file "libnssckbi.so*" || _found=
for _dir in $libdirs; do for _dir in $libdirs; do
[[ -e $dracutsysrootdir$_dir/libnssckbi.so ]] || continue [[ -e $dracutsysrootdir$_dir/libnssckbi.so ]] || continue
# this looks for directory-ish strings in the file # this looks for directory-ish strings in the file
for _p11roots in $(grep -o --binary-files=text "/[[:alpha:]][[:print:]]*" $dracutsysrootdir$_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 # the string can be a :-separated list of dirs
for _p11root in $(echo "$_p11roots" | tr ':' '\n') ; do for _p11root in $(echo "$_p11roots" | tr ':' '\n'); do
# check if it's actually a directory (there are # check if it's actually a directory (there are
# several false positives in the results) # several false positives in the results)
[[ -d "$dracutsysrootdir$_p11root" ]] || continue [[ -d "$dracutsysrootdir$_p11root" ]] || continue
@ -65,8 +65,8 @@ install() {
[[ -d "$dracutsysrootdir${_p11root}/blacklist" ]] || continue [[ -d "$dracutsysrootdir${_p11root}/blacklist" ]] || continue
# so now we know it's really a p11-kit trust dir; # so now we know it's really a p11-kit trust dir;
# install everything in it # install everything in it
for _p11item in $(find "$dracutsysrootdir$_p11root") ; do for _p11item in $(find "$dracutsysrootdir$_p11root"); do
if ! inst "${_p11item#$dracutsysrootdir}" ; then if ! inst "${_p11item#$dracutsysrootdir}"; then
dwarn "Couldn't install '${_p11item#$dracutsysrootdir}' from p11-kit trust dir '${_p11root#$dracutsysrootdir}'; HTTPS might not work." dwarn "Couldn't install '${_p11item#$dracutsysrootdir}' from p11-kit trust dir '${_p11root#$dracutsysrootdir}'; HTTPS might not work."
continue continue
fi fi
@ -77,4 +77,3 @@ install() {
fi fi
[[ $_found ]] || dwarn "Couldn't find SSL CA cert bundle or libnssckbi.so; HTTPS won't work." [[ $_found ]] || dwarn "Couldn't find SSL CA cert bundle or libnssckbi.so; HTTPS won't work."
} }


29
modules.d/45url-lib/url-lib.sh

@ -4,7 +4,7 @@
# Authors: # Authors:
# Will Woods <wwoods@redhat.com> # Will Woods <wwoods@redhat.com>


type mkuniqdir >/dev/null 2>&1 || . /lib/dracut-lib.sh type mkuniqdir > /dev/null 2>&1 || . /lib/dracut-lib.sh


# fetch_url URL [OUTFILE] # fetch_url URL [OUTFILE]
# fetch the given URL to a locally-visible location. # fetch the given URL to a locally-visible location.
@ -39,7 +39,8 @@ get_url_handler() {
# add_url_handler HANDLERNAME SCHEME [SCHEME...] # add_url_handler HANDLERNAME SCHEME [SCHEME...]
# associate the named handler with the named scheme(s). # associate the named handler with the named scheme(s).
add_url_handler() { add_url_handler() {
local handler="$1"; shift local handler="$1"
shift
local schemes="$@" scheme="" local schemes="$@" scheme=""
set -- set --
for scheme in $schemes; do for scheme in $schemes; do
@ -67,14 +68,17 @@ curl_fetch_url() {
curl $curl_args --output - -- "$url" > "$outloc" || return $? curl $curl_args --output - -- "$url" > "$outloc" || return $?
else else
local outdir="$(mkuniqdir /tmp curl_fetch_url)" local outdir="$(mkuniqdir /tmp curl_fetch_url)"
( cd "$outdir"; curl $curl_args --remote-name "$url" || return $? ) (
cd "$outdir"
curl $curl_args --remote-name "$url" || return $?
)
outloc="$outdir/$(ls -A $outdir)" outloc="$outdir/$(ls -A $outdir)"
fi fi
if ! [ -f "$outloc" ]; then if ! [ -f "$outloc" ]; then
warn "Downloading '$url' failed!" warn "Downloading '$url' failed!"
return 253 return 253
fi fi
if [ -z "$2" ]; then echo "$outloc" ; fi if [ -z "$2" ]; then echo "$outloc"; fi
} }
add_url_handler curl_fetch_url http https ftp tftp add_url_handler curl_fetch_url http https ftp tftp


@ -95,7 +99,10 @@ ctorrent_fetch_url() {
curl $curl_args --output - -- "$url" > "$torrent_outloc" || return $? curl $curl_args --output - -- "$url" > "$torrent_outloc" || return $?
else else
local outdir="$(mkuniqdir /tmp torrent_fetch_url)" local outdir="$(mkuniqdir /tmp torrent_fetch_url)"
( cd "$outdir"; curl $curl_args --remote-name "$url" || return $? ) (
cd "$outdir"
curl $curl_args --remote-name "$url" || return $?
)
torrent_outloc="$outdir/$(ls -A $outdir)" torrent_outloc="$outdir/$(ls -A $outdir)"
outloc=${torrent_outloc%.*} outloc=${torrent_outloc%.*}
fi fi
@ -108,10 +115,10 @@ ctorrent_fetch_url() {
warn "Torrent download of '$url' failed!" warn "Torrent download of '$url' failed!"
return 253 return 253
fi fi
if [ -z "$2" ]; then echo "$outloc" ; fi if [ -z "$2" ]; then echo "$outloc"; fi
} }


command -v ctorrent >/dev/null \ command -v ctorrent > /dev/null \
&& add_url_handler ctorrent_fetch_url torrent && add_url_handler ctorrent_fetch_url torrent


### NFS ############################################################## ### NFS ##############################################################
@ -152,6 +159,6 @@ nfs_fetch_url() {
cp -f -- "$mntdir/$filename" "$outloc" || return $? cp -f -- "$mntdir/$filename" "$outloc" || return $?
fi fi
[ -f "$outloc" ] || return 253 [ -f "$outloc" ] || return 253
if [ -z "$2" ]; then echo "$outloc" ; fi if [ -z "$2" ]; then echo "$outloc"; fi
} }
command -v nfs_to_var >/dev/null && add_url_handler nfs_fetch_url nfs nfs4 command -v nfs_to_var > /dev/null && add_url_handler nfs_fetch_url nfs nfs4

6
modules.d/50drm/module-setup.sh

@ -33,9 +33,9 @@ installkernel() {
if [[ $hostonly ]]; then if [[ $hostonly ]]; then
for i in /sys/bus/{pci/devices,platform/devices,virtio/devices,soc/devices/soc?}/*/modalias; do for i in /sys/bus/{pci/devices,platform/devices,virtio/devices,soc/devices/soc?}/*/modalias; do
[[ -e $i ]] || continue [[ -e $i ]] || continue
[[ -n $(<"$i") ]] || continue [[ -n $(< "$i") ]] || continue
if hostonly="" dracut_instmods --silent -s "drm_crtc_init|drm_dev_register|drm_encoder_init" -S "iw_handler_get_spy" $(<"$i"); then if hostonly="" dracut_instmods --silent -s "drm_crtc_init|drm_dev_register|drm_encoder_init" -S "iw_handler_get_spy" $(< "$i"); then
if strstr "$(modinfo -F filename $(<"$i") 2>/dev/null)" radeon.ko; then if strstr "$(modinfo -F filename $(< "$i") 2> /dev/null)" radeon.ko; then
hostonly='' instmods amdkfd hostonly='' instmods amdkfd
fi fi
fi fi

8
modules.d/50gensplash/module-setup.sh

@ -32,7 +32,7 @@ install() {
dwarn "${line}" dwarn "${line}"
else else
derror "${line}" derror "${line}"
(( $_ret == 0 )) && _ret=1 (($_ret == 0)) && _ret=1
fi fi
done done
fi fi
@ -40,7 +40,7 @@ install() {
return ${_ret} return ${_ret}
} }


find_binary splash_geninitramfs >/dev/null || return 1 find_binary splash_geninitramfs > /dev/null || return 1


_opts='' _opts=''
if [[ ${DRACUT_GENSPLASH_THEME} ]]; then if [[ ${DRACUT_GENSPLASH_THEME} ]]; then
@ -62,7 +62,7 @@ install() {


dinfo "Installing Gentoo Splash (using the ${_splash_theme} theme)" dinfo "Installing Gentoo Splash (using the ${_splash_theme} theme)"


pushd "${initdir}" >/dev/null pushd "${initdir}" > /dev/null
mv dev dev.old mv dev dev.old
call_splash_geninitramfs "${initdir}" ${_opts} ${_splash_theme} || { call_splash_geninitramfs "${initdir}" ${_opts} ${_splash_theme} || {
derror "Could not build splash" derror "Could not build splash"
@ -70,7 +70,7 @@ install() {
} }
rm -rf dev rm -rf dev
mv dev.old dev mv dev.old dev
popd >/dev/null popd > /dev/null


inst_multiple chvt inst_multiple chvt
inst /usr/share/splashutils/initrd.splash /lib/gensplash-lib.sh inst /usr/share/splashutils/initrd.splash /lib/gensplash-lib.sh

3
modules.d/50plymouth/module-setup.sh

@ -2,7 +2,7 @@


pkglib_dir() { pkglib_dir() {
local _dirs="/usr/lib/plymouth /usr/libexec/plymouth/" local _dirs="/usr/lib/plymouth /usr/libexec/plymouth/"
if find_binary dpkg-architecture &>/dev/null; then if find_binary dpkg-architecture &> /dev/null; then
_dirs+=" /usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/plymouth" _dirs+=" /usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/plymouth"
fi fi
for _dir in $_dirs; do for _dir in $_dirs; do
@ -48,4 +48,3 @@ install() {
inst_hook pre-pivot 90 "$moddir"/plymouth-newroot.sh inst_hook pre-pivot 90 "$moddir"/plymouth-newroot.sh
fi fi
} }


2
modules.d/50plymouth/plymouth-emergency.sh

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh


plymouth --hide-splash 2>/dev/null || : plymouth --hide-splash 2> /dev/null || :

2
modules.d/50plymouth/plymouth-newroot.sh

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh


if type plymouth >/dev/null 2>&1 && [ -z "$DRACUT_SYSTEMD" ]; then if type plymouth > /dev/null 2>&1 && [ -z "$DRACUT_SYSTEMD" ]; then
plymouth --newroot=$NEWROOT plymouth --newroot=$NEWROOT
fi fi

12
modules.d/50plymouth/plymouth-populate-initrd.sh

@ -15,10 +15,10 @@ inst_libdir_file "plymouth/text.so" "plymouth/details.so"
if [[ $hostonly ]]; then if [[ $hostonly ]]; then
inst_multiple \ inst_multiple \
"/usr/share/plymouth/themes/details/details.plymouth" \ "/usr/share/plymouth/themes/details/details.plymouth" \
"/usr/share/plymouth/themes/text/text.plymouth" \ "/usr/share/plymouth/themes/text/text.plymouth"


if [[ -d $dracutsysrootdir/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 for x in "/usr/share/plymouth/themes/${PLYMOUTH_THEME}"/*; do
[[ -f "$dracutsysrootdir$x" ]] || break [[ -f "$dracutsysrootdir$x" ]] || break
inst $x inst $x
done done
@ -27,18 +27,18 @@ if [[ $hostonly ]]; then
if [[ -L $dracutsysrootdir/usr/share/plymouth/themes/default.plymouth ]]; then if [[ -L $dracutsysrootdir/usr/share/plymouth/themes/default.plymouth ]]; then
inst /usr/share/plymouth/themes/default.plymouth inst /usr/share/plymouth/themes/default.plymouth
# Install plugin for this theme # Install plugin for this theme
PLYMOUTH_PLUGIN=$(grep "^ModuleName=" "$dracutsysrootdir"/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" inst_libdir_file "plymouth/${PLYMOUTH_PLUGIN}.so"
fi fi
else else
for x in "$dracutsysrootdir"/usr/share/plymouth/themes/{text,details}/* ; do for x in "$dracutsysrootdir"/usr/share/plymouth/themes/{text,details}/*; do
[[ -f "$x" ]] || continue [[ -f "$x" ]] || continue
THEME_DIR=$(dirname "${x#$dracutsysrootdir}") THEME_DIR=$(dirname "${x#$dracutsysrootdir}")
mkdir -m 0755 -p "${initdir}/$THEME_DIR" mkdir -m 0755 -p "${initdir}/$THEME_DIR"
inst_multiple "${x#$dracutsysrootdir}" inst_multiple "${x#$dracutsysrootdir}"
done done
( (
cd ${initdir}/usr/share/plymouth/themes; cd ${initdir}/usr/share/plymouth/themes
ln -s text/text.plymouth default.plymouth 2>&1; ln -s text/text.plymouth default.plymouth 2>&1
) )
fi fi

6
modules.d/50plymouth/plymouth-pretrigger.sh

@ -1,16 +1,16 @@
#!/bin/sh #!/bin/sh


if type plymouthd >/dev/null 2>&1 && [ -z "$DRACUT_SYSTEMD" ]; then if type plymouthd > /dev/null 2>&1 && [ -z "$DRACUT_SYSTEMD" ]; then
if getargbool 1 plymouth.enable && getargbool 1 rd.plymouth -d -n rd_NO_PLYMOUTH; then if getargbool 1 plymouth.enable && getargbool 1 rd.plymouth -d -n rd_NO_PLYMOUTH; then
# first trigger graphics subsystem # first trigger graphics subsystem
udevadm trigger --action=add --attr-match=class=0x030000 >/dev/null 2>&1 udevadm trigger --action=add --attr-match=class=0x030000 > /dev/null 2>&1
# first trigger graphics and tty subsystem # first trigger graphics and tty subsystem
udevadm trigger --action=add \ udevadm trigger --action=add \
--subsystem-match=graphics \ --subsystem-match=graphics \
--subsystem-match=drm \ --subsystem-match=drm \
--subsystem-match=tty \ --subsystem-match=tty \
--subsystem-match=acpi \ --subsystem-match=acpi \
>/dev/null 2>&1 > /dev/null 2>&1


udevadm settle --timeout=180 2>&1 | vinfo udevadm settle --timeout=180 2>&1 | vinfo



59
modules.d/80cms/cms-write-ifcfg.sh

@ -1,11 +1,10 @@
#!/bin/bash #!/bin/bash


type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh


mkdir -m 0755 -p /run/initramfs/state/etc/sysconfig/network-scripts mkdir -m 0755 -p /run/initramfs/state/etc/sysconfig/network-scripts


function cms_write_config() function cms_write_config() {
{
. /tmp/cms.conf . /tmp/cms.conf
SUBCHANNELS="$(echo $SUBCHANNELS | sed 'y/ABCDEF/abcdef/')" SUBCHANNELS="$(echo $SUBCHANNELS | sed 'y/ABCDEF/abcdef/')"
OLDIFS=$IFS OLDIFS=$IFS
@ -14,9 +13,9 @@ function cms_write_config()
IFS=$OLDIFS IFS=$OLDIFS
devbusid=${subch_array[1]} devbusid=${subch_array[1]}
if [ "$NETTYPE" = "ctc" ]; then if [ "$NETTYPE" = "ctc" ]; then
driver="ctcm" driver="ctcm"
else else
driver=$NETTYPE driver=$NETTYPE
fi fi


DEVICE=$(cd /sys/devices/${driver}/$devbusid/net/ && set -- * && [ "$1" != "*" ] && echo $1) DEVICE=$(cd /sys/devices/${driver}/$devbusid/net/ && set -- * && [ "$1" != "*" ] && echo $1)
@ -27,15 +26,15 @@ function cms_write_config()


strglobin "$IPADDR" '*:*:*' && ipv6=1 strglobin "$IPADDR" '*:*:*' && ipv6=1


# to please NetworkManager on startup in loader before loader reconfigures net # to please NetworkManager on startup in loader before loader reconfigures net
cat > /etc/sysconfig/network << EOF cat > /etc/sysconfig/network << EOF
HOSTNAME=$HOSTNAME HOSTNAME=$HOSTNAME
EOF EOF
echo "$HOSTNAME" > /etc/hostname echo "$HOSTNAME" > /etc/hostname
if [ "$ipv6" ]; then if [ "$ipv6" ]; then
echo "NETWORKING_IPV6=yes" >> /etc/sysconfig/network echo "NETWORKING_IPV6=yes" >> /etc/sysconfig/network
else else
echo "NETWORKING=yes" >> /etc/sysconfig/network echo "NETWORKING=yes" >> /etc/sysconfig/network
fi fi


cat > $IFCFGFILE << EOF cat > $IFCFGFILE << EOF
@ -47,14 +46,14 @@ MTU=$MTU
SUBCHANNELS=$SUBCHANNELS SUBCHANNELS=$SUBCHANNELS
EOF EOF
if [ "$ipv6" ]; then if [ "$ipv6" ]; then
cat >> $IFCFGFILE << EOF cat >> $IFCFGFILE << EOF
IPV6INIT=yes IPV6INIT=yes
IPV6_AUTOCONF=no IPV6_AUTOCONF=no
IPV6ADDR=$IPADDR/$NETMASK IPV6ADDR=$IPADDR/$NETMASK
IPV6_DEFAULTGW=$GATEWAY IPV6_DEFAULTGW=$GATEWAY
EOF EOF
else else
cat >> $IFCFGFILE << EOF cat >> $IFCFGFILE << EOF
IPADDR=$IPADDR IPADDR=$IPADDR
NETMASK=$NETMASK NETMASK=$NETMASK
BROADCAST=$BROADCAST BROADCAST=$BROADCAST
@ -62,23 +61,35 @@ GATEWAY=$GATEWAY
EOF EOF
fi fi
if [ "$ipv6" ]; then if [ "$ipv6" ]; then
DNS1=$(set -- ${DNS/,/ }; echo $1) DNS1=$(
DNS2=$(set -- ${DNS/,/ }; echo $2) set -- ${DNS/,/ }
echo $1
)
DNS2=$(
set -- ${DNS/,/ }
echo $2
)
else else
DNS1=$(set -- ${DNS/:/ }; echo $1) DNS1=$(
DNS2=$(set -- ${DNS/:/ }; echo $2) set -- ${DNS/:/ }
echo $1
)
DNS2=$(
set -- ${DNS/:/ }
echo $2
)
fi fi
# real DNS config for NetworkManager to generate /etc/resolv.conf # real DNS config for NetworkManager to generate /etc/resolv.conf
[ "$DNS1" != "" ] && echo "DNS1=$DNS1" >> $IFCFGFILE [ "$DNS1" != "" ] && echo "DNS1=$DNS1" >> $IFCFGFILE
[ "$DNS2" != "" ] && echo "DNS2=$DNS2" >> $IFCFGFILE [ "$DNS2" != "" ] && echo "DNS2=$DNS2" >> $IFCFGFILE
# just to please loader's readNetInfo && writeEnabledNetInfo # just to please loader's readNetInfo && writeEnabledNetInfo
# which eats DNS1,DNS2,... and generates it themselves based on DNS # which eats DNS1,DNS2,... and generates it themselves based on DNS
if [ "$ipv6" ]; then if [ "$ipv6" ]; then
[ "$DNS" != "" ] && echo "DNS=\"$DNS\"" >> $IFCFGFILE [ "$DNS" != "" ] && echo "DNS=\"$DNS\"" >> $IFCFGFILE
else else
[ "$DNS" != "" ] && echo "DNS=\"${DNS/:/,}\"" >> $IFCFGFILE [ "$DNS" != "" ] && echo "DNS=\"${DNS/:/,}\"" >> $IFCFGFILE
fi fi
# colons in SEARCHDNS already replaced with spaces above for /etc/resolv.conf # colons in SEARCHDNS already replaced with spaces above for /etc/resolv.conf
[ "$SEARCHDNS" != "" ] && echo "DOMAIN=\"$SEARCHDNS\"" >> $IFCFGFILE [ "$SEARCHDNS" != "" ] && echo "DOMAIN=\"$SEARCHDNS\"" >> $IFCFGFILE
[ "$NETTYPE" != "" ] && echo "NETTYPE=$NETTYPE" >> $IFCFGFILE [ "$NETTYPE" != "" ] && echo "NETTYPE=$NETTYPE" >> $IFCFGFILE
[ "$PEERID" != "" ] && echo "PEERID=$PEERID" >> $IFCFGFILE [ "$PEERID" != "" ] && echo "PEERID=$PEERID" >> $IFCFGFILE
@ -87,11 +98,11 @@ EOF
[ "$MACADDR" != "" ] && echo "MACADDR=$MACADDR" >> $IFCFGFILE [ "$MACADDR" != "" ] && echo "MACADDR=$MACADDR" >> $IFCFGFILE
optstr="" optstr=""
for option in LAYER2 PORTNO; do for option in LAYER2 PORTNO; do
[ -z "${!option}" ] && continue [ -z "${!option}" ] && continue
[ -n "$optstr" ] && optstr=${optstr}" " [ -n "$optstr" ] && optstr=${optstr}" "
optstr=${optstr}$(echo ${option} | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')"="${!option} optstr=${optstr}$(echo ${option} | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')"="${!option}
done done
# write single quotes since network.py removes double quotes but we need quotes # write single quotes since network.py removes double quotes but we need quotes
echo "OPTIONS='$optstr'" >> $IFCFGFILE echo "OPTIONS='$optstr'" >> $IFCFGFILE
unset option unset option
unset optstr unset optstr

26
modules.d/80cms/cmsifup.sh

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash


type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh


DEVICE=$1 DEVICE=$1


@ -17,17 +17,29 @@ if [ "$ipv6" ] && ! str_starts "$GATEWAY" "["; then
fi fi


if [ "$ipv6" ]; then if [ "$ipv6" ]; then
DNS1=$(set -- ${DNS/,/ }; echo $1) DNS1=$(
DNS2=$(set -- ${DNS/,/ }; echo $2) set -- ${DNS/,/ }
echo $1
)
DNS2=$(
set -- ${DNS/,/ }
echo $2
)
else else
DNS1=$(set -- ${DNS/:/ }; echo $1) DNS1=$(
DNS2=$(set -- ${DNS/:/ }; echo $2) set -- ${DNS/:/ }
echo $1
)
DNS2=$(
set -- ${DNS/:/ }
echo $2
)
fi fi


{ {
echo "ip=$IPADDR::$GATEWAY:$NETMASK:$HOSTNAME:$DEVICE:none:$MTU:$MACADDR" echo "ip=$IPADDR::$GATEWAY:$NETMASK:$HOSTNAME:$DEVICE:none:$MTU:$MACADDR"
for i in $DNS1 $DNS2; do for i in $DNS1 $DNS2; do
echo "nameserver=$i" echo "nameserver=$i"
done done
} > /etc/cmdline.d/80-cms.conf } > /etc/cmdline.d/80-cms.conf


@ -36,7 +48,7 @@ IFACES="$IFACES $DEVICE"
echo "$IFACES" >> /tmp/net.ifaces echo "$IFACES" >> /tmp/net.ifaces


if [ -x /usr/libexec/nm-initrd-generator ]; then if [ -x /usr/libexec/nm-initrd-generator ]; then
type nm_generate_connections >/dev/null 2>&1 || . /lib/nm-lib.sh type nm_generate_connections > /dev/null 2>&1 || . /lib/nm-lib.sh
nm_generate_connections nm_generate_connections
else else
exec ifup "$DEVICE" exec ifup "$DEVICE"

56
modules.d/80cms/cmssetup.sh

@ -1,15 +1,15 @@
#!/bin/bash #!/bin/bash


type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh


function sysecho () { function sysecho() {
file="$1" file="$1"
shift shift
local i=1 local i=1
while [ $i -le 10 ] ; do while [ $i -le 10 ]; do
if [ ! -f "$file" ]; then if [ ! -f "$file" ]; then
sleep 1 sleep 1
i=$((i+1)) i=$((i + 1))
else else
break break
fi fi
@ -27,23 +27,25 @@ function dasd_settle() {
return 1 return 1
fi fi
local i=1 local i=1
while [ $i -le 60 ] ; do while [ $i -le 60 ]; do
local status local status
read status < $dasd_status read status < $dasd_status
case $status in case $status in
online|unformatted) online | unformatted)
return 0 ;; return 0
;;
*) *)
sleep 0.1 sleep 0.1
i=$((i+1)) ;; i=$((i + 1))
;;
esac esac
done done
return 1 return 1
} }


function dasd_settle_all() { function dasd_settle_all() {
for dasdccw in $(while read line || [ -n "$line" ]; do echo "${line%%(*}"; done < /proc/dasd/devices) ; do for dasdccw in $(while read line || [ -n "$line" ]; do echo "${line%%(*}"; done < /proc/dasd/devices); do
if ! dasd_settle $dasdccw ; then if ! dasd_settle $dasdccw; then
echo $"Could not access DASD $dasdccw in time" echo $"Could not access DASD $dasdccw in time"
return 1 return 1
fi fi
@ -52,8 +54,7 @@ function dasd_settle_all() {
} }


# prints a canonocalized device bus ID for a given devno of any format # prints a canonocalized device bus ID for a given devno of any format
function canonicalize_devno() function canonicalize_devno() {
{
case ${#1} in case ${#1} in
3) echo "0.0.0${1}" ;; 3) echo "0.0.0${1}" ;;
4) echo "0.0.${1}" ;; 4) echo "0.0.${1}" ;;
@ -63,15 +64,14 @@ function canonicalize_devno()
} }


# read file from CMS and write it to /tmp # read file from CMS and write it to /tmp
function readcmsfile() # $1=dasdport $2=filename function readcmsfile() { # $1=dasdport $2=filename
{
local dev local dev
local numcpus local numcpus
local devname local devname
local ret=0 local ret=0
if [ $# -ne 2 ]; then return; fi if [ $# -ne 2 ]; then return; fi
# precondition: udevd created dasda block device node # precondition: udevd created dasda block device node
if ! dasd_cio_free -d $1 ; then if ! dasd_cio_free -d $1; then
echo $"DASD $1 could not be cleared from device blacklist" echo $"DASD $1 could not be cleared from device blacklist"
return 1 return 1
fi fi
@ -86,9 +86,9 @@ function readcmsfile() # $1=dasdport $2=filename
numcpus=$( numcpus=$(
while read line || [ -n "$line" ]; do while read line || [ -n "$line" ]; do
if strstr "$line" "# processors"; then if strstr "$line" "# processors"; then
echo ${line##*:}; echo ${line##*:}
break; break
fi; fi
done < /proc/cpuinfo done < /proc/cpuinfo
) )


@ -100,7 +100,7 @@ function readcmsfile() # $1=dasdport $2=filename
return 1 return 1
fi fi
udevadm settle udevadm settle
if ! dasd_settle $dev ; then if ! dasd_settle $dev; then
echo $"Could not access DASD $dev in time" echo $"Could not access DASD $dev in time"
return 1 return 1
fi fi
@ -108,7 +108,11 @@ function readcmsfile() # $1=dasdport $2=filename


udevadm settle udevadm settle


devname=$(cd /sys/bus/ccw/devices/$dev/block; set -- *; [ -b /dev/$1 ] && echo $1) devname=$(
cd /sys/bus/ccw/devices/$dev/block
set -- *
[ -b /dev/$1 ] && echo $1
)
devname=${devname:-dasda} devname=${devname:-dasda}


[[ -d /mnt ]] || mkdir -p /mnt [[ -d /mnt ]] || mkdir -p /mnt
@ -128,7 +132,10 @@ function readcmsfile() # $1=dasdport $2=filename
udevadm settle udevadm settle


# unbind all dasds to unload the dasd modules for a clean start # unbind all dasds to unload the dasd modules for a clean start
( cd /sys/bus/ccw/drivers/dasd-eckd; for i in *.*; do echo $i > unbind;done) (
cd /sys/bus/ccw/drivers/dasd-eckd
for i in *.*; do echo $i > unbind; done
)
udevadm settle udevadm settle
modprobe -r dasd_eckd_mod modprobe -r dasd_eckd_mod
udevadm settle udevadm settle
@ -139,8 +146,7 @@ function readcmsfile() # $1=dasdport $2=filename
return $ret return $ret
} }


processcmsfile() processcmsfile() {
{
source /tmp/cms.conf source /tmp/cms.conf
SUBCHANNELS="$(echo $SUBCHANNELS | sed 'y/ABCDEF/abcdef/')" SUBCHANNELS="$(echo $SUBCHANNELS | sed 'y/ABCDEF/abcdef/')"


@ -183,8 +189,8 @@ processcmsfile()
for i in ${!FCP_*}; do for i in ${!FCP_*}; do
echo "${!i}" | while read port rest || [ -n "$port" ]; do echo "${!i}" | while read port rest || [ -n "$port" ]; do
case $port in case $port in
*.*.*) *.*.*) ;;
;;
*.*) *.*)
port="0.$port" port="0.$port"
;; ;;

13
modules.d/80lvmmerge/lvmmerge.sh

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash


type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh


do_merge() { do_merge() {
sed -i -e 's/\(^[[:space:]]*\)locking_type[[:space:]]*=[[:space:]]*[[:digit:]]/\1locking_type = 1/' \ sed -i -e 's/\(^[[:space:]]*\)locking_type[[:space:]]*=[[:space:]]*[[:digit:]]/\1locking_type = 1/' \
@ -11,8 +11,8 @@ do_merge() {
umount -R /sysroot umount -R /sysroot


for tag in $(getargs rd.lvm.mergetags); do for tag in $(getargs rd.lvm.mergetags); do
lvm vgs --noheadings -o vg_name | \ lvm vgs --noheadings -o vg_name \
while read -r vg || [[ -n $vg ]]; do | while read -r vg || [[ -n $vg ]]; do
unset LVS unset LVS
declare -a LVS declare -a LVS
lvs=$(lvm lvs --noheadings -o lv_name "$vg") lvs=$(lvm lvs --noheadings -o lv_name "$vg")
@ -22,7 +22,7 @@ do_merge() {
tags=$(trim "$(lvm lvs --noheadings -o lv_tags "$vg/$lv")") tags=$(trim "$(lvm lvs --noheadings -o lv_tags "$vg/$lv")")
strstr ",${tags}," ",${tag}," || continue strstr ",${tags}," ",${tag}," || continue


if ! lvm lvs --noheadings -o lv_name "${vg}/${lv}_dracutsnap" &>/dev/null; then if ! lvm lvs --noheadings -o lv_name "${vg}/${lv}_dracutsnap" &> /dev/null; then
info "Creating backup ${lv}_dracutsnap of ${vg}/${lv}" info "Creating backup ${lv}_dracutsnap of ${vg}/${lv}"
lvm lvcreate -pr -s "${vg}/${lv}" --name "${lv}_dracutsnap" lvm lvcreate -pr -s "${vg}/${lv}" --name "${lv}_dracutsnap"
fi fi
@ -37,7 +37,7 @@ do_merge() {
systemctl --no-block stop sysroot.mount systemctl --no-block stop sysroot.mount
udevadm settle udevadm settle


for ((i=0; i < 100; i++)); do for ((i = 0; i < 100; i++)); do
lvm vgchange -an "$vg" && break lvm vgchange -an "$vg" && break
sleep 0.5 sleep 0.5
done done
@ -58,7 +58,7 @@ do_merge() {
systemctl --no-block reset-failed sysroot.mount systemctl --no-block reset-failed sysroot.mount
systemctl --no-block start sysroot.mount systemctl --no-block start sysroot.mount


for ((i=0; i < 100; i++)); do for ((i = 0; i < 100; i++)); do
[[ -d /sysroot/dev ]] && break [[ -d /sysroot/dev ]] && break
sleep 0.5 sleep 0.5
systemctl --no-block start sysroot.mount systemctl --no-block start sysroot.mount
@ -93,4 +93,3 @@ do_merge() {
if getarg rd.lvm.mergetags; then if getarg rd.lvm.mergetags; then
do_merge do_merge
fi fi


16
modules.d/81cio_ignore/module-setup.sh

@ -4,7 +4,7 @@


# called by dracut # called by dracut
check() { check() {
# do not add this module by default # do not add this module by default
local arch=${DRACUT_ARCH:-$(uname -m)} local arch=${DRACUT_ARCH:-$(uname -m)}
[ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1 [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1
return 0 return 0
@ -13,24 +13,24 @@ check() {
cmdline() { cmdline() {
local cio_accept local cio_accept


if [ -e /boot/zipl/active_devices.txt ] ; then if [ -e /boot/zipl/active_devices.txt ]; then
while read dev etc ; do while read dev etc; do
[ "$dev" = "#" -o "$dev" = "" ] && continue; [ "$dev" = "#" -o "$dev" = "" ] && continue
if [ -z "$cio_accept" ] ; then if [ -z "$cio_accept" ]; then
cio_accept="$dev" cio_accept="$dev"
else else
cio_accept="${cio_accept},${dev}" cio_accept="${cio_accept},${dev}"
fi fi
done < /boot/zipl/active_devices.txt done < /boot/zipl/active_devices.txt
fi fi
if [ -n "$cio_accept" ] ; then if [ -n "$cio_accept" ]; then
echo "rd.cio_accept=${cio_accept}" echo "rd.cio_accept=${cio_accept}"
fi fi
} }


# called by dracut # called by dracut
install() { install() {
if [[ $hostonly_cmdline == "yes" ]] ; then if [[ $hostonly_cmdline == "yes" ]]; then
local _cio_accept=$(cmdline) local _cio_accept=$(cmdline)
[[ $_cio_accept ]] && printf "%s\n" "$_cio_accept" >> "${initdir}/etc/cmdline.d/01cio_accept.conf" [[ $_cio_accept ]] && printf "%s\n" "$_cio_accept" >> "${initdir}/etc/cmdline.d/01cio_accept.conf"
fi fi

6
modules.d/81cio_ignore/parse-cio_accept.sh

@ -5,15 +5,15 @@
CIO_IGNORE=$(getarg cio_ignore) CIO_IGNORE=$(getarg cio_ignore)
CIO_ACCEPT=$(getarg rd.cio_accept) CIO_ACCEPT=$(getarg rd.cio_accept)


if [ -z $CIO_IGNORE ] ; then if [ -z $CIO_IGNORE ]; then
info "cio_ignored disabled on commandline" info "cio_ignored disabled on commandline"
return return
fi fi
if [ -n "$CIO_ACCEPT" ] ; then if [ -n "$CIO_ACCEPT" ]; then
OLDIFS="$IFS" OLDIFS="$IFS"
IFS=, IFS=,
set -- $CIO_ACCEPT set -- $CIO_ACCEPT
while (($# > 0)) ; do while (($# > 0)); do
info "Enabling device $1" info "Enabling device $1"
cio_ignore --remove $1 cio_ignore --remove $1
shift shift

6
modules.d/90btrfs/btrfs_device_ready.sh

@ -1,15 +1,15 @@
#!/bin/sh #!/bin/sh


type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh


btrfs_check_complete() { btrfs_check_complete() {
local _rootinfo _dev local _rootinfo _dev
_dev="${1:-/dev/root}" _dev="${1:-/dev/root}"
[ -e "$_dev" ] || return 0 [ -e "$_dev" ] || return 0
_rootinfo=$(udevadm info --query=env "--name=$_dev" 2>/dev/null) _rootinfo=$(udevadm info --query=env "--name=$_dev" 2> /dev/null)
if strstr "$_rootinfo" "ID_FS_TYPE=btrfs"; then if strstr "$_rootinfo" "ID_FS_TYPE=btrfs"; then
info "Checking, if btrfs device complete" info "Checking, if btrfs device complete"
btrfs device ready "$_dev" >/dev/null 2>&1 btrfs device ready "$_dev" > /dev/null 2>&1
return $? return $?
fi fi
return 0 return 0

8
modules.d/90btrfs/btrfs_finished.sh

@ -1,18 +1,18 @@
#!/bin/sh #!/bin/sh


type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh


btrfs_check_complete() { btrfs_check_complete() {
local _rootinfo _dev local _rootinfo _dev
_dev="${1:-/dev/root}" _dev="${1:-/dev/root}"
[ -e "$_dev" ] || return 0 [ -e "$_dev" ] || return 0
_rootinfo=$(udevadm info --query=env "--name=$_dev" 2>/dev/null) _rootinfo=$(udevadm info --query=env "--name=$_dev" 2> /dev/null)
if strstr "$_rootinfo" "ID_FS_TYPE=btrfs"; then if strstr "$_rootinfo" "ID_FS_TYPE=btrfs"; then
info "Checking, if btrfs device complete" info "Checking, if btrfs device complete"
unset __btrfs_mount unset __btrfs_mount
mount -o ro "$_dev" /tmp >/dev/null 2>&1 mount -o ro "$_dev" /tmp > /dev/null 2>&1
__btrfs_mount=$? __btrfs_mount=$?
[ $__btrfs_mount -eq 0 ] && umount "$_dev" >/dev/null 2>&1 [ $__btrfs_mount -eq 0 ] && umount "$_dev" > /dev/null 2>&1
return $__btrfs_mount return $__btrfs_mount
fi fi
return 0 return 0

4
modules.d/90btrfs/btrfs_timeout.sh

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh


type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh


info "Scanning for all btrfs devices" info "Scanning for all btrfs devices"
/sbin/btrfs device scan >/dev/null 2>&1 /sbin/btrfs device scan > /dev/null 2>&1

6
modules.d/90btrfs/module-setup.sh

@ -34,9 +34,11 @@ install() {
inst_rules "$moddir/80-btrfs.rules" inst_rules "$moddir/80-btrfs.rules"
case "$(btrfs --help)" in case "$(btrfs --help)" in
*device\ ready*) *device\ ready*)
inst_script "$moddir/btrfs_device_ready.sh" /sbin/btrfs_finished ;; inst_script "$moddir/btrfs_device_ready.sh" /sbin/btrfs_finished
;;
*) *)
inst_script "$moddir/btrfs_finished.sh" /sbin/btrfs_finished ;; inst_script "$moddir/btrfs_finished.sh" /sbin/btrfs_finished
;;
esac esac
fi fi



6
modules.d/90crypt/crypt-cleanup.sh

@ -1,13 +1,13 @@
#!/bin/sh #!/bin/sh


# close everything which is not busy # close everything which is not busy
rm -f -- /etc/udev/rules.d/70-luks.rules >/dev/null 2>&1 rm -f -- /etc/udev/rules.d/70-luks.rules > /dev/null 2>&1


if ! getarg rd.luks.uuid -d rd_LUKS_UUID >/dev/null 2>&1 && getargbool 1 rd.luks -d -n rd_NO_LUKS >/dev/null 2>&1; then if ! getarg rd.luks.uuid -d rd_LUKS_UUID > /dev/null 2>&1 && getargbool 1 rd.luks -d -n rd_NO_LUKS > /dev/null 2>&1; then
while true; do while true; do
local do_break="y" local do_break="y"
for i in /dev/mapper/luks-*; do for i in /dev/mapper/luks-*; do
cryptsetup luksClose $i >/dev/null 2>&1 && do_break=n cryptsetup luksClose $i > /dev/null 2>&1 && do_break=n
done done
[ "$do_break" = "y" ] && break [ "$do_break" = "y" ] && break
done done

96
modules.d/90crypt/crypt-lib.sh

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh


command -v getarg >/dev/null || . /lib/dracut-lib.sh command -v getarg > /dev/null || . /lib/dracut-lib.sh


# check if the crypttab contains an entry for a LUKS UUID # check if the crypttab contains an entry for a LUKS UUID
crypttab_contains() { crypttab_contains() {
@ -49,30 +49,67 @@ crypttab_contains() {
# Turn off input echo before tty command is executed and turn on after. # Turn off input echo before tty command is executed and turn on after.
# It's useful when password is read from stdin. # It's useful when password is read from stdin.
ask_for_password() { ask_for_password() {
local cmd; local prompt; local tries=3 local cmd
local ply_cmd; local ply_prompt; local ply_tries=3 local prompt
local tty_cmd; local tty_prompt; local tty_tries=3 local tries=3
local ply_cmd
local ply_prompt
local ply_tries=3
local tty_cmd
local tty_prompt
local tty_tries=3
local ret local ret


while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
--cmd) ply_cmd="$2"; tty_cmd="$2"; shift;; --cmd)
--ply-cmd) ply_cmd="$2"; shift;; ply_cmd="$2"
--tty-cmd) tty_cmd="$2"; shift;; tty_cmd="$2"
--prompt) ply_prompt="$2"; tty_prompt="$2"; shift;; shift
--ply-prompt) ply_prompt="$2"; shift;; ;;
--tty-prompt) tty_prompt="$2"; shift;; --ply-cmd)
--tries) ply_tries="$2"; tty_tries="$2"; shift;; ply_cmd="$2"
--ply-tries) ply_tries="$2"; shift;; shift
--tty-tries) tty_tries="$2"; shift;; ;;
--tty-echo-off) tty_echo_off=yes;; --tty-cmd)
tty_cmd="$2"
shift
;;
--prompt)
ply_prompt="$2"
tty_prompt="$2"
shift
;;
--ply-prompt)
ply_prompt="$2"
shift
;;
--tty-prompt)
tty_prompt="$2"
shift
;;
--tries)
ply_tries="$2"
tty_tries="$2"
shift
;;
--ply-tries)
ply_tries="$2"
shift
;;
--tty-tries)
tty_tries="$2"
shift
;;
--tty-echo-off) tty_echo_off=yes ;;
esac esac
shift shift
done done


{ flock -s 9; {
flock -s 9
# Prompt for password with plymouth, if installed and running. # Prompt for password with plymouth, if installed and running.
if type plymouth >/dev/null 2>&1 && plymouth --ping 2>/dev/null; then if type plymouth > /dev/null 2>&1 && plymouth --ping 2> /dev/null; then
plymouth ask-for-password \ plymouth ask-for-password \
--prompt "$ply_prompt" --number-of-tries=$ply_tries \ --prompt "$ply_prompt" --number-of-tries=$ply_tries \
--command="$ply_cmd" --command="$ply_cmd"
@ -85,17 +122,17 @@ ask_for_password() {


local i=1 local i=1
while [ $i -le $tty_tries ]; do while [ $i -le $tty_tries ]; do
[ -n "$tty_prompt" ] && \ [ -n "$tty_prompt" ] \
printf "$tty_prompt [$i/$tty_tries]:" >&2 && printf "$tty_prompt [$i/$tty_tries]:" >&2
eval "$tty_cmd" && ret=0 && break eval "$tty_cmd" && ret=0 && break
ret=$? ret=$?
i=$(($i+1)) i=$(($i + 1))
[ -n "$tty_prompt" ] && printf '\n' >&2 [ -n "$tty_prompt" ] && printf '\n' >&2
done done


[ "$tty_echo_off" = yes ] && stty $stty_orig [ "$tty_echo_off" = yes ] && stty $stty_orig
fi fi
} 9>/.console_lock } 9> /.console_lock


[ $ret -ne 0 ] && echo "Wrong password" >&2 [ $ret -ne 0 ] && echo "Wrong password" >&2
return $ret return $ret
@ -107,14 +144,17 @@ ask_for_password() {
# example: # example:
# test_dev -f LABEL="nice label" /some/file1 # test_dev -f LABEL="nice label" /some/file1
test_dev() { test_dev() {
local test_op=$1; local dev="$2"; local f="$3" local test_op=$1
local ret=1; local mount_point=$(mkuniqdir /mnt testdev) local dev="$2"
local f="$3"
local ret=1
local mount_point=$(mkuniqdir /mnt testdev)
local path local path


[ -n "$dev" -a -n "$*" ] || return 1 [ -n "$dev" -a -n "$*" ] || return 1
[ -d "$mount_point" ] || die 'Mount point does not exist!' [ -d "$mount_point" ] || die 'Mount point does not exist!'


if mount -r "$dev" "$mount_point" >/dev/null 2>&1; then if mount -r "$dev" "$mount_point" > /dev/null 2>&1; then
test $test_op "${mount_point}/${f}" test $test_op "${mount_point}/${f}"
ret=$? ret=$?
umount "$mount_point" umount "$mount_point"
@ -139,7 +179,8 @@ test_dev() {
# Returns true if /dev/dm-1 UUID starts with "123". # Returns true if /dev/dm-1 UUID starts with "123".
match_dev() { match_dev() {
[ -z "$1" -o "$1" = '*' ] && return 0 [ -z "$1" -o "$1" = '*' ] && return 0
local devlist; local dev local devlist
local dev


devlist="$(devnames "$1")" || return 255 devlist="$(devnames "$1")" || return 255
dev="$(devnames "$2")" || return 255 dev="$(devnames "$2")" || return 255
@ -162,8 +203,11 @@ $dev
# May print: # May print:
# /dev/sdc1:/keys/some.key # /dev/sdc1:/keys/some.key
getkey() { getkey() {
local keys_file="$1"; local for_dev="$2" local keys_file="$1"
local luks_dev; local key_dev; local key_path local for_dev="$2"
local luks_dev
local key_dev
local key_path


[ -z "$keys_file" -o -z "$for_dev" ] && die 'getkey: wrong usage!' [ -z "$keys_file" -o -z "$for_dev" ] && die 'getkey: wrong usage!'
[ -f "$keys_file" ] || return 1 [ -f "$keys_file" ] || return 1

4
modules.d/90crypt/crypt-run-generator.sh

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh


. /lib/dracut-lib.sh . /lib/dracut-lib.sh
type crypttab_contains >/dev/null 2>&1 || . /lib/dracut-crypt-lib.sh type crypttab_contains > /dev/null 2>&1 || . /lib/dracut-crypt-lib.sh


dev=$1 dev=$1
luks=$2 luks=$2
@ -24,7 +24,7 @@ fi


echo "$luks $dev - timeout=0,$allowdiscards" >> /etc/crypttab echo "$luks $dev - timeout=0,$allowdiscards" >> /etc/crypttab


if command -v systemctl >/dev/null; then if command -v systemctl > /dev/null; then
systemctl daemon-reload systemctl daemon-reload
systemctl start cryptsetup.target systemctl start cryptsetup.target
fi fi

2
modules.d/90crypt/cryptroot-ask.sh

@ -157,7 +157,7 @@ else
info "No key found for $device. Will try $numtries time(s) more later." info "No key found for $device. Will try $numtries time(s) more later."
initqueue --unique --onetime --settled \ initqueue --unique --onetime --settled \
--name cryptroot-ask-$luksname \ --name cryptroot-ask-$luksname \
$(command -v cryptroot-ask) "$device" "$luksname" "$is_keysource" "$(($numtries-1))" $(command -v cryptroot-ask) "$device" "$luksname" "$is_keysource" "$(($numtries - 1))"
exit 0 exit 0
fi fi
unset tmp unset tmp

40
modules.d/90crypt/module-setup.sh

@ -46,7 +46,7 @@ installkernel() {
IFS=$_OLD_IFS IFS=$_OLD_IFS
# try to load the cipher part with "crypto-" prepended # try to load the cipher part with "crypto-" prepended
# in non-hostonly mode # in non-hostonly mode
hostonly= instmods $(for k in "$@"; do echo "crypto-$k";done) hostonly= instmods $(for k in "$@"; do echo "crypto-$k"; done)
fi fi
done done
} }
@ -62,10 +62,10 @@ cmdline() {
UUID=$( UUID=$(
blkid -u crypto -o export $dev \ blkid -u crypto -o export $dev \
| while read line || [ -n "$line" ]; do | while read line || [ -n "$line" ]; do
[[ ${line#UUID} = $line ]] && continue [[ ${line#UUID} = $line ]] && continue
printf "%s" "${line#UUID=}" printf "%s" "${line#UUID=}"
break break
done done
) )
[[ ${UUID} ]] || continue [[ ${UUID} ]] || continue
printf "%s" " rd.luks.uuid=luks-${UUID}" printf "%s" " rd.luks.uuid=luks-${UUID}"
@ -95,14 +95,14 @@ install() {
[[ $_mapper = \#* ]] && continue [[ $_mapper = \#* ]] && continue
[[ $_dev ]] || continue [[ $_dev ]] || continue


[[ $_dev == PARTUUID=* ]] && \ [[ $_dev == PARTUUID=* ]] \
_dev="/dev/disk/by-partuuid/${_dev#PARTUUID=}" && _dev="/dev/disk/by-partuuid/${_dev#PARTUUID=}"


[[ $_dev == UUID=* ]] && \ [[ $_dev == UUID=* ]] \
_dev="/dev/disk/by-uuid/${_dev#UUID=}" && _dev="/dev/disk/by-uuid/${_dev#UUID=}"


[[ $_dev == ID=* ]] && \ [[ $_dev == ID=* ]] \
_dev="/dev/disk/by-id/${_dev#ID=}" && _dev="/dev/disk/by-id/${_dev#ID=}"


echo "$_dev $(blkid $_dev -s UUID -o value)" >> "${initdir}/etc/block_uuid.map" echo "$_dev $(blkid $_dev -s UUID -o value)" >> "${initdir}/etc/block_uuid.map"


@ -147,15 +147,15 @@ install() {
# the cryptsetup targets are already pulled in by 00systemd, but not # the cryptsetup targets are already pulled in by 00systemd, but not
# the enablement symlinks # the enablement symlinks
inst_multiple -o \ inst_multiple -o \
$systemdutildir/system-generators/systemd-cryptsetup-generator \ $systemdutildir/system-generators/systemd-cryptsetup-generator \
$systemdutildir/systemd-cryptsetup \ $systemdutildir/systemd-cryptsetup \
$systemdsystemunitdir/systemd-ask-password-console.path \ $systemdsystemunitdir/systemd-ask-password-console.path \
$systemdsystemunitdir/systemd-ask-password-console.service \ $systemdsystemunitdir/systemd-ask-password-console.service \
$systemdsystemunitdir/cryptsetup.target \ $systemdsystemunitdir/cryptsetup.target \
$systemdsystemunitdir/sysinit.target.wants/cryptsetup.target \ $systemdsystemunitdir/sysinit.target.wants/cryptsetup.target \
$systemdsystemunitdir/remote-cryptsetup.target \ $systemdsystemunitdir/remote-cryptsetup.target \
$systemdsystemunitdir/initrd-root-device.target.wants/remote-cryptsetup.target \ $systemdsystemunitdir/initrd-root-device.target.wants/remote-cryptsetup.target \
systemd-ask-password systemd-tty-ask-password-agent systemd-ask-password systemd-tty-ask-password-agent
fi fi


dracut_need_initqueue dracut_need_initqueue

9
modules.d/90crypt/parse-crypt.sh

@ -1,7 +1,6 @@
#!/bin/sh #!/bin/sh


type crypttab_contains >/dev/null 2>&1 || . /lib/dracut-crypt-lib.sh type crypttab_contains > /dev/null 2>&1 || . /lib/dracut-crypt-lib.sh



_cryptgetargsname() { _cryptgetargsname() {
debug_off debug_off
@ -12,15 +11,15 @@ _cryptgetargsname() {
set -- set --
for _o in $(getargs rd.luks.name); do for _o in $(getargs rd.luks.name); do
if [ "${_o%=*}" = "${_key%=}" ]; then if [ "${_o%=*}" = "${_key%=}" ]; then
[ -n "${_o%=*}" ] && set -- "$@" "${_o#*=}"; [ -n "${_o%=*}" ] && set -- "$@" "${_o#*=}"
_found=1; _found=1
fi fi
done done
if [ -n "$_found" ]; then if [ -n "$_found" ]; then
[ $# -gt 0 ] && printf '%s' "$*" [ $# -gt 0 ] && printf '%s' "$*"
return 0 return 0
fi fi
return 1; return 1
} }


if ! getargbool 1 rd.luks -d -n rd_NO_LUKS; then if ! getargbool 1 rd.luks -d -n rd_NO_LUKS; then

6
modules.d/90crypt/parse-keydev.sh

@ -1,8 +1,8 @@
#!/bin/sh #!/bin/sh


if getargbool 1 rd.luks -n rd_NO_LUKS && \ if getargbool 1 rd.luks -n rd_NO_LUKS \
[ -n "$(getarg rd.luks.key)" ]; then && [ -n "$(getarg rd.luks.key)" ]; then
exec 7>/etc/udev/rules.d/65-luks-keydev.rules exec 7> /etc/udev/rules.d/65-luks-keydev.rules
echo 'SUBSYSTEM!="block", GOTO="luks_keydev_end"' >&7 echo 'SUBSYSTEM!="block", GOTO="luks_keydev_end"' >&7
echo 'ACTION!="add|change", GOTO="luks_keydev_end"' >&7 echo 'ACTION!="add|change", GOTO="luks_keydev_end"' >&7



5
modules.d/90crypt/probe-keydev.sh

@ -2,8 +2,9 @@


. /lib/dracut-crypt-lib.sh . /lib/dracut-crypt-lib.sh



real_keydev="$1"
real_keydev="$1"; keypath="$2"; luksdev="$3" keypath="$2"
luksdev="$3"


[ -z "$real_keydev" -o -z "$keypath" ] && die 'probe-keydev: wrong usage!' [ -z "$real_keydev" -o -z "$keypath" ] && die 'probe-keydev: wrong usage!'
[ -z "$luksdev" ] && luksdev='*' [ -z "$luksdev" ] && luksdev='*'

2
modules.d/90dm/dm-pre-udev.sh

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/sh


strstr "$(cat /proc/misc)" device-mapper || modprobe dm_mod strstr "$(cat /proc/misc)" device-mapper || modprobe dm_mod
modprobe dm_mirror 2>/dev/null modprobe dm_mirror 2> /dev/null

10
modules.d/90dm/dm-shutdown.sh

@ -5,7 +5,7 @@ _remove_dm() {
local s local s
local devname local devname


for s in /sys/block/${dev}/holders/dm-* ; do for s in /sys/block/${dev}/holders/dm-*; do
[ -e ${s} ] || continue [ -e ${s} ] || continue
_remove_dm ${s##*/} _remove_dm ${s##*/}
done done
@ -30,12 +30,12 @@ _do_dm_shutdown() {
local dev local dev


info "Disassembling device-mapper devices" info "Disassembling device-mapper devices"
for dev in /sys/block/dm-* ; do for dev in /sys/block/dm-*; do
[ -e ${dev} ] || continue [ -e ${dev} ] || continue
if [ "x$final" != "x" ]; then if [ "x$final" != "x" ]; then
_remove_dm ${dev##*/} || ret=$? _remove_dm ${dev##*/} || ret=$?
else else
_remove_dm ${dev##*/} >/dev/null 2>&1 || ret=$? _remove_dm ${dev##*/} > /dev/null 2>&1 || ret=$?
fi fi
done done
if [ "x$final" != "x" ]; then if [ "x$final" != "x" ]; then
@ -45,8 +45,8 @@ _do_dm_shutdown() {
return $ret return $ret
} }


if command -v dmsetup >/dev/null && if command -v dmsetup > /dev/null \
[ "x$(dmsetup status)" != "xNo devices found" ]; then && [ "x$(dmsetup status)" != "xNo devices found" ]; then
_do_dm_shutdown $1 _do_dm_shutdown $1
else else
: :

5
modules.d/90dm/module-setup.sh

@ -18,8 +18,8 @@ installkernel() {


# called by dracut # called by dracut
install() { install() {
modinfo -k "$kernel" dm_mod >/dev/null 2>&1 && \ modinfo -k "$kernel" dm_mod > /dev/null 2>&1 \
inst_hook pre-udev 30 "$moddir/dm-pre-udev.sh" && inst_hook pre-udev 30 "$moddir/dm-pre-udev.sh"


inst_multiple dmsetup inst_multiple dmsetup
inst_multiple -o dmeventd inst_multiple -o dmeventd
@ -40,4 +40,3 @@ install() {


inst_hook shutdown 25 "$moddir/dm-shutdown.sh" inst_hook shutdown 25 "$moddir/dm-shutdown.sh"
} }


10
modules.d/90dmraid/dmraid.sh

@ -1,13 +1,13 @@
#!/bin/sh #!/bin/sh


type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh


dev="$1" dev="$1"
devenc=$(str_replace "$1" '/' '\2f') devenc=$(str_replace "$1" '/' '\2f')


[ -e /tmp/dmraid.$devenc ] && exit 0 [ -e /tmp/dmraid.$devenc ] && exit 0


>/tmp/dmraid.$devenc > /tmp/dmraid.$devenc


DM_RAIDS=$(getargs rd.dm.uuid -d rd_DM_UUID=) DM_RAIDS=$(getargs rd.dm.uuid -d rd_DM_UUID=)


@ -24,10 +24,10 @@ if [ -n "$DM_RAIDS" ] || getargbool 0 rd.auto; then
fi fi


info "Found dmraid sets:" info "Found dmraid sets:"
echo $SETS|vinfo echo $SETS | vinfo


if [ -n "$DM_RAIDS" ]; then if [ -n "$DM_RAIDS" ]; then
# only activate specified DM RAIDS # only activate specified DM RAIDS
for r in $DM_RAIDS; do for r in $DM_RAIDS; do
for s in $SETS; do for s in $SETS; do
if [ "${s##$r}" != "$s" ]; then if [ "${s##$r}" != "$s" ]; then
@ -37,7 +37,7 @@ if [ -n "$DM_RAIDS" ] || getargbool 0 rd.auto; then
done done
done done
else else
# scan and activate all DM RAIDS # scan and activate all DM RAIDS
for s in $SETS; do for s in $SETS; do
info "Activating $s" info "Activating $s"
dmraid -ay -i -p --rm_partitions "$s" 2>&1 | vinfo dmraid -ay -i -p --rm_partitions "$s" 2>&1 | vinfo

2
modules.d/90dmraid/module-setup.sh

@ -47,7 +47,7 @@ cmdline() {
for holder in "$DEVPATH"/holders/*; do for holder in "$DEVPATH"/holders/*; do
[[ -e "$holder" ]] || continue [[ -e "$holder" ]] || continue
dev="/dev/${holder##*/}" dev="/dev/${holder##*/}"
DM_NAME="$(dmsetup info -c --noheadings -o name "$dev" 2>/dev/null)" DM_NAME="$(dmsetup info -c --noheadings -o name "$dev" 2> /dev/null)"
[[ ${DM_NAME} ]] && break [[ ${DM_NAME} ]] && break
done done



Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save