-#!/bin/bash
+#!/bin/bash --norc
#
# Generator script for a dracut initramfs
# Tries to retain some degree of compatibility with the command line
#
# store for logging
+
+# Verify bash version, current minimum is 4
+if (( BASH_VERSINFO[0] < 4 )); then
+ printf -- 'You need at least Bash 4 to use dracut, sorry.' >&2
+ exit 1
+fi
+
dracut_args=( "$@" )
+readonly dracut_cmd="$(readlink -f $0)"
set -o pipefail
# 80x25 linebreak here ^
cat << EOF
-Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
+Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
Version: $DRACUT_VERSION
# 80x25 linebreak here ^
cat << EOF
-Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
+Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]
Version: $DRACUT_VERSION
--logfile [FILE] Logfile to use (overrides configuration setting)
--reproducible Create reproducible images
--loginstall [DIR] Log all files installed from the host to [DIR]
+ --uefi Create an UEFI executable with the kernel cmdline and
+ kernel combined
+ --uefi-stub [FILE] Use the UEFI stub [FILE] to create an UEFI executable
+ --kernel-image [FILE] location of the kernel image
If [LIST] has multiple arguments, then you have to put these in quotes.
EOF
}
-# function push()
-# push values to a stack
-# $1 = stack variable
-# $2.. values
-# example:
-# push stack 1 2 "3 4"
-push() {
- local _i
- local __stack=$1; shift
- for _i in "$@"; do
- eval ${__stack}'[${#'${__stack}'[@]}]="$_i"'
- done
-}
-
# Fills up host_devs stack variable and makes sure there are no duplicates
push_host_devs() {
local _dev
- for _dev in ${host_devs[@]}; do
- [ "$_dev" = "$1" ] && return
+ for _dev in "$@"; do
+ [[ " ${host_devs[@]} " == *" $_dev "* ]] && return
+ host_devs+=( "$_dev" )
done
- push host_devs "$1"
-}
-
-
-# function pop()
-# pops the last value from a stack
-# assigns value to second argument variable
-# or echo to stdout, if no second argument
-# $1 = stack variable
-# $2 = optional variable to store the value
-# example:
-# pop stack val
-# val=$(pop stack)
-pop() {
- local __stack=$1; shift
- local __resultvar=$1
- local _value;
- # check for empty stack
- eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
-
- eval _value='${'${__stack}'[${#'${__stack}'[@]}-1]}'
-
- if [[ "$__resultvar" ]]; then
- eval $__resultvar="'$_value'"
- else
- printf "%s" "$_value"
- fi
- eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
- return 0
}
# Little helper function for reading args from the commandline.
--long no-early-microcode \
--long reproducible \
--long loginstall: \
+ --long uefi \
+ --long uefi-stub: \
+ --long kernel-image: \
-- "$@")
if (( $? != 0 )); then
PARMS_TO_STORE+=" $1";
fi
case $1 in
- --kver) kernel="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- -a|--add) push add_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --force-add) push force_add_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --add-drivers) push add_drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --force-drivers) push force_drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --omit-drivers) push omit_drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- -m|--modules) push dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- -o|--omit) push omit_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- -d|--drivers) push drivers_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --filesystems) push filesystems_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- -I|--install) push install_items_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --install-optional)
- push install_optional_items_l \
- "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --fwdir) push fw_dir_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --libdirs) push libdirs_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --fscks) push fscks_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --add-fstab) push add_fstab_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --mount) push fstab_lines "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --add-device|--device)
- push add_device_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
- --kernel-cmdline) push kernel_cmdline_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
+ --kver) kernel="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
+ -a|--add) add_dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --force-add) force_add_dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --add-drivers) add_drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --force-drivers) force_drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --omit-drivers) omit_drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ -m|--modules) dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ -o|--omit) omit_dracutmodules_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ -d|--drivers) drivers_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --filesystems) filesystems_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ -I|--install) install_items_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --install-optional) install_optional_items_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --fwdir) fw_dir_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --libdirs) libdirs_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --fscks) fscks_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --add-fstab) add_fstab_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --mount) fstab_lines+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --add-device|--device) add_device_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
+ --kernel-cmdline) kernel_cmdline_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
--nofscks) nofscks_l="yes";;
--ro-mnt) ro_mnt_l="yes";;
-k|--kmoddir) drivers_dir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
-q|--quiet) ((verbosity_mod_l--));;
-l|--local)
allowlocal="yes"
- [[ -f "$(readlink -f "${0%/*}")/dracut-functions.sh" ]] \
+ [[ -f "$(readlink -f "${0%/*}")/dracut-init.sh" ]] \
&& dracutbasedir="$(readlink -f "${0%/*}")"
;;
-H|--hostonly|--host-only)
persistent_policy_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
--fstab) use_fstab_l="yes" ;;
-h|--help) long_usage; exit 1 ;;
- -i|--include) push include_src "$2"; PARMS_TO_STORE+=" '$2'";
+ -i|--include) include_src+=("$2"); PARMS_TO_STORE+=" '$2'";
shift;;
--bzip2) compress_l="bzip2";;
--lzma) compress_l="lzma";;
--regenerate-all) regenerate_all="yes";;
--noimageifnotneeded) noimageifnotneeded="yes";;
--reproducible) reproducible_l="yes";;
+ --uefi) uefi="yes";;
+ --uefi-stub)
+ uefi_stub_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
+ --kernel-image)
+ kernel_image_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;;
--) shift; break;;
*) # should not even reach this point
while (($# > 0)); do
if [ "${1%%=*}" == "++include" ]; then
- push include_src "$2"
- push include_target "$3"
+ include_src+=("$2")
+ include_target+=("$3")
PARMS_TO_STORE+=" --include '$2' '$3'"
shift 2
fi
cd /lib/modules
for i in *; do
[[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
- dracut --kver="$i" "${dracut_args[@]}"
+ "$dracut_cmd" --kver="$i" "${dracut_args[@]}"
((ret+=$?))
done
exit $ret
export PATH="${NPATH#:}"
unset NPATH
-# these optins add to the stuff in the config file
-if (( ${#add_dracutmodules_l[@]} )); then
- while pop add_dracutmodules_l val; do
- add_dracutmodules+=" $val "
- done
-fi
-
-if (( ${#force_add_dracutmodules_l[@]} )); then
- while pop force_add_dracutmodules_l val; do
- force_add_dracutmodules+=" $val "
- done
-fi
-
-if (( ${#fscks_l[@]} )); then
- while pop fscks_l val; do
- fscks+=" $val "
- done
-fi
-
-if (( ${#add_fstab_l[@]} )); then
- while pop add_fstab_l val; do
- add_fstab+=" $val "
- done
-fi
-
-if (( ${#fstab_lines_l[@]} )); then
- while pop fstab_lines_l val; do
- push fstab_lines $val
- done
-fi
-
-if (( ${#install_items_l[@]} )); then
- while pop install_items_l val; do
- install_items+=" $val "
- done
-fi
-
-if (( ${#install_optional_items_l[@]} )); then
- while pop install_optional_items_l val; do
- install_optional_items+=" $val "
- done
-fi
+# these options add to the stuff in the config file
+(( ${#add_dracutmodules_l[@]} )) && add_dracutmodules+=" ${add_dracutmodules_l[@]} "
+(( ${#force_add_dracutmodules_l[@]} )) && force_add_dracutmodules+=" ${force_add_dracutmodules_l[@]} "
+(( ${#fscks_l[@]} )) && fscks+=" ${fscks_l[@]} "
+(( ${#add_fstab_l[@]} )) && add_fstab+=" ${add_fstab_l[@]} "
+(( ${#fstab_lines_l[@]} )) && fstab_lines+=( "${fstab_lines_l[@]}" )
+(( ${#install_items_l[@]} )) && install_items+=" ${install_items_l[@]} "
+(( ${#install_optional_items_l[@]} )) && install_optional_items+=" ${install_optional_items_l[@]} "
# these options override the stuff in the config file
-if (( ${#dracutmodules_l[@]} )); then
- dracutmodules=''
- while pop dracutmodules_l val; do
- dracutmodules+="$val "
- done
-fi
-
-if (( ${#omit_dracutmodules_l[@]} )); then
- omit_dracutmodules=''
- while pop omit_dracutmodules_l val; do
- omit_dracutmodules+="$val "
- done
-fi
-
-if (( ${#filesystems_l[@]} )); then
- filesystems=''
- while pop filesystems_l val; do
- filesystems+="$val "
- done
-fi
-
-if (( ${#fw_dir_l[@]} )); then
- fw_dir=''
- while pop fw_dir_l val; do
- fw_dir+="$val "
- done
-fi
-
-if (( ${#libdirs_l[@]} )); then
- libdirs=''
- while pop libdirs_l val; do
- libdirs+="$val "
- done
-fi
+(( ${#dracutmodules_l[@]} )) && dracutmodules="${dracutmodules_l[@]}"
+(( ${#omit_dracutmodules_l[@]} )) && omit_dracutmodules="${omit_dracutmodules_l[@]}"
+(( ${#filesystems_l[@]} )) && filesystems="${filesystems_l[@]}"
+(( ${#fw_dir_l[@]} )) && fw_dir="${fw_dir_l[@]}"
+(( ${#libdirs_l[@]} ))&& libdirs="${libdirs_l[@]}"
[[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
[[ ! $stdloglvl ]] && stdloglvl=4
[[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
[[ $lvmconf_l ]] && lvmconf=$lvmconf_l
[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
-[[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
+[[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware /lib/firmware/$kernel"
[[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
[[ $tmpdir ]] || tmpdir=/var/tmp
[[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
[[ $logfile_l ]] && logfile="$logfile_l"
[[ $reproducible_l ]] && reproducible="$reproducible_l"
[[ $loginstall_l ]] && loginstall="$loginstall_l"
+[[ $uefi_stub_l ]] && uefi_stub="$uefi_stub_l"
+[[ $kernel_image_l ]] && kernel_image="$kernel_image_l"
# eliminate IFS hackery when messing with fw_dir
fw_dir=${fw_dir//:/ }
fi
# handle compression options.
-[[ $compress ]] || compress="gzip"
+if [[ $_no_compress_l = "cat" ]]; then
+ compress="cat"
+fi
+
+if ! [[ $compress ]]; then
+ # check all known compressors, if none specified
+ for i in pigz gzip lz4 lzop lzma xz lbzip2 bzip2 cat; do
+ command -v "$i" &>/dev/null || continue
+ compress="$i"
+ break
+ done
+ if [[ $compress = cat ]]; then
+ printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
+ fi
+fi
+
+# choose the right arguments for the compressor
case $compress in
- bzip2) compress="bzip2 -9";;
- lzma) compress="lzma -9 -T0";;
- xz) compress="xz --check=crc32 --lzma2=dict=1MiB -T0";;
- gzip) compress="gzip -n -9";
- if command -v pigz > /dev/null 2>&1; then
+ bzip2|lbzip2)
+ if [[ "$compress" = lbzip2 ]] || command -v lbzip2 &>/dev/null; then
+ compress="lbzip2 -9"
+ else
+ compress="bzip2 -9"
+ fi
+ ;;
+ lzma)
+ compress="lzma -9 -T0"
+ ;;
+ xz)
+ compress="xz --check=crc32 --lzma2=dict=1MiB -T0"
+ ;;
+ gzip|pigz)
+ if [[ "$compress" = pigz ]] || command -v pigz &>/dev/null; then
compress="pigz -9 -n -T -R"
- elif command -v gzip --help 2>&1 | grep -q rsyncable; then
+ elif command -v gzip &>/dev/null && gzip --help 2>&1 | grep -q rsyncable; then
compress="gzip -n -9 --rsyncable"
+ else
+ compress="gzip -n -9"
fi
;;
- lzo) compress="lzop -9";;
- lz4) compress="lz4 -l -9";;
+ lzo|lzop)
+ compress="lzop -9"
+ ;;
+ lz4)
+ compress="lz4 -l -9"
+ ;;
esac
-if [[ $_no_compress_l = "cat" ]]; then
- compress="cat"
-fi
[[ $hostonly = yes ]] && hostonly="-h"
[[ $hostonly != "-h" ]] && unset hostonly
[[ $reproducible == yes ]] && DRACUT_REPRODUCIBLE=1
readonly TMPDIR="$tmpdir"
-readonly initdir="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)"
+readonly initdir="$(mktemp -p "$TMPDIR/" -d -t initramfs.XXXXXX)"
[ -d "$initdir" ] || {
- printf "%s\n" "dracut: mktemp --tmpdir='$TMPDIR/' -d -t initramfs.XXXXXX failed." >&2
+ printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t initramfs.XXXXXX failed." >&2
exit 1
}
if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then
- readonly early_cpio_dir="$(mktemp --tmpdir="$TMPDIR/" -d -t early_cpio.XXXXXX)"
+ readonly early_cpio_dir="$(mktemp -p "$TMPDIR/" -d -t early_cpio.XXXXXX)"
[ -d "$early_cpio_dir" ] || {
- printf "%s\n" "dracut: mktemp --tmpdir='$TMPDIR/' -d -t early_cpio.XXXXXX failed." >&2
+ printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t early_cpio.XXXXXX failed." >&2
exit 1
}
fi
ret=$?;
[[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; };
[[ $keep ]] && echo "Not removing $early_cpio_dir." >&2 || { [[ $early_cpio_dir ]] && rm -Rf -- "$early_cpio_dir"; };
+ [[ $keep ]] && echo "Not removing $uefi_outdir." >&2 || { [[ $uefi_outdir ]] && rm -Rf -- "$uefi_outdir"; };
[[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
exit $ret;
' EXIT
. $dracutbasedir/dracut-version.sh
fi
-if [[ -f $dracutbasedir/dracut-functions.sh ]]; then
- . $dracutbasedir/dracut-functions.sh
+if [[ -f $dracutbasedir/dracut-init.sh ]]; then
+ . $dracutbasedir/dracut-init.sh
else
- printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2
+ printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-init.sh." >&2
printf "%s\n" "dracut: Are you running from a git checkout?" >&2
- printf "%s\n" "dracut: Try passing -l as an argument to $0" >&2
+ printf "%s\n" "dracut: Try passing -l as an argument to $dracut_cmd" >&2
exit 1
fi
rm -fr -- ${initdir}/*
fi
-# Verify bash version, current minimum is 3.1
-if (( BASH_VERSINFO[0] < 4 )); then
- dfatal 'You need at least Bash 4 to use dracut, sorry.'
- exit 1
-fi
-
dracutfunctions=$dracutbasedir/dracut-functions.sh
export dracutfunctions
-if (( ${#drivers_l[@]} )); then
- drivers=''
- while pop drivers_l val; do
- drivers+="$val "
- done
-fi
+(( ${#drivers_l[@]} )) && drivers="${drivers_l[@]}"
drivers=${drivers/-/_}
-if (( ${#add_drivers_l[@]} )); then
- while pop add_drivers_l val; do
- add_drivers+=" $val "
- done
-fi
+(( ${#add_drivers_l[@]} )) && add_drivers+=" ${add_drivers_l[@]} "
add_drivers=${add_drivers/-/_}
-if (( ${#force_drivers_l[@]} )); then
- while pop force_drivers_l val; do
- force_drivers+=" $val "
- done
-fi
+(( ${#force_drivers_l[@]} )) && force_drivers+=" ${force_drivers_l[@]} "
force_drivers=${force_drivers/-/_}
-if (( ${#omit_drivers_l[@]} )); then
- while pop omit_drivers_l val; do
- omit_drivers+=" $val "
- done
-fi
+(( ${#omit_drivers_l[@]} )) && omit_drivers+=" ${omit_drivers_l[@]} "
omit_drivers=${omit_drivers/-/_}
-if (( ${#kernel_cmdline_l[@]} )); then
- while pop kernel_cmdline_l val; do
- kernel_cmdline+=" $val "
- done
-fi
+(( ${#kernel_cmdline_l[@]} )) && kernel_cmdline+=" ${kernel_cmdline_l[@]} "
omit_drivers_corrected=""
for d in $omit_drivers; do
#" keep vim happy
done
-dinfo "Executing: $0 ${dracut_args[@]}"
+dinfo "Executing: $dracut_cmd ${dracut_args[@]}"
[[ $do_list = yes ]] && {
for mod in $dracutbasedir/modules.d/*; do
abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
-if [[ -d $srcmods ]]; then
- [[ -f $srcmods/modules.dep ]] || {
- dwarn "$srcmods/modules.dep is missing. Did you run depmod?"
- }
+if [[ $no_kernel != yes ]] && [[ -d $srcmods ]]; then
+ if ! [[ -f $srcmods/modules.dep ]]; then
+ dwarn "$srcmods/modules.dep is missing. Did you run depmod?"
+ elif ! ( command -v gzip &>/dev/null && command -v xz &>/dev/null); then
+ read _mod < $srcmods/modules.dep
+ _mod=${_mod%%:*}
+ if [[ -f $srcmods/"$_mod" ]]; then
+ # Check, if kernel modules are compressed, and if we can uncompress them
+ case "$_mod" in
+ *.ko.gz) kcompress=gzip;;
+ *.ko.xz) kcompress=xz;;
+ esac
+ if [[ $kcompress ]]; then
+ if ! command -v "$kcompress" &>/dev/null; then
+ dfatal "Kernel modules are compressed with $kcompress, but $kcompress is not available."
+ exit 1
+ fi
+ fi
+ fi
+ fi
fi
if [[ ! $print_cmdline ]]; then
fi
loginstall=$(readlink -f "$loginstall")
fi
+
+ if [[ $uefi = yes ]]; then
+ if ! command -v objcopy &>/dev/null; then
+ dfatal "Need 'objcopy' to create a UEFI executable"
+ exit 1
+ fi
+ unset EFI_MACHINE_TYPE_NAME
+ case $(arch) in
+ x86_64)
+ EFI_MACHINE_TYPE_NAME=x64;;
+ ia32)
+ EFI_MACHINE_TYPE_NAME=ia32;;
+ *)
+ dfatal "Architecture '$(arch)' not supported to create a UEFI executable"
+ exit 1
+ ;;
+ esac
+
+ if ! [[ -s $uefi_stub ]]; then
+ for uefi_stub in \
+ "/lib/systemd/boot/efi/linux${EFI_MACHINE_TYPE_NAME}.efi.stub" \
+ "/usr/lib/gummiboot/linux${EFI_MACHINE_TYPE_NAME}.efi.stub"; do
+ [[ -s $uefi_stub ]] || continue
+ break
+ done
+ fi
+ if ! [[ -s $uefi_stub ]]; then
+ dfatal "Can't find a uefi stub '$uefi_stub' to create a UEFI executable"
+ exit 1
+ fi
+
+ if ! [[ $kernel_image ]]; then
+ for kernel_image in "/lib/modules/$kernel/vmlinuz" "/boot/vmlinuz-$kernel"; do
+ [[ -s "$kernel_image" ]] || continue
+ break
+ done
+ fi
+ if ! [[ -s $kernel_image ]]; then
+ dfatal "Can't find a kernel image '$kernel_image' to create a UEFI executable"
+ exit 1
+ fi
+ fi
fi
if [[ $acpi_override = yes ]] && ! check_kernel_config CONFIG_ACPI_INITRD_TABLE_OVERRIDE; then
if [[ $early_microcode = yes ]]; then
if [[ $hostonly ]]; then
[[ $(get_cpu_vendor) == "AMD" ]] \
- && ! check_kernel_config CONFIG_MICROCODE_AMD_EARLY \
+ && ! check_kernel_config CONFIG_MICROCODE_AMD \
&& unset early_microcode
[[ $(get_cpu_vendor) == "Intel" ]] \
- && ! check_kernel_config CONFIG_MICROCODE_INTEL_EARLY \
+ && ! check_kernel_config CONFIG_MICROCODE_INTEL \
&& unset early_microcode
else
- ! check_kernel_config CONFIG_MICROCODE_AMD_EARLY \
- && ! check_kernel_config CONFIG_MICROCODE_INTEL_EARLY \
+ ! check_kernel_config CONFIG_MICROCODE_AMD \
+ && ! check_kernel_config CONFIG_MICROCODE_INTEL \
&& unset early_microcode
fi
[[ $early_microcode != yes ]] \
- && dwarn "Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]_EARLY!=y"
+ && dwarn "Disabling early microcode, because kernel does not support it. CONFIG_MICROCODE_[AMD|INTEL]!=y"
fi
# Need to be able to have non-root users read stuff (rpcbind etc)
;;
esac
[ -z "$dev" ] && dwarn "Bad fstab entry $@" && continue
+ if [[ "$3" == btrfs ]]; then
+ for i in $(btrfs_devs "$2"); do
+ push_host_devs "$i"
+ done
+ fi
push_host_devs "$dev"
host_fs_types["$dev"]="$3"
done
for f in $add_fstab; do
[[ -e $f ]] || continue
- while read dev rest; do
+ while read dev rest || [ -n "$dev" ]; do
push_host_devs "$dev"
done < "$f"
done
done
if (( ${#add_device_l[@]} )); then
- while pop add_device_l val; do
- add_device+=" $val "
- push_host_devs "$val"
- done
+ add_device+=" ${add_device_l[@]} "
+ push_host_devs "${add_device_l[@]}"
fi
if [[ $hostonly ]]; then
_dev=$(find_block_device "$mp")
_bdev=$(readlink -f "/dev/block/$_dev")
[[ -b $_bdev ]] && _dev=$_bdev
- push_host_devs $_dev
- [[ "$mp" == "/" ]] && root_dev="$_dev"
+ [[ "$mp" == "/" ]] && root_devs+=("$_dev")
push_host_devs "$_dev"
+ if [[ $(find_mp_fstype "$mp") == btrfs ]]; then
+ for i in $(btrfs_devs "$mp"); do
+ [[ "$mp" == "/" ]] && root_devs+=("$i")
+ push_host_devs "$i"
+ done
+ fi
done
if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then
- while read dev type rest; do
+ while read dev type rest || [ -n "$dev" ]; do
[[ -b $dev ]] || continue
[[ "$type" == "partition" ]] || continue
- while read _d _m _t _o _r; do
+ while read _d _m _t _o _r || [ -n "$_d" ]; do
[[ "$_d" == \#* ]] && continue
[[ $_d ]] || continue
[[ $_t != "swap" ]] && continue
[[ "$_d" -ef "$dev" ]] || continue
if [[ -f /etc/crypttab ]]; then
- while read _mapper _a _p _o; do
+ while read _mapper _a _p _o || [ -n "$_mapper" ]; do
[[ $_mapper = \#* ]] && continue
[[ "$_d" -ef /dev/mapper/"$_mapper" ]] || continue
[[ "$_o" ]] || _o="$_p"
done < /etc/crypttab
fi
- push_host_devs "$(readlink -f "$dev")"
+ _dev="$(readlink -f "$dev")"
+ push_host_devs "$_dev"
+ swap_devs+=("$_dev")
break
done < /etc/fstab
done < /proc/swaps
fi
+
+ # collect all "x-initrd.mount" entries from /etc/fstab
+ if [[ -f /etc/fstab ]]; then
+ while read _d _m _t _o _r || [ -n "$_d" ]; do
+ [[ "$_d" == \#* ]] && continue
+ [[ $_d ]] || continue
+ [[ "$_o" != *x-initrd.mount* ]] && continue
+ _dev=$(expand_persistent_dev "$_d")
+ _dev="$(readlink -f "$_dev")"
+ [[ -b $_dev ]] || continue
+
+ push_host_devs "$_dev"
+ if [[ "$_t" == btrfs ]]; then
+ for i in $(find_btrfs_devs "$_m"); do
+ push_host_devs "$i"
+ done
+ fi
+ done < /etc/fstab
+ fi
+
# record all host modaliases
declare -A host_modalias
- find /sys/devices/ -name uevent -print > "$initdir/.modalias"
- while read m; do
- while read line; do
- [[ "$line" != MODALIAS\=* ]] && continue
- modalias="${line##MODALIAS=}" && [[ $modalias ]] && host_modalias["$modalias"]=1
- break
- done < "$m"
+ find /sys/devices -name modalias -exec cat '{}' \; > "$initdir/.modalias"
+ while read -r modalias || [ -n "$modalias" ]; do
+ [[ $modalias ]] && host_modalias["$modalias"]=1
done < "$initdir/.modalias"
rm -f -- "$initdir/.modalias"
- while read _k _s _v; do
+ while read _k _s _v || [ -n "$_k" ]; do
[ "$_k" != "name" -a "$_k" != "driver" ] && continue
host_modalias["$_v"]=1
done </proc/crypto
# check /proc/modules
declare -A host_modules
- while read m rest; do
+ while read m rest || [ -n "$m" ]; do
host_modules["$m"]=1
done </proc/modules
fi
return 1
}
-for dev in ${host_devs[@]}; do
+for dev in "${host_devs[@]}"; do
_get_fs_type "$dev"
check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
done
[[ -d $udevdir ]] \
|| udevdir="$(pkg-config udev --variable=udevdir 2>/dev/null)"
if ! [[ -d "$udevdir" ]]; then
- [[ -d /lib/udev ]] && udevdir=/lib/udev
+ [[ ! -h /lib ]] && [[ -d /lib/udev ]] && udevdir=/lib/udev
[[ -d /usr/lib/udev ]] && udevdir=/usr/lib/udev
fi
|| systemdutildir=$(pkg-config systemd --variable=systemdutildir 2>/dev/null)
if ! [[ -d "$systemdutildir" ]]; then
- [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd
+ [[ ! -h /lib ]] && [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd
[[ -d /usr/lib/systemd ]] && systemdutildir=/usr/lib/systemd
fi
omit_drivers mdadmconf lvmconf root_dev \
use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
- debug host_fs_types host_devs sshkey add_fstab \
+ debug host_fs_types host_devs swap_devs sshkey add_fstab \
DRACUT_VERSION udevdir prefix filesystems drivers \
systemdutildir systemdsystemunitdir systemdsystemconfdir \
host_modalias host_modules hostonly_cmdline loginstall \
dracut_module_included "fips" && export DRACUT_FIPS_MODE=1
-if [[ $print_cmdline ]]; then
- modules_loaded=" "
+do_print_cmdline()
+{
+ local -A _mods_to_print
+ for i in $modules_loaded $mods_to_load; do
+ _mods_to_print[$i]=1
+ done
+
# source our modules.
for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
_d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
+ [[ ${_mods_to_print[$_d_mod]} ]] || continue
module_cmdline "$_d_mod"
done
unset moddir
+}
+
+if [[ $print_cmdline ]]; then
+ do_print_cmdline
printf "\n"
exit 0
fi
fi
if [[ $kernel_only != yes ]]; then
- for d in usr/bin usr/sbin bin etc lib sbin tmp usr var $libdirs; do
+ for d in usr/bin usr/sbin bin etc lib sbin tmp usr var var/tmp $libdirs; do
[[ -e "${initdir}${prefix}/$d" ]] && continue
if [ -L "/$d" ]; then
inst_symlink "/$d" "${prefix}/$d"
# source our modules.
for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
_d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
- if [[ "$mods_to_load" == *\ $_d_mod\ * ]]; then
- if [[ $show_modules = yes ]]; then
- printf "%s\n" "$_d_mod"
- else
- dinfo "*** Including module: $_d_mod ***"
- fi
- if [[ $kernel_only == yes ]]; then
+ [[ "$mods_to_load" == *\ $_d_mod\ * ]] || continue
+ if [[ $show_modules = yes ]]; then
+ printf "%s\n" "$_d_mod"
+ else
+ dinfo "*** Including module: $_d_mod ***"
+ fi
+ if [[ $kernel_only == yes ]]; then
+ module_installkernel "$_d_mod" || {
+ dfatal "installkernel failed in module $_d_mod"
+ exit 1
+ }
+ else
+ module_install "$_d_mod"
+ if [[ $no_kernel != yes ]]; then
module_installkernel "$_d_mod" || {
dfatal "installkernel failed in module $_d_mod"
exit 1
}
- else
- module_install "$_d_mod"
- if [[ $no_kernel != yes ]]; then
- module_installkernel "$_d_mod" || {
- dfatal "installkernel failed in module $_d_mod"
- exit 1
- }
- fi
- fi
- mods_to_load=${mods_to_load// $_d_mod /}
- modules_loaded+="$_d_mod "
-
- #print the module install size
- if [ -n "$printsize" ]; then
- _isize_new=$(du -sk ${initdir}|cut -f1)
- _isize_delta=$((_isize_new - _isize))
- printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
- _isize=$_isize_new
fi
fi
+ mods_to_load=${mods_to_load// $_d_mod /}
+ modules_loaded+="$_d_mod "
+
+ #print the module install size
+ if [ -n "$printsize" ]; then
+ _isize_new=$(du -sk ${initdir}|cut -f1)
+ _isize_delta=$((_isize_new - _isize))
+ printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
+ _isize=$_isize_new
+ fi
done
unset moddir
[[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
- while pop fstab_lines line; do
+ for line in "${fstab_lines[@]}"; do
line=($line)
[ -z "${line[3]}" ] && line[3]="defaults"
[ -z "${line[4]}" ] && line[4]="0"
[ -z "${line[5]}" ] && line[5]="2"
+ strstr "${line[2]}" "nfs" && line[5]="0"
echo "${line[@]}" >> "${initdir}/etc/fstab"
done
if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
dinfo "*** Resolving executable dependencies ***"
- find "$initdir" -type f \
- '(' -perm -0100 -or -perm -0010 -or -perm -0001 ')' \
- -not -path '*.ko' -print0 \
+ find "$initdir" -type f -perm /0111 -not -path '*.ko' -print0 \
| xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R ${DRACUT_FIPS_MODE:+-H} --
dinfo "*** Resolving executable dependencies done***"
fi
done
fi
-while pop include_src src && pop include_target tgt; do
- if [[ $src && $tgt ]]; then
+for ((i=0; i < ${#include_src[@]}; i++)); do
+ src="${include_src[$i]}"
+ target="${include_target[$i]}"
+ if [[ $src && $target ]]; then
if [[ -f $src ]]; then
- inst $src $tgt
+ inst $src $target
else
ddebug "Including directory: $src"
- mkdir -p "${initdir}/${tgt}"
+ destdir="${initdir}/${target}"
+ mkdir -p "$destdir"
# check for preexisting symlinks, so we can cope with the
# symlinks to $prefix
- for i in "$src"/*; do
- [[ -e "$i" || -h "$i" ]] || continue
- s=${initdir}/${tgt}/${i#$src/}
- if [[ -d "$i" ]]; then
- if ! [[ -e "$s" ]]; then
- mkdir -m 0755 -p "$s"
- chmod --reference="$i" "$s"
+ # Objectname is a file or a directory
+ for objectname in "$src"/*; do
+ [[ -e "$objectname" || -h "$objectname" ]] || continue
+ if [[ -d "$objectname" ]]; then
+ # objectname is a directory, let's compute the final directory name
+ object_destdir=${destdir}/${objectname#$src/}
+ if ! [[ -e "$object_destdir" ]]; then
+ mkdir -m 0755 -p "$object_destdir"
+ chmod --reference="$objectname" "$object_destdir"
fi
- cp --reflink=auto --sparse=auto -fa -t "$s" "$i"/*
+ cp --reflink=auto --sparse=auto -fa -t "$object_destdir" "$objectname"/*
else
- cp --reflink=auto --sparse=auto -fa -t "$s" "$i"
+ cp --reflink=auto --sparse=auto -fa -t "$destdir" "$objectname"
fi
done
fi
# strip kernel modules, but do not touch signed modules
find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \
- | while read -r -d $'\0' f; do
+ | while read -r -d $'\0' f || [ -n "$f" ]; do
SIG=$(tail -c 28 "$f")
[[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; }
done | xargs -r -0 strip -g
fi
if [[ $hostonly_cmdline ]] ; then
+ unset _stored_cmdline
if [ -d $initdir/etc/cmdline.d ];then
dinfo "Stored kernel commandline:"
for conf in $initdir/etc/cmdline.d/*.conf ; do
+ [ -e "$conf" ] || continue
dinfo "$(< $conf)"
+ _stored_cmdline=1
done
- else
+ fi
+ if ! [[ $_stored_cmdline ]]; then
dinfo "No dracut internal kernel commandline stored in initrd"
fi
fi
rm -f -- "$outfile"
-dinfo "*** Creating image file ***"
+dinfo "*** Creating image file '$outfile' ***"
+
+if [[ $uefi = yes ]]; then
+ uefi_outfile="$outfile"
+ readonly uefi_outdir="$(mktemp -p "$TMPDIR/" -d -t initrd.XXXXXX)"
+ # redirect initrd output
+ outfile="$uefi_outdir/initrd"
+fi
if [[ $DRACUT_REPRODUCIBLE ]]; then
find "$initdir" -newer "$dracutbasedir/dracut-functions.sh" -print0 \
| $compress >> "$outfile"
); then
dfatal "dracut: creation of $outfile failed"
+ rm -f "$outfile"
exit 1
fi
-dinfo "*** Creating image file done ***"
+
+dinfo "*** Creating initrd image file '$outfile' done ***"
if (( maxloglvl >= 5 )); then
if [[ $allowlocal ]]; then
fi
fi
+if [[ $uefi = yes ]]; then
+ if [[ $kernel_cmdline ]]; then
+ echo -n "$kernel_cmdline" > "$uefi_outdir/cmdline.txt"
+ elif [[ $hostonly_cmdline = yes ]] && [ -d $initdir/etc/cmdline.d ];then
+ for conf in $initdir/etc/cmdline.d/*.conf ; do
+ [ -e "$conf" ] || continue
+ printf "%s " "$(< $conf)" >> "$uefi_outdir/cmdline.txt"
+ done
+ else
+ do_print_cmdline > "$uefi_outdir/cmdline.txt"
+ fi
+ echo -ne "\x00" >> "$uefi_outdir/cmdline.txt"
+
+ dinfo "Using UEFI kernel cmdline:"
+ dinfo $(< "$uefi_outdir/cmdline.txt")
+
+ [[ -s /usr/lib/os-release ]] && uefi_osrelease="/usr/lib/os-release"
+ [[ -s /etc/os-release ]] && uefi_osrelease="/etc/os-release"
+
+ objcopy \
+ ${uefi_osrelease:+--add-section .osrel=$uefi_osrelease --change-section-vma .osrel=0x20000} \
+ --add-section .cmdline="$uefi_outdir/cmdline.txt" --change-section-vma .cmdline=0x30000 \
+ --add-section .linux="$kernel_image" --change-section-vma .linux=0x40000 \
+ --add-section .initrd="$outfile" --change-section-vma .initrd=0x3000000 \
+ "$uefi_stub" "$uefi_outfile"
+ dinfo "*** Creating UEFI image file '$uefi_outfile' done ***"
+fi
+
exit 0