usr/sbin/dracut000075500000157517150252071140007535 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # Generator script for a dracut initramfs # Tries to retain some degree of compatibility with the command line # of the various mkinitrd implementations out there # # Copyright 2005-2013 Red Hat, Inc. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # unset BASH_ENV # store for logging dracut_args=( "$@" ) set -o pipefail usage() { [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut if [[ -f $dracutbasedir/dracut-version.sh ]]; then . $dracutbasedir/dracut-version.sh fi # 80x25 linebreak here ^ cat << EOF Usage: $0 [OPTION]... [ []] Version: $DRACUT_VERSION Creates initial ramdisk images for preloading modules -h, --help Display all options If a [LIST] has multiple arguments, then you have to put these in quotes. For example: # dracut --add-drivers "module1 module2" ... EOF } long_usage() { [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut if [[ -f $dracutbasedir/dracut-version.sh ]]; then . $dracutbasedir/dracut-version.sh fi # 80x25 linebreak here ^ cat << EOF Usage: $0 [OPTION]... [ []] Version: $DRACUT_VERSION Creates initial ramdisk images for preloading modules --kver [VERSION] Set kernel version to [VERSION]. -f, --force Overwrite existing initramfs file. -a, --add [LIST] Add a space-separated list of dracut modules. --rebuild Append arguments to those of existing image and rebuild -m, --modules [LIST] Specify a space-separated list of dracut modules to call when building the initramfs. Modules are located in /usr/lib/dracut/modules.d. -o, --omit [LIST] Omit a space-separated list of dracut modules. --force-add [LIST] Force to add a space-separated list of dracut modules to the default set of modules, when -H is specified. -d, --drivers [LIST] Specify a space-separated list of kernel modules to exclusively include in the initramfs. --add-drivers [LIST] Specify a space-separated list of kernel modules to add to the initramfs. --force-drivers [LIST] Specify a space-separated list of kernel modules to add to the initramfs and make sure they are tried to be loaded via modprobe same as passing rd.driver.pre=DRIVER kernel parameter. --omit-drivers [LIST] Specify a space-separated list of kernel modules not to add to the initramfs. --filesystems [LIST] Specify a space-separated list of kernel filesystem modules to exclusively include in the generic initramfs. -k, --kmoddir [DIR] Specify the directory, where to look for kernel modules --fwdir [DIR] Specify additional directories, where to look for firmwares, separated by : --kernel-only Only install kernel drivers and firmware files --no-kernel Do not install kernel drivers and firmware files --print-cmdline Print the kernel command line for the given disk layout --early-microcode Combine early microcode with ramdisk --no-early-microcode Do not combine early microcode with ramdisk --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters --strip Strip binaries in the initramfs --nostrip Do not strip binaries in the initramfs --prelink Prelink binaries in the initramfs --noprelink Do not prelink binaries in the initramfs --hardlink Hardlink files in the initramfs --nohardlink Do not hardlink files in the initramfs --prefix [DIR] Prefix initramfs files with [DIR] --noprefix Do not prefix initramfs files --mdadmconf Include local /etc/mdadm.conf --nomdadmconf Do not include local /etc/mdadm.conf --lvmconf Include local /etc/lvm/lvm.conf --nolvmconf Do not include local /etc/lvm/lvm.conf --fscks [LIST] Add a space-separated list of fsck helpers. --nofscks Inhibit installation of any fsck helpers. --ro-mnt Mount / and /usr read-only by default. -h, --help This message --debug Output debug information of the build process --profile Output profile information of the build process -L, --stdlog [0-6] Specify logging level (to standard error) 0 - suppress any messages 1 - only fatal errors 2 - all errors 3 - warnings 4 - info 5 - debug info (here starts lots of output) 6 - trace info (and even more) -v, --verbose Increase verbosity level -q, --quiet Decrease verbosity level -c, --conf [FILE] Specify configuration file to use. Default: /etc/dracut.conf --confdir [DIR] Specify configuration directory to use *.conf files from. Default: /etc/dracut.conf.d --tmpdir [DIR] Temporary directory to be used instead of default /var/tmp. -l, --local Local mode. Use modules from the current working directory instead of the system-wide installed in /usr/lib/dracut/modules.d. Useful when running dracut from a git checkout. -H, --hostonly Host-Only mode: Install only what is needed for booting the local host instead of a generic host. -N, --no-hostonly Disables Host-Only mode --hostonly-mode Specify the hostonly mode to use. could be one of "sloppy" or "strict". "sloppy" mode is used by default. In "sloppy" hostonly mode, extra drivers and modules will be installed, so minor hardware change won't make the image unbootable (eg. changed keyboard), and the image is still portable among similar hosts. With "strict" mode enabled, anything not necessary for booting the local host in its current state will not be included, and modules may do some extra job to save more space. Minor change of hardware or environment could make the image unbootable. DO NOT use "strict" mode unless you know what you are doing. --hostonly-cmdline Store kernel command line arguments needed in the initramfs --no-hostonly-cmdline Do not store kernel command line arguments needed in the initramfs --no-hostonly-default-device Do not generate implicit host devices like root, swap, fstab, etc. Use "--mount" or "--add-device" to explicitly add devices as needed. --hostonly-i18n Install only needed keyboard and font files according to the host configuration (default). --no-hostonly-i18n Install all keyboard and font files available. --persistent-policy [POLICY] Use [POLICY] to address disks and partitions. POLICY can be any directory name found in /dev/disk. E.g. "by-uuid", "by-label" --fstab Use /etc/fstab to determine the root device. --add-fstab [FILE] Add file to the initramfs fstab --mount "[DEV] [MP] [FSTYPE] [FSOPTS]" Mount device [DEV] on mountpoint [MP] with filesystem [FSTYPE] and options [FSOPTS] in the initramfs --add-device "[DEV]" Bring up [DEV] in initramfs -i, --include [SOURCE] [TARGET] Include the files in the SOURCE directory into the Target directory in the final initramfs. If SOURCE is a file, it will be installed to TARGET in the final initramfs. -I, --install [LIST] Install the space separated list of files into the initramfs. --install-optional [LIST] Install the space separated list of files into the initramfs, if they exist. --gzip Compress the generated initramfs using gzip. This will be done by default, unless another compression option or --no-compress is passed. --bzip2 Compress the generated initramfs using bzip2. Make sure your kernel has bzip2 decompression support compiled in, otherwise you will not be able to boot. --lzma Compress the generated initramfs using lzma. Make sure your kernel has lzma support compiled in, otherwise you will not be able to boot. --xz Compress the generated initramfs using xz. Make sure that your kernel has xz support compiled in, otherwise you will not be able to boot. --lzo Compress the generated initramfs using lzop. Make sure that your kernel has lzo support compiled in, otherwise you will not be able to boot. --lz4 Compress the generated initramfs using lz4. Make sure that your kernel has lz4 support compiled in, otherwise you will not be able to boot. --compress [COMPRESSION] Compress the generated initramfs with the passed compression program. Make sure your kernel knows how to decompress the generated initramfs, otherwise you will not be able to boot. --no-compress Do not compress the generated initramfs. This will override any other compression options. --list-modules List all available dracut modules. -M, --show-modules Print included module's name to standard output during build. --keep Keep the temporary initramfs for debugging purposes --printsize Print out the module install size --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module) --logfile [FILE] Logfile to use (overrides configuration setting) If [LIST] has multiple arguments, then you have to put these in quotes. For example: # dracut --add-drivers "module1 module2" ... 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 } # 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. # it automatically handles -a b and -a=b variants, and returns 1 if # we need to shift $3. read_arg() { # $1 = arg name # $2 = arg value # $3 = arg parameter local rematch='^[^=]*=(.*)$' if [[ $2 =~ $rematch ]]; then read "$1" <<< "${BASH_REMATCH[1]}" else read "$1" <<< "$3" # There is no way to shift our callers args, so # return 1 to indicate they should do it instead. return 1 fi } dropindirs_sort() { local suffix=$1; shift local -a files local f d for d in "$@"; do for i in "$d/"*"$suffix"; do if [[ -e "$i" ]]; then printf "%s\n" "${i##*/}" fi done done | sort -Vu | { readarray -t files for f in "${files[@]}"; do for d in "$@"; do if [[ -e "$d/$f" ]]; then printf "%s\n" "$d/$f" continue 2 fi done done } } rearrange_params() { # Workaround -i, --include taking 2 arguments set -- "${@/--include/++include}" # This prevents any long argument ending with "-i" # -i, like --opt-i but I think we can just prevent that set -- "${@/%-i/++include}" TEMP=$(unset POSIXLY_CORRECT; getopt \ -o "a:m:o:d:I:k:c:L:fvqlHhMN" \ --long kver: \ --long add: \ --long force-add: \ --long add-drivers: \ --long force-drivers: \ --long omit-drivers: \ --long modules: \ --long omit: \ --long drivers: \ --long filesystems: \ --long install: \ --long install-optional: \ --long fwdir: \ --long libdirs: \ --long fscks: \ --long add-fstab: \ --long mount: \ --long device: \ --long add-device: \ --long nofscks: \ --long ro-mnt \ --long kmoddir: \ --long conf: \ --long confdir: \ --long tmpdir: \ --long stdlog: \ --long compress: \ --long prefix: \ --long rebuild: \ --long force \ --long kernel-only \ --long no-kernel \ --long print-cmdline \ --long kernel-cmdline: \ --long strip \ --long nostrip \ --long prelink \ --long noprelink \ --long hardlink \ --long nohardlink \ --long noprefix \ --long mdadmconf \ --long nomdadmconf \ --long lvmconf \ --long nolvmconf \ --long debug \ --long profile \ --long sshkey: \ --long logfile: \ --long verbose \ --long quiet \ --long local \ --long hostonly \ --long host-only \ --long no-hostonly \ --long no-host-only \ --long hostonly-mode: \ --long hostonly-cmdline \ --long no-hostonly-cmdline \ --long no-hostonly-default-device \ --long persistent-policy: \ --long fstab \ --long help \ --long bzip2 \ --long lzma \ --long xz \ --long lzo \ --long lz4 \ --long no-compress \ --long gzip \ --long list-modules \ --long show-modules \ --long keep \ --long printsize \ --long regenerate-all \ --long noimageifnotneeded \ --long early-microcode \ --long no-early-microcode \ --long no-hostonly-i18n \ --long hostonly-i18n \ -- "$@") if (( $? != 0 )); then usage exit 1 fi } verbosity_mod_l=0 unset kernel unset outfile rearrange_params "$@" eval set -- "$TEMP" # parse command line args to check if '--rebuild' option is present unset append_args_l unset rebuild_file while : do if [ "$1" == "--" ]; then shift; break fi if [ "$1" == "--rebuild" ]; then append_args_l="yes" rebuild_file=$2 if [ ! -e $rebuild_file ]; then echo "Image file '$rebuild_file', for rebuild, does not exist!" exit 1 fi abs_rebuild_file=$(readlink -f "$rebuild_file") && rebuild_file="$abs_rebuild_file" shift; continue fi shift done # get output file name and kernel version from command line arguments while (($# > 0)); do case ${1%%=*} in ++include) shift 2;; *) if ! [[ ${outfile+x} ]]; then outfile=$1 elif ! [[ ${kernel+x} ]]; then kernel=$1 else printf "\nUnknown arguments: %s\n\n" "$*" >&2 usage; exit 1; fi ;; esac shift done # extract input image file provided with rebuild option to get previous parameters, if any if [[ $append_args_l == "yes" ]]; then unset rebuild_param # determine resultant file if ! [[ $outfile ]]; then outfile=$rebuild_file fi if ! rebuild_param=$(lsinitrd $rebuild_file '*lib/dracut/build-parameter.txt'); then echo "Image '$rebuild_file' has no rebuild information stored" exit 1 fi # prepend previous parameters to current command line args if [[ $rebuild_param ]]; then TEMP="$rebuild_param $TEMP" eval set -- "$TEMP" rearrange_params "$@" fi # clean the temporarily used scratch-pad directory rm -rf $scratch_dir fi unset PARMS_TO_STORE PARMS_TO_STORE="" eval set -- "$TEMP" while :; do if [ $1 != "--" ] && [ $1 != "--rebuild" ]; 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;; --nofscks) nofscks_l="yes";; --ro-mnt) ro_mnt_l="yes";; -k|--kmoddir) drivers_dir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; -c|--conf) conffile="$2"; PARMS_TO_STORE+=" '$2'"; shift;; --confdir) confdir="$2"; PARMS_TO_STORE+=" '$2'"; shift;; --tmpdir) tmpdir_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; -L|--stdlog) stdloglvl_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; --compress) compress_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; --prefix) prefix_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; --rebuild) if [ $rebuild_file == $outfile ]; then force=yes fi shift ;; -f|--force) force=yes;; --kernel-only) kernel_only="yes"; no_kernel="no";; --no-kernel) kernel_only="no"; no_kernel="yes";; --print-cmdline) print_cmdline="yes"; hostonly_l="yes"; kernel_only="yes"; no_kernel="yes";; --early-microcode) early_microcode_l="yes";; --no-early-microcode) early_microcode_l="no";; --strip) do_strip_l="yes";; --nostrip) do_strip_l="no";; --prelink) do_prelink_l="yes";; --noprelink) do_prelink_l="no";; --hardlink) do_hardlink_l="yes";; --nohardlink) do_hardlink_l="no";; --noprefix) prefix_l="/";; --mdadmconf) mdadmconf_l="yes";; --nomdadmconf) mdadmconf_l="no";; --lvmconf) lvmconf_l="yes";; --nolvmconf) lvmconf_l="no";; --debug) debug="yes";; --profile) profile="yes";; --sshkey) sshkey="$2"; PARMS_TO_STORE+=" '$2'"; shift;; --logfile) logfile_l="$2"; shift;; -v|--verbose) ((verbosity_mod_l++));; -q|--quiet) ((verbosity_mod_l--));; -l|--local) allowlocal="yes" [[ -f "$(readlink -f "${0%/*}")/dracut-init.sh" ]] \ && dracutbasedir="$(readlink -f "${0%/*}")" ;; -H|--hostonly|--host-only) hostonly_l="yes" ;; -N|--no-hostonly|--no-host-only) hostonly_l="no" ;; --hostonly-mode) hostonly_mode_l="$2"; PARMS_TO_STORE+=" '$2'"; shift;; --hostonly-cmdline) hostonly_cmdline_l="yes" ;; --hostonly-i18n) i18n_install_all_l="no" ;; --no-hostonly-i18n) i18n_install_all_l="yes" ;; --no-hostonly-cmdline) hostonly_cmdline_l="no" ;; --no-hostonly-default-device) hostonly_default_device="no" ;; --persistent-policy) 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'"; shift;; --bzip2) compress_l="bzip2";; --lzma) compress_l="lzma";; --xz) compress_l="xz";; --lzo) compress_l="lzo";; --lz4) compress_l="lz4";; --no-compress) _no_compress_l="cat";; --gzip) compress_l="gzip";; --list-modules) do_list="yes";; -M|--show-modules) show_modules_l="yes" ;; --keep) keep="yes";; --printsize) printsize="yes";; --regenerate-all) regenerate_all="yes";; --noimageifnotneeded) noimageifnotneeded="yes";; --) shift; break;; *) # should not even reach this point printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage; exit 1;; esac shift done # getopt cannot handle multiple arguments, so just handle "-I,--include" # the old fashioned way while (($# > 0)); do if [ ${1%%=*} == "++include" ]; then push include_src "$2" push include_target "$3" PARMS_TO_STORE+=" --include '$2' '$3'" shift 2 fi shift done if [[ $regenerate_all == "yes" ]]; then ret=0 if [[ $kernel ]]; then printf -- "--regenerate-all cannot be called with a kernel version\n" >&2 exit 1 fi if [[ $outfile ]]; then printf -- "--regenerate-all cannot be called with a image file\n" >&2 exit 1 fi ((len=${#dracut_args[@]})) for ((i=0; i < len; i++)); do [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \ unset dracut_args[$i] done cd /lib/modules for i in *; do [[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue dracut --kver="$i" "${dracut_args[@]}" ((ret+=$?)) done exit $ret fi if ! [[ $kernel ]]; then kernel=$(uname -r) fi if [[ $kernel ]]; then if ! [[ -d /lib/modules/$kernel ]] && [[ $no_kernel != yes ]]; then printf -- "Kernel version $kernel has no module directory /lib/modules/$kernel\n" >&2 fi fi if ! [[ $outfile ]]; then [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id if [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then outfile="/boot/${MACHINE_ID}/$kernel/initrd" else outfile="/boot/initramfs-$kernel.img" fi fi for i in /usr/sbin /sbin /usr/bin /bin; do rl=$i if [ -L "$i" ]; then rl=$(readlink -f $i) fi if [[ "$NPATH" != *:$rl* ]] ; then NPATH+=":$rl" fi done export PATH="${NPATH#:}" unset LC_MESSAGES unset LC_CTYPE export LC_ALL=C export LANG=C unset NPATH unset LD_LIBRARY_PATH unset LD_PRELOAD unset GREP_OPTIONS export DRACUT_LOG_LEVEL=warning [[ $debug ]] && { export DRACUT_LOG_LEVEL=debug export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): '; set -x } [[ $profile ]] && { export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: '; set -x debug=yes } [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut # if we were not passed a config file, try the default one if [[ ! -f $conffile ]]; then if [[ $allowlocal ]]; then conffile="$dracutbasedir/dracut.conf" else conffile="/etc/dracut.conf" fi fi if [[ ! -d $confdir ]]; then if [[ $allowlocal ]]; then confdir="$dracutbasedir/dracut.conf.d" else confdir="/etc/dracut.conf.d" fi fi # source our config file [[ -f $conffile ]] && . "$conffile" # source our config dir for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do [[ -e $f ]] && . "$f" done # 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 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 [[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l [[ ! $stdloglvl ]] && stdloglvl=4 stdloglvl=$((stdloglvl + verbosity_mod_l)) ((stdloglvl > 6)) && stdloglvl=6 ((stdloglvl < 0)) && stdloglvl=0 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l [[ $do_strip_l ]] && do_strip=$do_strip_l [[ $do_strip ]] || do_strip=yes [[ $do_prelink_l ]] && do_prelink=$do_prelink_l [[ $do_prelink ]] || do_prelink=yes [[ $do_hardlink_l ]] && do_hardlink=$do_hardlink_l [[ $do_hardlink ]] || do_hardlink=yes [[ $prefix_l ]] && prefix=$prefix_l [[ $prefix = "/" ]] && unset prefix [[ $hostonly_l ]] && hostonly=$hostonly_l [[ $hostonly_cmdline_l ]] && hostonly_cmdline=$hostonly_cmdline_l [[ $hostonly_mode_l ]] && hostonly_mode=$hostonly_mode_l [[ $i18n_install_all_l ]] && i18n_install_all=$i18n_install_all_l [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l [[ $use_fstab_l ]] && use_fstab=$use_fstab_l [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l [[ $lvmconf_l ]] && lvmconf=$lvmconf_l [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut [[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware /lib/firmware/$kernel" [[ $tmpdir_l ]] && tmpdir="$tmpdir_l" [[ $tmpdir ]] || tmpdir=/var/tmp [[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS [[ $compress_l ]] && compress=$compress_l [[ $show_modules_l ]] && show_modules=$show_modules_l [[ $nofscks_l ]] && nofscks="yes" [[ $ro_mnt_l ]] && ro_mnt="yes" [[ $early_microcode_l ]] && early_microcode=$early_microcode_l [[ $early_microcode ]] || early_microcode=no [[ $logfile_l ]] && logfile="$logfile_l" # eliminate IFS hackery when messing with fw_dir fw_dir=${fw_dir//:/ } # handle compression options. [[ $compress ]] || compress="gzip" case $compress in bzip2) compress="bzip2 -9";; lzma) compress="lzma -9 -T0";; xz) compress="xz --check=crc32 --lzma2=dict=1MiB -T0";; gzip) compress="gzip -9"; command -v pigz > /dev/null 2>&1 && compress="pigz -9";; lzo) 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 case $hostonly_mode in '') [[ $hostonly ]] && hostonly_mode="sloppy" ;; sloppy|strict) if [[ ! $hostonly ]]; then unset hostonly_mode fi ;; *) printf "%s\n" "dracut: Invalid hostonly mode '$hostonly_mode'." >&2 exit 1 esac readonly TMPDIR="$tmpdir" readonly DRACUT_TMPDIR="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)" [ -d "$DRACUT_TMPDIR" ] || { printf "%s\n" "dracut: mktemp -p '$TMPDIR/' -d -t dracut.XXXXXX failed." >&2 exit 1 } # clean up after ourselves no matter how we die. trap ' ret=$?; [[ $keep ]] && echo "Not removing $DRACUT_TMPDIR." >&2 || { [[ $DRACUT_TMPDIR ]] && rm -rf -- "$DRACUT_TMPDIR"; }; exit $ret; ' EXIT # clean up after ourselves no matter how we die. trap 'exit 1;' SIGINT readonly initdir="${DRACUT_TMPDIR}/initramfs" mkdir "$initdir" export DRACUT_KERNEL_LAZY="1" export DRACUT_RESOLVE_LAZY="1" if [[ $print_cmdline ]]; then stdloglvl=0 sysloglvl=0 fileloglvl=0 kmsgloglvl=0 fi if [[ -f $dracutbasedir/dracut-version.sh ]]; then . $dracutbasedir/dracut-version.sh fi if [[ -f $dracutbasedir/dracut-init.sh ]]; then . $dracutbasedir/dracut-init.sh else 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 exit 1 fi if ! [[ $print_cmdline ]]; then inst /bin/sh if ! $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then unset DRACUT_RESOLVE_LAZY export DRACUT_RESOLVE_DEPS=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 case "$(arch)" in i686|x86_64) ;; *) if [[ $early_microcode = yes ]]; then early_microcode=no dinfo "Disabling early microcode for $(arch)" fi ;; esac if [[ $early_microcode = yes ]] || ( [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]] ); then readonly early_cpio_dir="${DRACUT_TMPDIR}/earlycpio" mkdir "$early_cpio_dir" fi if (( ${#drivers_l[@]} )); then drivers='' while pop drivers_l val; do drivers+="$val " done fi drivers=${drivers/-/_} if (( ${#add_drivers_l[@]} )); then while pop add_drivers_l val; do add_drivers+=" $val " done fi add_drivers=${add_drivers/-/_} if (( ${#force_drivers_l[@]} )); then while pop force_drivers_l val; do force_drivers+=" $val " done fi force_drivers=${force_drivers/-/_} if (( ${#omit_drivers_l[@]} )); then while pop omit_drivers_l val; do omit_drivers+=" $val " done fi omit_drivers=${omit_drivers/-/_} if (( ${#kernel_cmdline_l[@]} )); then while pop kernel_cmdline_l val; do kernel_cmdline+=" $val " done fi omit_drivers_corrected="" for d in $omit_drivers; do [[ " $drivers $add_drivers " == *\ $d\ * ]] && continue [[ " $drivers $force_drivers " == *\ $d\ * ]] && continue omit_drivers_corrected+="$d|" done omit_drivers="${omit_drivers_corrected%|}" unset omit_drivers_corrected # prepare args for logging for ((i=0; i < ${#dracut_args[@]}; i++)); do [[ "${dracut_args[$i]}" == *\ * ]] && \ dracut_args[$i]="\"${dracut_args[$i]}\"" #" keep vim happy done dinfo "Executing: $0 ${dracut_args[@]}" [[ $do_list = yes ]] && { for mod in $dracutbasedir/modules.d/*; do [[ -d $mod ]] || continue; [[ -e $mod/install || -e $mod/installkernel || \ -e $mod/module-setup.sh ]] || continue printf "%s\n" "${mod##*/??}" done exit 0 } # This is kinda legacy -- eventually it should go away. case $dracutmodules in ""|auto) dracutmodules="all" ;; esac abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile" if [[ -d $srcmods ]]; then if ! [[ -f $srcmods/modules.dep ]]; then if [[ -n "$(find "$srcmods" -name '*.ko*')" ]]; then dfatal "$srcmods/modules.dep is missing. Did you run depmod?" exit 1 else dwarn "$srcmods/modules.dep is missing. Did you run depmod?" fi fi fi if [[ ! $print_cmdline ]]; then if [[ -f $outfile && ! $force ]]; then dfatal "Will not override existing initramfs ($outfile) without --force" exit 1 fi outdir=${outfile%/*} [[ $outdir ]] || outdir="/" if [[ ! -d "$outdir" ]]; then dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible." exit 1 elif [[ ! -w "$outdir" ]]; then dfatal "No permission to write to $outdir." exit 1 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then dfatal "No permission to write $outfile." exit 1 fi fi # Need to be able to have non-root users read stuff (rpcbind etc) chmod 755 "$initdir" if [[ $hostonly ]]; then for i in /sys /proc /run /dev; do if ! findmnt --target "$i" &>/dev/null; then dwarning "Turning off host-only mode: '$i' is not mounted!" unset hostonly fi done fi declare -A host_fs_types for line in "${fstab_lines[@]}"; do set -- $line #dev mp fs fsopts push host_devs "$1" host_fs_types["$1"]="$3" done for f in $add_fstab; do [[ -e $f ]] || continue while read dev rest; do push host_devs "$dev" done < "$f" done for dev in $add_device; do push host_devs "$dev" done if (( ${#add_device_l[@]} )); then while pop add_device_l val; do add_device+=" $val " push host_devs "$val" done fi if [[ $hostonly ]] && [[ "$hostonly_default_device" != "no" ]]; then # in hostonly mode, determine all devices, which have to be accessed # and examine them for filesystem types for mp in \ "/" \ "/etc" \ "/bin" \ "/sbin" \ "/lib" \ "/lib64" \ "/usr" \ "/usr/bin" \ "/usr/sbin" \ "/usr/lib" \ "/usr/lib64" \ "/boot" \ "/boot/efi" \ ; do mp=$(readlink -f "$mp") mountpoint "$mp" >/dev/null 2>&1 || continue _dev=$(find_block_device "$mp") _bdev=$(readlink -f "/dev/block/$_dev") [[ -b $_bdev ]] && _dev=$_bdev push host_devs $_dev [[ "$mp" == "/" ]] && root_dev="$_dev" push host_devs "$_dev" done if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then while read dev type rest; do [[ -b $dev ]] || continue [[ "$type" == "partition" ]] || continue while read _d _m _t _o _r; do [[ "$_d" == \#* ]] && continue [[ $_d ]] || continue [[ $_t != "swap" ]] && continue [[ $_m != "swap" ]] && [[ $_m != "none" ]] && continue [[ "$_o" == *noauto* ]] && continue _d=$(expand_persistent_dev "$_d") [[ "$_d" -ef "$dev" ]] || continue if [[ -f /etc/crypttab ]]; then while read _mapper _a _p _o || [ -n "$_mapper" ]; do [[ $_mapper = \#* ]] && continue [[ "$_d" -ef /dev/mapper/"$_mapper" ]] || continue [[ "$_o" ]] || _o="$_p" # skip entries with password files [[ "$_p" == /* ]] && [[ -f $_p ]] && continue 2 # skip mkswap swap [[ $_o == *swap* ]] && continue 2 done < /etc/crypttab fi _dev="$(readlink -f "$dev")" push host_devs "$_dev" push 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 ]] && push host_devs "$_dev" done < /etc/fstab fi fi if [[ $hostonly ]]; then # 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" done < "$initdir/.modalias" rm -f -- "$initdir/.modalias" while read _k _s _v; do [ "$_k" != "name" -a "$_k" != "driver" ] && continue host_modalias["$_v"]=1 done /dev/null) if ! [[ -d "$systemdutildir" ]]; then [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd [[ -d /usr/lib/systemd ]] && systemdutildir=/usr/lib/systemd fi [[ -d $systemdsystemunitdir ]] \ || systemdsystemunitdir=$(pkg-config systemd --variable=systemdsystemunitdir 2>/dev/null) [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system [[ -d $systemdsystemconfdir ]] \ || systemdsystemconfdir=$(pkg-config systemd --variable=systemdsystemconfdir 2>/dev/null) [[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir=/etc/systemd/system [[ -d $tmpfilesdir ]] \ || tmpfilesdir=$(pkg-config systemd --variable=tmpfilesdir 2>/dev/null) if ! [[ -d "$tmpfilesdir" ]]; then [[ -f /lib/tmpfiles.d ]] && tmpfilesdir=/lib/tmpfiles.d [[ -f /usr/lib/tmpfiles.d ]] && tmpfilesdir=/usr/lib/tmpfiles.d fi export initdir dracutbasedir \ dracutmodules force_add_dracutmodules add_dracutmodules omit_dracutmodules \ mods_to_load \ fw_dir drivers_dir debug no_kernel kernel_only \ 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 swap_devs sshkey add_fstab \ DRACUT_VERSION udevdir prefix filesystems drivers \ systemdutildir systemdsystemunitdir systemdsystemconfdir \ host_modalias host_modules hostonly_cmdline loginstall \ tmpfilesdir mods_to_load="" # check all our modules to see if they should be sourced. # This builds a list of modules that we will install next. for_each_module_dir check_module for_each_module_dir check_mount dracut_module_included "fips" && export DRACUT_FIPS_MODE=1 if [[ $print_cmdline ]]; then modules_loaded=" " # 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]} module_cmdline "$_d_mod" done unset moddir printf "\n" exit 0 fi # Create some directory structure first [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}" [[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib" [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib" if [[ $prefix ]]; then for d in bin etc lib sbin tmp usr var $libdirs; do [[ "$d" == */* ]] && continue ln -sfn "${prefix#/}/${d#/}" "$initdir/$d" done fi if [[ $kernel_only != yes ]]; then for d in usr/bin usr/sbin bin etc lib sbin tmp usr var $libdirs; do [[ -e "${initdir}${prefix}/$d" ]] && continue if [ -L "/$d" ]; then inst_symlink "/$d" "${prefix}/$d" else mkdir -m 0755 -p "${initdir}${prefix}/$d" fi done for d in dev proc sys sysroot root run; do if [ -L "/$d" ]; then inst_symlink "/$d" else mkdir -m 0755 -p "$initdir/$d" fi done ln -sfn ../run "$initdir/var/run" ln -sfn ../run/lock "$initdir/var/lock" else for d in lib "$libdir"; do [[ -e "${initdir}${prefix}/$d" ]] && continue if [ -h "/$d" ]; then inst "/$d" "${prefix}/$d" else mkdir -m 0755 -p "${initdir}${prefix}/$d" fi done fi if [[ $kernel_only != yes ]]; then mkdir -p "${initdir}/etc/cmdline.d" for _d in $hookdirs; do mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d done if [[ "$UID" = "0" ]]; then [ -c ${initdir}/dev/null ] || mknod ${initdir}/dev/null c 1 3 [ -c ${initdir}/dev/kmsg ] || mknod ${initdir}/dev/kmsg c 1 11 [ -c ${initdir}/dev/console ] || mknod ${initdir}/dev/console c 5 1 fi fi _isize=0 #initramfs size modules_loaded=" " # 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 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 done unset moddir for i in $modules_loaded; do mkdir -p $initdir/lib/dracut printf "%s\n" "$i" >> $initdir/lib/dracut/modules.txt done dinfo "*** Including modules done ***" ## final stuff that has to happen if [[ $no_kernel != yes ]]; then if [[ $hostonly ]]; then echo "$(get_loaded_kernel_modules)" > $initdir/lib/dracut/loaded-kernel-modules.txt fi if [[ $drivers ]]; then hostonly='' instmods $drivers fi if [[ $add_drivers ]]; then hostonly='' instmods -c $add_drivers fi if [[ $force_drivers ]]; then hostonly='' instmods -c $force_drivers rm -f $initdir/etc/cmdline.d/20-force_driver.conf for mod in $force_drivers; do echo "rd.driver.pre=$mod" >>$initdir/etc/cmdline.d/20-force_drivers.conf done fi if [[ $filesystems ]]; then hostonly='' instmods -c $filesystems fi dinfo "*** Installing kernel module dependencies and firmware ***" dracut_kernel_post dinfo "*** Installing kernel module dependencies and firmware done ***" if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \ [[ -f ${initdir}/lib/modules/$kernel/modules.dep && ! -s ${initdir}/lib/modules/$kernel/modules.dep ]]; then for i in ${initdir}/etc/cmdline.d/*.conf; do # We need no initramfs image and do not generate one. [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0 done fi fi fi if [[ $kernel_only != yes ]]; then (( ${#install_items[@]} > 0 )) && inst_multiple ${install_items[@]} (( ${#install_optional_items[@]} > 0 )) && inst_multiple -o ${install_optional_items[@]} [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf" while pop fstab_lines line; 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 for f in $add_fstab; do cat "$f" >> "${initdir}/etc/fstab" done if [ -d ${initdir}/$systemdutildir ]; then mkdir -p ${initdir}/etc/conf.d { printf "%s\n" "systemdutildir=\"$systemdutildir\"" printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\"" printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\"" } > ${initdir}/etc/conf.d/systemd.conf fi 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 \ | xargs -r -0 $DRACUT_INSTALL ${initdir:+-D "$initdir"} -R ${DRACUT_FIPS_MODE:+-H} -- dinfo "*** Resolving executable dependencies done***" fi fi while pop include_src src && pop include_target target; do if [[ $src && $target ]]; then if [[ -f $src ]]; then inst $src $target else ddebug "Including directory: $src" destdir="${initdir}/${target}" mkdir -p "$destdir" # check for preexisting symlinks, so we can cope with the # symlinks to $prefix # 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 "$object_destdir" "$objectname"/* else cp --reflink=auto --sparse=auto -fa -t "$destdir" "$objectname" fi done fi fi done if [[ $kernel_only != yes ]]; then # make sure that library links are correct and up to date for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do [[ -f $f ]] && inst_simple "$f" done if ! ldconfig -r "$initdir"; then if [[ $UID = 0 ]]; then derror "ldconfig exited ungracefully" else derror "ldconfig might need uid=0 (root) for chroot()" fi fi fi PRELINK_BIN="$(command -v prelink)" if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then if [[ $DRACUT_FIPS_MODE ]]; then dinfo "*** Installing prelink files ***" inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf /etc/prelink.cache elif [[ $do_prelink == yes ]]; then dinfo "*** Pre-linking files ***" inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf chroot "$initdir" "$PRELINK_BIN" -a rm -f -- "$initdir/$PRELINK_BIN" rm -fr -- "$initdir"/etc/prelink.* dinfo "*** Pre-linking files done ***" fi fi if [[ $do_hardlink = yes ]] && command -v hardlink >/dev/null; then dinfo "*** Hardlinking files ***" hardlink "$initdir" 2>&1 dinfo "*** Hardlinking files done ***" fi # strip binaries if [[ $do_strip = yes ]] ; then for p in strip xargs find; do if ! type -P $p >/dev/null; then dinfo "Could not find '$p'. Not stripping the initramfs." do_strip=no fi done fi if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then dinfo "*** Stripping files ***" find "$initdir" -type f \ -executable -not -path '*/lib/modules/*.ko' -print0 \ | xargs -r -0 strip -g 2>/dev/null # 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 SIG=$(tail -c 28 "$f") [[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; } done | xargs -r -0 strip -g dinfo "*** Stripping files done ***" fi if [[ $early_microcode = yes ]]; then dinfo "*** Generating early-microcode cpio image contents ***" ucode_dir=(amd-ucode intel-ucode) ucode_dest=(AuthenticAMD.bin GenuineIntel.bin) _dest_dir="$early_cpio_dir/d/kernel/x86/microcode" _dest_idx="0 1" mkdir -p $_dest_dir if [[ $hostonly ]]; then [[ $(get_cpu_vendor) == "AMD" ]] && _dest_idx="0" [[ $(get_cpu_vendor) == "Intel" ]] && _dest_idx="1" fi for idx in $_dest_idx; do _fw=${ucode_dir[$idx]} for _fwdir in $fw_dir; do if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then _src="*" dinfo "*** Constructing ${ucode_dest[$idx]} ****" if [[ $hostonly ]]; then _src=$(get_ucode_file) [[ $_src ]] || break [[ -r $_fwdir/$_fw/$_src ]] || break fi for i in $_fwdir/$_fw/$_src; do [ -e "$i" ] && break break 2 done for i in $_fwdir/$_fw/$_src; do [[ -e "$i" ]] || continue # skip gpg files str_ends "$i" ".asc" && continue cat "$i" >> $_dest_dir/${ucode_dest[$idx]} done create_early_cpio="yes" fi done done if ! [[ $create_early_cpio = yes ]]; then dinfo "*** No early-microcode cpio image needed ***" fi fi if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then dinfo "*** Packaging ACPI tables to override BIOS provided ones ***" _dest_dir="$early_cpio_dir/d/kernel/firmware/acpi" mkdir -p $_dest_dir for table in $acpi_table_dir/*.aml; do dinfo " Adding ACPI table: $table" cp $table $_dest_dir create_early_cpio="yes" done fi dinfo "*** Store current command line parameters ***" if ! ( echo $PARMS_TO_STORE > $initdir/lib/dracut/build-parameter.txt ); then dfatal "Could not store the current command line parameters" exit 1 fi rm -f -- "$outfile" dinfo "*** Creating image file ***" [[ "$UID" != 0 ]] && cpio_owner_root="-R 0:0" if [[ $create_early_cpio = yes ]]; then dinfo "*** Creating microcode section ***" echo 1 > "$early_cpio_dir/d/early_cpio" # The microcode blob is _before_ the initramfs blob, not after if ! ( umask 077 cd "$early_cpio_dir/d" find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet > "${DRACUT_TMPDIR}/initramfs.img" ); then dfatal "dracut: creation of $outfile failed" exit 1 else dinfo "*** Created microcode section ***" fi fi if ! ( umask 077 cd "$initdir" find . -print0 | cpio --null $cpio_owner_root -H newc -o --quiet | \ $compress >> "${DRACUT_TMPDIR}/initramfs.img"; ); then dfatal "dracut: creation of $outfile failed" exit 1 fi dinfo "*** Creating image file done ***" if (( maxloglvl >= 5 )) && (( verbosity_mod_l >= 0 )); then if [[ $allowlocal ]]; then "$dracutbasedir/lsinitrd.sh" "${DRACUT_TMPDIR}/initramfs.img" | ddebug else lsinitrd "${DRACUT_TMPDIR}/initramfs.img" | ddebug fi fi if cp --reflink=auto "${DRACUT_TMPDIR}/initramfs.img" "$outfile" |& derror ; then dinfo "*** Creating initramfs image file '$outfile' done ***" else rm -f -- "$outfile" dfatal "dracut: creation of $outfile failed" exit 1 fi if ! sync "$outfile" 2> /dev/null; then dinfo "dracut: sync operartion on newly created initramfs $outfile failed" exit 1 fi exit 0 dracut-initramfs-restore000075500000002127150252660330011433 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh set -e KERNEL_VERSION="$(uname -r)" [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut SKIP="$dracutbasedir/skipcpio" [[ -x $SKIP ]] || SKIP=cat [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id if [[ $MACHINE_ID ]] && [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]] ; then IMG="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd" fi [[ -f $IMG ]] || IMG="/boot/initramfs-${KERNEL_VERSION}.img" cd /run/initramfs [ -f .need_shutdown -a -f "$IMG" ] || exit 1 if $SKIP "$IMG" | zcat | cpio -id --no-absolute-filenames --quiet >/dev/null; then rm -f -- .need_shutdown elif $SKIP "$IMG" | xzcat | cpio -id --no-absolute-filenames --quiet >/dev/null; then rm -f -- .need_shutdown elif $SKIP "$IMG" | lz4 -d -c | cpio -id --no-absolute-filenames --quiet >/dev/null; then rm -f -- .need_shutdown else # something failed, so we clean up echo "Unpacking of $IMG to /run/initramfs failed" >&2 rm -f -- /run/initramfs/shutdown exit 1 fi exit 0 dracut-init.sh000075500000002244150252660330007332 0ustar00#!/bin/bash # # functions used by dracut and other tools. # # Copyright 2005-2009 Red Hat, Inc. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # export LC_MESSAGES=C if [[ $DRACUT_KERNEL_LAZY ]] && ! [[ $DRACUT_KERNEL_LAZY_HASHDIR ]]; then if ! [[ -d "$initdir/.kernelmodseen" ]]; then mkdir -p "$initdir/.kernelmodseen" fi DRACUT_KERNEL_LAZY_HASHDIR="$initdir/.kernelmodseen" fi if [[ $initdir ]] && ! [[ -d $initdir ]]; then mkdir -p "$initdir" fi [[ $dracutbasedir ]] || export dracutbasedir=${BASH_SOURCE%/*} . $dracutbasedir/dracut-functions.sh dracut.conf.d/01-microcode.conf000064400000000026150252660330012225 0ustar00early_microcode="yes" dracut.conf.d/02-rescue.conf000064400000000032150252660330011545 0ustar00dracut_rescue_image="yes" dracut.conf.d/99-microcode-override.conf000064400000000425150252660330014066 0ustar00## Uncomment the following line in order to disable ## microcode_ctl module that is used for $fw_dir variable overriding. ## ## Please refer to /usr/share/doc/microcode_ctl/README.caveats ## for additional information. ## #omit_dracutmodules+=' microcode_ctl-fw_dir_override ' dracut.conf.d/01-dist.conf000064400000001014150252660330011222 0ustar00# dracut config file customized for RedHat/Fedora. # i18n i18n_vars="/etc/sysconfig/keyboard:KEYTABLE-KEYMAP /etc/sysconfig/i18n:SYSFONT-FONT,FONTACM-FONT_MAP,FONT_UNIMAP" i18n_default_font="latarcyrheb-sun16" i18n_install_all="yes" stdloglvl=3 sysloglvl=5 install_optional_items+=" vi /etc/virc ps grep cat rm " prefix="/" systemdutildir=/usr/lib/systemd systemdsystemunitdir=/usr/lib/systemd/system systemdsystemconfdir=/etc/systemd/system udevdir=/usr/lib/udev hostonly="yes" hostonly_cmdline="no" early_microcode="yes" dracut.conf.d/76-phys-port-name.conf000064400000000165150252660330013164 0ustar00install_items+=" /usr/lib/udev/phys-port-name-gen " install_items+=" /usr/lib/udev/rules.d/76-phys-port-name.rules " dracut.conf.d/50-nss-softokn.conf000064400000000101150252660330012543 0ustar00# turn on nss-softokn module add_dracutmodules+=" nss-softokn " dracut-version.sh000075500000000033150252660330010046 0ustar00DRACUT_VERSION=033-572.el7 dracut-logger.sh000075500000032114150252660330007645 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 et filetype=sh # # logging faciality module for dracut both at build- and boot-time # # Copyright 2010 Amadeusz Żołnowski # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . __DRACUT_LOGGER__=1 ## @brief Logging facility module for dracut both at build- and boot-time. # # @section intro Introduction # # The logger takes a bit from Log4j philosophy. There are defined 6 logging # levels: # - TRACE (6) # The TRACE Level designates finer-grained informational events than the # DEBUG. # - DEBUG (5) # The DEBUG Level designates fine-grained informational events that are most # useful to debug an application. # - INFO (4) # The INFO level designates informational messages that highlight the # progress of the application at coarse-grained level. # - WARN (3) # The WARN level designates potentially harmful situations. # - ERROR (2) # The ERROR level designates error events that might still allow the # application to continue running. # - FATAL (1) # The FATAL level designates very severe error events that will presumably # lead the application to abort. # Descriptions are borrowed from Log4j documentation: # http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html # # @section usage Usage # # First of all you have to start with dlog_init() function which initializes # required variables. Don't call any other logging function before that one! # If you're ready with this, you can use following functions which corresponds # clearly to levels listed in @ref intro Introduction. Here they are: # - dtrace() # - ddebug() # - dinfo() # - dwarn() # - derror() # - dfatal() # They take all arguments given as a single message to be logged. See dlog() # function for details how it works. Note that you shouldn't use dlog() by # yourself. It's wrapped with above functions. # # @see dlog_init() dlog() # # @section conf Configuration # # Logging is controlled by following global variables: # - @var stdloglvl - logging level to standard error (console output) # - @var sysloglvl - logging level to syslog (by logger command) # - @var fileloglvl - logging level to file # - @var kmsgloglvl - logging level to /dev/kmsg (only for boot-time) # - @var logfile - log file which is used when @var fileloglvl is higher # than 0 # and two global variables: @var maxloglvl and @var syslogfacility which must # not be overwritten. Both are set by dlog_init(). @var maxloglvl holds # maximum logging level of those three and indicates that dlog_init() was run. # @var syslogfacility is set either to 'user' (when building initramfs) or # 'daemon' (when booting). # # Logging level set by the variable means that messages from this logging level # and above (FATAL is the highest) will be shown. Logging levels may be set # independently for each destination (stderr, syslog, file, kmsg). # # @see dlog_init() ## @brief Initializes dracut Logger. # # @retval 1 if something has gone wrong # @retval 0 on success. # # @note This function need to be called before any other from this file. # # If any of the variables is not set, this function set it to default: # - @var stdloglvl = 4 (info) # - @var sysloglvl = 0 (no logging) # - @var fileloglvl is set to 4 when @var logfile is set too, otherwise it's # - @var kmsgloglvl = 0 (no logging) # set to 0 # # @warning Function sets global variables @var maxloglvl and @syslogfacility. # See file doc comment for details. dlog_init() { local __oldumask local ret=0; local errmsg [ -z "$stdloglvl" ] && stdloglvl=4 [ -z "$sysloglvl" ] && sysloglvl=0 [ -z "$kmsgloglvl" ] && kmsgloglvl=0 # Skip initialization if it's already done. [ -n "$maxloglvl" ] && return 0 if [ -z "$fileloglvl" ]; then [ -w "$logfile" ] && fileloglvl=4 || fileloglvl=0 elif (( $fileloglvl > 0 )); then if [[ $logfile ]]; then __oldumask=$(umask) umask 0377 ! [ -e "$logfile" ] && >"$logfile" umask $__oldumask if [ -w "$logfile" -a -f "$logfile" ]; then # Mark new run in the log file echo >>"$logfile" if command -v date >/dev/null; then echo "=== $(date) ===" >>"$logfile" else echo "===============================================" >>"$logfile" fi echo >>"$logfile" else # We cannot log to file, so turn this facility off. fileloglvl=0 ret=1 errmsg="'$logfile' is not a writable file" fi fi fi if (( $UID != 0 )); then kmsgloglvl=0 sysloglvl=0 fi if (( $sysloglvl > 0 )); then if [[ -d /run/systemd/journal ]] \ && type -P systemd-cat &>/dev/null \ && systemctl --quiet is-active systemd-journald.socket &>/dev/null \ && { echo "dracut-$DRACUT_VERSION" | systemd-cat -t 'dracut' &>/dev/null; } ; then readonly _systemdcatfile="$DRACUT_TMPDIR/systemd-cat" mkfifo "$_systemdcatfile" readonly _dlogfd=15 systemd-cat -t 'dracut' --level-prefix=true <"$_systemdcatfile" & exec 15>"$_systemdcatfile" elif ! [ -S /dev/log -a -w /dev/log ] || ! command -v logger >/dev/null; then # We cannot log to syslog, so turn this facility off. kmsgloglvl=$sysloglvl sysloglvl=0 ret=1 errmsg="No '/dev/log' or 'logger' included for syslog logging" fi fi if (($sysloglvl > 0)) || (($kmsgloglvl > 0 )); then if [ -n "$dracutbasedir" ]; then readonly syslogfacility=user else readonly syslogfacility=daemon fi export syslogfacility fi local lvl; local maxloglvl_l=0 for lvl in $stdloglvl $sysloglvl $fileloglvl $kmsgloglvl; do (( $lvl > $maxloglvl_l )) && maxloglvl_l=$lvl done readonly maxloglvl=$maxloglvl_l export maxloglvl if (($stdloglvl < 6)) && (($kmsgloglvl < 6)) && (($fileloglvl < 6)) && (($sysloglvl < 6)); then unset dtrace dtrace() { :; }; fi if (($stdloglvl < 5)) && (($kmsgloglvl < 5)) && (($fileloglvl < 5)) && (($sysloglvl < 5)); then unset ddebug ddebug() { :; }; fi if (($stdloglvl < 4)) && (($kmsgloglvl < 4)) && (($fileloglvl < 4)) && (($sysloglvl < 4)); then unset dinfo dinfo() { :; }; fi if (($stdloglvl < 3)) && (($kmsgloglvl < 3)) && (($fileloglvl < 3)) && (($sysloglvl < 3)); then unset dwarn dwarn() { :; }; unset dwarning dwarning() { :; }; fi if (($stdloglvl < 2)) && (($kmsgloglvl < 2)) && (($fileloglvl < 2)) && (($sysloglvl < 2)); then unset derror derror() { :; }; fi if (($stdloglvl < 1)) && (($kmsgloglvl < 1)) && (($fileloglvl < 1)) && (($sysloglvl < 1)); then unset dfatal dfatal() { :; }; fi [ -n "$errmsg" ] && derror "$errmsg" return $ret } ## @brief Converts numeric logging level to the first letter of level name. # # @param lvl Numeric logging level in range from 1 to 6. # @retval 1 if @a lvl is out of range. # @retval 0 if @a lvl is correct. # @result Echoes first letter of level name. _lvl2char() { case "$1" in 1) echo F;; 2) echo E;; 3) echo W;; 4) echo I;; 5) echo D;; 6) echo T;; *) return 1;; esac } ## @brief Converts numeric level to logger priority defined by POSIX.2. # # @param lvl Numeric logging level in range from 1 to 6. # @retval 1 if @a lvl is out of range. # @retval 0 if @a lvl is correct. # @result Echoes logger priority. _lvl2syspri() { printf $syslogfacility. case "$1" in 1) echo crit;; 2) echo error;; 3) echo warning;; 4) echo info;; 5) echo debug;; 6) echo debug;; *) return 1;; esac } ## @brief Converts dracut-logger numeric level to syslog log level # # @param lvl Numeric logging level in range from 1 to 6. # @retval 1 if @a lvl is out of range. # @retval 0 if @a lvl is correct. # @result Echoes kernel console numeric log level # # Conversion is done as follows: # # # FATAL(1) -> LOG_EMERG (0) # none -> LOG_ALERT (1) # none -> LOG_CRIT (2) # ERROR(2) -> LOG_ERR (3) # WARN(3) -> LOG_WARNING (4) # none -> LOG_NOTICE (5) # INFO(4) -> LOG_INFO (6) # DEBUG(5) -> LOG_DEBUG (7) # TRACE(6) / # # # @see /usr/include/sys/syslog.h _dlvl2syslvl() { local lvl case "$1" in 1) lvl=0;; 2) lvl=3;; 3) lvl=4;; 4) lvl=6;; 5) lvl=7;; 6) lvl=7;; *) return 1;; esac [ "$syslogfacility" = user ] && echo $((8+$lvl)) || echo $((24+$lvl)) } ## @brief Prints to stderr and/or writes to file, to syslog and/or /dev/kmsg # given message with given level (priority). # # @param lvl Numeric logging level. # @param msg Message. # @retval 0 It's always returned, even if logging failed. # # @note This function is not supposed to be called manually. Please use # dtrace(), ddebug(), or others instead which wrap this one. # # This is core logging function which logs given message to standard error, file # and/or syslog (with POSIX shell command logger) and/or to /dev/kmsg. # The format is following: # # X: some message # # where @c X is the first letter of logging level. See module description for # details on that. # # Message to syslog is sent with tag @c dracut. Priorities are mapped as # following: # - @c FATAL to @c crit # - @c ERROR to @c error # - @c WARN to @c warning # - @c INFO to @c info # - @c DEBUG and @c TRACE both to @c debug _do_dlog() { local lvl="$1"; shift local lvlc=$(_lvl2char "$lvl") || return 0 local msg="$*" local lmsg="$lvlc: $*" (( $lvl <= $stdloglvl )) && echo "$msg" >&2 if (( $lvl <= $sysloglvl )); then if [[ "$_dlogfd" ]]; then printf -- "<%s>%s\n" "$(($(_dlvl2syslvl $lvl) & 7))" "$msg" >&$_dlogfd else logger -t "dracut[$$]" -p $(_lvl2syspri $lvl) -- "$msg" fi fi if (( $lvl <= $fileloglvl )) && [[ -w "$logfile" ]] && [[ -f "$logfile" ]]; then echo "$lmsg" >>"$logfile" fi (( $lvl <= $kmsgloglvl )) && \ echo "<$(_dlvl2syslvl $lvl)>dracut[$$] $msg" >/dev/kmsg } ## @brief Internal helper function for _do_dlog() # # @param lvl Numeric logging level. # @param msg Message. # @retval 0 It's always returned, even if logging failed. # # @note This function is not supposed to be called manually. Please use # dtrace(), ddebug(), or others instead which wrap this one. # # This function calls _do_dlog() either with parameter msg, or if # none is given, it will read standard input and will use every line as # a message. # # This enables: # dwarn "This is a warning" # echo "This is a warning" | dwarn dlog() { [ -z "$maxloglvl" ] && return 0 (( $1 <= $maxloglvl )) || return 0 if (( $# > 1 )); then _do_dlog "$@" else while read line || [ -n "$line" ]; do _do_dlog "$1" "$line" done fi } ## @brief Logs message at TRACE level (6) # # @param msg Message. # @retval 0 It's always returned, even if logging failed. dtrace() { set +x dlog 6 "$@" [ -n "$debug" ] && set -x || : } ## @brief Logs message at DEBUG level (5) # # @param msg Message. # @retval 0 It's always returned, even if logging failed. ddebug() { set +x dlog 5 "$@" [ -n "$debug" ] && set -x || : } ## @brief Logs message at INFO level (4) # # @param msg Message. # @retval 0 It's always returned, even if logging failed. dinfo() { set +x dlog 4 "$@" [ -n "$debug" ] && set -x || : } ## @brief Logs message at WARN level (3) # # @param msg Message. # @retval 0 It's always returned, even if logging failed. dwarn() { set +x dlog 3 "$@" [ -n "$debug" ] && set -x || : } ## @brief It's an alias to dwarn() function. # # @param msg Message. # @retval 0 It's always returned, even if logging failed. dwarning() { set +x dwarn "$@" [ -n "$debug" ] && set -x || : } ## @brief Logs message at ERROR level (2) # # @param msg Message. # @retval 0 It's always returned, even if logging failed. derror() { set +x dlog 2 "$@" [ -n "$debug" ] && set -x || : } ## @brief Logs message at FATAL level (1) # # @param msg Message. # @retval 0 It's always returned, even if logging failed. dfatal() { set +x dlog 1 "$@" [ -n "$debug" ] && set -x || : } modules.d/91crypt-gpg/crypt-gpg-lib.sh000075500000002064150252660330013547 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=4 sw=4 sts=0 et filetype=sh command -v ask_for_password >/dev/null || . /lib/dracut-crypt-lib.sh # gpg_decrypt mnt_point keypath keydev device # # Decrypts encrypted symmetrically key to standard output. # # mnt_point - mount point where is already mounted # keypath - GPG encrypted key path relative to # keydev - device on which key resides; only to display in prompt # device - device to be opened by cryptsetup; only to display in prompt gpg_decrypt() { local mntp="$1" local keypath="$2" local keydev="$3" local device="$4" local gpghome=/tmp/gnupg local opts="--homedir $gpghome --no-mdc-warning --skip-verify --quiet" opts="$opts --logger-file /dev/null --batch --no-tty --passphrase-fd 0" mkdir -m 0700 -p "$gpghome" ask_for_password \ --cmd "gpg $opts --decrypt $mntp/$keypath" \ --prompt "Password ($keypath on $keydev for $device)" \ --tries 3 --tty-echo-off rm -rf -- "$gpghome" } modules.d/91crypt-gpg/module-setup.sh000075500000000534150252660330013512 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # GPG support is optional check() { require_binaries gpg || return 1 return 255 } depends() { echo crypt } install() { inst_multiple gpg inst "$moddir/crypt-gpg-lib.sh" "/lib/dracut-crypt-gpg-lib.sh" } modules.d/90livenet/parse-livenet.sh000075500000001716150252660330013401 0ustar00#!/bin/sh # live net images - just like live images, but specified like: # root=live:[url-to-backing-file] [ -z "$root" ] && root=$(getarg root=) . /lib/url-lib.sh # live updates updates=$(getarg live.updates=) if [ -n "$updates" ]; then # make sure network comes up even if we're doing a local live device if [ -z "$netroot" ]; then echo > /tmp/net.ifaces fi echo "$updates" > /tmp/liveupdates.info echo '[ -e /tmp/liveupdates.done ]' > \ $hookdir/initqueue/finished/liveupdates.sh fi str_starts "$root" "live:" && liveurl="$root" str_starts "$liveurl" "live:" || return liveurl="${liveurl#live:}" # setting netroot to "livenet:..." makes "livenetroot" get run after ifup if get_url_handler "$liveurl" >/dev/null; then info "livenet: root image at $liveurl" netroot="livenet:$liveurl" root="livenet" # quiet complaints from init rootok=1 wait_for_dev -n /dev/root else info "livenet: no url handler for $liveurl" fi modules.d/90livenet/module-setup.sh000075500000000554150252660330013245 0ustar00#!/bin/bash # module-setup.sh for livenet check() { return 255 } depends() { echo network url-lib dmsquash-live img-lib return 0 } install() { inst_hook cmdline 29 "$moddir/parse-livenet.sh" inst_hook initqueue/online 95 "$moddir/fetch-liveupdate.sh" inst_script "$moddir/livenetroot.sh" "/sbin/livenetroot" dracut_need_initqueue } modules.d/90livenet/livenetroot.sh000075500000001240150252660330013165 0ustar00#!/bin/sh # livenetroot - fetch a live image from the network and run it type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh . /lib/url-lib.sh PATH=/usr/sbin:/usr/bin:/sbin:/bin [ -e /tmp/livenet.downloaded ] && exit 0 # args get passed from 40network/netroot netroot="$2" liveurl="${netroot#livenet:}" info "fetching $liveurl" imgfile=$(fetch_url "$liveurl") if [ $? != 0 ]; then warn "failed to download live image: error $?" exit 1 fi > /tmp/livenet.downloaded # TODO: couldn't dmsquash-live-root handle this? if [ ${imgfile##*.} = "iso" ]; then root=$(losetup -f) losetup $root $imgfile else root=$imgfile fi exec /sbin/dmsquash-live-root $root modules.d/90livenet/fetch-liveupdate.sh000075500000001531150252660330014047 0ustar00#!/bin/bash # fetch-liveupdate - fetch an update image for dmsquash-live media. # this gets called by the "initqueue/online" hook for each network interface # that comes online. # no updates requested? we're not needed. [ -e /tmp/liveupdates.info ] || return 0 command -v getarg >/dev/null || . /lib/dracut-lib.sh command -v fetch_url >/dev/null || . /lib/url-lib.sh command -v unpack_img >/dev/null || . /lib/img-lib.sh read url < /tmp/liveupdates.info info "fetching live updates from $url" fetch_url "$url" /tmp/updates.img if [ $? != 0 ]; then warn "failed to fetch update image!" warn "url: $url" return 1 fi unpack_img /tmp/updates.img /updates.tmp.$$ if [ $? != 0 ]; then warn "failed to unpack update image!" warn "url: $url" return 1 fi copytree /updates.tmp.$$ /updates mv /tmp/liveupdates.info /tmp/liveupdates.done modules.d/95iscsi/cleanup-iscsi.sh000075500000000306150252660330013025 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh [ -z "${DRACUT_SYSTEMD}" ] && [ -e /sys/module/bnx2i ] && killproc iscsiuio modules.d/95iscsi/module-setup.sh000075500000012756150252660330012725 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { local _rootdev # If our prerequisites are not met, fail anyways. require_binaries iscsistart hostname iscsi-iname || return 1 # If hostonly was requested, fail the check if we are not actually # booting from root. is_iscsi() { local _dev=$1 [[ -L "/sys/dev/block/$_dev" ]] || return cd "$(readlink -f "/sys/dev/block/$_dev")" until [[ -d sys || -d iscsi_session ]]; do cd .. done [[ -d iscsi_session ]] } [[ $hostonly ]] || [[ $mount_needs ]] && { pushd . >/dev/null for_each_host_dev_and_slaves is_iscsi local _is_iscsi=$? popd >/dev/null [[ $_is_iscsi == 0 ]] || return 255 } return 0 } get_ibft_mod() { local ibft_mac=$1 local iface_mac iface_mod # Return the iSCSI offload module for a given MAC address for iface_desc in $(iscsiadm -m iface | cut -f 2 -d ' '); do iface_mod=${iface_desc%%,*} iface_mac=${iface_desc#*,} iface_mac=${iface_mac%%,*} if [ "$ibft_mac" = "$iface_mac" ] ; then echo $iface_mod return 0 fi done } install_ibft() { # When iBFT / iscsi_boot is detected: # - Use 'ip=ibft' to set up iBFT network interface # Note: bnx2i is using a different MAC address of iSCSI offloading # so the 'ip=ibft' parameter must not be set # - specify firmware booting cmdline parameter for d in /sys/firmware/* ; do if [ -d ${d}/ethernet0 ] ; then read ibft_mac < ${d}/ethernet0/mac ibft_mod=$(get_ibft_mod $ibft_mac) fi if [ -z "$ibft_mod" ] && [ -d ${d}/ethernet1 ] ; then read ibft_mac < ${d}/ethernet1/mac ibft_mod=$(get_ibft_mod $ibft_mac) fi if [ -d ${d}/initiator ] ; then if [ ${d##*/} = "ibft" ] && [ "$ibft_mod" != "bnx2i" ] ; then echo -n "ip=ibft " fi echo -n "rd.iscsi.firmware=1" fi done } depends() { echo network rootfs-block } installkernel() { local _arch=$(uname -m) instmods bnx2i qla4xxx cxgb3i cxgb4i be2iscsi hostonly="" instmods iscsi_tcp iscsi_ibft crc32c iscsi_boot_sysfs iscsi_module_filter() { local _funcs='iscsi_register_transport' # subfunctions inherit following FDs local _merge=8 _side2=9 function bmf1() { local _f while read _f; do case "$_f" in *.ko) [[ $(< $_f) =~ $_funcs ]] && echo "$_f" ;; *.ko.gz) [[ $(gzip -dc <$_f) =~ $_funcs ]] && echo "$_f" ;; *.ko.xz) [[ $(xz -dc <$_f) =~ $_funcs ]] && echo "$_f" ;; esac done return 0 } function rotor() { local _f1 _f2 while read _f1; do echo "$_f1" if read _f2; then echo "$_f2" 1>&${_side2} fi done | bmf1 1>&${_merge} return 0 } # Use two parallel streams to filter alternating modules. set +x eval "( ( rotor ) ${_side2}>&1 | bmf1 ) ${_merge}>&1" [[ $debug ]] && set -x return 0 } { find_kernel_modules_by_path drivers/scsi; if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then find_kernel_modules_by_path drivers/s390/scsi; fi;} \ | iscsi_module_filter | instmods } cmdline() { install_ibft } # called by dracut install() { inst_multiple umount iscsistart hostname iscsi-iname inst_multiple -o iscsiuio inst_libdir_file 'libgcc_s.so*' # Detect iBFT and perform mandatory steps if [[ $hostonly_cmdline == "yes" ]] ; then local _ibftconf=$(install_ibft) [[ $_ibftconf ]] && printf "%s\n" "$_ibftconf" >> "${initdir}/etc/cmdline.d/95iscsi.conf" fi inst_hook cmdline 90 "$moddir/parse-iscsiroot.sh" inst_hook cleanup 90 "$moddir/cleanup-iscsi.sh" inst "$moddir/iscsiroot.sh" "/sbin/iscsiroot" if ! dracut_module_included "systemd"; then inst "$moddir/mount-lun.sh" "/bin/mount-lun.sh" else inst_multiple -o \ $systemdsystemunitdir/iscsi.service \ $systemdsystemunitdir/iscsid.service \ $systemdsystemunitdir/iscsid.socket \ $systemdsystemunitdir/iscsiuio.service \ $systemdsystemunitdir/iscsiuio.socket \ iscsiadm iscsid mkdir -p "${initdir}/$systemdsystemunitdir/sockets.target.wants" for i in \ iscsiuio.socket \ ; do ln_r "$systemdsystemunitdir/${i}" "$systemdsystemunitdir/sockets.target.wants/${i}" done mkdir -p "${initdir}/$systemdsystemunitdir/basic.target.wants" for i in \ iscsid.service \ ; do ln_r "$systemdsystemunitdir/${i}" "$systemdsystemunitdir/basic.target.wants/${i}" done # Make sure iscsid is started after dracut-cmdline and ready for the initqueue mkdir -p "${initdir}/$systemdsystemunitdir/iscsid.service.d" ( echo "[Unit]" echo "After=dracut-cmdline.service" echo "Before=dracut-initqueue.service" ) > "${initdir}/$systemdsystemunitdir/iscsid.service.d/dracut.conf" fi inst_dir /var/lib/iscsi dracut_need_initqueue } modules.d/95iscsi/parse-iscsiroot.sh000075500000012306150252660330013417 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # Preferred format: # root=iscsi:[]:[]:[]:[]: # [root=*] netroot=iscsi:[]:[]:[]:[]: # # Legacy formats: # [net]root=[iscsi] iscsiroot=[]:[]:[]:[]: # [net]root=[iscsi] iscsi_firmware # # root= takes precedence over netroot= if root=iscsi[...] # # This script is sourced, so root should be set. But let's be paranoid [ -z "$root" ] && root=$(getarg root=) if [ -z "$netroot" ]; then for nroot in $(getargs netroot=); do [ "${nroot%%:*}" = "iscsi" ] && break done if [ "${nroot%%:*}" = "iscsi" ]; then netroot="$nroot" else for nroot in $(getargs netroot=); do [ "${nroot%%:*}" = "dhcp" ] && break done netroot="$nroot" fi fi [ -z "$iscsiroot" ] && iscsiroot=$(getarg iscsiroot=) [ -z "$iscsi_firmware" ] && getargbool 0 rd.iscsi.firmware -y iscsi_firmware && iscsi_firmware="1" [ -n "$iscsiroot" ] && [ -n "$iscsi_firmware" ] && die "Mixing iscsiroot and iscsi_firmware is dangerous" type write_fs_tab >/dev/null 2>&1 || . /lib/fs-lib.sh # Root takes precedence over netroot if [ "${root%%:*}" = "iscsi" ] ; then if [ -n "$netroot" ] ; then echo "Warning: root takes precedence over netroot. Ignoring netroot" fi netroot=$root # if root is not specified try to mount the whole iSCSI LUN printf 'ENV{DEVTYPE}!="partition", SYMLINK=="disk/by-path/*-iscsi-*-*", SYMLINK+="root"\n' >> /etc/udev/rules.d/99-iscsi-root.rules root=/dev/root write_fs_tab /dev/root fi # If it's not empty or iscsi we don't continue for nroot in $(getargs netroot); do [ "${nroot%%:*}" = "iscsi" ] || continue netroot="$nroot" break done if [ -n "$iscsiroot" ] ; then [ -z "$netroot" ] && netroot=$root # @deprecated echo "Warning: Argument iscsiroot is deprecated and might be removed in a future" echo "release. See 'man dracut.kernel' for more information." # Accept iscsiroot argument? [ -z "$netroot" ] || [ "$netroot" = "iscsi" ] || \ die "Argument iscsiroot only accepted for empty root= or [net]root=iscsi" # Override root with iscsiroot content? [ -z "$netroot" ] || [ "$netroot" = "iscsi" ] && netroot=iscsi:$iscsiroot fi # iscsi_firmware does not need argument checking if [ -n "$iscsi_firmware" ]; then if [ "$root" != "dhcp" ] && [ "$netroot" != "dhcp" ]; then [ -z "$netroot" ] && netroot=iscsi: fi modprobe -b -q iscsi_boot_sysfs 2>/dev/null modprobe -b -q iscsi_ibft # if no ip= is given, but firmware echo "[ -f '/tmp/iscsistarted-firmware' ]" > $hookdir/initqueue/finished/iscsi_started.sh initqueue --unique --online /sbin/iscsiroot online "iscsi:" "$NEWROOT" initqueue --unique --onetime --timeout /sbin/iscsiroot timeout "iscsi:" "$NEWROOT" initqueue --unique --onetime --settled /sbin/iscsiroot online "iscsi:" "'$NEWROOT'" fi if [ -z "$netroot" ] || ! [ "${netroot%%:*}" = "iscsi" ]; then return 1 fi initqueue --unique --onetime --timeout /sbin/iscsiroot timeout "$netroot" "$NEWROOT" initqueue --onetime modprobe --all -b -q qla4xxx cxgb3i cxgb4i bnx2i be2iscsi # ISCSI actually supported? if ! [ -e /sys/module/iscsi_tcp ]; then modprobe -b -q iscsi_tcp || die "iscsiroot requested but kernel/initrd does not support iscsi" fi if [ -n "$netroot" ] && [ "$root" != "/dev/root" ] && [ "$root" != "dhcp" ]; then if ! getargbool 1 rd.neednet >/dev/null || ! getarg "ip="; then initqueue --unique --onetime --settled /sbin/iscsiroot dummy "'$netroot'" "'$NEWROOT'" fi fi if arg=$(getarg rd.iscsi.initiator -d iscsi_initiator=) && [ -n "$arg" ] && ! [ -f /run/initiatorname.iscsi ] ; then iscsi_initiator=$arg echo "InitiatorName=$iscsi_initiator" > /run/initiatorname.iscsi ln -fs /run/initiatorname.iscsi /dev/.initiatorname.iscsi if ! [ -e /etc/iscsi/initiatorname.iscsi ]; then mkdir -p /etc/iscsi ln -fs /run/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi fi fi # If not given on the cmdline and initiator-name available via iBFT if [ -z $iscsi_initiator ] && [ -f /sys/firmware/ibft/initiator/initiator-name ] && ! [ -f /tmp/iscsi_set_initiator ]; then iscsi_initiator=$(while read line || [ -n "$line" ]; do echo $line;done < /sys/firmware/ibft/initiator/initiator-name) if [ -n "$iscsi_initiator" ]; then echo "InitiatorName=$iscsi_initiator" > /run/initiatorname.iscsi rm -f /etc/iscsi/initiatorname.iscsi mkdir -p /etc/iscsi ln -fs /run/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi > /tmp/iscsi_set_initiator systemctl try-restart iscsid && sleep 1 fi fi for nroot in $(getargs netroot); do [ "${nroot%%:*}" = "iscsi" ] || continue type parse_iscsi_root >/dev/null 2>&1 || . /lib/net-lib.sh parse_iscsi_root "$nroot" || return 1 netroot_enc=$(str_replace "$nroot" '/' '\2f') echo "[ -f '/tmp/iscsistarted-$netroot_enc' ]" > $hookdir/initqueue/finished/iscsi_started.sh done # Done, all good! rootok=1 # Shut up init error check [ -z "$root" ] && root="iscsi" modules.d/95iscsi/mount-lun.sh000075500000000672150252660330012232 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh if [ -z $iscsi_lun ]; then iscsi_lun=0 fi NEWROOT=${NEWROOT:-"/sysroot"} for disk in /dev/disk/by-path/*-iscsi-*-$iscsi_lun; do if mount -t ${fstype:-auto} -o "$rflags" $disk $NEWROOT; then if [ ! -d $NEWROOT/proc ]; then umount $disk continue fi break fi done modules.d/95iscsi/iscsiroot.sh000075500000023511150252660330012307 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # This implementation is incomplete: Discovery mode is not implemented and # the argument handling doesn't follow currently agreed formats. This is mainly # because rfc4173 does not say anything about iscsi_initiator but open-iscsi's # iscsistart needs this. # type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type parse_iscsi_root >/dev/null 2>&1 || . /lib/net-lib.sh type write_fs_tab >/dev/null 2>&1 || . /lib/fs-lib.sh PATH=/usr/sbin:/usr/bin:/sbin:/bin # Huh? Empty $1? [ -z "$1" ] && exit 1 # Huh? Empty $2? [ -z "$2" ] && exit 1 # Huh? Empty $3? This isn't really necessary, since NEWROOT isn't # used here. But let's be consistent [ -z "$3" ] && exit 1 # root is in the form root=iscsi:[]:[]:[]:[]: netif="$1" iroot="$2" # If it's not iscsi we don't continue [ "${iroot%%:*}" = "iscsi" ] || exit 1 iroot=${iroot#iscsi} iroot=${iroot#:} # XXX modprobe crc32c should go in the cmdline parser, but I haven't yet # figured out a way how to check whether this is built-in or not modprobe crc32c 2>/dev/null if [ -z "${DRACUT_SYSTEMD}" ] && [ -e /sys/module/bnx2i ] && ! [ -e /tmp/iscsiuio-started ]; then iscsiuio > /tmp/iscsiuio-started fi handle_firmware() { if ! iscsistart -f; then warn "iscistart: Could not get list of targets from firmware. Skipping." echo 'skipped' > "/tmp/iscsistarted-firmware" return 0 fi for p in $(getargs rd.iscsi.param -d iscsi_param); do iscsi_param="$iscsi_param --param $p" done if ! iscsistart -b $iscsi_param; then warn "'iscsistart -b $iscsi_param' failed with return code $?" fi echo 'started' > "/tmp/iscsistarted-iscsi:" echo 'started' > "/tmp/iscsistarted-firmware" need_shutdown return 0 } handle_netroot() { local iscsi_initiator iscsi_target_name iscsi_target_ip iscsi_target_port local iscsi_target_group iscsi_protocol iscsirw iscsi_lun local iscsi_username iscsi_password local iscsi_in_username iscsi_in_password local iscsi_iface_name iscsi_netdev_name local iscsi_param local p # override conf settings by command line options arg=$(getargs rd.iscsi.initiator -d iscsi_initiator=) [ -n "$arg" ] && iscsi_initiator="$arg" arg=$(getargs rd.iscsi.target.name -d iscsi_target_name=) [ -n "$arg" ] && iscsi_target_name="$arg" arg=$(getargs rd.iscsi.target.ip -d iscsi_target_ip) [ -n "$arg" ] && iscsi_target_ip="$arg" arg=$(getargs rd.iscsi.target.port -d iscsi_target_port=) [ -n "$arg" ] && iscsi_target_port="$arg" arg=$(getargs rd.iscsi.target.group -d iscsi_target_group=) [ -n "$arg" ] && iscsi_target_group="$arg" arg=$(getargs rd.iscsi.username -d iscsi_username=) [ -n "$arg" ] && iscsi_username="$arg" arg=$(getargs rd.iscsi.password -d iscsi_password) [ -n "$arg" ] && iscsi_password="$arg" arg=$(getargs rd.iscsi.in.username -d iscsi_in_username=) [ -n "$arg" ] && iscsi_in_username="$arg" arg=$(getargs rd.iscsi.in.password -d iscsi_in_password=) [ -n "$arg" ] && iscsi_in_password="$arg" for p in $(getargs rd.iscsi.param -d iscsi_param); do iscsi_param="$iscsi_param --param $p" done parse_iscsi_root "$1" || return 1 # Bail out early, if there is no route to the destination if is_ip "$iscsi_target_ip" && [ "$netif" != "timeout" ] && ! all_ifaces_setup && getargbool 1 rd.iscsi.testroute; then ip route get "$iscsi_target_ip" >/dev/null 2>&1 || return 0 fi # XXX is this needed? getarg ro && iscsirw=ro getarg rw && iscsirw=rw fsopts="${fsopts:+$fsopts,}${iscsirw}" if [ -z "$iscsi_initiator" ] && [ -f /sys/firmware/ibft/initiator/initiator-name ] && ! [ -f /tmp/iscsi_set_initiator ]; then iscsi_initiator=$(while read line || [ -n "$line" ]; do echo $line;done < /sys/firmware/ibft/initiator/initiator-name) echo "InitiatorName=$iscsi_initiator" > /run/initiatorname.iscsi rm -f /etc/iscsi/initiatorname.iscsi mkdir -p /etc/iscsi ln -fs /run/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi systemctl restart iscsid sleep 1 > /tmp/iscsi_set_initiator fi if [ -z "$iscsi_initiator" ]; then [ -f /run/initiatorname.iscsi ] && . /run/initiatorname.iscsi [ -f /etc/initiatorname.iscsi ] && . /etc/initiatorname.iscsi [ -f /etc/iscsi/initiatorname.iscsi ] && . /etc/iscsi/initiatorname.iscsi iscsi_initiator=$InitiatorName fi if [ -z "$iscsi_initiator" ]; then iscsi_initiator=$(iscsi-iname) echo "InitiatorName=$iscsi_initiator" > /run/initiatorname.iscsi rm -f /etc/iscsi/initiatorname.iscsi mkdir -p /etc/iscsi ln -fs /run/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi systemctl restart iscsid > /tmp/iscsi_set_initiator # FIXME: iscsid is not yet ready, when the service is :-/ sleep 1 fi if [ -z $iscsi_target_port ]; then iscsi_target_port=3260 fi if [ -z $iscsi_target_group ]; then iscsi_target_group=1 fi if [ -z $iscsi_lun ]; then iscsi_lun=0 fi echo "InitiatorName=$iscsi_initiator" > /run/initiatorname.iscsi ln -fs /run/initiatorname.iscsi /dev/.initiatorname.iscsi if ! [ -e /etc/iscsi/initiatorname.iscsi ]; then mkdir -p /etc/iscsi ln -fs /run/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi fi # FIXME $iscsi_protocol?? if [ "$root" = "dhcp" ] || [ "$netroot" = "dhcp" ]; then # if root is not specified try to mount the whole iSCSI LUN printf 'SYMLINK=="disk/by-path/*-iscsi-*-%s", SYMLINK+="root"\n' "$iscsi_lun" >> /etc/udev/rules.d/99-iscsi-root.rules udevadm control --reload write_fs_tab /dev/root wait_for_dev -n /dev/root # install mount script [ -z "$DRACUT_SYSTEMD" ] && \ echo "iscsi_lun=$iscsi_lun . /bin/mount-lun.sh " > $hookdir/mount/01-$$-iscsi.sh fi if [ -n "$DRACUT_SYSTEMD" ] && command -v systemd-run >/dev/null 2>&1; then netroot_enc=$(systemd-escape "iscsistart_${1}") status=$(systemctl is-active "$netroot_enc" 2>/dev/null) is_active=$? if [ $is_active -ne 0 ]; then if [ "$status" != "activating" ] && ! systemctl is-failed "$netroot_enc" >/dev/null 2>&1; then systemd-run --service-type=oneshot --remain-after-exit --quiet \ --description="Login iSCSI Target $iscsi_target_name" \ -p 'DefaultDependencies=no' \ --unit="$netroot_enc" -- \ $(command -v iscsistart) \ -i "$iscsi_initiator" -t "$iscsi_target_name" \ -g "$iscsi_target_group" -a "$iscsi_target_ip" \ -p "$iscsi_target_port" \ ${iscsi_username:+-u "$iscsi_username"} \ ${iscsi_password:+-w "$iscsi_password"} \ ${iscsi_in_username:+-U "$iscsi_in_username"} \ ${iscsi_in_password:+-W "$iscsi_in_password"} \ ${iscsi_iface_name:+--param "iface.iscsi_ifacename=$iscsi_iface_name"} \ ${iscsi_netdev_name:+--param "iface.net_ifacename=$iscsi_netdev_name"} \ ${iscsi_param} >/dev/null 2>&1 \ && { > $hookdir/initqueue/work ; } while : ; do status=$(systemctl is-active "$netroot_enc" 2>/dev/null) [ "$status" != "activating" ] && break sleep 1 done else systemctl --no-block restart "$netroot_enc" >/dev/null 2>&1 \ && { > $hookdir/initqueue/work ; } fi fi else iscsistart -i "$iscsi_initiator" -t "$iscsi_target_name" \ -g "$iscsi_target_group" -a "$iscsi_target_ip" \ -p "$iscsi_target_port" \ ${iscsi_username:+-u "$iscsi_username"} \ ${iscsi_password:+-w "$iscsi_password"} \ ${iscsi_in_username:+-U "$iscsi_in_username"} \ ${iscsi_in_password:+-W "$iscsi_in_password"} \ ${iscsi_iface_name:+--param "iface.iscsi_ifacename=$iscsi_iface_name"} \ ${iscsi_netdev_name:+--param "iface.net_ifacename=$iscsi_netdev_name"} \ ${iscsi_param} \ && { > $hookdir/initqueue/work ; } fi netroot_enc=$(str_replace "$1" '/' '\2f') echo 'started' > "/tmp/iscsistarted-iscsi:${netroot_enc}" return 0 } ret=0 if [ "$netif" != "timeout" ] && getargbool 1 rd.iscsi.waitnet; then all_ifaces_setup || exit 0 fi if [ "$netif" = "timeout" ] && all_ifaces_setup; then # s.th. went wrong and the timeout script hits # restart systemctl restart iscsid # damn iscsid is not ready after unit says it's ready sleep 2 fi if getargbool 0 rd.iscsi.firmware -d -y iscsi_firmware ; then if [ "$netif" = "timeout" ] || [ "$netif" = "online" ]; then handle_firmware ret=$? fi fi if ! [ "$netif" = "online" ]; then # loop over all netroot parameter if nroot=$(getarg netroot) && [ "$nroot" != "dhcp" ]; then for nroot in $(getargs netroot); do [ "${nroot%%:*}" = "iscsi" ] || continue nroot="${nroot##iscsi:}" if [ -n "$nroot" ]; then handle_netroot "$nroot" ret=$(($ret + $?)) fi done else if [ -n "$iroot" ]; then handle_netroot "$iroot" ret=$? fi fi fi need_shutdown # now we have a root filesystem somewhere in /dev/sd* # let the normal block handler handle root= exit $ret modules.d/95ssh-client/module-setup.sh000075500000003446150252660330013660 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # fixme: assume user is root check() { [[ $mount_needs ]] && return 1 # If our prerequisites are not met, fail. require_binaries ssh scp || return 1 if [[ $sshkey ]]; then [ ! -f $sshkey ] && { derror "ssh key: $sshkey is not found!" return 1 } fi return 255 } depends() { # We depend on network modules being loaded echo network } inst_sshenv() { if [ -d /root/.ssh ]; then inst_dir /root/.ssh chmod 700 ${initdir}/root/.ssh fi # Copy over ssh key and knowhosts if needed [[ $sshkey ]] && { inst_simple $sshkey [[ -f /root/.ssh/known_hosts ]] && inst_simple /root/.ssh/known_hosts [[ -f /etc/ssh/ssh_known_hosts ]] && inst_simple /etc/ssh/ssh_known_hosts } # Copy over root and system-wide ssh configs. [[ -f /root/.ssh/config ]] && inst_simple /root/.ssh/config if [[ -f /etc/ssh/ssh_config ]]; then inst_simple /etc/ssh/ssh_config sed -i -e 's/\(^[[:space:]]*\)ProxyCommand/\1# ProxyCommand/' ${initdir}/etc/ssh/ssh_config while read key val || [ -n "$key" ]; do if [[ $key == "GlobalKnownHostsFile" ]]; then inst_simple "$val" # Copy customized UserKnowHostsFile elif [[ $key == "UserKnownHostsFile" ]]; then # Make sure that ~/foo will be copied as /root/foo in kdump's initramfs if str_starts "$val" "~/"; then val="/root/${val#"~/"}" fi inst_simple "$val" fi done < /etc/ssh/ssh_config fi return 0 } install() { inst_multiple ssh scp inst_sshenv } modules.d/45url-lib/module-setup.sh000075500000002014150252660330013136 0ustar00#!/bin/bash # module-setup for url-lib check() { require_binaries curl || return 1 return 255 } depends() { echo network return 0 } install() { local _dir _crt _found _lib inst_simple "$moddir/url-lib.sh" "/lib/url-lib.sh" inst_multiple curl # also install libs for curl https inst_libdir_file "libnsspem.so*" inst_libdir_file "libnsssysinit.so*" inst_libdir_file "libsoftokn3.so*" inst_libdir_file "libsqlite3.so*" for _dir in $libdirs; do [[ -d $_dir ]] || continue for _lib in $_dir/libcurl.so.*; do [[ -e $_lib ]] || continue _crt=$(grep -F --binary-files=text -z .crt $_lib) [[ $_crt ]] || continue [[ $_crt == /*/* ]] || continue if ! inst "$_crt"; then dwarn "Couldn't install '$_crt' SSL CA cert bundle; HTTPS might not work." continue fi _found=1 done done [[ $_found ]] || dwarn "Couldn't find SSL CA cert bundle; HTTPS won't work." } modules.d/45url-lib/url-lib.sh000075500000007657150252660330012103 0ustar00#!/bin/sh # url-lib.sh - functions for handling URLs (file fetching etc.) # # Authors: # Will Woods type mkuniqdir >/dev/null 2>&1 || . /lib/dracut-lib.sh # fetch_url URL [OUTFILE] # fetch the given URL to a locally-visible location. # if OUTFILE is given, the URL will be fetched to that filename, # overwriting it if present. # If the URL is something mountable (e.g. nfs://) and no OUTFILE is given, # the server will be left mounted until pre-pivot. # the return values are as follows: # 0: success # 253: unknown error (file missing) # 254: unhandled URL scheme / protocol # 255: bad arguments / unparseable URLs # other: fetch command failure (whatever curl/mount/etc return) fetch_url() { local url="$1" outloc="$2" local handler="$(get_url_handler $url)" [ -n "$handler" ] || return 254 [ -n "$url" ] || return 255 "$handler" "$url" "$outloc" } # get_url_handler URL # returns the first HANDLERNAME corresponding to the URL's scheme get_url_handler() { local scheme="${1%%:*}" item="" for item in $url_handler_map; do [ "$scheme" = "${item%%:*}" ] && echo "${item#*:}" && return 0 done return 1 } # add_url_handler HANDLERNAME SCHEME [SCHEME...] # associate the named handler with the named scheme(s). add_url_handler() { local handler="$1"; shift local schemes="$@" scheme="" set -- for scheme in $schemes; do [ "$(get_url_handler $scheme)" = "$handler" ] && continue set -- "$@" "$scheme:$handler" done set -- $@ $url_handler_map # add new items to *front* of list url_handler_map="$@" } ### HTTP, HTTPS, FTP ################################################# export CURL_HOME="/run/initramfs/url-lib" mkdir -p $CURL_HOME curl_args="--globoff --location --retry 3 --fail --show-error" getargbool 0 rd.noverifyssl && curl_args="$curl_args --insecure" proxy=$(getarg proxy=) [ -n "$proxy" ] && curl_args="$curl_args --proxy $proxy" curl_fetch_url() { local url="$1" outloc="$2" echo "$url" > /proc/self/fd/0 if [ -n "$outloc" ]; then curl $curl_args --output - -- "$url" > "$outloc" || return $? else local outdir="$(mkuniqdir /tmp curl_fetch_url)" ( cd "$outdir"; curl $curl_args --remote-name "$url" || return $? ) outloc="$outdir/$(ls -A $outdir)" fi if ! [ -f "$outloc" ]; then warn "Downloading '$url' failed!" return 253 fi if [ -z "$2" ]; then echo "$outloc" ; fi } add_url_handler curl_fetch_url http https ftp set_http_header() { echo "header = \"$1: $2\"" >> $CURL_HOME/.curlrc } ### NFS ############################################################## [ -e /lib/nfs-lib.sh ] && . /lib/nfs-lib.sh nfs_already_mounted() { local server="$1" path="$2" localdir="" s="" p="" cat /proc/mounts | while read src mnt rest; do splitsep ":" "$src" s p if [ "$server" = "$s" ]; then if [ "$path" = "$p" ]; then echo $mnt elif str_starts "$path" "$p"; then echo $mnt/${path#$p/} fi fi done } nfs_fetch_url() { local url="$1" outloc="$2" nfs="" server="" path="" options="" nfs_to_var "$url" || return 255 local filepath="${path%/*}" filename="${path##*/}" mntdir="" # skip mount if server:/filepath is already mounted mntdir=$(nfs_already_mounted "$server" "$filepath") if [ -z "$mntdir" ]; then local mntdir="$(mkuniqdir /run nfs_mnt)" mount_nfs "$nfs:$server:$filepath${options:+:$options}" "$mntdir" # lazy unmount during pre-pivot hook inst_hook --hook pre-pivot --name 99url-lib-umount-nfs umount -l -- "$mntdir" fi if [ -z "$outloc" ]; then outloc="$mntdir/$filename" else cp -f -- "$mntdir/$filename" "$outloc" || return $? fi [ -f "$outloc" ] || return 253 if [ -z "$2" ]; then echo "$outloc" ; fi } command -v nfs_to_var >/dev/null && add_url_handler nfs_fetch_url nfs nfs4 modules.d/03modsign/module-setup.sh000075500000001426150252660330013230 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # Licensed under the GPLv2 # # Copyright 2013 Red Hat, Inc. # Peter Jones check() { require_binaries keyctl || return 1 # do not include module in hostonly mode, # if no keys are present if [[ $hostonly ]]; then x=$(echo /lib/modules/keys/*) [[ "${x}" = "/lib/modules/keys/*" ]] && return 255 fi return 0 } depends() { return 0 } install() { inst_dir /lib/modules/keys inst_binary /usr/bin/keyctl inst_hook pre-trigger 01 "$moddir/load-modsign-keys.sh" for x in /lib/modules/keys/* ; do [[ "${x}" = "/lib/modules/keys/*" ]] && break inst_simple "${x}" done } modules.d/03modsign/load-modsign-keys.sh000075500000000530150252660330014126 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # Licensed under the GPLv2 # # Copyright 2013 Red Hat, Inc. # Peter Jones for x in /lib/modules/keys/* ; do [ "${x}" = "/lib/modules/keys/*" ] && break keyctl padd asymmetric "" @s < ${x} done modules.d/99microcode_ctl-fw_dir_override/module-setup.sh000075500000010022150252660330017554 0ustar00#!/bin/bash # Hack in additional firmware directories for supported caveats. # # SPDX-License-Identifier: CC0-1.0 check() { return 0 } install() { local FW_DIR=/lib/firmware local DATA_DIR=/usr/share/microcode_ctl/ucode_with_caveats local CFG_DIR="/etc/microcode_ctl/ucode_with_caveats" local check_caveats=/usr/libexec/microcode_ctl/check_caveats local fw_path_para=$(< /sys/module/firmware_class/parameters/path) local verbose_opt local cc_out local path local ignored local do_skip_host_only local p verbose_opt= [ 4 -gt "$stdloglvl" ] || verbose_opt="-v" # HACK: we override external fw_dir variable in order to get # an additional ucode based on the kernel version. dinfo " microcode_ctl module: mangling fw_dir" [ -z "$fw_dir_l" ] || { dinfo " microcode_ctl: avoid touching fw_dir as" \ "it has been changed (fw_dir_l is '$fw_dir_l')" return 0 } # Reset fw_dir to avoid inclusion of kernel-version-specific directories # populated with microcode for the late load, only in case it is set # to the default value to avoid meddling with user-enforced changes. # The second variant has been introduced in dracut-057~5. [ \( "x$fw_dir" != \ "x/lib/firmware/updates /lib/firmware /lib/firmware/$kernel" \) -a \ \( "x$fw_dir" != \ "x${fw_path_para:+$fw_path_para }/lib/firmware/updates/$kernel /lib/firmware/updates /lib/firmware/$kernel /lib/firmware" \) ] || { fw_dir="/lib/firmware/updates /lib/firmware" dinfo " microcode_ctl: reset fw_dir to \"${fw_dir}\"" } fw_dir_add="" while read -d $'\n' -r i; do dinfo " microcode_ctl: processing data directory " \ "\"$DATA_DIR/$i\"..." if [ "x" != "x$hostonly" ]; then do_skip_host_only=0 local sho_overrides=" $CFG_DIR/skip-host-only-check $CFG_DIR/skip-host-only-check-$i $FW_DIR/$kernel/skip-host-only-check $FW_DIR/$kernel/skip-host-only-check-$i" for p in $(echo "$sho_overrides"); do [ -e "$p" ] || continue do_skip_host_only=1 dinfo " microcode_ctl: $i; skipping" \ "Host-Only check, since \"$p\" exists." break done else do_skip_host_only=1 fi match_model_opt="" [ 1 = "$do_skip_host_only" ] || match_model_opt="-m" if ! cc_out=$($check_caveats -e -k "$kernel" -c "$i" \ $verbose_opt $match_model_opt) then dinfo " microcode_ctl: kernel version \"$kernel\"" \ "failed early load check for \"$i\", skipping" continue fi path=$(printf "%s" "$cc_out" | sed -n 's/^paths //p') [ -n "$path" ] || { ignored=$(printf "%s" "$cc_out" | \ sed -n 's/^skip_cfgs //p') if [ -n "$ignored" ]; then dinfo " microcode_ctl: configuration" \ "\"$i\" is ignored" else dinfo " microcode_ctl: no microcode paths" \ "are associated with \"$i\", skipping" fi continue } dinfo " microcode_ctl: $i: caveats check for kernel" \ "version \"$kernel\" passed, adding" \ "\"$DATA_DIR/$i\" to fw_dir variable" if [ 0 -eq "$do_skip_host_only" ]; then fw_dir_add="$DATA_DIR/$i " else fw_dir_add="$DATA_DIR/$i $fw_dir_add" fi # The list of directories is reverse-sorted in order to preserve the # "last wins" policy in case of presence of multiple microcode # revisions. # # In case of hostonly == 0, all microcode revisions will be included, # but since the microcode search is done with the "first wins" policy # by the (early) microcode loading code, the correct microcode revision # still has to be picked. # # Note that dracut without patch [1] puts only the last directory # in the early cpio; we try to address this by putting only the last # matching caveat in the search path, but that workaround works only # for host-only mode; non-host-only mode early cpio generation is still # broken without that patch. # # [1] https://github.com/dracutdevs/dracut/commit/c44d2252bb4b done <<-EOF $(find "$DATA_DIR" -maxdepth 1 -mindepth 1 -type d -printf "%f\n" \ | LC_ALL=C sort) EOF fw_dir="${fw_dir_add}${fw_dir}" dinfo " microcode_ctl: final fw_dir: \"${fw_dir}\"" } modules.d/90dmraid/61-dmraid-imsm.rules000064400000001732150252660330013557 0ustar00# This file causes block devices with RAID (dmraid) signatures to # automatically cause dmraid_scan to be run. # See udev(8) for syntax SUBSYSTEM!="block", GOTO="dm_end" ACTION!="add|change", GOTO="dm_end" # Also don't process disks that are slated to be a multipath device ENV{DM_MULTIPATH_DEVICE_PATH}=="?*", GOTO="dm_end" ENV{ID_FS_TYPE}=="linux_raid_member", GOTO="dm_end" ENV{ID_FS_TYPE}!="*_raid_member", , GOTO="dm_end" ENV{ID_FS_TYPE}=="isw_raid_member", ENV{rd_NO_MDIMSM}!="?*", GOTO="dm_end" ENV{ID_FS_TYPE}=="ddf_raid_member", ENV{rd_NO_MDDDF}!="?*", GOTO="dm_end" ENV{rd_NO_DM}=="?*", GOTO="dm_end" ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="dm_end" PROGRAM=="/bin/sh -c 'for i in $sys/$devpath/holders/dm-[0-9]*; do [ -e $$i ] && exit 0; done; exit 1;' ", \ GOTO="dm_end" ENV{DEVTYPE}!="partition", \ RUN+="/sbin/partx -d --nr 1-1024 $env{DEVNAME}" RUN+="/sbin/initqueue --onetime --unique --settled /sbin/dmraid_scan $env{DEVNAME}" LABEL="dm_end" modules.d/90dmraid/module-setup.sh000075500000004106150252660330013034 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { local _rootdev # if we don't have dmraid installed on the host system, no point # in trying to support it in the initramfs. require_binaries dmraid || return 1 [[ $hostonly ]] || [[ $mount_needs ]] && { for dev in "${!host_fs_types[@]}"; do [[ "${host_fs_types[$dev]}" != *_raid_member ]] && continue DEVPATH=$(get_devpath_block "$dev") for holder in "$DEVPATH"/holders/*; do [[ -e "$holder" ]] || continue [[ -e "$holder/dm" ]] && return 0 break done done return 255 } return 0 } depends() { echo dm rootfs-block return 0 } cmdline() { local _activated declare -A _activated for dev in "${!host_fs_types[@]}"; do local holder DEVPATH DM_NAME majmin [[ "${host_fs_types[$dev]}" != *_raid_member ]] && continue DEVPATH=$(get_devpath_block "$dev") for holder in "$DEVPATH"/holders/*; do [[ -e "$holder" ]] || continue dev="/dev/${holder##*/}" DM_NAME="$(dmsetup info -c --noheadings -o name "$dev" 2>/dev/null)" [[ ${DM_NAME} ]] && break done [[ ${DM_NAME} ]] || continue if ! [[ ${_activated[${DM_NAME}]} ]]; then printf "%s" " rd.dm.uuid=${DM_NAME}" _activated["${DM_NAME}"]=1 fi done } install() { local _i if [[ $hostonly_cmdline == "yes" ]]; then cmdline >> "${initdir}/etc/cmdline.d/90dmraid.conf" echo >> "${initdir}/etc/cmdline.d/90dmraid.conf" fi inst_multiple dmraid inst_multiple -o kpartx inst $(command -v partx) /sbin/partx inst "$moddir/dmraid.sh" /sbin/dmraid_scan inst_rules 64-md-raid.rules inst_libdir_file "libdmraid-events*.so*" inst_rules "$moddir/61-dmraid-imsm.rules" #inst "$moddir/dmraid-cleanup.sh" /sbin/dmraid-cleanup inst_hook pre-trigger 30 "$moddir/parse-dm.sh" } modules.d/90dmraid/parse-dm.sh000075500000001647150252660330012130 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # nodmraid for anaconda / rc.sysinit compatibility if ! getargbool 1 rd.dm -d -n rd_NO_DM || getarg "rd.dm=0" -d nodmraid; then info "rd.dm=0: removing DM RAID activation" udevproperty rd_NO_DM=1 fi if ! command -v mdadm >/dev/null \ || ! getargbool 1 rd.md.imsm -d -n rd_NO_MDIMSM -n noiswmd \ || ! getargbool 1 rd.md -d -n rd_NO_MD; then info "rd.md.imsm=0: no MD RAID for imsm/isw raids" udevproperty rd_NO_MDIMSM=1 fi if ! command -v mdadm >/dev/null \ || ! getargbool 1 rd.md.ddf -n rd_NO_MDDDF -n noddfmd \ || ! getargbool 1 rd.md -d -n rd_NO_MD; then info "rd.md.ddf=0: no MD RAID for SNIA ddf raids" udevproperty rd_NO_MDDDF=1 fi DM_RAIDS=$(getargs rd.dm.uuid -d rd_DM_UUID=) if [ -z "$DM_RAIDS" ] && ! getargbool 0 rd.auto; then udevproperty rd_NO_DM=1 fi modules.d/90dmraid/dmraid.sh000075500000002603150252660330011651 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh dev="$1" devenc=$(str_replace "$1" '/' '\2f') [ -e /tmp/dmraid.$devenc ] && exit 0 >/tmp/dmraid.$devenc DM_RAIDS=$(getargs rd.dm.uuid -d rd_DM_UUID=) if [ -n "$DM_RAIDS" ] || getargbool 0 rd.auto; then DM_CLEANUP="no" # run dmraid if udev has settled info "Scanning for dmraid devices $DM_RAIDS" SETS=$(dmraid -c -s) if [ "$SETS" = "no raid disks" -o "$SETS" = "no raid sets" ]; then return fi info "Found dmraid sets:" echo $SETS|vinfo if [ -n "$DM_RAIDS" ]; then # only activate specified DM RAIDS for r in $DM_RAIDS; do for s in $SETS; do if [ "${s##$r}" != "$s" ]; then info "Activating $s" dmraid -ay -i -p --rm_partitions "$s" 2>&1 | vinfo [ -e "/dev/mapper/$s" ] && kpartx -a "/dev/mapper/$s" 2>&1 | vinfo udevsettle fi done done else # scan and activate all DM RAIDS for s in $SETS; do info "Activating $s" dmraid -ay -i -p --rm_partitions "$s" 2>&1 | vinfo [ -e "/dev/mapper/$s" ] && kpartx -a "/dev/mapper/$s" 2>&1 | vinfo done fi need_shutdown fi modules.d/99kdumpbase/module-setup.sh000075500000063432150252660330013567 0ustar00#!/bin/bash . $dracutfunctions . /lib/kdump/kdump-lib.sh if ! [[ -d "${initdir}/tmp" ]]; then mkdir -p "${initdir}/tmp" fi check() { [[ $debug ]] && set -x #kdumpctl sets this explicitly if [ -z "$IN_KDUMP" ] || [ ! -f /etc/kdump.conf ] then return 1 fi return 0 } depends() { local _dep="base shutdown" if [ -n "$( find /sys/devices -name drm )" ] || [ -d /sys/module/hyperv_fb ]; then _dep="$_dep drm" fi if is_generic_fence_kdump || is_pcs_fence_kdump; then _dep="$_dep network" fi echo $_dep return 0 } kdump_to_udev_name() { local dev="${1//\"/}" case "$dev" in UUID=*) dev=`blkid -U "${dev#UUID=}"` ;; LABEL=*) dev=`blkid -L "${dev#LABEL=}"` ;; esac echo $(get_persistent_dev "$dev") } kdump_is_bridge() { [ -d /sys/class/net/"$1"/bridge ] } kdump_is_bond() { [ -d /sys/class/net/"$1"/bonding ] } kdump_is_team() { [ -f /usr/bin/teamnl ] && teamnl $1 ports &> /dev/null } kdump_is_vlan() { [ -f /proc/net/vlan/"$1" ] } # $1: netdev name source_ifcfg_file() { local ifcfg_file ifcfg_file=$(get_ifcfg_filename $1) if [ -f "${ifcfg_file}" ]; then . ${ifcfg_file} else dwarning "The ifcfg file of $1 is not found!" fi } # $1: netdev name kdump_setup_dns() { local _nameserver _dns local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf source_ifcfg_file $1 [ -n "$DNS1" ] && echo "nameserver=$DNS1" > "$_dnsfile" [ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile" while read content; do _nameserver=$(echo $content | grep ^nameserver) [ -z "$_nameserver" ] && continue _dns=$(echo $_nameserver | cut -d' ' -f2) [ -z "$_dns" ] && continue if [ ! -f $_dnsfile ] || [ ! $(cat $_dnsfile | grep -q $_dns) ]; then echo "nameserver=$_dns" >> "$_dnsfile" fi done < "/etc/resolv.conf" } #$1: netdev name #$2: srcaddr #if it use static ip echo it, or echo null kdump_static_ip() { local _netdev="$1" _srcaddr="$2" _ipv6_flag local _netmask _gateway _ipaddr _target _nexthop _ipaddr=$(ip addr show dev $_netdev permanent | awk "/ $_srcaddr\/.* /{print \$2}") if is_ipv6_address $_srcaddr; then _ipv6_flag="-6" fi if [ -n "$_ipaddr" ]; then _gateway=$(ip $_ipv6_flag route list dev $_netdev | \ awk '/^default /{print $3}' | head -n 1) if [ "x" != "x"$_ipv6_flag ]; then # _ipaddr="2002::56ff:feb6:56d5/64", _netmask is the number after "/" _netmask=${_ipaddr#*\/} _srcaddr="[$_srcaddr]" _gateway="[$_gateway]" else _netmask=$(ipcalc -m $_ipaddr | cut -d'=' -f2) fi echo -n "${_srcaddr}::${_gateway}:${_netmask}::" fi /sbin/ip $_ipv6_flag route show | grep -v default | grep ".*via.* $_netdev " |\ while read _route; do _target=`echo $_route | cut -d ' ' -f1` _nexthop=`echo $_route | cut -d ' ' -f3` if [ "x" != "x"$_ipv6_flag ]; then _target="[$_target]" _nexthop="[$_nexthop]" fi echo "rd.route=$_target:$_nexthop:$_netdev" done >> ${initdir}/etc/cmdline.d/45route-static.conf } kdump_get_mac_addr() { cat /sys/class/net/$1/address } #Bonding or team master modifies the mac address #of its slaves, we should use perm address kdump_get_perm_addr() { local addr=$(ethtool -P $1 | sed -e 's/Permanent address: //') if [ -z "$addr" ] || [ "$addr" = "00:00:00:00:00:00" ] then derror "Can't get the permanent address of $1" else echo "$addr" fi } # Prefix kernel assigned names with "kdump-". EX: eth0 -> kdump-eth0 # Because kernel assigned names are not persistent between 1st and 2nd # kernel. We could probably end up with eth0 being eth1, eth0 being # eth1, and naming conflict happens. kdump_setup_ifname() { local _ifname # If ifname already has 'kdump-' prefix, we must be switching from # fadump to kdump. Skip prefixing 'kdump-' in this case as adding # another prefix may truncate the ifname. Since an ifname with # 'kdump-' is already persistent, this should be fine. if [[ $1 =~ eth* ]] && [[ ! $1 =~ ^kdump-* ]]; then _ifname="kdump-$1" else _ifname="$1" fi echo "$_ifname" } kdump_setup_bridge() { local _netdev=$1 local _brif _dev _mac _kdumpdev for _dev in `ls /sys/class/net/$_netdev/brif/`; do _kdumpdev=$_dev if kdump_is_bond "$_dev"; then kdump_setup_bond "$_dev" elif kdump_is_team "$_dev"; then kdump_setup_team "$_dev" elif kdump_is_vlan "$_dev"; then kdump_setup_vlan "$_dev" else _mac=$(kdump_get_mac_addr $_dev) _kdumpdev=$(kdump_setup_ifname $_dev) echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/41bridge.conf fi _brif+="$_kdumpdev," done echo " bridge=$_netdev:$(echo $_brif | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/41bridge.conf } kdump_setup_bond() { local _netdev=$1 local _dev _mac _slaves _kdumpdev for _dev in `cat /sys/class/net/$_netdev/bonding/slaves`; do _mac=$(kdump_get_perm_addr $_dev) _kdumpdev=$(kdump_setup_ifname $_dev) echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf _slaves+="$_kdumpdev," done echo -n " bond=$_netdev:$(echo $_slaves | sed 's/,$//')" >> ${initdir}/etc/cmdline.d/42bond.conf # Get bond options specified in ifcfg source_ifcfg_file $_netdev bondoptions=":$(echo $BONDING_OPTS | xargs echo | tr " " ",")" echo "$bondoptions" >> ${initdir}/etc/cmdline.d/42bond.conf } kdump_setup_team() { local _netdev=$1 local _dev _mac _slaves _kdumpdev for _dev in `teamnl $_netdev ports | awk -F':' '{print $2}'`; do _mac=$(kdump_get_perm_addr $_dev) _kdumpdev=$(kdump_setup_ifname $_dev) echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf _slaves+="$_kdumpdev," done echo " team=$_netdev:$(echo $_slaves | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/44team.conf #Buggy version teamdctl outputs to stderr! #Try to use the latest version of teamd. teamdctl "$_netdev" config dump > ${initdir}/tmp/$$-$_netdev.conf if [ $? -ne 0 ] then derror "teamdctl failed." exit 1 fi inst_dir /etc/teamd inst_simple ${initdir}/tmp/$$-$_netdev.conf "/etc/teamd/$_netdev.conf" rm -f ${initdir}/tmp/$$-$_netdev.conf } kdump_setup_vlan() { local _netdev=$1 local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")" local _netmac="$(kdump_get_mac_addr $_phydev)" local _kdumpdev #Just support vlan over bond, it is not easy #to support all other complex setup if kdump_is_bridge "$_phydev"; then derror "Vlan over bridge is not supported!" exit 1 elif kdump_is_team "$_phydev"; then derror "Vlan over team is not supported!" exit 1 elif kdump_is_bond "$_phydev"; then kdump_setup_bond "$_phydev" echo " vlan=$(kdump_setup_ifname $_netdev):$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf else _kdumpdev="$(kdump_setup_ifname $_phydev)" echo " vlan=$(kdump_setup_ifname $_netdev):$_kdumpdev ifname=$_kdumpdev:$_netmac" > ${initdir}/etc/cmdline.d/43vlan.conf fi } # setup s390 znet cmdline # $1: netdev name kdump_setup_znet() { local _options="" local _netdev=$1 source_ifcfg_file $_netdev for i in $OPTIONS; do _options=${_options},$i done echo rd.znet=${NETTYPE},${SUBCHANNELS}${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf } # Setup dracut to bringup a given network interface kdump_setup_netdev() { local _netdev=$1 _srcaddr=$2 local _static _proto _ip_conf _ip_opts _ifname_opts if [ "$(uname -m)" = "s390x" ]; then kdump_setup_znet $_netdev fi _netmac=$(kdump_get_mac_addr $_netdev) _static=$(kdump_static_ip $_netdev $_srcaddr) if [ -n "$_static" ]; then _proto=none elif is_ipv6_address $_srcaddr; then _proto=either6 else _proto=dhcp fi _ip_conf="${initdir}/etc/cmdline.d/40ip.conf" _ip_opts=" ip=${_static}$(kdump_setup_ifname $_netdev):${_proto}" # dracut doesn't allow duplicated configuration for same NIC, even they're exactly the same. # so we have to avoid adding duplicates # We should also check /proc/cmdline for existing ip=xx arg. # For example, iscsi boot will specify ip=xxx arg in cmdline. if [ ! -f $_ip_conf ] || ! grep -q $_ip_opts $_ip_conf &&\ ! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then echo "$_ip_opts" >> $_ip_conf fi if kdump_is_bridge "$_netdev"; then kdump_setup_bridge "$_netdev" elif kdump_is_bond "$_netdev"; then kdump_setup_bond "$_netdev" elif kdump_is_team "$_netdev"; then kdump_setup_team "$_netdev" elif kdump_is_vlan "$_netdev"; then kdump_setup_vlan "$_netdev" else _ifname_opts=" ifname=$(kdump_setup_ifname $_netdev):$(kdump_get_mac_addr $_netdev)" echo "$_ifname_opts" >> $_ip_conf fi kdump_setup_dns "$_netdev" } get_ip_route_field() { if `echo $1 | grep -q $2`; then echo ${1##*$2} | cut -d ' ' -f1 fi } #Function:kdump_install_net #$1: config values of net line in kdump.conf #$2: srcaddr of network device kdump_install_net() { local _server _netdev _srcaddr _route _serv_tmp local config_val="$1" _server=$(get_remote_host $config_val) if is_hostname $_server; then _serv_tmp=`getent ahosts $_server | grep -v : | head -n 1` if [ -z "$_serv_tmp" ]; then _serv_tmp=`getent ahosts $_server | head -n 1` fi _server=`echo $_serv_tmp | cut -d' ' -f1` fi _route=`/sbin/ip -o route get to $_server 2>&1` [ $? != 0 ] && echo "Bad kdump location: $config_val" && exit 1 #the field in the ip output changes if we go to another subnet _srcaddr=$(get_ip_route_field "$_route" "src") _netdev=$(get_ip_route_field "$_route" "dev") kdump_setup_netdev "${_netdev}" "${_srcaddr}" #save netdev used for kdump as cmdline # Whoever calling kdump_install_net() is setting up the default gateway, # ie. bootdev/kdumpnic. So don't override the setting if calling # kdump_install_net() for another time. For example, after setting eth0 as # the default gate way for network dump, eth1 in the fence kdump path will # call kdump_install_net again and we don't want eth1 to be the default # gateway. if [ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ] && [ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]; then echo "kdumpnic=$(kdump_setup_ifname $_netdev)" > ${initdir}/etc/cmdline.d/60kdumpnic.conf echo "bootdev=$(kdump_setup_ifname $_netdev)" > ${initdir}/etc/cmdline.d/70bootdev.conf fi } default_dump_target_install_conf() { local _target _fstype local _mntpoint _save_path is_user_configured_dump_target && return _save_path=$(get_option_value "path") [ -z "$_save_path" ] && _save_path=$DEFAULT_PATH # strip the duplicated "/" _save_path=$(echo $_save_path | tr -s /) _mntpoint=$(get_mntpoint_from_path $_save_path) _target=$(get_target_from_path $_save_path) if is_atomic && is_bind_mount $_mntpoint; then _save_path=${_save_path##"$_mntpoint"} # the real dump path in the 2nd kernel, if the mount point is bind mounted. _save_path=$(get_bind_mount_directory $_mntpoint)/$_save_path _mntpoint=$(get_mntpoint_from_target $_target) # the absolute path in the 1st kernel _save_path=$_mntpoint/$_save_path fi _fstype=$(get_fs_type_from_target $_target) if $(is_fs_type_nfs $_fstype); then kdump_install_net "$_target" _fstype="nfs" else _target=$(kdump_to_udev_name $_target) fi echo "$_fstype $_target" >> ${initdir}/tmp/$$-kdump.conf # strip the duplicated "/" _save_path=$(echo $_save_path | tr -s /) # don't touch the path under root mount if [ "$_mntpoint" != "/" ]; then _save_path=${_save_path##"$_mntpoint"} fi #erase the old path line, then insert the parsed path sed -i "/^path/d" ${initdir}/tmp/$$-kdump.conf echo "path $_save_path" >> ${initdir}/tmp/$$-kdump.conf } adjust_bind_mount_path() { local _target=$1 local _save_path=$(get_option_value "path") [ -z "$_save_path" ] && _save_path=$DEFAULT_PATH # strip the duplicated "/" _save_path=$(echo $_save_path | tr -s /) local _absolute_save_path=$(get_mntpoint_from_target $_target)/$_save_path _absolute_save_path=$(echo "$_absolute_save_path" | tr -s /) local _mntpoint=$(get_mntpoint_from_path $_absolute_save_path) if is_bind_mount $_mntpoint; then _save_path=${_absolute_save_path##"$_mntpoint"} # the real dump path in the 2nd kernel, if the mount point is bind mounted. _save_path=$(get_bind_mount_directory $_mntpoint)/$_save_path #erase the old path line, then insert the parsed path sed -i "/^path/d" ${initdir}/tmp/$$-kdump.conf echo "path $_save_path" >> ${initdir}/tmp/$$-kdump.conf fi } #install kdump.conf and what user specifies in kdump.conf kdump_install_conf() { sed -ne '/^#/!p' /etc/kdump.conf > ${initdir}/tmp/$$-kdump.conf while read config_opt config_val; do # remove inline comments after the end of a directive. case "$config_opt" in ext[234]|xfs|btrfs|minix|raw) sed -i -e "s#^$config_opt[[:space:]]\+$config_val#$config_opt $(kdump_to_udev_name $config_val)#" ${initdir}/tmp/$$-kdump.conf if is_atomic; then adjust_bind_mount_path "$config_val" fi ;; ssh|nfs) kdump_install_net "$config_val" ;; dracut_args) if [[ $(get_dracut_args_fstype "$config_val") = nfs* ]] ; then kdump_install_net "$(get_dracut_args_target "$config_val")" fi ;; kdump_pre|kdump_post|extra_bins) dracut_install $config_val ;; core_collector) dracut_install "${config_val%%[[:blank:]]*}" ;; esac done <<< "$(read_strip_comments /etc/kdump.conf)" default_dump_target_install_conf kdump_configure_fence_kdump "${initdir}/tmp/$$-kdump.conf" inst "${initdir}/tmp/$$-kdump.conf" "/etc/kdump.conf" rm -f ${initdir}/tmp/$$-kdump.conf } # Default sysctl parameters should suffice for kdump kernel. # Remove custom configurations sysctl.conf & sysctl.d/* remove_sysctl_conf() { # As custom configurations like vm.min_free_kbytes can lead # to OOM issues in kdump kernel, avoid them rm -f "${initdir}/etc/sysctl.conf" rm -rf "${initdir}/etc/sysctl.d" rm -rf "${initdir}/run/sysctl.d" rm -rf "${initdir}/usr/lib/sysctl.d" } kdump_iscsi_get_rec_val() { local result # The open-iscsi 742 release changed to using flat files in # /var/lib/iscsi. result=$(/sbin/iscsiadm --show -m session -r ${1} | grep "^${2} = ") result=${result##* = } echo $result } kdump_get_iscsi_initiator() { local _initiator local initiator_conf="/etc/iscsi/initiatorname.iscsi" [ -f "$initiator_conf" ] || return 1 while read _initiator; do [ -z "${_initiator%%#*}" ] && continue # Skip comment lines case $_initiator in InitiatorName=*) initiator=${_initiator#InitiatorName=} echo "rd.iscsi.initiator=${initiator}" return 0;; *) ;; esac done < ${initiator_conf} return 1 } # Figure out iBFT session according to session type is_ibft() { [ "$(kdump_iscsi_get_rec_val $1 "node.discovery_type")" = fw ] } kdump_setup_iscsi_device() { local path=$1 local tgt_name; local tgt_ipaddr; local username; local password; local userpwd_str; local username_in; local password_in; local userpwd_in_str; local netdev local srcaddr local idev local netroot_str ; local initiator_str; local netroot_conf="${initdir}/etc/cmdline.d/50iscsi.conf" local initiator_conf="/etc/iscsi/initiatorname.iscsi" dinfo "Found iscsi component $1" # Check once before getting explicit values, so we can bail out early, # e.g. in case of pure-hardware(all-offload) iscsi. if ! /sbin/iscsiadm -m session -r ${path} &>/dev/null ; then return 1 fi if is_ibft ${path}; then return fi tgt_name=$(kdump_iscsi_get_rec_val ${path} "node.name") tgt_ipaddr=$(kdump_iscsi_get_rec_val ${path} "node.conn\[0\].address") # get and set username and password details username=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.username") [ "$username" == "" ] && username="" password=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.password") [ "$password" == "" ] && password="" username_in=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.username_in") [ -n "$username" ] && userpwd_str="$username:$password" # get and set incoming username and password details [ "$username_in" == "" ] && username_in="" password_in=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.password_in") [ "$password_in" == "" ] && password_in="" [ -n "$username_in" ] && userpwd_in_str=":$username_in:$password_in" netdev=$(/sbin/ip route get to ${tgt_ipaddr} | \ sed 's|.*dev \(.*\).*|\1|g') srcaddr=$(echo $netdev | awk '{ print $3; exit }') netdev=$(echo $netdev | awk '{ print $1; exit }') kdump_setup_netdev $netdev $srcaddr # prepare netroot= command line # FIXME: Do we need to parse and set other parameters like protocol, port # iscsi_iface_name, netdev_name, LUN etc. if is_ipv6_address $tgt_ipaddr; then tgt_ipaddr="[$tgt_ipaddr]" fi netroot_str="netroot=iscsi:${userpwd_str}${userpwd_in_str}@$tgt_ipaddr::::$tgt_name" [[ -f $netroot_conf ]] || touch $netroot_conf # If netroot target does not exist already, append. if ! grep -q $netroot_str $netroot_conf; then echo $netroot_str >> $netroot_conf dinfo "Appended $netroot_str to $netroot_conf" fi # Setup initator initiator_str=$(kdump_get_iscsi_initiator) [ $? -ne "0" ] && derror "Failed to get initiator name" && return 1 # If initiator details do not exist already, append. if ! grep -q "$initiator_str" $netroot_conf; then echo "$initiator_str" >> $netroot_conf dinfo "Appended "$initiator_str" to $netroot_conf" fi } kdump_check_iscsi_targets () { # If our prerequisites are not met, fail anyways. type -P iscsistart >/dev/null || return 1 kdump_check_setup_iscsi() ( local _dev _dev=$1 [[ -L /sys/dev/block/$_dev ]] || return cd "$(readlink -f /sys/dev/block/$_dev)" until [[ -d sys || -d iscsi_session ]]; do cd .. done [[ -d iscsi_session ]] && kdump_setup_iscsi_device "$PWD" ) [[ $hostonly ]] || [[ $mount_needs ]] && { for_each_host_dev_and_slaves_all kdump_check_setup_iscsi } } # hostname -a is deprecated, do it by ourself get_alias() { local ips local entries local alias_set ips=$(hostname -I) for ip in $ips do # in /etc/hosts, alias can come at the 2nd column entries=$(grep $ip /etc/hosts | awk '{ $1=""; print $0 }') if [ $? -eq 0 ]; then alias_set="$alias_set $entries" fi done echo $alias_set } is_localhost() { local hostnames=$(hostname -A) local shortnames=$(hostname -A -s) local aliasname=$(get_alias) local nodename=$1 hostnames="$hostnames $shortnames $aliasname" for name in ${hostnames}; do if [ "$name" == "$nodename" ]; then return 0 fi done return 1 } # retrieves fence_kdump nodes from Pacemaker cluster configuration get_pcs_fence_kdump_nodes() { local nodes pcs cluster sync > /dev/null 2>&1 && pcs cluster cib-upgrade > /dev/null 2>&1 # get cluster nodes from cluster cib, get interface and ip address nodelist=`pcs cluster cib | xmllint --xpath "/cib/status/node_state/@uname" -` # nodelist is formed as 'uname="node1" uname="node2" ... uname="nodeX"' # we need to convert each to node1, node2 ... nodeX in each iteration for node in ${nodelist}; do # convert $node from 'uname="nodeX"' to 'nodeX' eval $node nodename=$uname # Skip its own node name if is_localhost $nodename; then continue fi nodes="$nodes $nodename" done echo $nodes } # retrieves fence_kdump args from config file get_pcs_fence_kdump_args() { if [ -f $FENCE_KDUMP_CONFIG_FILE ]; then . $FENCE_KDUMP_CONFIG_FILE echo $FENCE_KDUMP_OPTS fi } get_generic_fence_kdump_nodes() { local filtered local nodes nodes=$(get_option_value "fence_kdump_nodes") for node in ${nodes}; do # Skip its own node name if is_localhost $node; then continue fi filtered="$filtered $node" done echo $filtered } # setup fence_kdump in cluster # setup proper network and install needed files kdump_configure_fence_kdump () { local kdump_cfg_file=$1 local nodes local args if is_generic_fence_kdump; then nodes=$(get_generic_fence_kdump_nodes) elif is_pcs_fence_kdump; then nodes=$(get_pcs_fence_kdump_nodes) # set appropriate options in kdump.conf echo "fence_kdump_nodes $nodes" >> ${kdump_cfg_file} args=$(get_pcs_fence_kdump_args) if [ -n "$args" ]; then echo "fence_kdump_args $args" >> ${kdump_cfg_file} fi else # fence_kdump not configured return 1 fi # setup network for each node for node in ${nodes}; do kdump_install_net $node done dracut_install /etc/hosts dracut_install /etc/nsswitch.conf dracut_install $FENCE_KDUMP_SEND } # Install a random seed used to feed /dev/urandom # By the time kdump service starts, /dev/uramdom is already fed by systemd kdump_install_random_seed() { local poolsize=`cat /proc/sys/kernel/random/poolsize` if [ ! -d ${initdir}/var/lib/ ]; then mkdir -p ${initdir}/var/lib/ fi dd if=/dev/urandom of=${initdir}/var/lib/random-seed \ bs=$poolsize count=1 2> /dev/null } remove_cpu_online_rule() { local file=${initdir}/usr/lib/udev/rules.d/40-redhat.rules sed -i '/SUBSYSTEM=="cpu"/d' $file } install() { local arch kdump_install_conf remove_sysctl_conf # Onlining secondary cpus breaks kdump completely on KVM on Power hosts # Though we use maxcpus=1 by default but 40-redhat.rules will bring up all # possible cpus by default. (rhbz1270174 rhbz1266322) # Thus before we get the kernel fix and the systemd rule fix let's remove # the cpu online rule in kdump initramfs. arch=$(uname -m) if [[ "$arch" = "ppc64le" ]] || [[ "$arch" = "ppc64" ]]; then remove_cpu_online_rule fi if is_ssh_dump_target; then kdump_install_random_seed fi dracut_install -o /etc/adjtime /etc/localtime inst "$moddir/monitor_dd_progress" "/kdumpscripts/monitor_dd_progress" chmod +x ${initdir}/kdumpscripts/monitor_dd_progress inst "/bin/grep" "/bin/grep" inst "/bin/cat" "/bin/cat" inst "/bin/rm" "/bin/rm" inst "/bin/dd" "/bin/dd" inst "/bin/tail" "/bin/tail" inst "/bin/date" "/bin/date" inst "/bin/sync" "/bin/sync" inst "/bin/cut" "/bin/cut" inst "/bin/head" "/bin/head" inst "/sbin/makedumpfile" "/sbin/makedumpfile" inst "/sbin/vmcore-dmesg" "/sbin/vmcore-dmesg" inst "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh" inst "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump-lib-initramfs.sh" inst "$moddir/kdump.sh" "/usr/bin/kdump.sh" inst "$moddir/kdump-capture.service" "$systemdsystemunitdir/kdump-capture.service" ln_r "$systemdsystemunitdir/kdump-capture.service" "$systemdsystemunitdir/initrd.target.wants/kdump-capture.service" inst "$moddir/kdump-error-handler.sh" "/usr/bin/kdump-error-handler.sh" inst "$moddir/kdump-error-handler.service" "$systemdsystemunitdir/kdump-error-handler.service" # Replace existing emergency service and emergency target cp "$moddir/kdump-emergency.service" "$initdir/$systemdsystemunitdir/emergency.service" cp "$moddir/kdump-emergency.target" "$initdir/$systemdsystemunitdir/emergency.target" # Also redirect dracut-emergency to kdump error handler ln_r "$systemdsystemunitdir/emergency.service" "$systemdsystemunitdir/dracut-emergency.service" # Check for all the devices and if any device is iscsi, bring up iscsi # target. Ideally all this should be pushed into dracut iscsi module # at some point of time. kdump_check_iscsi_targets # For the lvm type target under kdump, in /etc/lvm/lvm.conf we can # safely replace "reserved_memory=XXXX"(default value is 8192) with # "reserved_memory=1024" to lower memory pressure under kdump. We do # it unconditionally here, if "/etc/lvm/lvm.conf" doesn't exist, it # actually does nothing. sed -i -e \ 's/\(^[[:space:]]*reserved_memory[[:space:]]*=\)[[:space:]]*[[:digit:]]*/\1 1024/' \ ${initdir}/etc/lvm/lvm.conf &>/dev/null # Kdump turns out to require longer default systemd mount timeout # than 1st kernel(90s by default), we use default 300s for kdump. grep -r "^[[:space:]]*DefaultTimeoutStartSec=" ${initdir}/etc/systemd/system.conf* &>/dev/null if [ $? -ne 0 ]; then mkdir -p ${initdir}/etc/systemd/system.conf.d echo "[Manager]" > ${initdir}/etc/systemd/system.conf.d/kdump.conf echo "DefaultTimeoutStartSec=300s" >> ${initdir}/etc/systemd/system.conf.d/kdump.conf fi } modules.d/99kdumpbase/kdump-error-handler.sh000075500000000221150252660330015011 0ustar00#!/bin/sh . /lib/kdump-lib-initramfs.sh set -o pipefail export PATH=$PATH:$KDUMP_SCRIPT_DIR get_kdump_confs do_default_action do_final_action modules.d/99kdumpbase/kdump-capture.service000064400000001655150252660330014747 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. [Unit] Description=Kdump Vmcore Save Service After=initrd.target initrd-parse-etc.service sysroot.mount After=dracut-initqueue.service dracut-pre-mount.service dracut-mount.service dracut-pre-pivot.service Before=initrd-cleanup.service ConditionPathExists=/etc/initrd-release OnFailure=emergency.target OnFailureIsolate=yes [Service] Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot Type=oneshot ExecStart=/bin/kdump.sh StandardInput=null StandardOutput=syslog StandardError=syslog+console KillMode=process RemainAfterExit=yes # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/99kdumpbase/kdump-emergency.target000064400000000703150252660330015101 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. [Unit] Description=Emergency Mode Documentation=man:systemd.special(7) Requires=emergency.service After=emergency.service AllowIsolate=yes IgnoreOnIsolate=yes modules.d/99kdumpbase/monitor_dd_progress000064400000000742150252660330014605 0ustar00#!/bin/sh SRC_FILE_MB=$1 while true do DD_PID=`pidof dd` if [ -n "$DD_PID" ]; then break fi done while true do sleep 5 if [ ! -d /proc/$DD_PID ]; then break fi kill -s USR1 $DD_PID CURRENT_SIZE=`tail -n 1 /tmp/dd_progress_file | sed "s/[^0-9].*//g"` [ -n "$CURRENT_SIZE" ] && { CURRENT_MB=$(($CURRENT_SIZE / 1048576)) echo -e "Copied $CURRENT_MB MB / $SRC_FILE_MB MB\r" } done rm -f /tmp/dd_progress_file modules.d/99kdumpbase/kdump-emergency.service000064400000001611150252660330015252 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # This service will be placed in kdump initramfs and replace both the systemd # emergency service and dracut emergency shell. IOW, any emergency will be # kick this service and in turn isolating to kdump error handler. [Unit] Description=Kdump Emergency DefaultDependencies=no IgnoreOnIsolate=yes [Service] ExecStart=/usr/bin/systemctl --no-block isolate kdump-error-handler.service Type=oneshot StandardInput=tty-force StandardOutput=inherit StandardError=inherit KillMode=process IgnoreSIGPIPE=no # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/99kdumpbase/kdump.sh000075500000011234150252660330012255 0ustar00#!/bin/sh # continue here only if we have to save dump. if [ -f /etc/fadump.initramfs ] && [ ! -f /proc/device-tree/rtas/ibm,kernel-dump ]; then exit 0 fi exec &> /dev/console . /lib/dracut-lib.sh . /lib/kdump-lib-initramfs.sh set -o pipefail DUMP_RETVAL=0 export PATH=$PATH:$KDUMP_SCRIPT_DIR do_dump() { local _ret eval $DUMP_INSTRUCTION _ret=$? if [ $_ret -ne 0 ]; then echo "kdump: saving vmcore failed" fi return $_ret } do_kdump_pre() { if [ -n "$KDUMP_PRE" ]; then "$KDUMP_PRE" fi } do_kdump_post() { if [ -n "$KDUMP_POST" ]; then "$KDUMP_POST" "$1" fi } add_dump_code() { DUMP_INSTRUCTION=$1 } dump_raw() { local _raw=$1 [ -b "$_raw" ] || return 1 echo "kdump: saving to raw disk $_raw" if ! $(echo -n $CORE_COLLECTOR|grep -q makedumpfile); then _src_size=`ls -l /proc/vmcore | cut -d' ' -f5` _src_size_mb=$(($_src_size / 1048576)) monitor_dd_progress $_src_size_mb & fi echo "kdump: saving vmcore" $CORE_COLLECTOR /proc/vmcore | dd of=$_raw bs=$DD_BLKSIZE >> /tmp/dd_progress_file 2>&1 || return 1 sync echo "kdump: saving vmcore complete" return 0 } dump_ssh() { local _opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes" local _dir="$KDUMP_PATH/$HOST_IP-$DATEDIR" local _host=$2 echo "kdump: saving to $_host:$_dir" cat /var/lib/random-seed > /dev/urandom ssh -q $_opt $_host mkdir -p $_dir || return 1 save_vmcore_dmesg_ssh ${DMESG_COLLECTOR} ${_dir} "${_opt}" $_host echo "kdump: saving vmcore" if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then scp -q $_opt /proc/vmcore "$_host:$_dir/vmcore-incomplete" || return 1 ssh $_opt $_host "mv $_dir/vmcore-incomplete $_dir/vmcore" || return 1 else $CORE_COLLECTOR /proc/vmcore | ssh $_opt $_host "dd bs=512 of=$_dir/vmcore-incomplete" || return 1 ssh $_opt $_host "mv $_dir/vmcore-incomplete $_dir/vmcore.flat" || return 1 fi echo "kdump: saving vmcore complete" return 0 } save_vmcore_dmesg_ssh() { local _dmesg_collector=$1 local _path=$2 local _opts="$3" local _location=$4 echo "kdump: saving vmcore-dmesg.txt" $_dmesg_collector /proc/vmcore | ssh $_opts $_location "dd of=$_path/vmcore-dmesg-incomplete.txt" _exitcode=$? if [ $_exitcode -eq 0 ]; then ssh -q $_opts $_location mv $_path/vmcore-dmesg-incomplete.txt $_path/vmcore-dmesg.txt echo "kdump: saving vmcore-dmesg.txt complete" else echo "kdump: saving vmcore-dmesg.txt failed" fi } get_host_ip() { local _host if is_nfs_dump_target || is_ssh_dump_target then kdumpnic=$(getarg kdumpnic=) [ -z "$kdumpnic" ] && echo "kdump: failed to get kdumpnic!" && return 1 _host=`ip addr show dev $kdumpnic|grep '[ ]*inet'` [ $? -ne 0 ] && echo "kdump: wrong kdumpnic: $kdumpnic" && return 1 _host=`echo $_host | head -n 1 | cut -d' ' -f2` _host="${_host%%/*}" [ -z "$_host" ] && echo "kdump: wrong kdumpnic: $kdumpnic" && return 1 HOST_IP=$_host fi return 0 } read_kdump_conf() { if [ ! -f "$KDUMP_CONF" ]; then echo "kdump: $KDUMP_CONF not found" return fi get_kdump_confs # rescan for add code for dump target while read config_opt config_val; do # remove inline comments after the end of a directive. case "$config_opt" in dracut_args) config_val=$(get_dracut_args_target "$config_val") [[ -n "$config_val" ]] && add_dump_code "dump_fs $config_val" ;; ext[234]|xfs|btrfs|minix|nfs) add_dump_code "dump_fs $config_val" ;; raw) add_dump_code "dump_raw $config_val" ;; ssh) add_dump_code "dump_ssh $SSH_KEY_LOCATION $config_val" ;; esac done <<< "$(read_strip_comments $KDUMP_CONF)" } fence_kdump_notify() { if [ -n "$FENCE_KDUMP_NODES" ]; then $FENCE_KDUMP_SEND $FENCE_KDUMP_ARGS $FENCE_KDUMP_NODES & fi } read_kdump_conf fence_kdump_notify get_host_ip if [ $? -ne 0 ]; then echo "kdump: get_host_ip exited with non-zero status!" exit 1 fi if [ -z "$DUMP_INSTRUCTION" ]; then add_dump_code "dump_fs $NEWROOT" fi do_kdump_pre if [ $? -ne 0 ]; then echo "kdump: kdump_pre script exited with non-zero status!" do_final_action fi make_trace_mem "kdump saving vmcore" '1:shortmem' '2+:mem' '3+:slab' do_dump DUMP_RETVAL=$? do_kdump_post $DUMP_RETVAL if [ $? -ne 0 ]; then echo "kdump: kdump_post script exited with non-zero status!" fi if [ $DUMP_RETVAL -ne 0 ]; then exit 1 fi do_final_action modules.d/99kdumpbase/kdump-error-handler.service000064400000001741150252660330016044 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # This service will run the real kdump error handler code. Executing the # default action configured in kdump.conf [Unit] Description=Kdump Error Handler DefaultDependencies=no After=systemd-vconsole-setup.service Wants=systemd-vconsole-setup.service AllowIsolate=yes [Service] Environment=HOME=/ Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot WorkingDirectory=/ ExecStart=/bin/kdump-error-handler.sh ExecStopPost=-/usr/bin/systemctl --fail --no-block default Type=oneshot StandardInput=tty-force StandardOutput=inherit StandardError=inherit KillMode=process IgnoreSIGPIPE=no # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/05busybox/module-setup.sh000075500000001360150252660330013262 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { require_binaries busybox || return 1 return 255 } depends() { return 0 } install() { local _i _progs _path _busybox _busybox=$(type -P busybox) inst $_busybox /usr/bin/busybox for _i in $($_busybox | sed -ne '1,/Currently/!{s/,//g; s/busybox//g; p}') do _progs="$_progs $_i" done # FIXME: switch_root should be in the above list, but busybox version hangs # (using busybox-1.15.1-7.fc14.i686 at the time of writing) for _i in $_progs; do _path=$(find_binary "$_i") [ -z "$_path" ] && continue ln_r /usr/bin/busybox $_path done } modules.d/95fcoe/module-setup.sh000075500000005676150252660330012532 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { local _fcoe_ctlr [[ $hostonly ]] || [[ $mount_needs ]] && { for c in /sys/bus/fcoe/devices/ctlr_* ; do [ -L $c ] || continue _fcoe_ctlr=$c done [ -z "$_fcoe_ctlr" ] && return 255 } require_binaries dcbtool fipvlan lldpad ip readlink fcoemon fcoeadm || return 1 return 0 } depends() { echo network rootfs-block return 0 } installkernel() { instmods fcoe 8021q edd } get_vlan_parent() { local link=$1 [ -d $link ] || return read iflink < $link/iflink for if in /sys/class/net/* ; do read idx < $if/ifindex if [ $idx -eq $iflink ] ; then echo ${if##*/} fi done } # called by dracut cmdline() { for c in /sys/bus/fcoe/devices/ctlr_* ; do [ -L $c ] || continue read enabled < $c/enabled [ $enabled -eq 0 ] && continue d=$(cd -P $c; echo $PWD) i=${d%/*} read mac < ${i}/address s=$(dcbtool gc ${i##*/} dcb | sed -n 's/^DCB State:\t*\(.*\)/\1/p') if [ -z "$s" ] ; then p=$(get_vlan_parent ${i}) if [ "$p" ] ; then s=$(dcbtool gc ${p} dcb | sed -n 's/^DCB State:\t*\(.*\)/\1/p') fi fi if [ "$s" = "on" ] ; then dcb="dcb" else dcb="nodcb" fi # Some Combined Network Adapters(CNAs) implement DCB in firmware. # Do not run software-based DCB or LLDP on CNAs that implement DCB. # If the network interface provides hardware DCB/DCBX capabilities, # DCB_REQUIRED in "/etc/fcoe/cfg-xxx" is expected to set to "no". # # Force "nodcb" if there's any DCB_REQUIRED="no"(child or vlan parent). grep -q "^[[:blank:]]*DCB_REQUIRED=\"no\"" /etc/fcoe/cfg-${i##*/} &>/dev/null [ $? -eq 0 ] && dcb="nodcb" if [ "$p" ] ; then grep -q "^[[:blank:]]*DCB_REQUIRED=\"no\"" /etc/fcoe/cfg-${p} &>/dev/null [ $? -eq 0 ] && dcb="nodcb" fi echo "fcoe=${mac}:${dcb}" done } # called by dracut install() { inst_multiple ip dcbtool fipvlan lldpad readlink lldptool fcoemon fcoeadm inst_libdir_file 'libhbalinux.so*' [[ -e /etc/hba.conf ]] && inst "/etc/hba.conf" "/etc/hba.conf" mkdir -m 0755 -p "$initdir/var/lib/lldpad" mkdir -m 0755 -p "$initdir/etc/fcoe" if [[ $hostonly_cmdline == "yes" ]] ; then local _fcoeconf=$(cmdline) [[ $_fcoeconf ]] && printf "%s\n" "$_fcoeconf" >> "${initdir}/etc/cmdline.d/95fcoe.conf" fi inst "$moddir/fcoe-up.sh" "/sbin/fcoe-up" inst "$moddir/fcoe-edd.sh" "/sbin/fcoe-edd" inst "$moddir/fcoe-genrules.sh" "/sbin/fcoe-genrules.sh" inst_hook pre-trigger 03 "$moddir/lldpad.sh" inst_hook cmdline 99 "$moddir/parse-fcoe.sh" inst_hook cleanup 90 "$moddir/cleanup-fcoe.sh" dracut_need_initqueue } modules.d/95fcoe/fcoe-up.sh000075500000004464150252660330011437 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # We get called like this: # fcoe-up # # Note currently only nodcb is supported, the dcb option is reserved for # future use. PATH=/usr/sbin:/usr/bin:/sbin:/bin # Huh? Missing arguments ?? [ -z "$1" -o -z "$2" ] && exit 1 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh netif=$1 dcb=$2 vlan="yes" iflink=$(cat /sys/class/net/$netif/iflink) ifindex=$(cat /sys/class/net/$netif/ifindex) if [ "$iflink" != "$ifindex" ] ; then # Skip VLAN devices exit 0 fi ip link set dev $netif up linkup "$netif" netdriver=$(readlink -f /sys/class/net/$netif/device/driver) netdriver=${netdriver##*/} write_fcoemon_cfg() { echo FCOE_ENABLE=\"yes\" > /etc/fcoe/cfg-$netif if [ "$dcb" = "dcb" ]; then echo DCB_REQUIRED=\"yes\" >> /etc/fcoe/cfg-$netif else echo DCB_REQUIRED=\"no\" >> /etc/fcoe/cfg-$netif fi if [ "$vlan" = "yes" ]; then echo AUTO_VLAN=\"yes\" >> /etc/fcoe/cfg-$netif else echo AUTO_VLAN=\"no\" >> /etc/fcoe/cfg-$netif fi echo MODE=\"fabric\" >> /etc/fcoe/cfg-$netif } if [ "$dcb" = "dcb" ]; then # wait for lldpad to be ready i=0 while [ $i -lt 60 ]; do lldptool -p && break info "Waiting for lldpad to be ready" sleep 1 i=$(($i+1)) done while [ $i -lt 60 ]; do dcbtool sc "$netif" dcb on && break info "Retrying to turn dcb on" sleep 1 i=$(($i+1)) done while [ $i -lt 60 ]; do dcbtool sc "$netif" pfc e:1 a:1 w:1 && break info "Retrying to turn dcb on" sleep 1 i=$(($i+1)) done while [ $i -lt 60 ]; do dcbtool sc "$netif" app:fcoe e:1 a:1 w:1 && break info "Retrying to turn fcoe on" sleep 1 i=$(($i+1)) done sleep 1 write_fcoemon_cfg fcoemon --syslog elif [ "$netdriver" = "bnx2x" ]; then # If driver is bnx2x, do not use /sys/module/fcoe/parameters/create but fipvlan modprobe 8021q udevadm settle --timeout=30 # Sleep for 13 s to allow dcb negotiation sleep 13 fipvlan "$netif" -c -s else vlan="no" write_fcoemon_cfg fcoemon --syslog fi need_shutdown modules.d/95fcoe/lldpad.sh000064400000000553150252660330011331 0ustar00#!/bin/bash # Note lldpad will stay running after switchroot, the system initscripts # are to kill it and start a new lldpad to take over. Data is transfered # between the 2 using a shm segment lldpad -d # wait for lldpad to be ready i=0 while [ $i -lt 60 ]; do lldptool -p && break info "Waiting for lldpad to be ready" sleep 1 i=$(($i+1)) done modules.d/95fcoe/fcoe-edd.sh000075500000002371150252660330011542 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh dcb="$1" _modprobe_r_edd="0" check_edd() { local cnt=0 [ -d /sys/firmware/edd ] && return 0 _modprobe_r_edd="1" modprobe edd || return $? while [ $cnt -lt 600 ]; do [ -d /sys/firmware/edd ] && return 0 cnt=$(($cnt+1)) sleep 0.1 done return 1 } check_edd || exit 1 for disk in /sys/firmware/edd/int13_*; do [ -d "$disk" ] || continue if [ -e "${disk}/pci_dev/driver" ]; then driver=$(readlink "${disk}/pci_dev/driver") driver=${driver##*/} fi # i40e uses dev_port 1 for a virtual fcoe function if [ "${driver}" == "i40e" ]; then dev_port=1 fi for nic in "${disk}"/pci_dev/net/*; do [ -d "$nic" ] || continue if [ -n "${dev_port}" -a -e "${nic}/dev_port" ]; then if [ "$(cat ${nic}/dev_port)" -ne "${dev_port}" ]; then continue fi fi if [ -e ${nic}/address ]; then fcoe_interface=${nic##*/} if ! [ -e "/tmp/.fcoe-$fcoe_interface" ]; then /sbin/fcoe-up "$fcoe_interface" "$dcb" > "/tmp/.fcoe-$fcoe_interface" fi fi done done [ "$_modprobe_r_edd" = "1" ] && modprobe -r edd unset _modprobe_r_edd modules.d/95fcoe/fcoe-genrules.sh000075500000001461150252660330012631 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # We use (fcoe_interface or fcoe_mac) and fcoe_dcb as set by parse-fcoe.sh # If neither mac nor interface are set we don't continue [ -z "$fcoe_interface" -a -z "$fcoe_mac" ] && return # Write udev rules { if [ -n "$fcoe_mac" ] ; then printf 'ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="%s", RUN+="/sbin/initqueue --onetime --unique --name fcoe-up-$env{INTERFACE} /sbin/fcoe-up $env{INTERFACE} %s"\n' "$fcoe_mac" "$fcoe_dcb" else printf 'ACTION=="add", SUBSYSTEM=="net", NAME=="%s", RUN+="/sbin/initqueue --onetime --unique --name fcoe-up-$env{INTERFACE} /sbin/fcoe-up $env{INTERFACE} %s"\n' "$fcoe_interface" "$fcoe_dcb" fi } >> /etc/udev/rules.d/92-fcoe.rules modules.d/95fcoe/parse-fcoe.sh000075500000003407150252660330012121 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # Supported formats: # fcoe=: # fcoe=: # # Note currently only nodcb is supported, the dcb option is reserved for # future use. # # Note letters in the macaddress must be lowercase! # # Examples: # fcoe=eth0:nodcb # fcoe=4a:3f:4c:04:f8:d7:nodcb [ -z "$fcoe" ] && fcoe=$(getarg fcoe=) # If it's not set we don't continue [ -z "$fcoe" ] && return # BRCM: Later, should check whether bnx2x is loaded first before loading bnx2fc so do not load bnx2fc when there are no Broadcom adapters [ -e /sys/bus/fcoe/ctlr_create ] || modprobe -b -a fcoe || die "FCoE requested but kernel/initrd does not support FCoE" initqueue --onetime modprobe -b -q bnx2fc parse_fcoe_opts() { local OLDIFS="$IFS" local IFS=: set $fcoe IFS="$OLDIFS" case $# in 2) fcoe_interface=$1 fcoe_dcb=$2 return 0 ;; 7) fcoe_mac=$1:$2:$3:$4:$5:$6 fcoe_dcb=$7 return 0 ;; *) warn "Invalid arguments for fcoe=$fcoe" return 1 ;; esac } parse_fcoe_opts if [ "$fcoe_interface" = "edd" ]; then if [ "$fcoe_dcb" != "nodcb" -a "$fcoe_dcb" != "dcb" ] ; then warn "Invalid FCoE DCB option: $fcoe_dcb" fi /sbin/initqueue --settled --unique /sbin/fcoe-edd $fcoe_dcb else for fcoe in $(getargs fcoe=); do unset fcoe_mac unset fcoe_interface parse_fcoe_opts if [ "$fcoe_dcb" != "nodcb" -a "$fcoe_dcb" != "dcb" ] ; then warn "Invalid FCoE DCB option: $fcoe_dcb" fi . $(command -v fcoe-genrules.sh) done fi modules.d/95fcoe/cleanup-fcoe.sh000064400000000553150252660330012432 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh if [ -e /var/run/lldpad.pid ]; then lldpad -k mkdir -m 0755 -p /run/initramfs/state/dev/shm cp /dev/shm/lldpad.state /run/initramfs/state/dev/shm/ > /dev/null 2>&1 echo "files /dev/shm/lldpad.state" >> /run/initramfs/rwtab fi modules.d/95cifs/module-setup.sh000075500000002232150252660330012523 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { # If our prerequisites are not met, fail anyways. require_binaries mount.cifs || return 1 [[ $hostonly ]] || [[ $mount_needs ]] && { for fs in "${host_fs_types[@]}"; do [[ "$fs" == "cifs" ]] && return 0 done return 255 } return 0 } depends() { # We depend on network modules being loaded echo network } installkernel() { instmods cifs ipv6 } install() { local _i local _nsslibs inst_multiple -o mount.cifs inst_multiple /etc/services /etc/nsswitch.conf /etc/protocols inst_libdir_file 'libcap-ng.so*' _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \ | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|') _nsslibs=${_nsslibs#|} _nsslibs=${_nsslibs%|} inst_libdir_file -n "$_nsslibs" 'libnss_*.so*' inst_hook cmdline 90 "$moddir/parse-cifsroot.sh" inst "$moddir/cifsroot.sh" "/sbin/cifsroot" inst "$moddir/cifs-lib.sh" "/lib/cifs-lib.sh" dracut_need_initqueue } modules.d/95cifs/parse-cifsroot.sh000075500000002414150252660330013042 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # root=cifs://[user:pass@]/ # # This syntax can come from DHCP root-path as well. # # If a username or password are not specified as part of the root, then they # will be pulled from cifsuser and cifspass on the kernel command line, # respectively. # type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh . /lib/cifs-lib.sh # This script is sourced, so root should be set. But let's be paranoid [ -z "$root" ] && root=$(getarg root=) if [ -z "$netroot" ]; then for netroot in $(getargs netroot=); do [ "${netroot%%:*}" = "cifs" ] && break done [ "${netroot%%:*}" = "cifs" ] || unset netroot fi # Root takes precedence over netroot if [ "${root%%:*}" = "cifs" ] ; then if [ -n "$netroot" ] ; then warn "root takes precedence over netroot. Ignoring netroot" fi netroot=$root unset root fi # If it's not cifs we don't continue [ "${netroot%%:*}" = "cifs" ] || return # Check required arguments cifs_to_var $netroot # If we don't have a server, we need dhcp if [ -z "$server" ] ; then DHCPORSERVER="1" fi; # Done, all good! rootok=1 echo '[ -e $NEWROOT/proc ]' > $hookdir/initqueue/finished/cifsroot.sh modules.d/95cifs/cifsroot.sh000075500000001317150252660330011733 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh . /lib/cifs-lib.sh [ "$#" = 3 ] || exit 1 # root is in the form root=cifs://user:pass@[server]/[folder] either from # cmdline or dhcp root-path netif="$1" root="$2" NEWROOT="$3" cifs_to_var $root echo server: $server echo path: $path echo options: $options mount.cifs //$server/$path $NEWROOT -o $options && { [ -e /dev/root ] || ln -s null /dev/root ; } # inject new exit_if_exists echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm -f -- "$job"' > $hookdir/initqueue/cifs.sh # force udevsettle to break > $hookdir/initqueue/work modules.d/95cifs/cifs-lib.sh000075500000002067150252660330011576 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # cifs_to_var CIFSROOT # use CIFSROOT to set $server, $path, and $options. # CIFSROOT is something like: cifs://[[:]]@/ # NETIF is used to get information from DHCP options, if needed. type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh cifs_to_var() { local cifsuser; local cifspass # Check required arguments server=${1##cifs://} cifsuser=${server%@*} cifspass=${cifsuser#*:} if [ "$cifspass" != "$cifsuser" ]; then cifsuser=${cifsuser%:*} else cifspass=$(getarg cifspass) fi if [ "$cifsuser" != "$server" ]; then server="${server#*@}" else cifsuser=$(getarg cifsuser) fi path=${server#*/} server=${server%/*} if [ ! "$cifsuser" -o ! "$cifspass" ]; then die "For CIFS support you need to specify a cifsuser and cifspass either in the cifsuser and cifspass commandline parameters or in the root= CIFS URL." fi options="user=$cifsuser,pass=$cifspass" } modules.d/10i18n/module-setup.sh000075500000016467150252660330012360 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { [[ "$mount_needs" ]] && return 1 require_binaries setfont loadkeys kbd_mode || return 1 return 0 } depends() { return 0 } install() { if dracut_module_included "systemd"; then unset FONT unset KEYMAP [[ -f /etc/vconsole.conf ]] && . /etc/vconsole.conf fi KBDSUBDIRS=consolefonts,consoletrans,keymaps,unimaps DEFAULT_FONT="${i18n_default_font:-LatArCyrHeb-16}" I18N_CONF="/etc/locale.conf" VCONFIG_CONF="/etc/vconsole.conf" # This is from 10redhat-i18n. findkeymap () { local MAP=$1 [[ ! -f $MAP ]] && \ MAP=$(find ${kbddir}/keymaps -type f -name $MAP -o -name $MAP.\* | head -n1) [[ " $KEYMAPS " = *" $MAP "* ]] && return KEYMAPS="$KEYMAPS $MAP" case $MAP in *.gz) cmd=zgrep;; *.bz2) cmd=bzgrep;; *) cmd=grep ;; esac for INCL in $($cmd "^include " $MAP | while read a a b; do echo ${a//\"/}; done); do for FN in $(find ${kbddir}/keymaps -type f -name $INCL\*); do findkeymap $FN done done } # Function gathers variables from distributed files among the tree, maps to # specified names and prints the result in format "new-name=value". # # $@ = list in format specified below (BNF notation) # # ::= | " " # ::= ":" # ::= | "," # ::= "-" | # # We assume no whitespace are allowed between symbols. # is a file holding in your system. # is a variable holding value of meaning the same as . # is a variable which will be set up inside initramfs. # If has the same name as we can omit . # # Example: # /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS # = /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS # = /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS # = /etc/conf.d/keymaps # = KEYMAP,extended_keymaps-EXT_KEYMAPS # = KEYMAP # = KEYMAP # = extended_keymaps-EXT_KEYMAPS # = extended_keymaps # = EXT_KEYMAPS gather_vars() { local item map value for item in $@ do item=(${item/:/ }) for map in ${item[1]//,/ } do map=(${map//-/ }) if [[ -f "${item[0]}" ]]; then value=$(grep "^${map[0]}=" "${item[0]}") value=${value#*=} echo "${map[1]:-${map[0]}}=${value}" fi done done } install_base() { inst_multiple setfont loadkeys kbd_mode stty if ! dracut_module_included "systemd"; then inst ${moddir}/console_init.sh /lib/udev/console_init inst_rules ${moddir}/10-console.rules inst_hook cmdline 20 "${moddir}/parse-i18n.sh" fi } install_all_kbd() { local rel f for _src in $(eval echo ${kbddir}/{${KBDSUBDIRS}}); do inst_dir "$_src" cp --reflink=auto --sparse=auto -prfL -t "${initdir}/${_src}" "$_src"/* done # remove unnecessary files rm -f -- "${initdir}${kbddir}/consoletrans/utflist" find "${initdir}${kbddir}/" -name README\* -delete find "${initdir}${kbddir}/" -name '*.gz' -print -quit \ | while read line; do inst_multiple gzip done find "${initdir}${kbddir}/" -name '*.bz2' -print -quit \ | while read line; do inst_multiple bzip2 done } install_local_i18n() { local map eval $(gather_vars ${i18n_vars}) [ -f $I18N_CONF ] && . $I18N_CONF [ -f $VCONFIG_CONF ] && . $VCONFIG_CONF shopt -q -s nocasematch if [[ ${UNICODE} ]] then if [[ ${UNICODE} = YES || ${UNICODE} = 1 ]] then UNICODE=1 elif [[ ${UNICODE} = NO || ${UNICODE} = 0 ]] then UNICODE=0 else UNICODE='' fi fi if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]] then UNICODE=1 fi shopt -q -u nocasematch # Gentoo user may have KEYMAP set to something like "-u pl2", KEYMAP=${KEYMAP#-* } # KEYTABLE is a bit special - it defines base keymap name and UNICODE # determines whether non-UNICODE or UNICODE version is used if [[ ${KEYTABLE} ]]; then if [[ ${UNICODE} == 1 ]]; then [[ ${KEYTABLE} =~ .*\.uni.* ]] || KEYTABLE=${KEYTABLE%.map*}.uni fi KEYMAP=${KEYTABLE} fi # I'm not sure of the purpose of UNIKEYMAP and GRP_TOGGLE. They were in # original redhat-i18n module. Anyway it won't hurt. EXT_KEYMAPS+=\ ${UNIKEYMAP}\ ${GRP_TOGGLE} [[ ${KEYMAP} ]] || { dinfo 'No KEYMAP configured.' return 1 } findkeymap ${KEYMAP} for map in ${EXT_KEYMAPS} do ddebug "Adding extra map: ${map}" findkeymap ${map} done inst_opt_decompress ${KEYMAPS} inst_opt_decompress ${kbddir}/consolefonts/${DEFAULT_FONT}.* if [[ ${FONT} ]] && [[ ${FONT} != ${DEFAULT_FONT} ]] then FONT=${FONT%.psf*} inst_opt_decompress ${kbddir}/consolefonts/${FONT}.* fi if [[ ${FONT_MAP} ]] then FONT_MAP=${FONT_MAP%.trans} inst_simple ${kbddir}/consoletrans/${FONT_MAP}.trans fi if [[ ${FONT_UNIMAP} ]] then FONT_UNIMAP=${FONT_UNIMAP%.uni} inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni fi if dracut_module_included "systemd" && [[ -f ${I18N_CONF} ]]; then inst_simple ${I18N_CONF} else mksubdirs ${initdir}${I18N_CONF} print_vars LC_ALL LANG >> ${initdir}${I18N_CONF} fi if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then inst_simple ${VCONFIG_CONF} else mksubdirs ${initdir}${VCONFIG_CONF} print_vars KEYMAP EXT_KEYMAPS UNICODE FONT FONT_MAP FONT_UNIMAP >> ${initdir}${VCONFIG_CONF} fi return 0 } checks() { for kbddir in ${kbddir} /usr/lib/kbd /lib/kbd /usr/share /usr/share/kbd do [[ -d "${kbddir}" ]] && \ for dir in ${KBDSUBDIRS//,/ } do [[ -d "${kbddir}/${dir}" ]] && continue false done && break kbddir='' done [[ -f $I18N_CONF && -f $VCONFIG_CONF ]] || \ [[ ! ${hostonly} || ${i18n_vars} ]] || { derror 'i18n_vars not set! Please set up i18n_vars in ' \ 'configuration file.' } return 0 } if checks; then install_base if [[ ${hostonly} ]] && ! [[ ${i18n_install_all} == "yes" ]]; then install_local_i18n || install_all_kbd else install_all_kbd fi fi } modules.d/10i18n/README000064400000010504150252660330010240 0ustar00dracut i18n module ------------------ INDEX 0. Introduction 1. Hostonly vs Generic 2. Configuration 2.1. Variables 2.2. Setting up mappings 2.3. Additional settings 3. Kernel parameters ~ 0. Introduction i18n module provides internationalization for initramfs at runtime. It is intended to be generic across different GNU/Linux distributions. i18n and keyboard settings are stored in different files among distributions. To deal with it avoiding hardcoding those differences in the installation script we handle it by mappings between variables used by dracut and the ones in the system. Package maintainer is expected to create those for his/her distribution and it's appreciated to share it with us, so we can include it in source package. 1. Hostonly vs Generic If you invoke dracut with '-H' option, i18n module install script will gather variables values from your configuration files using mappings provided in "/etc/dracut.conf.d/.conf". Those variables will be put in "etc/vconsole.conf" and "etc/locale.conf" files inside initramfs image. Next it will install only declared font, keymaps and so. When building generic image (dracut without '-H' option), install script copies all content of directories: consolefonts, consoletrans, unimaps and keymaps to image. Take into account that's about 4 MiB. 2. Configuration 2.1. Variables The following variables are used by i18n install script and at initramfs runtime: KEYMAP - keyboard translation table loaded by loadkeys KEYTABLE - base name for keyboard translation table; if UNICODE is true, Unicode version will be loaded. Overrides KEYMAP. EXT_KEYMAPS - list of extra keymaps to bo loaded (sep. by space) UNICODE - boolean, indicating UTF-8 mode FONT - console font FONT_MAP - see description of '-m' parameter in setfont manual FONT_UNIMAP - see description of '-u' parameter in setfont manual The following are appended to EXT_KEYMAPS only during build time: UNIKEYMAP GRP_TOGGLE They were used in 10redhat-i18n module, but not sure of its purpose. I'm leaving it in case... The following are taken from the environment: LANG LC_ALL If UNICODE variable is not provided, script indicates if UTF-8 should be used on the basis of LANG value (if it ends with ".utf8" or similar). 2.2. Setting up mappings Mappings between variables listed in 2.1. and the ones spread around your system are set up in /etc/dracut.conf.d/.conf. You need to assign mappings to i18n_vars. Here's an example: i18n_vars="/etc/conf.d/keymaps:KEYMAP,EXTENDED_KEYMAPS-EXT_KEYMAPS /etc/conf.d/consolefont:CONSOLEFONT-FONT,CONSOLETRANSLATION-FONT_MAP /etc/rc.conf:UNICODE" First we've got name of file in host file system tree. After colon there's mapping: -. If both variables have the same name you can enter just a single, but it's important to specify it! The module will source only variables you've listed. Below there's detailed description in BNF: ::= | " " ::= ":" ::= | "," ::= "-" | We assume no whitespace are allowed between symbols. is a file holding in your system. is a variable holding value of meaning the same as . is a variable which will be set up inside initramfs. If has the same name as we can omit . Example: /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS = /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS = /etc/conf.d/keymaps:KEYMAP,extended_keymaps-EXT_KEYMAPS = /etc/conf.d/keymaps = KEYMAP,extended_keymaps-EXT_KEYMAPS = KEYMAP = KEYMAP = extended_keymaps-EXT_KEYMAPS = extended_keymaps = EXT_KEYMAPS 2.3. Additional settings If you encounter following error message: "Directories consolefonts, consoletrans, keymaps, unimaps not found.", you can provide path where those directories lie in your system by setting kbddir in configuration file (the same where you put mappings). 3. Kernel parameters If you create generic initramfs you can set up i18n by kernel parameters using variables listed in 2.1. (except of UNIKEYMAP and GRP_TOGGLE) The recommended minimum is: FONT and KEYMAP. modules.d/10i18n/parse-i18n.sh000075500000002357150252660330011615 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh inst_key_val() { local _value local _file local _default _default=$1 shift _file=$1 shift _value=$(getarg $@) [ -z "${_value}" ] && _value=$_default if [ -n "${_value}" ]; then printf '%s="%s"\n' $2 ${_value} >> $_file fi unset _file unset _value } inst_key_val '' /etc/vconsole.conf rd.vconsole.keymap vconsole.keymap KEYMAP -d KEYTABLE inst_key_val '' /etc/vconsole.conf rd.vconsole.font vconsole.font FONT -d SYSFONT inst_key_val '' /etc/vconsole.conf rd.vconsole.font.map vconsole.font.map FONT_MAP -d CONTRANS inst_key_val '' /etc/vconsole.conf rd.vconsole.font.unimap vconsole.font.unimap FONT_UNIMAP -d UNIMAP inst_key_val 1 /etc/vconsole.conf rd.vconsole.font.unicode vconsole.font.unicode UNICODE vconsole.unicode inst_key_val '' /etc/vconsole.conf rd.vconsole.keymap.ext vconsole.keymap.ext EXT_KEYMAP inst_key_val '' /etc/locale.conf rd.locale.LANG locale.LANG LANG inst_key_val '' /etc/locale.conf rd.locale.LC_ALL locale.LC_ALL LC_ALL if [ -f /etc/locale.conf ]; then . /etc/locale.conf export LANG export LC_ALL fi modules.d/10i18n/10-console.rules000064400000000250150252660330012311 0ustar00# Console initialization - keyboard, font, etc. KERNEL=="tty0", RUN+="/sbin/initqueue --onetime --unique --name console_init_$name /lib/udev/console_init $root/$name" modules.d/10i18n/console_init.sh000075500000003272150252660330012410 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh [ -n "$DRACUT_SYSTEMD" ] && exit 0 if [ -x $systemdutildir/systemd-vconsole-setup ]; then $systemdutildir/systemd-vconsole-setup "$@" fi [ -e /etc/vconsole.conf ] && . /etc/vconsole.conf DEFAULT_FONT=LatArCyrHeb-16 DEFAULT_KEYMAP=/etc/sysconfig/console/default.kmap set_keyboard() { local param [ "${UNICODE}" = 1 ] && param=-u || param=-a kbd_mode ${param} } set_terminal() { local dev=$1 if [ "${UNICODE}" = 1 ]; then printf '\033%%G' >&7 stty -F ${dev} iutf8 else printf '\033%%@' >&7 stty -F ${dev} -iutf8 fi } set_keymap() { local utf_switch if [ -z "${KEYMAP}" ]; then [ -f "${DEFAULT_KEYMAP}" ] && KEYMAP=${DEFAULT_KEYMAP} fi [ -n "${KEYMAP}" ] || return 1 [ "${UNICODE}" = 1 ] && utf_switch=-u loadkeys -q ${utf_switch} ${KEYMAP} ${EXT_KEYMAPS} } set_font() { local dev=$1; local trans=''; local uni='' [ -z "${FONT}" ] && FONT=${DEFAULT_FONT} [ -n "${FONT_MAP}" ] && trans="-m ${FONT_MAP}" [ -n "${FONT_UNIMAP}" ] && uni="-u ${FONT_UNIMAP}" setfont ${FONT} -C ${dev} ${trans} ${uni} } dev_close() { exec 6>&- exec 7>&- } dev_open() { local dev=$1 exec 6<${dev} && \ exec 7>>${dev} } dev=/dev/${1#/dev/} devname=${dev#/dev/} [ -c "${dev}" ] || { echo "Usage: $0 device" >&2 exit 1 } dev_open ${dev} for fd in 6 7; do if ! [ -t ${fd} ]; then echo "ERROR: File descriptor not opened: ${fd}" >&2 dev_close exit 1 fi done set_keyboard set_terminal ${dev} set_font ${dev} set_keymap dev_close modules.d/00systemd-bootchart/module-setup.sh000075500000000577150252660330015246 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { [[ "$mount_needs" ]] && return 1 require_binaries $systemdutildir/systemd-bootchart || return 1 return 255 } depends() { return 0 } install() { inst_symlink /init /sbin/init inst_multiple $systemdutildir/systemd-bootchart } modules.d/98selinux/module-setup.sh000075500000000432150252660330013271 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { return 255 } depends() { return 0 } install() { inst_hook pre-pivot 50 "$moddir/selinux-loadpolicy.sh" inst_multiple setenforce } modules.d/98selinux/selinux-loadpolicy.sh000075500000004440150252660330014475 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # FIXME: load selinux policy. this should really be done after we switchroot rd_load_policy() { # If SELinux is disabled exit now getarg "selinux=0" > /dev/null && return 0 SELINUX="enforcing" [ -e "$NEWROOT/etc/selinux/config" ] && . "$NEWROOT/etc/selinux/config" # Check whether SELinux is in permissive mode permissive=0 getarg "enforcing=0" > /dev/null if [ $? -eq 0 -o "$SELINUX" = "permissive" ]; then permissive=1 fi # Attempt to load SELinux Policy if [ -x "$NEWROOT/usr/sbin/load_policy" -o -x "$NEWROOT/sbin/load_policy" ]; then local ret=0 local out info "Loading SELinux policy" mount -o bind /sys $NEWROOT/sys # load_policy does mount /proc and /sys/fs/selinux in # libselinux,selinux_init_load_policy() if [ -x "$NEWROOT/sbin/load_policy" ]; then out=$(LANG=C chroot "$NEWROOT" /sbin/load_policy -i 2>&1) ret=$? info $out else out=$(LANG=C chroot "$NEWROOT" /usr/sbin/load_policy -i 2>&1) ret=$? info $out fi umount $NEWROOT/sys/fs/selinux umount $NEWROOT/sys if [ "$SELINUX" = "disabled" ]; then return 0; fi if [ $ret -eq 0 -o $ret -eq 2 ]; then # If machine requires a relabel, force to permissive mode [ -e "$NEWROOT"/.autorelabel ] && LANG=C /usr/sbin/setenforce 0 mount --rbind /dev "$NEWROOT/dev" LANG=C chroot "$NEWROOT" /sbin/restorecon -R /dev umount -R "$NEWROOT/dev" return 0 fi warn "Initial SELinux policy load failed." if [ $ret -eq 3 -o $permissive -eq 0 ]; then warn "Machine in enforcing mode." warn "Not continuing" action_on_fail -n selinux || exit 1 fi return 0 elif [ $permissive -eq 0 -a "$SELINUX" != "disabled" ]; then warn "Machine in enforcing mode and cannot execute load_policy." warn "To disable selinux, add selinux=0 to the kernel command line." warn "Not continuing" action_on_fail -n selinux || exit 1 fi } rd_load_policy modules.d/03rescue/module-setup.sh000075500000000644150252660330013057 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { # do not add this module by default return 255 } depends() { return 0 } install() { inst_multiple -o ps grep more cat rm strace free showmount \ ping netstat rpcinfo vi scp ping6 ssh \ fsck fsck.ext2 fsck.ext4 fsck.ext3 fsck.ext4dev fsck.vfat e2fsck } modules.d/98systemd/dracut-cmdline-ask.sh000075500000000646150252660330014325 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh sleep 0.5 echo sleep 0.5 echo sleep 0.5 echo echo echo echo echo "Enter additional kernel command line parameter (end with ctrl-d or .)" while read -e -p "> " line; do [[ "$line" == "." ]] && break [[ "$line" ]] && printf -- "%s\n" "$line" >> /etc/cmdline.d/99-cmdline-ask.conf done exit 0 modules.d/98systemd/rootfs-generator.sh000075500000007160150252660330014154 0ustar00#!/bin/sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh generator_wait_for_dev() { local _name local _timeout _name="$(str_replace "$1" '/' '\x2f')" _timeout=$(getarg rd.timeout) _timeout=${_timeout:-0} if ! [ -e "$hookdir/initqueue/finished/devexists-${_name}.sh" ]; then printf '[ -e "%s" ]\n' $1 \ >> "$hookdir/initqueue/finished/devexists-${_name}.sh" { printf '[ -e "%s" ] || ' $1 printf 'warn "\"%s\" does not exist"\n' $1 } >> "$hookdir/emergency/80-${_name}.sh" fi _name=$(dev_unit_name "$1") if ! [ -L "$GENERATOR_DIR"/initrd.target.wants/${_name}.device ]; then [ -d "$GENERATOR_DIR"/initrd.target.wants ] || mkdir -p "$GENERATOR_DIR"/initrd.target.wants ln -s ../${_name}.device "$GENERATOR_DIR"/initrd.target.wants/${_name}.device fi if ! [ -f "$GENERATOR_DIR"/${_name}.device.d/timeout.conf ]; then mkdir -p "$GENERATOR_DIR"/${_name}.device.d { echo "[Unit]" echo "JobTimeoutSec=$_timeout" } > "$GENERATOR_DIR"/${_name}.device.d/timeout.conf fi } generator_mount_rootfs() { local _type=$2 local _flags=$3 local _name [ -z "$1" ] && return 0 _name=$(dev_unit_name "$1") [ -d "$GENERATOR_DIR" ] || mkdir -p "$GENERATOR_DIR" if ! [ -f "$GENERATOR_DIR"/sysroot.mount ]; then { echo "[Unit]" echo "Before=initrd-root-fs.target" echo "Requires=systemd-fsck@${_name}.service" echo "After=systemd-fsck@${_name}.service" echo "[Mount]" echo "Where=/sysroot" echo "What=$1" echo "Options=${_flags}" echo "Type=${_type}" } > "$GENERATOR_DIR"/sysroot.mount fi if ! [ -L "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount ]; then [ -d "$GENERATOR_DIR"/initrd-root-fs.target.requires ] || mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.requires ln -s ../sysroot.mount "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount fi } generator_fsck_after_pre_mount() { local _name [ -z "$1" ] && return 0 _name=$(dev_unit_name "$1") [ -d /run/systemd/generator/systemd-fsck@${_name}.service.d ] || mkdir -p /run/systemd/generator/systemd-fsck@${_name}.service.d if ! [ -f /run/systemd/generator/systemd-fsck@${_name}.service.d/after-pre-mount.conf ]; then { echo "[Unit]" echo "After=dracut-pre-mount.service" } > /run/systemd/generator/systemd-fsck@${_name}.service.d/after-pre-mount.conf fi } root=$(getarg root=) case "$root" in block:LABEL=*|LABEL=*) root="${root#block:}" root="$(echo $root | sed 's,/,\\x2f,g')" root="block:/dev/disk/by-label/${root#LABEL=}" rootok=1 ;; block:UUID=*|UUID=*) root="${root#block:}" root="block:/dev/disk/by-uuid/${root#UUID=}" rootok=1 ;; block:PARTUUID=*|PARTUUID=*) root="${root#block:}" root="block:/dev/disk/by-partuuid/${root#PARTUUID=}" rootok=1 ;; block:PARTLABEL=*|PARTLABEL=*) root="${root#block:}" root="block:/dev/disk/by-partlabel/${root#PARTLABEL=}" rootok=1 ;; /dev/nfs) # ignore legacy /dev/nfs ;; /dev/*) root="block:${root}" rootok=1 ;; esac GENERATOR_DIR="$1" if [ "$rootok" = "1" ]; then generator_wait_for_dev "${root#block:}" "$RDRETRY" generator_fsck_after_pre_mount "${root#block:}" strstr "$(cat /proc/cmdline)" 'root=' || generator_mount_rootfs "${root#block:}" "$(getarg rootfstype=)" "$(getarg rootflags=)" fi exit 0 modules.d/98systemd/dracut-pre-trigger.service.8000064400000003014150252660330015546 0ustar00'\" t .\" Title: dracut-pre-trigger.service .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.78.1 .\" Date: 09/12/2013 .\" Manual: dracut .\" Source: dracut .\" Language: English .\" .TH "DRACUT\-PRE\-TRIGGER" "8" "09/12/2013" "dracut" "dracut" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" dracut-pre-trigger.service \- runs the dracut hooks before udevd is triggered .SH "SYNOPSIS" .sp dracut\-pre\-trigger\&.service .SH "DESCRIPTION" .sp This service runs all dracut hooks before udevd is triggered in the initramfs\&. .SH "AUTHORS" .sp Harald Hoyer .SH "SEE ALSO" .sp \fBdracut\&.bootup\fR(7) \fBdracut\fR(8) modules.d/98systemd/module-setup.sh000075500000023761150252660330013304 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { [[ $mount_needs ]] && return 1 if require_binaries $systemdutildir/systemd; then SYSTEMD_VERSION=$($systemdutildir/systemd --version | { read a b a; echo $b; }) (( $SYSTEMD_VERSION >= 198 )) && return 0 return 255 fi return 1 } depends() { return 0 } installkernel() { instmods autofs4 ipv6 instmods -s efivarfs } ug_check_and_add() { local name="$1" local file="$2" if egrep -q "^$name:" "$file" 2>/dev/null \ && ! egrep -q "^$name:" "$initdir$file" 2>/dev/null; then egrep "^$name:" "$file" 2>/dev/null >> "$initdir$file" fi } install() { local _mods if [[ "$prefix" == /run/* ]]; then dfatal "systemd does not work with a prefix, which contains \"/run\"!!" exit 1 fi ug_check_and_add "wheel" "/etc/passwd" ug_check_and_add "wheel" "/etc/group" ug_check_and_add "adm" "/etc/passwd" ug_check_and_add "adm" "/etc/group" inst_multiple -o \ $systemdutildir/systemd \ $systemdutildir/systemd-cgroups-agent \ $systemdutildir/systemd-shutdown \ $systemdutildir/systemd-reply-password \ $systemdutildir/systemd-fsck \ $systemdutildir/systemd-udevd \ $systemdutildir/systemd-journald \ $systemdutildir/systemd-sysctl \ $systemdutildir/systemd-modules-load \ $systemdutildir/systemd-vconsole-setup \ $systemdutildir/system-generators/systemd-fstab-generator \ \ $systemdsystemunitdir/cryptsetup.target \ $systemdsystemunitdir/emergency.target \ $systemdsystemunitdir/sysinit.target \ $systemdsystemunitdir/basic.target \ $systemdsystemunitdir/halt.target \ $systemdsystemunitdir/kexec.target \ $systemdsystemunitdir/initrd.target \ $systemdsystemunitdir/initrd-fs.target \ $systemdsystemunitdir/initrd-root-fs.target \ $systemdsystemunitdir/local-fs.target \ $systemdsystemunitdir/local-fs-pre.target \ $systemdsystemunitdir/remote-fs.target \ $systemdsystemunitdir/remote-fs-pre.target \ $systemdsystemunitdir/network.target \ $systemdsystemunitdir/nss-lookup.target \ $systemdsystemunitdir/nss-user-lookup.target \ $systemdsystemunitdir/poweroff.target \ $systemdsystemunitdir/reboot.target \ $systemdsystemunitdir/rescue.target \ $systemdsystemunitdir/rpcbind.target \ $systemdsystemunitdir/shutdown.target \ $systemdsystemunitdir/final.target \ $systemdsystemunitdir/sigpwr.target \ $systemdsystemunitdir/sockets.target \ $systemdsystemunitdir/swap.target \ $systemdsystemunitdir/timers.target \ $systemdsystemunitdir/paths.target \ $systemdsystemunitdir/umount.target \ \ $systemdsystemunitdir/sys-kernel-config.mount \ \ $systemdsystemunitdir/kmod-static-nodes.service \ $systemdsystemunitdir/systemd-tmpfiles-setup-dev.service \ $systemdsystemunitdir/systemd-ask-password-console.path \ $systemdsystemunitdir/systemd-udevd-control.socket \ $systemdsystemunitdir/systemd-udevd-kernel.socket \ $systemdsystemunitdir/systemd-ask-password-plymouth.path \ $systemdsystemunitdir/systemd-journald.socket \ $systemdsystemunitdir/systemd-ask-password-console.service \ $systemdsystemunitdir/systemd-modules-load.service \ $systemdsystemunitdir/systemd-halt.service \ $systemdsystemunitdir/systemd-poweroff.service \ $systemdsystemunitdir/systemd-reboot.service \ $systemdsystemunitdir/systemd-kexec.service \ $systemdsystemunitdir/systemd-fsck@.service \ $systemdsystemunitdir/systemd-udevd.service \ $systemdsystemunitdir/systemd-udev-trigger.service \ $systemdsystemunitdir/systemd-udev-settle.service \ $systemdsystemunitdir/systemd-ask-password-plymouth.service \ $systemdsystemunitdir/systemd-journald.service \ $systemdsystemunitdir/systemd-vconsole-setup.service \ $systemdsystemunitdir/systemd-random-seed-load.service \ $systemdsystemunitdir/systemd-sysctl.service \ \ $systemdsystemunitdir/sysinit.target.wants/systemd-modules-load.service \ $systemdsystemunitdir/sysinit.target.wants/systemd-ask-password-console.path \ $systemdsystemunitdir/sysinit.target.wants/systemd-journald.service \ $systemdsystemunitdir/sockets.target.wants/systemd-udevd-control.socket \ $systemdsystemunitdir/sockets.target.wants/systemd-udevd-kernel.socket \ $systemdsystemunitdir/sockets.target.wants/systemd-journald.socket \ $systemdsystemunitdir/sockets.target.wants/systemd-journald-dev-log.socket \ $systemdsystemunitdir/sysinit.target.wants/systemd-udevd.service \ $systemdsystemunitdir/sysinit.target.wants/systemd-udev-trigger.service \ $systemdsystemunitdir/sysinit.target.wants/kmod-static-nodes.service \ $systemdsystemunitdir/sysinit.target.wants/systemd-tmpfiles-setup-dev.service \ $systemdsystemunitdir/sysinit.target.wants/systemd-sysctl.service \ \ $systemdsystemunitdir/ctrl-alt-del.target \ $systemdsystemunitdir/syslog.socket \ $systemdsystemunitdir/initrd-switch-root.target \ $systemdsystemunitdir/initrd-switch-root.service \ $systemdsystemunitdir/initrd-cleanup.service \ $systemdsystemunitdir/initrd-udevadm-cleanup-db.service \ $systemdsystemunitdir/initrd-parse-etc.service \ \ $systemdsystemunitdir/slices.target \ $systemdsystemunitdir/system.slice \ $systemdsystemunitdir/-.slice \ \ $tmpfilesdir/systemd.conf \ \ systemd-run systemd-escape \ journalctl systemctl echo swapoff systemd-cgls systemd-tmpfiles inst_multiple -o \ /usr/lib/modules-load.d/*.conf \ /usr/lib/sysctl.d/*.conf modules_load_get() { local _line i for i in "$1"/*.conf; do [[ -f $i ]] || continue while read _line; do case $_line in \#*) ;; \;*) ;; *) echo $_line esac done < "$i" done } _mods=$(modules_load_get /usr/lib/modules-load.d) [[ $_mods ]] && hostonly='' instmods $_mods if [[ $hostonly ]]; then inst_multiple -o \ /etc/systemd/journald.conf \ /etc/systemd/system.conf \ /etc/hostname \ /etc/machine-id \ /etc/vconsole.conf \ /etc/locale.conf \ /etc/modules-load.d/*.conf \ /etc/sysctl.d/*.conf \ /etc/sysctl.conf _mods=$(modules_load_get /etc/modules-load.d) [[ $_mods ]] && hostonly='' instmods $_mods fi if ! [[ -e "$initdir/etc/machine-id" ]]; then > "$initdir/etc/machine-id" fi # install adm user/group for journald inst_multiple nologin egrep '^systemd-journal:' "$initdir/etc/passwd" 2>/dev/null >> "$initdir/etc/passwd" egrep '^systemd-journal:' /etc/group >> "$initdir/etc/group" ln_r $systemdutildir/systemd "/init" ln_r $systemdutildir/systemd "/sbin/init" inst_script "$moddir/dracut-emergency.sh" /bin/dracut-emergency inst_simple "$moddir/emergency.service" ${systemdsystemunitdir}/emergency.service inst_simple "$moddir/dracut-emergency.service" ${systemdsystemunitdir}/dracut-emergency.service inst_simple "$moddir/emergency.service" ${systemdsystemunitdir}/rescue.service ln_r "${systemdsystemunitdir}/initrd.target" "${systemdsystemunitdir}/default.target" inst_script "$moddir/dracut-cmdline.sh" /bin/dracut-cmdline inst_script "$moddir/dracut-cmdline-ask.sh" /bin/dracut-cmdline-ask inst_script "$moddir/dracut-pre-udev.sh" /bin/dracut-pre-udev inst_script "$moddir/dracut-pre-trigger.sh" /bin/dracut-pre-trigger inst_script "$moddir/dracut-initqueue.sh" /bin/dracut-initqueue inst_script "$moddir/dracut-pre-mount.sh" /bin/dracut-pre-mount inst_script "$moddir/dracut-mount.sh" /bin/dracut-mount inst_script "$moddir/dracut-pre-pivot.sh" /bin/dracut-pre-pivot inst_script "$moddir/rootfs-generator.sh" $systemdutildir/system-generators/dracut-rootfs-generator inst_binary true ln_r $(type -P true) "/usr/bin/loginctl" ln_r $(type -P true) "/bin/loginctl" inst_rules \ 70-uaccess.rules \ 71-seat.rules \ 73-seat-late.rules \ 90-vconsole.rules \ 99-systemd.rules for i in \ emergency.target \ dracut-emergency.service \ rescue.service \ systemd-ask-password-console.service \ systemd-ask-password-plymouth.service \ ; do mkdir -p "${initdir}${systemdsystemunitdir}/${i}.wants" ln_r "${systemdsystemunitdir}/systemd-vconsole-setup.service" \ "${systemdsystemunitdir}/${i}.wants/systemd-vconsole-setup.service" done mkdir -p "${initdir}/$systemdsystemunitdir/initrd.target.wants" for i in \ dracut-cmdline.service \ dracut-cmdline-ask.service \ dracut-initqueue.service \ dracut-mount.service \ dracut-pre-mount.service \ dracut-pre-pivot.service \ dracut-pre-trigger.service \ dracut-pre-udev.service \ ; do inst_simple "$moddir/${i}" "$systemdsystemunitdir/${i}" ln_r "$systemdsystemunitdir/${i}" "$systemdsystemunitdir/initrd.target.wants/${i}" done inst_simple "$moddir/dracut-tmpfiles.conf" "$tmpfilesdir/dracut-tmpfiles.conf" mkdir -p "$initdir/etc/systemd" # We must use a volatile journal, and we don't want rate-limiting { echo "[Journal]" echo "Storage=volatile" echo "RateLimitInterval=0" echo "RateLimitBurst=0" } >> "$initdir/etc/systemd/journald.conf" } modules.d/98systemd/dracut-emergency.service000064400000001716150252660330015136 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # See systemd.special(7) for details [Unit] Description=Dracut Emergency Shell DefaultDependencies=no After=systemd-vconsole-setup.service Wants=systemd-vconsole-setup.service ConditionPathExists=!/lib/dracut/no-emergency-shell Conflicts=shutdown.target emergency.target [Service] Environment=HOME=/ Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot WorkingDirectory=/ ExecStart=/bin/dracut-emergency ExecStopPost=-/bin/rm -f -- /.console_lock Type=oneshot StandardInput=tty-force StandardOutput=inherit StandardError=inherit KillMode=process IgnoreSIGPIPE=no # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/98systemd/dracut-cmdline.sh000075500000005232150252660330013545 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT [ -d /run/initramfs ] || mkdir -p -m 0755 /run/initramfs [ -d /run/lock ] || mkdir -p -m 0755 /run/lock [ -d /run/log ] || mkdir -p -m 0755 /run/log if [ -f /dracut-state.sh ]; then . /dracut-state.sh 2>/dev/null fi type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh [ -f /etc/initrd-release ] && . /etc/initrd-release [ -n "$VERSION" ] && info "dracut-$VERSION" info "Using kernel command line parameters:" $(getcmdline) getargbool 0 rd.udev.log-priority=info -d rd.udev.info -d -n -y rdudevinfo && echo 'udev_log="info"' >> /etc/udev/udev.conf getargbool 0 rd.udev.log-priority=debug -d rd.udev.debug -d -n -y rdudevdebug && echo 'udev_log="debug"' >> /etc/udev/udev.conf source_conf /etc/conf.d # Get the "root=" parameter from the kernel command line, but differentiate # between the case where it was set to the empty string and the case where it # wasn't specified at all. if ! root="$(getarg root=)"; then root_unset='UNSET' fi rflags="$(getarg rootflags=)" getargbool 0 ro && rflags="${rflags},ro" getargbool 0 rw && rflags="${rflags},rw" rflags="${rflags#,}" fstype="$(getarg rootfstype=)" if [ -z "$fstype" ]; then fstype="auto" fi export root export rflags export fstype make_trace_mem "hook cmdline" '1+:mem' '1+:iomem' '3+:slab' '4+:komem' # run scriptlets to parse the command line getarg 'rd.break=cmdline' -d 'rdbreak=cmdline' && emergency_shell -n cmdline "Break before cmdline" source_hook cmdline [ -f /lib/dracut/parse-resume.sh ] && . /lib/dracut/parse-resume.sh case "${root}${root_unset}" in block:LABEL=*|LABEL=*) root="${root#block:}" root="$(echo $root | sed 's,/,\\x2f,g')" root="block:/dev/disk/by-label/${root#LABEL=}" rootok=1 ;; block:UUID=*|UUID=*) root="${root#block:}" root="block:/dev/disk/by-uuid/${root#UUID=}" rootok=1 ;; block:PARTUUID=*|PARTUUID=*) root="${root#block:}" root="block:/dev/disk/by-partuuid/${root#PARTUUID=}" rootok=1 ;; block:PARTLABEL=*|PARTLABEL=*) root="${root#block:}" root="block:/dev/disk/by-partlabel/${root#PARTLABEL=}" rootok=1 ;; /dev/*) root="block:${root}" rootok=1 ;; UNSET|gpt-auto) # systemd's gpt-auto-generator handles this case. rootok=1 ;; esac [ -z "${root}${root_unset}" ] && die "Empty root= argument" [ -z "$rootok" ] && die "Don't know how to handle 'root=$root'" [ "$root" = "UNSET" ] && unset root export root rflags fstype netroot NEWROOT export -p > /dracut-state.sh exit 0 modules.d/98systemd/dracut-cmdline.service.8.asc000064400000000672150252660330015506 0ustar00DRACUT-CMDLINE.SERVICE(8) ========================= :doctype: manpage :man source: dracut :man manual: dracut NAME ---- dracut-cmdline.service - runs the dracut hooks to parse the kernel command line SYNOPSIS -------- dracut-cmdline.service DESCRIPTION ----------- This service runs all the dracut hooks to parse the kernel command line in the initramfs. AUTHORS ------- Harald Hoyer SEE ALSO -------- *dracut.bootup*(7) *dracut*(8) modules.d/98systemd/dracut-pre-udev.service000064400000002262150252660330014704 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # See systemd.special(7) for details [Unit] Description=dracut pre-udev hook Documentation=man:dracut-pre-udev.service(8) DefaultDependencies=no Before=systemd-udevd.service dracut-pre-trigger.service After=dracut-cmdline.service Wants=dracut-cmdline.service ConditionPathExists=/etc/initrd-release ConditionDirectoryNotEmpty=|/lib/dracut/hooks/pre-udev ConditionKernelCommandLine=|rd.break=pre-udev ConditionKernelCommandLine=|rd.driver.blacklist ConditionKernelCommandLine=|rd.driver.pre ConditionKernelCommandLine=|rd.driver.post Conflicts=shutdown.target emergency.target [Service] Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot Type=oneshot ExecStart=-/bin/dracut-pre-udev StandardInput=null StandardOutput=syslog StandardError=syslog+console KillMode=process RemainAfterExit=yes # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/98systemd/dracut-initqueue.service.8000064400000003014150252660330015327 0ustar00'\" t .\" Title: dracut-initqueue.service .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.78.1 .\" Date: 09/12/2013 .\" Manual: dracut .\" Source: dracut .\" Language: English .\" .TH "DRACUT\-INITQUEUE\&." "8" "09/12/2013" "dracut" "dracut" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" dracut-initqueue.service \- runs the dracut main loop to find the real root .SH "SYNOPSIS" .sp dracut\-initqueue\&.service .SH "DESCRIPTION" .sp This service runs all the main loop of dracut in the initramfs to find the real root\&. .SH "AUTHORS" .sp Harald Hoyer .SH "SEE ALSO" .sp \fBdracut\&.bootup\fR(7) \fBdracut\fR(8) modules.d/98systemd/dracut-pre-pivot.service.8.asc000064400000000655150252660330016021 0ustar00DRACUT-PRE-PIVOT.SERVICE(8) =========================== :doctype: manpage :man source: dracut :man manual: dracut NAME ---- dracut-pre-pivot.service - runs the dracut hooks before switching root SYNOPSIS -------- dracut-pre-pivot.service DESCRIPTION ----------- This service runs all dracut hooks before the system switched to the real root. AUTHORS ------- Harald Hoyer SEE ALSO -------- *dracut.bootup*(7) *dracut*(8) modules.d/98systemd/dracut-pre-udev.sh000075500000002763150252660330013667 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh export DRACUT_SYSTEMD=1 if [ -f /dracut-state.sh ]; then . /dracut-state.sh 2>/dev/null fi type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh source_conf /etc/conf.d make_trace_mem "hook pre-udev" '1:shortmem' '2+:mem' '3+:slab' # pre pivot scripts are sourced just before we doing cleanup and switch over # to the new root. getarg 'rd.break=pre-udev' 'rdbreak=pre-udev' && emergency_shell -n pre-udev "Break pre-udev" source_hook pre-udev _modprobe_d=/etc/modprobe.d if [ -d /usr/lib/modprobe.d ] ; then _modprobe_d=/usr/lib/modprobe.d elif [ -d /lib/modprobe.d ] ; then _modprobe_d=/lib/modprobe.d elif [ ! -d $_modprobe_d ] ; then mkdir -p $_modprobe_d fi for i in $(getargs rd.driver.pre -d rdloaddriver=); do ( IFS=, for p in $i; do modprobe $p 2>&1 | vinfo done ) done [ -d /etc/modprobe.d ] || mkdir -p /etc/modprobe.d for i in $(getargs rd.driver.blacklist -d rdblacklist=); do ( IFS=, for p in $i; do echo "blacklist $p" >> $_modprobe_d/initramfsblacklist.conf done ) done for p in $(getargs rd.driver.post -d rdinsmodpost=); do echo "blacklist $p" >> $_modprobe_d/initramfsblacklist.conf _do_insmodpost=1 done [ -n "$_do_insmodpost" ] && initqueue --settled --unique --onetime insmodpost.sh unset _do_insmodpost _modprobe_d unset i export -p > /dracut-state.sh exit 0 modules.d/98systemd/dracut-pre-pivot.service.8000064400000003003150252660330015242 0ustar00'\" t .\" Title: dracut-pre-pivot.service .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.78.1 .\" Date: 09/12/2013 .\" Manual: dracut .\" Source: dracut .\" Language: English .\" .TH "DRACUT\-PRE\-PIVOT\&" "8" "09/12/2013" "dracut" "dracut" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" dracut-pre-pivot.service \- runs the dracut hooks before switching root .SH "SYNOPSIS" .sp dracut\-pre\-pivot\&.service .SH "DESCRIPTION" .sp This service runs all dracut hooks before the system switched to the real root\&. .SH "AUTHORS" .sp Harald Hoyer .SH "SEE ALSO" .sp \fBdracut\&.bootup\fR(7) \fBdracut\fR(8) modules.d/98systemd/dracut-pre-mount.service.8.asc000064400000000662150252660330016020 0ustar00DRACUT-PRE-MOUNT.SERVICE(8) =========================== :doctype: manpage :man source: dracut :man manual: dracut NAME ---- dracut-pre-mount.service - runs the dracut hooks before /sysroot is mounted SYNOPSIS -------- dracut-pre-mount.service DESCRIPTION ----------- This service runs all dracut hooks before the real root is mounted on /sysroot. AUTHORS ------- Harald Hoyer SEE ALSO -------- *dracut.bootup*(7) *dracut*(8) modules.d/98systemd/emergency.service000064400000001724150252660330013655 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # See systemd.special(7) for details [Unit] Description=Emergency Shell DefaultDependencies=no After=systemd-vconsole-setup.service Wants=systemd-vconsole-setup.service ConditionPathExists=!/lib/dracut/no-emergency-shell Conflicts=shutdown.target [Service] Environment=HOME=/ Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot WorkingDirectory=/ ExecStart=-/bin/dracut-emergency ExecStopPost=-/usr/bin/systemctl --no-block isolate default.target StandardInput=tty-force StandardOutput=inherit StandardError=inherit KillMode=process IgnoreSIGPIPE=no TimeoutStartSec=0 # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/98systemd/dracut-mount.service.8.asc000064400000000640150252660330015230 0ustar00DRACUT-MOUNT.SERVICE(8) ======================= :doctype: manpage :man source: dracut :man manual: dracut NAME ---- dracut-mount.service - runs the dracut hooks after /sysroot is mounted SYNOPSIS -------- dracut-mount.service DESCRIPTION ----------- This service runs all dracut hooks after the real root is mounted on /sysroot. AUTHORS ------- Harald Hoyer SEE ALSO -------- *dracut.bootup*(7) *dracut*(8) modules.d/98systemd/dracut-shutdown.service000064400000001245150252660330015030 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. [Unit] Description=Restore /run/initramfs Documentation=man:dracut-shutdown.service(8) After=getty@tty1.service display-manager.service Before=systemd-reboot.service shutdown.target DefaultDependencies=no ConditionPathExists=/run/initramfs/.need_shutdown ConditionPathExists=!/run/initramfs/bin/sh [Service] ExecStart=-/usr/lib/dracut/dracut-initramfs-restore Type=oneshot RemainAfterExit=yes modules.d/98systemd/dracut-cmdline.service000064400000002210150252660330014561 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # See systemd.special(7) for details [Unit] Description=dracut cmdline hook Documentation=man:dracut-cmdline.service(8) DefaultDependencies=no Before=dracut-pre-udev.service After=systemd-journald.socket Wants=systemd-journald.socket ConditionPathExists=/etc/initrd-release ConditionPathExistsGlob=|/etc/cmdline.d/*.conf ConditionDirectoryNotEmpty=|/lib/dracut/hooks/cmdline ConditionKernelCommandLine=|rd.break=cmdline ConditionKernelCommandLine=|resume ConditionKernelCommandLine=|noresume Conflicts=shutdown.target emergency.target [Service] Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot Type=oneshot ExecStart=-/bin/dracut-cmdline StandardInput=null StandardOutput=syslog StandardError=syslog+console KillMode=process RemainAfterExit=yes # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/98systemd/dracut-pre-udev.service.8000064400000002777150252660330015065 0ustar00'\" t .\" Title: dracut-pre-udev.service .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.78.1 .\" Date: 09/12/2013 .\" Manual: dracut .\" Source: dracut .\" Language: English .\" .TH "DRACUT\-PRE\-UDEV\&." "8" "09/12/2013" "dracut" "dracut" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" dracut-pre-udev.service \- runs the dracut hooks before udevd is started .SH "SYNOPSIS" .sp dracut\-pre\-udev\&.service .SH "DESCRIPTION" .sp This service runs all dracut hooks before udevd is started in the initramfs\&. .SH "AUTHORS" .sp Harald Hoyer .SH "SEE ALSO" .sp \fBdracut\&.bootup\fR(7) \fBdracut\fR(8) modules.d/98systemd/dracut-initqueue.service000064400000002567150252660330015175 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # See systemd.special(7) for details [Unit] Description=dracut initqueue hook Documentation=man:dracut-initqueue.service(8) DefaultDependencies=no Before=remote-fs-pre.target Wants=remote-fs-pre.target After=systemd-udev-trigger.service Wants=systemd-udev-trigger.service ConditionPathExists=/etc/initrd-release ConditionPathExists=|/lib/dracut/need-initqueue ConditionPathExistsGlob=|/lib/dracut/hooks/initqueue/*.sh ConditionPathExistsGlob=|/lib/dracut/hooks/initqueue/settled/*.sh ConditionPathExistsGlob=|/lib/dracut/hooks/initqueue/finished/*.sh ConditionPathExistsGlob=|/lib/dracut/hooks/initqueue/online/*.sh ConditionPathExistsGlob=|/lib/dracut/hooks/initqueue/timeout/*.sh ConditionKernelCommandLine=|rd.break=initqueue Conflicts=shutdown.target emergency.target [Service] Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot Type=oneshot ExecStart=-/bin/dracut-initqueue StandardInput=null StandardOutput=syslog StandardError=syslog+console KillMode=process RemainAfterExit=yes # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/98systemd/dracut-pre-mount.service.8000064400000003010150252660330015241 0ustar00'\" t .\" Title: dracut-pre-mount.service .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.78.1 .\" Date: 09/12/2013 .\" Manual: dracut .\" Source: dracut .\" Language: English .\" .TH "DRACUT\-PRE\-MOUNT\&" "8" "09/12/2013" "dracut" "dracut" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" dracut-pre-mount.service \- runs the dracut hooks before /sysroot is mounted .SH "SYNOPSIS" .sp dracut\-pre\-mount\&.service .SH "DESCRIPTION" .sp This service runs all dracut hooks before the real root is mounted on /sysroot\&. .SH "AUTHORS" .sp Harald Hoyer .SH "SEE ALSO" .sp \fBdracut\&.bootup\fR(7) \fBdracut\fR(8) modules.d/98systemd/dracut-pre-pivot.service000064400000002042150252660330015076 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # See systemd.special(7) for details [Unit] Description=dracut pre-pivot and cleanup hook Documentation=man:dracut-pre-pivot.service(8) After=initrd.target initrd-parse-etc.service sysroot.mount After=dracut-initqueue.service dracut-pre-mount.service dracut-mount.service Before=initrd-cleanup.service Wants=remote-fs.target After=remote-fs.target ConditionPathExists=/etc/initrd-release Conflicts=shutdown.target emergency.target [Service] Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot Type=oneshot ExecStart=-/bin/dracut-pre-pivot StandardInput=null StandardOutput=syslog StandardError=syslog+console KillMode=process RemainAfterExit=yes # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/98systemd/dracut-mount.sh000075500000002222150252660330013270 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh export DRACUT_SYSTEMD=1 if [ -f /dracut-state.sh ]; then . /dracut-state.sh 2>/dev/null fi type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh source_conf /etc/conf.d make_trace_mem "hook mount" '1:shortmem' '2+:mem' '3+:slab' getarg 'rd.break=mount' -d 'rdbreak=mount' && emergency_shell -n mount "Break mount" # mount scripts actually try to mount the root filesystem, and may # be sourced any number of times. As soon as one suceeds, no more are sourced. i=0 while :; do if ismounted "$NEWROOT"; then usable_root "$NEWROOT" && break; umount "$NEWROOT" fi for f in $hookdir/mount/*.sh; do [ -f "$f" ] && . "$f" if ismounted "$NEWROOT"; then usable_root "$NEWROOT" && break; warn "$NEWROOT has no proper rootfs layout, ignoring and removing offending mount hook" umount "$NEWROOT" rm -f -- "$f" fi done i=$(($i+1)) [ $i -gt 20 ] && action_on_fail "Can't mount root filesystem" && break done export -p > /dracut-state.sh exit 0 modules.d/98systemd/dracut-pre-pivot.sh000075500000002227150252660330014060 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh export DRACUT_SYSTEMD=1 if [ -f /dracut-state.sh ]; then . /dracut-state.sh 2>/dev/null fi type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh source_conf /etc/conf.d make_trace_mem "hook pre-pivot" '1:shortmem' '2+:mem' '3+:slab' '4+:komem' # pre pivot scripts are sourced just before we doing cleanup and switch over # to the new root. getarg 'rd.break=pre-pivot' 'rdbreak=pre-pivot' && emergency_shell -n pre-pivot "Break pre-pivot" source_hook pre-pivot cleanup_trace_mem # pre pivot cleanup scripts are sourced just before we switch over to the new root. getarg 'rd.break=cleanup' 'rdbreak=cleanup' && emergency_shell -n cleanup "Break cleanup" source_hook cleanup getarg rd.break -d rdbreak && emergency_shell -n switch_root "Break before switch_root" # remove helper symlink [ -h /dev/root ] && rm -f -- /dev/root [ -h /dev/nfs ] && rm -f -- /dev/nfs udevadm settle cnt=0 while ! udevadm settle --timeout=0; do info "udev still not settled. Waiting." udevadm settle cnt=$(($cnt+1)) [ $cnt -gt 10 ] && break done exit 0 modules.d/98systemd/dracut-pre-mount.service000064400000002042150252660330015077 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # See systemd.special(7) for details [Unit] Description=dracut pre-mount hook Documentation=man:dracut-pre-mount.service(8) DefaultDependencies=no Before=initrd-root-fs.target sysroot.mount After=dracut-initqueue.service After=cryptsetup.target ConditionPathExists=/etc/initrd-release ConditionDirectoryNotEmpty=|/lib/dracut/hooks/pre-mount ConditionKernelCommandLine=|rd.break=pre-mount Conflicts=shutdown.target emergency.target [Service] Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot Type=oneshot ExecStart=-/bin/dracut-pre-mount StandardInput=null StandardOutput=syslog StandardError=syslog+console KillMode=process RemainAfterExit=yes # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/98systemd/dracut-initqueue.sh000075500000004257150252660330014150 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh export DRACUT_SYSTEMD=1 if [ -f /dracut-state.sh ]; then . /dracut-state.sh 2>/dev/null fi type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh source_conf /etc/conf.d make_trace_mem "hook initqueue" '1:shortmem' '2+:mem' '3+:slab' getarg 'rd.break=initqueue' -d 'rdbreak=initqueue' && emergency_shell -n initqueue "Break before initqueue" RDRETRY=$(getarg rd.retry -d 'rd_retry=') RDRETRY=${RDRETRY:-180} RDRETRY=$(($RDRETRY*2)) export RDRETRY main_loop=0 export main_loop while :; do check_finished && break udevadm settle --exit-if-exists=$hookdir/initqueue/work check_finished && break if [ -f $hookdir/initqueue/work ]; then rm -f -- "$hookdir/initqueue/work" fi for job in $hookdir/initqueue/*.sh; do [ -e "$job" ] || break job=$job . $job check_finished && break 2 done udevadm settle --timeout=0 >/dev/null 2>&1 || continue for job in $hookdir/initqueue/settled/*.sh; do [ -e "$job" ] || break job=$job . $job check_finished && break 2 done udevadm settle --timeout=0 >/dev/null 2>&1 || continue # no more udev jobs and queues empty. sleep 0.5 for i in /run/systemd/ask-password/ask.*; do [ -e "$i" ] && continue 2 done if [ $main_loop -gt $((2*$RDRETRY/3)) ]; then warn "dracut-initqueue timeout - starting timeout scripts" for job in $hookdir/initqueue/timeout/*.sh; do [ -e "$job" ] || break job=$job . $job udevadm settle --timeout=0 >/dev/null 2>&1 || main_loop=0 [ -f $hookdir/initqueue/work ] && main_loop=0 done fi main_loop=$(($main_loop+1)) if [ $main_loop -gt $RDRETRY ]; then if ! [ -f /sysroot/etc/fstab ] || ! [ -e /sysroot/sbin/init ] ; then action_on_fail "Could not boot." && break fi warn "Not all disks have been found." warn "You might want to regenerate your initramfs." break fi done unset job unset queuetriggered unset main_loop unset RDRETRY export -p > /dracut-state.sh exit 0 modules.d/98systemd/dracut-pre-mount.sh000075500000001156150252660330014061 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh export DRACUT_SYSTEMD=1 if [ -f /dracut-state.sh ]; then . /dracut-state.sh 2>/dev/null fi type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh source_conf /etc/conf.d make_trace_mem "hook pre-mount" '1:shortmem' '2+:mem' '3+:slab' '4+:komem' # pre pivot scripts are sourced just before we doing cleanup and switch over # to the new root. getarg 'rd.break=pre-mount' 'rdbreak=pre-mount' && emergency_shell -n pre-mount "Break pre-mount" source_hook pre-mount export -p > /dracut-state.sh exit 0 modules.d/98systemd/initrd.target000064400000000367150252660330013020 0ustar00[Unit] Description=Initrd Target Requires=basic.target Conflicts=rescue.service rescue.target After=basic.target rescue.service rescue.target AllowIsolate=yes OnFailure=emergency.target OnFailureIsolate=yes ConditionPathExists=/etc/initrd-release modules.d/98systemd/rescue.service000064400000001555150252660330013167 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # See systemd.special(7) for details [Unit] Description=Rescue Shell DefaultDependencies=no [Service] Environment=HOME=/ Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot WorkingDirectory=/ ExecStartPre=-/bin/plymouth quit ExecStart=-/bin/sh -i -l ExecStopPost=-/bin/rm -f -- /.console_lock ExecStopPost=-/usr/bin/systemctl --fail --no-block default Type=idle StandardInput=tty-force StandardOutput=inherit StandardError=inherit KillMode=process IgnoreSIGPIPE=no # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/98systemd/dracut-pre-udev.service.8.asc000064400000000650150252660330015616 0ustar00DRACUT-PRE-UDEV.SERVICE(8) ========================== :doctype: manpage :man source: dracut :man manual: dracut NAME ---- dracut-pre-udev.service - runs the dracut hooks before udevd is started SYNOPSIS -------- dracut-pre-udev.service DESCRIPTION ----------- This service runs all dracut hooks before udevd is started in the initramfs. AUTHORS ------- Harald Hoyer SEE ALSO -------- *dracut.bootup*(7) *dracut*(8) modules.d/98systemd/dracut-mount.service000064400000002002150252660330014307 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # See systemd.special(7) for details [Unit] Description=dracut mount hook Documentation=man:dracut-mount.service(8) After=initrd-root-fs.target initrd-parse-etc.service After=dracut-initqueue.service dracut-pre-mount.service ConditionPathExists=/etc/initrd-release ConditionDirectoryNotEmpty=|/lib/dracut/hooks/mount ConditionKernelCommandLine=|rd.break=mount Conflicts=shutdown.target emergency.target [Service] Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot Type=oneshot ExecStart=-/bin/dracut-mount StandardInput=null StandardOutput=syslog StandardError=syslog+console KillMode=process RemainAfterExit=yes # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/98systemd/dracut-shutdown.service.8000064400000007027150252660330015202 0ustar00'\" t .\" Title: dracut-shutdown.service .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.78.1 .\" Date: 09/12/2013 .\" Manual: dracut .\" Source: dracut .\" Language: English .\" .TH "DRACUT\-SHUTDOWN\&.S" "8" "09/12/2013" "dracut" "dracut" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" dracut-shutdown.service \- unpack the initramfs to /run/initramfs .SH "SYNOPSIS" .sp dracut\-shutdown\&.service .SH "DESCRIPTION" .sp This service unpacks the initramfs image to /run/initramfs\&. systemd pivots into /run/initramfs at shutdown, so the root filesytem can be safely unmounted\&. .sp The following steps are executed during a shutdown: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} systemd switches to the shutdown\&.target .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} systemd starts /lib/systemd/system/shutdown\&.target\&.wants/dracut\-shutdown\&.service .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} dracut\-shutdown\&.service executes /usr/lib/dracut/dracut\-initramfs\-restore which unpacks the initramfs to /run/initramfs .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} systemd finishes shutdown\&.target .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} systemd kills all processes .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} systemd tries to unmount everything and mounts the remaining read\-only .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} systemd checks, if there is a /run/initramfs/shutdown executable .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} if yes, it does a pivot_root to /run/initramfs and executes \&./shutdown\&. The old root is then mounted on /oldroot\&. /usr/lib/dracut/modules\&.d/99shutdown/shutdown\&.sh is the shutdown executable\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} shutdown will try to umount every /oldroot mount and calls the various shutdown hooks from the dracut modules .RE .sp This ensures, that all devices are disassembled and unmounted cleanly\&. .sp To debug the shutdown process, you can get a shell in the shutdown procedure by injecting "rd\&.break=pre\-shutdown rd\&.shell" or "rd\&.break=shutdown rd\&.shell"\&. .sp .if n \{\ .RS 4 .\} .nf # mkdir \-p /run/initramfs/etc/cmdline\&.d # echo "rd\&.break=pre\-shutdown rd\&.shell" > /run/initramfs/etc/cmdline\&.d/debug\&.conf # touch /run/initramfs/\&.need_shutdown .fi .if n \{\ .RE .\} .SH "AUTHORS" .sp Harald Hoyer .SH "SEE ALSO" .sp \fBdracut\fR(8) modules.d/98systemd/dracut-mount.service.8000064400000002771150252660330014472 0ustar00'\" t .\" Title: dracut-mount.service .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.78.1 .\" Date: 09/12/2013 .\" Manual: dracut .\" Source: dracut .\" Language: English .\" .TH "DRACUT\-MOUNT\&.SERV" "8" "09/12/2013" "dracut" "dracut" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" dracut-mount.service \- runs the dracut hooks after /sysroot is mounted .SH "SYNOPSIS" .sp dracut\-mount\&.service .SH "DESCRIPTION" .sp This service runs all dracut hooks after the real root is mounted on /sysroot\&. .SH "AUTHORS" .sp Harald Hoyer .SH "SEE ALSO" .sp \fBdracut\&.bootup\fR(7) \fBdracut\fR(8) modules.d/98systemd/dracut-initqueue.service.8.asc000064400000000667150252660330016107 0ustar00DRACUT-INITQUEUE.SERVICE(8) =========================== :doctype: manpage :man source: dracut :man manual: dracut NAME ---- dracut-initqueue.service - runs the dracut main loop to find the real root SYNOPSIS -------- dracut-initqueue.service DESCRIPTION ----------- This service runs all the main loop of dracut in the initramfs to find the real root. AUTHORS ------- Harald Hoyer SEE ALSO -------- *dracut.bootup*(7) *dracut*(8) modules.d/98systemd/dracut-pre-trigger.sh000075500000001114150252660330014354 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh export DRACUT_SYSTEMD=1 if [ -f /dracut-state.sh ]; then . /dracut-state.sh 2>/dev/null fi type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh source_conf /etc/conf.d make_trace_mem "hook pre-trigger" '1:shortmem' '2+:mem' '3+:slab' '4+:komem' source_hook pre-trigger getarg 'rd.break=pre-trigger' 'rdbreak=pre-trigger' && emergency_shell -n pre-trigger "Break pre-trigger" udevadm control --reload >/dev/null 2>&1 || : export -p > /dracut-state.sh exit 0 modules.d/98systemd/dracut-cmdline.service.8000064400000003021150252660330014730 0ustar00'\" t .\" Title: dracut-cmdline.service .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.78.1 .\" Date: 09/12/2013 .\" Manual: dracut .\" Source: dracut .\" Language: English .\" .TH "DRACUT\-CMDLINE\&.SE" "8" "09/12/2013" "dracut" "dracut" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" dracut-cmdline.service \- runs the dracut hooks to parse the kernel command line .SH "SYNOPSIS" .sp dracut\-cmdline\&.service .SH "DESCRIPTION" .sp This service runs all the dracut hooks to parse the kernel command line in the initramfs\&. .SH "AUTHORS" .sp Harald Hoyer .SH "SEE ALSO" .sp \fBdracut\&.bootup\fR(7) \fBdracut\fR(8) modules.d/98systemd/dracut-pre-trigger.service.8.asc000064400000000670150252660340016321 0ustar00DRACUT-PRE-TRIGGER.SERVICE(8) ============================= :doctype: manpage :man source: dracut :man manual: dracut NAME ---- dracut-pre-trigger.service - runs the dracut hooks before udevd is triggered SYNOPSIS -------- dracut-pre-trigger.service DESCRIPTION ----------- This service runs all dracut hooks before udevd is triggered in the initramfs. AUTHORS ------- Harald Hoyer SEE ALSO -------- *dracut.bootup*(7) *dracut*(8) modules.d/98systemd/dracut-tmpfiles.conf000064400000000207150252660340014263 0ustar00d /run/initramfs 0755 root root - d /run/initramfs/log 0755 root root - L /var/log - - - - ../run/initramfs/log modules.d/98systemd/dracut-pre-trigger.service000064400000002222150252660340015401 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # See systemd.special(7) for details [Unit] Description=dracut pre-trigger hook Documentation=man:dracut-pre-trigger.service(8) DefaultDependencies=no Before=systemd-udev-trigger.service dracut-initqueue.service After=dracut-pre-udev.service systemd-udevd.service systemd-tmpfiles-setup-dev.service Wants=dracut-pre-udev.service systemd-udevd.service ConditionPathExists=/etc/initrd-release ConditionDirectoryNotEmpty=|/lib/dracut/hooks/pre-trigger ConditionKernelCommandLine=|rd.break=pre-trigger Conflicts=shutdown.target emergency.target [Service] Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot Type=oneshot ExecStart=-/bin/dracut-pre-trigger StandardInput=null StandardOutput=syslog StandardError=syslog+console KillMode=process RemainAfterExit=yes # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/98systemd/dracut-emergency.sh000075500000002476150252660340014120 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh export DRACUT_SYSTEMD=1 if [ -f /dracut-state.sh ]; then . /dracut-state.sh 2>/dev/null fi type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh source_conf /etc/conf.d type plymouth >/dev/null 2>&1 && plymouth quit export _rdshell_name="dracut" action="Boot" hook="emergency" source_hook "$hook" _emergency_action=$(getarg rd.emergency) if getargbool 1 rd.shell -d -y rdshell || getarg rd.break -d rdbreak; then echo rdsosreport echo echo echo 'Entering emergency mode. Exit the shell to continue.' echo 'Type "journalctl" to view system logs.' echo 'You might want to save "/run/initramfs/rdsosreport.txt" to a USB stick or /boot' echo 'after mounting them and attach it to a bug report.' echo echo [ -f /etc/profile ] && . /etc/profile [ -z "$PS1" ] && export PS1="$_name:\${PWD}# " exec sh -i -l else warn "$action has failed. To debug this issue add \"rd.shell rd.debug\" to the kernel command line." [ -z "$_emergency_action" ] && _emergency_action=halt fi /bin/rm -f -- /.console_lock case "$_emergency_action" in reboot) reboot || exit 1;; poweroff) poweroff || exit 1;; halt) halt || exit 1;; esac exit 0 modules.d/98systemd/dracut-shutdown.service.8.asc000064400000003231150252660340015741 0ustar00DRACUT-SHUTDOWN.SERVICE(8) =========================== :doctype: manpage :man source: dracut :man manual: dracut NAME ---- dracut-shutdown.service - unpack the initramfs to /run/initramfs SYNOPSIS -------- dracut-shutdown.service DESCRIPTION ----------- This service unpacks the initramfs image to /run/initramfs. systemd pivots into /run/initramfs at shutdown, so the root filesytem can be safely unmounted. The following steps are executed during a shutdown: * systemd switches to the shutdown.target * systemd starts /lib/systemd/system/shutdown.target.wants/dracut-shutdown.service * dracut-shutdown.service executes /usr/lib/dracut/dracut-initramfs-restore which unpacks the initramfs to /run/initramfs * systemd finishes shutdown.target * systemd kills all processes * systemd tries to unmount everything and mounts the remaining read-only * systemd checks, if there is a /run/initramfs/shutdown executable * if yes, it does a pivot_root to /run/initramfs and executes ./shutdown. The old root is then mounted on /oldroot. /usr/lib/dracut/modules.d/99shutdown/shutdown.sh is the shutdown executable. * shutdown will try to umount every /oldroot mount and calls the various shutdown hooks from the dracut modules This ensures, that all devices are disassembled and unmounted cleanly. To debug the shutdown process, you can get a shell in the shutdown procedure by injecting "rd.break=pre-shutdown rd.shell" or "rd.break=shutdown rd.shell". ---- # mkdir -p /run/initramfs/etc/cmdline.d # echo "rd.break=pre-shutdown rd.shell" > /run/initramfs/etc/cmdline.d/debug.conf # touch /run/initramfs/.need_shutdown ---- AUTHORS ------- Harald Hoyer SEE ALSO -------- *dracut*(8) modules.d/98systemd/dracut-cmdline-ask.service000064400000001722150252660340015345 0ustar00# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # See systemd.special(7) for details [Unit] Description=dracut ask for additional cmdline parameters DefaultDependencies=no Before=dracut-cmdline.service After=systemd-journald.socket Wants=systemd-journald.socket ConditionPathExists=/etc/initrd-release ConditionKernelCommandLine=rd.cmdline=ask Conflicts=shutdown.target emergency.target [Service] Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot Type=oneshot ExecStart=-/bin/dracut-cmdline-ask StandardInput=tty StandardOutput=inherit StandardError=inherit RemainAfterExit=yes KillMode=process IgnoreSIGPIPE=no # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. KillSignal=SIGHUP modules.d/90dmsquash-live/parse-dmsquash-live.sh000075500000003232150252660340015625 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # live images are specified with # root=live:backingdev [ -z "$root" ] && root=$(getarg root=) # support legacy syntax of passing liveimg and then just the base root if getargbool 0 rd.live.image -d -y liveimg; then liveroot="live:$root" fi if [ "${root%%:*}" = "live" ] ; then liveroot=$root fi [ "${liveroot%%:*}" = "live" ] || return modprobe -q loop case "$liveroot" in live:LABEL=*|LABEL=*) \ root="${root#live:}" root="$(echo $root | sed 's,/,\\x2f,g')" root="live:/dev/disk/by-label/${root#LABEL=}" rootok=1 ;; live:CDLABEL=*|CDLABEL=*) \ root="${root#live:}" root="$(echo $root | sed 's,/,\\x2f,g')" root="live:/dev/disk/by-label/${root#CDLABEL=}" rootok=1 ;; live:UUID=*|UUID=*) \ root="${root#live:}" root="live:/dev/disk/by-uuid/${root#UUID=}" rootok=1 ;; live:PARTUUID=*|PARTUUID=*) \ root="${root#live:}" root="live:/dev/disk/by-partuuid/${root#PARTUUID=}" rootok=1 ;; live:PARTLABEL=*|PARTLABEL=*) \ root="${root#live:}" root="live:/dev/disk/by-partlabel/${root#PARTLABEL=}" rootok=1 ;; live:/*.[Ii][Ss][Oo]|/*.[Ii][Ss][Oo]) root="${root#live:}" root="liveiso:${root}" rootok=1 ;; live:/dev/*) rootok=1 ;; live:/*.[Ii][Mm][Gg]|/*.[Ii][Mm][Gg]) [ -f "${root#live:}" ] && rootok=1 ;; esac info "root was $liveroot, is now $root" # make sure that init doesn't complain [ -z "$root" ] && root="live" wait_for_dev -n /dev/mapper/live-rw modules.d/90dmsquash-live/module-setup.sh000075500000002255150252660340014362 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { # a live host-only image doesn't really make a lot of sense [[ $hostonly ]] && return 1 return 255 } depends() { # if dmsetup is not installed, then we cannot support fedora/red hat # style live images echo dm rootfs-block img-lib return 0 } installkernel() { instmods squashfs loop iso9660 } install() { inst_multiple umount dmsetup blkid dd losetup grep blockdev inst_multiple -o checkisomd5 inst_hook cmdline 30 "$moddir/parse-dmsquash-live.sh" inst_hook cmdline 31 "$moddir/parse-iso-scan.sh" inst_hook pre-udev 30 "$moddir/dmsquash-live-genrules.sh" inst_hook pre-udev 30 "$moddir/dmsquash-liveiso-genrules.sh" inst_hook pre-pivot 20 "$moddir/apply-live-updates.sh" inst_script "$moddir/dmsquash-live-root.sh" "/sbin/dmsquash-live-root" inst_script "$moddir/iso-scan.sh" "/sbin/iso-scan" # should probably just be generally included inst_rules 60-cdrom_id.rules inst_simple "$moddir/checkisomd5@.service" "/etc/systemd/system/checkisomd5@.service" dracut_need_initqueue } modules.d/90dmsquash-live/apply-live-updates.sh000075500000000754150252660340015466 0ustar00#!/bin/sh if [ -b /dev/mapper/live-rw ] && [ -d /updates ]; then info "Applying updates to live image..." mount -o bind /run $NEWROOT/run # avoid overwriting symlinks (e.g. /lib -> /usr/lib) with directories ( cd /updates find . -depth -type d | while read dir; do mkdir -p "$NEWROOT/$dir" done find . -depth \! -type d | while read file; do cp -a "$file" "$NEWROOT/$file" done ) umount $NEWROOT/run fi modules.d/90dmsquash-live/iso-scan.sh000075500000001605150252660340013451 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh PATH=/usr/sbin:/usr/bin:/sbin:/bin isofile=$1 [ -z "$isofile" ] && exit 1 ismounted "/run/initramfs/isoscan" && exit 0 mkdir -p "/run/initramfs/isoscan" do_iso_scan() { local _name local dev for dev in /dev/disk/by-uuid/*; do _name=$(dev_unit_name "$dev") [ -e /tmp/isoscan-${_name} ] && continue > /tmp/isoscan-${_name} mount -t auto -o ro "$dev" "/run/initramfs/isoscan" || continue if [ -f "/run/initramfs/isoscan/$isofile" ]; then losetup -f "/run/initramfs/isoscan/$isofile" rm -f -- "$job" exit 0 else umount "/run/initramfs/isoscan" fi done } do_iso_scan rmdir "/run/initramfs/isoscan" exit 1 modules.d/90dmsquash-live/dmsquash-live-genrules.sh000075500000001316150252660340016340 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh case "$root" in live:/dev/*) { printf 'KERNEL=="%s", RUN+="/sbin/initqueue --settled --onetime --unique /sbin/dmsquash-live-root $env{DEVNAME}"\n' \ ${root#live:/dev/} printf 'SYMLINK=="%s", RUN+="/sbin/initqueue --settled --onetime --unique /sbin/dmsquash-live-root $env{DEVNAME}"\n' \ ${root#live:/dev/} } >> /etc/udev/rules.d/99-live-squash.rules wait_for_dev -n "${root#live:}" ;; live:*) if [ -f "${root#live:}" ]; then /sbin/initqueue --settled --onetime --unique /sbin/dmsquash-live-root "${root#live:}" fi ;; esac modules.d/90dmsquash-live/dmsquash-live-root.sh000075500000024360150252660340015503 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh command -v unpack_archive >/dev/null || . /lib/img-lib.sh PATH=/usr/sbin:/usr/bin:/sbin:/bin if getargbool 0 rd.live.debug -n -y rdlivedebug; then exec > /tmp/liveroot.$$.out exec 2>> /tmp/liveroot.$$.out set -x fi [ -z "$1" ] && exit 1 livedev="$1" # parse various live image specific options that make sense to be # specified as their own things live_dir=$(getarg rd.live.dir -d live_dir) [ -z "$live_dir" ] && live_dir="LiveOS" squash_image=$(getarg rd.live.squashimg) [ -z "$squash_image" ] && squash_image="squashfs.img" getargbool 0 rd.live.ram -d -y live_ram && live_ram="yes" getargbool 0 rd.live.overlay.reset -d -y reset_overlay && reset_overlay="yes" getargbool 0 rd.live.overlay.readonly -d -y readonly_overlay && readonly_overlay="--readonly" || readonly_overlay="" overlay=$(getarg rd.live.overlay -d overlay) getargbool 0 rd.writable.fsimg -d -y writable_fsimg && writable_fsimg="yes" overlay_size=$(getarg rd.live.overlay.size=) [ -z "$overlay_size" ] && overlay_size=512 getargbool 0 rd.live.overlay.thin && thin_snapshot="yes" # CD/DVD media check [ -b $livedev ] && fs=$(blkid -s TYPE -o value $livedev) if [ "$fs" = "iso9660" -o "$fs" = "udf" ]; then check="yes" fi getarg rd.live.check -d check || check="" if [ -n "$check" ]; then type plymouth >/dev/null 2>&1 && plymouth --hide-splash if [ -n "$DRACUT_SYSTEMD" ]; then p=$(str_replace "$livedev" "-" '\x2d') systemctl start checkisomd5@${p}.service else checkisomd5 --verbose $livedev fi if [ $? -eq 1 ]; then die "CD check failed!" exit 1 fi type plymouth >/dev/null 2>&1 && plymouth --show-splash fi ln -s $livedev /run/initramfs/livedev # determine filesystem type for a filesystem image det_img_fs() { udevadm settle blkid -s TYPE -u noraid -o value "$1" } modprobe squashfs CMDLINE=$(getcmdline) for arg in $CMDLINE; do case $arg in ro|rw) liverw=$arg ;; esac; done # mount the backing of the live image first mkdir -m 0755 -p /run/initramfs/live if [ -f $livedev ]; then # no mount needed - we've already got the LiveOS image in initramfs # check filesystem type and handle accordingly fstype=$(det_img_fs $livedev) case $fstype in squashfs) SQUASHED=$livedev;; auto) die "cannot mount live image (unknown filesystem type)" ;; *) FSIMG=$livedev ;; esac [ -e /sys/fs/$fstype ] || modprobe $fstype else if [ "$(blkid -o value -s TYPE $livedev)" != "ntfs" ]; then mount -n -t $fstype -o ${liverw:-ro} $livedev /run/initramfs/live else # Symlinking /usr/bin/ntfs-3g as /sbin/mount.ntfs seems to boot # at the first glance, but ends with lots and lots of squashfs # errors, because systemd attempts to kill the ntfs-3g process?! if [ -x "/usr/bin/ntfs-3g" ]; then ( exec -a @ntfs-3g ntfs-3g -o ${liverw:-ro} $livedev /run/initramfs/live ) | vwarn else die "Failed to mount block device of live image: Missing NTFS support" exit 1 fi fi if [ "$?" != "0" ]; then die "Failed to mount block device of live image" exit 1 fi fi # overlay setup helper function do_live_overlay() { # create a sparse file for the overlay # overlay: if non-ram overlay searching is desired, do it, # otherwise, create traditional overlay in ram OVERLAY_LOOPDEV=$( losetup -f ) l=$(blkid -s LABEL -o value $livedev) || l="" u=$(blkid -s UUID -o value $livedev) || u="" if [ -z "$overlay" ]; then pathspec="/${live_dir}/overlay-$l-$u" elif ( echo $overlay | grep -q ":" ); then # pathspec specified, extract pathspec=$( echo $overlay | sed -e 's/^.*://' ) fi if [ -z "$pathspec" -o "$pathspec" = "auto" ]; then pathspec="/${live_dir}/overlay-$l-$u" fi devspec=$( echo $overlay | sed -e 's/:.*$//' ) # need to know where to look for the overlay setup="" if [ -n "$devspec" -a -n "$pathspec" -a -n "$overlay" ]; then mkdir -m 0755 /run/initramfs/overlayfs mount -n -t auto $devspec /run/initramfs/overlayfs || : if [ -f /run/initramfs/overlayfs$pathspec -a -w /run/initramfs/overlayfs$pathspec ]; then losetup $OVERLAY_LOOPDEV /run/initramfs/overlayfs$pathspec if [ -n "$reset_overlay" ]; then dd if=/dev/zero of=$OVERLAY_LOOPDEV bs=64k count=1 conv=fsync 2>/dev/null fi setup="yes" fi umount -l /run/initramfs/overlayfs || : fi if [ -z "$setup" -o -n "$readonly_overlay" ]; then if [ -n "$setup" ]; then warn "Using temporary overlay." elif [ -n "$devspec" -a -n "$pathspec" ]; then warn "Unable to find persistent overlay; using temporary" sleep 5 fi dd if=/dev/null of=/overlay bs=1024 count=1 seek=$((overlay_size*1024)) 2> /dev/null if [ -n "$setup" -a -n "$readonly_overlay" ]; then RO_OVERLAY_LOOPDEV=$( losetup -f ) losetup $RO_OVERLAY_LOOPDEV /overlay else losetup $OVERLAY_LOOPDEV /overlay fi fi # set up the snapshot sz=$(blockdev --getsz $BASE_LOOPDEV) if [ -n "$readonly_overlay" ]; then echo 0 $sz snapshot $BASE_LOOPDEV $OVERLAY_LOOPDEV p 8 | dmsetup create $readonly_overlay live-ro base="/dev/mapper/live-ro" over=$RO_OVERLAY_LOOPDEV else base=$BASE_LOOPDEV over=$OVERLAY_LOOPDEV fi if [ -n "$thin_snapshot" ]; then modprobe dm_thin_pool mkdir /run/initramfs/thin-overlay # In block units (512b) thin_data_sz=$(( $overlay_size * 1024 * 1024 / 512 )) thin_meta_sz=$(( $thin_data_sz / 10 )) # It is important to have the backing file on a tmpfs # this is needed to let the loopdevice support TRIM dd if=/dev/null of=/run/initramfs/thin-overlay/meta bs=1b count=1 seek=$((thin_meta_sz)) 2> /dev/null dd if=/dev/null of=/run/initramfs/thin-overlay/data bs=1b count=1 seek=$((thin_data_sz)) 2> /dev/null THIN_META_LOOPDEV=$( losetup --show -f /run/initramfs/thin-overlay/meta ) THIN_DATA_LOOPDEV=$( losetup --show -f /run/initramfs/thin-overlay/data ) echo 0 $thin_data_sz thin-pool $THIN_META_LOOPDEV $THIN_DATA_LOOPDEV 1024 1024 | dmsetup create live-overlay-pool dmsetup message /dev/mapper/live-overlay-pool 0 "create_thin 0" # Create a snapshot of the base image echo 0 $sz thin /dev/mapper/live-overlay-pool 0 $base | dmsetup create live-rw else echo 0 $sz snapshot $base $over p 8 | dmsetup create live-rw fi # Create a device that always points to a ro base image echo 0 $sz linear $base 0 | dmsetup create --readonly live-base } # live cd helper function do_live_from_base_loop() { do_live_overlay } # we might have a genMinInstDelta delta file for anaconda to take advantage of if [ -e /run/initramfs/live/${live_dir}/osmin.img ]; then OSMINSQFS=/run/initramfs/live/${live_dir}/osmin.img fi if [ -n "$OSMINSQFS" ]; then # decompress the delta data dd if=$OSMINSQFS of=/run/initramfs/osmin.img 2> /dev/null OSMIN_SQUASHED_LOOPDEV=$( losetup -f ) losetup -r $OSMIN_SQUASHED_LOOPDEV /run/initramfs/osmin.img mkdir -m 0755 -p /run/initramfs/squashfs.osmin mount -n -t squashfs -o ro $OSMIN_SQUASHED_LOOPDEV /run/initramfs/squashfs.osmin OSMIN_LOOPDEV=$( losetup -f ) losetup -r $OSMIN_LOOPDEV /run/initramfs/squashfs.osmin/osmin umount -l /run/initramfs/squashfs.osmin fi # we might have an embedded fs image on squashfs (compressed live) if [ -e /run/initramfs/live/${live_dir}/${squash_image} ]; then SQUASHED="/run/initramfs/live/${live_dir}/${squash_image}" fi if [ -e "$SQUASHED" ] ; then if [ -n "$live_ram" ] ; then echo "Copying live image to RAM..." echo "(this may take a few minutes)" dd if=$SQUASHED of=/run/initramfs/squashed.img bs=512 2> /dev/null umount -n /run/initramfs/live echo "Done copying live image to RAM." SQUASHED="/run/initramfs/squashed.img" fi SQUASHED_LOOPDEV=$( losetup -f ) losetup -r $SQUASHED_LOOPDEV $SQUASHED mkdir -m 0755 -p /run/initramfs/squashfs mount -n -t squashfs -o ro $SQUASHED_LOOPDEV /run/initramfs/squashfs fi # we might have an embedded fs image to use as rootfs (uncompressed live) if [ -e /run/initramfs/live/${live_dir}/ext3fs.img ]; then FSIMG="/run/initramfs/live/${live_dir}/ext3fs.img" elif [ -e /run/initramfs/live/${live_dir}/rootfs.img ]; then FSIMG="/run/initramfs/live/${live_dir}/rootfs.img" elif [ -f /run/initramfs/squashfs/LiveOS/ext3fs.img ]; then FSIMG="/run/initramfs/squashfs/LiveOS/ext3fs.img" elif [ -f /run/initramfs/squashfs/LiveOS/rootfs.img ]; then FSIMG="/run/initramfs/squashfs/LiveOS/rootfs.img" fi if [ -n "$FSIMG" ] ; then BASE_LOOPDEV=$( losetup -f ) if [ -n "$writable_fsimg" ] ; then # mount the provided fileysstem read/write echo "Unpacking live filesystem (may take some time)" mkdir /run/initramfs/fsimg/ if [ -n "$SQUASHED" ]; then cp -v $FSIMG /run/initramfs/fsimg/rootfs.img else unpack_archive $FSIMG /run/initramfs/fsimg/ fi losetup $BASE_LOOPDEV /run/initramfs/fsimg/rootfs.img echo "0 $( blockdev --getsize $BASE_LOOPDEV ) linear $BASE_LOOPDEV 0" | dmsetup create live-rw else # mount the filesystem read-only and add a dm snapshot for writes losetup -r $BASE_LOOPDEV $FSIMG do_live_from_base_loop fi fi [ -e "$SQUASHED" ] && umount -l /run/initramfs/squashfs if [ -b "$OSMIN_LOOPDEV" ]; then # set up the devicemapper snapshot device, which will merge # the normal live fs image, and the delta, into a minimzied fs image echo "0 $( blockdev --getsz $BASE_LOOPDEV ) snapshot $BASE_LOOPDEV $OSMIN_LOOPDEV p 8" | dmsetup create --readonly live-osimg-min fi ROOTFLAGS="$(getarg rootflags)" if [ -n "$ROOTFLAGS" ]; then ROOTFLAGS="-o $ROOTFLAGS" fi ln -s /dev/mapper/live-rw /dev/root printf 'mount %s /dev/mapper/live-rw %s\n' "$ROOTFLAGS" "$NEWROOT" > $hookdir/mount/01-$$-live.sh need_shutdown exit 0 modules.d/90dmsquash-live/checkisomd5@.service000064400000000414150252660340015253 0ustar00[Unit] Description=Media check on %f DefaultDependencies=no Before=shutdown.target [Service] Type=oneshot RemainAfterExit=no ExecStart=/bin/checkisomd5 --verbose %f StandardInput=tty-force StandardOutput=inherit StandardError=inherit TimeoutSec=0 SuccessExitStatus=2 modules.d/90dmsquash-live/dmsquash-liveiso-genrules.sh000075500000000616150252660340017055 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh if [ "${root%%:*}" = "liveiso" ]; then { printf 'KERNEL=="loop-control", RUN+="/sbin/initqueue --settled --onetime --unique /sbin/dmsquash-live-root `/sbin/losetup -f --show %s`"\n' \ ${root#liveiso:} } >> /etc/udev/rules.d/99-liveiso-mount.rules fi modules.d/90dmsquash-live/parse-iso-scan.sh000075500000000465150252660340014564 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # live images are specified with # root=live:backingdev isofile=$(getarg iso-scan/filename) if [ -n "$isofile" ]; then /sbin/initqueue --settled --unique /sbin/iso-scan "$isofile" fi modules.d/90kernel-modules/module-setup.sh000075500000007253150252660340014531 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh installkernel() { if [[ -z $drivers ]]; then block_module_filter() { local _blockfuncs='ahci_platform_get_resources|ata_scsi_ioctl|scsi_add_host|blk_cleanup_queue|register_mtd_blktrans|scsi_esp_register|register_virtio_device|usb_stor_disconnect|mmc_add_host|sdhci_add_host' # subfunctions inherit following FDs local _merge=8 _side2=9 function bmf1() { local _f while read _f; do case "$_f" in *.ko) [[ $(< $_f) =~ $_blockfuncs ]] && echo "$_f" ;; *.ko.gz) [[ $(gzip -dc <$_f) =~ $_blockfuncs ]] && echo "$_f" ;; *.ko.xz) [[ $(xz -dc <$_f) =~ $_blockfuncs ]] && echo "$_f" ;; esac done return 0 } function rotor() { local _f1 _f2 while read _f1; do echo "$_f1" if read _f2; then echo "$_f2" 1>&${_side2} fi done | bmf1 1>&${_merge} return 0 } # Use two parallel streams to filter alternating modules. set +x eval "( ( rotor ) ${_side2}>&1 | bmf1 ) ${_merge}>&1" [[ $debug ]] && set -x return 0 } hostonly='' instmods \ sr_mod sd_mod scsi_dh ata_piix hid_generic unix \ ehci-hcd ehci-pci ehci-platform \ ohci-hcd ohci-pci \ uhci-hcd \ xhci-hcd xhci-pci xhci-plat-hcd instmods yenta_socket scsi_dh_rdac scsi_dh_emc scsi_dh_alua \ atkbd i8042 usbhid firewire-ohci pcmcia hv-vmbus \ atkbd i8042 usbhid firewire-ohci pcmcia usb_storage \ nvme hv-vmbus sdhci_acpi nfit instmods \ "=drivers/hid" \ "=drivers/input/serio" \ "=drivers/input/keyboard" if [[ "$(uname -m)" == arm* || "$(uname -m)" == aarch64 ]]; then # arm/aarch64 specific modules hostonly='' instmods \ connector-hdmi connector-dvi encoder-tfp410 \ encoder-tpd12s015 i2c-tegra gpio-regulator \ as3722-regulator orion-ehci ehci-tegra instmods \ "=drivers/dma" \ "=drivers/i2c/busses" \ "=drivers/regulator" \ "=drivers/rtc" \ "=drivers/usb/host" \ "=drivers/usb/phy" \ "=drivers/scsi/hisi_sas" \ ${NULL} fi # install virtual machine support instmods virtio virtio_blk virtio_ring virtio_pci virtio_scsi \ "=drivers/pcmcia" =ide "=drivers/usb/storage" find_kernel_modules | block_module_filter | instmods # if not on hostonly mode, install all known filesystems, # if the required list is not set via the filesystems variable if ! [[ $hostonly ]]; then if [[ -z $filesystems ]]; then silent_omit_drivers="kernel/fs/nfs|kernel/fs/nfsd|kernel/fs/lockd" \ instmods '=fs' fi else for i in "${host_fs_types[@]}"; do hostonly='' instmods $i done fi fi : } install() { inst_multiple -o /lib/modprobe.d/*.conf [[ $hostonly ]] && inst_multiple -o /etc/modprobe.d/*.conf /etc/modprobe.conf if ! dracut_module_included "systemd"; then inst_hook cmdline 01 "$moddir/parse-kernel.sh" fi inst_simple "$moddir/insmodpost.sh" /sbin/insmodpost.sh } modules.d/90kernel-modules/insmodpost.sh000075500000000457150252660340014304 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh . /lib/dracut-lib.sh for modlist in $(getargs rd.driver.post -d rdinsmodpost=); do ( IFS=, for m in $modlist; do modprobe $m done ) done modules.d/90kernel-modules/parse-kernel.sh000075500000002007150252660340014466 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh _modprobe_d=/etc/modprobe.d if [ -d /usr/lib/modprobe.d ] ; then _modprobe_d=/usr/lib/modprobe.d elif [ -d /lib/modprobe.d ] ; then _modprobe_d=/lib/modprobe.d elif [ ! -d $_modprobe_d ] ; then mkdir -p $_modprobe_d fi for i in $(getargs rd.driver.pre -d rdloaddriver=); do ( IFS=, for p in $i; do modprobe $p 2>&1 | vinfo done ) done [ -d /etc/modprobe.d ] || mkdir -p /etc/modprobe.d for i in $(getargs rd.driver.blacklist -d rdblacklist=); do ( IFS=, for p in $i; do echo "blacklist $p" >> $_modprobe_d/initramfsblacklist.conf done ) done for p in $(getargs rd.driver.post -d rdinsmodpost=); do echo "blacklist $p" >> $_modprobe_d/initramfsblacklist.conf _do_insmodpost=1 done [ -n "$_do_insmodpost" ] && initqueue --settled --unique --onetime insmodpost.sh unset _do_insmodpost _modprobe_d modules.d/99shutdown/module-setup.sh000075500000001170150252660340013457 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { return 0 } depends() { echo base return 0 } install() { local _d inst_multiple umount poweroff reboot halt losetup stat inst_multiple -o kexec inst "$moddir/shutdown.sh" "$prefix/shutdown" [ -e "${initdir}/lib" ] || mkdir -m 0755 -p ${initdir}/lib mkdir -m 0755 -p ${initdir}/lib/dracut mkdir -m 0755 -p ${initdir}/lib/dracut/hooks for _d in $hookdirs shutdown shutdown-emergency; do mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d done } modules.d/99shutdown/shutdown.sh000075500000006055150252660340012716 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # Licensed under the GPLv2 # # Copyright 2011, Red Hat, Inc. # Harald Hoyer ACTION="$1" [ -w /dev/console ] && exec >/dev/console 2>>/dev/console export TERM=linux export PATH=/usr/sbin:/usr/bin:/sbin:/bin . /lib/dracut-lib.sh if [ "$(stat -c '%T' -f /)" = "tmpfs" ]; then mount -o remount,rw / fi mkdir /oldsys for i in sys proc run dev; do mkdir /oldsys/$i mount --move /oldroot/$i /oldsys/$i done # if "kexec" was installed after creating the initramfs, we try to copy it from the real root # libz normally is pulled in via kmod/modprobe and udevadm if [ "$ACTION" = "kexec" ] && ! command -v kexec >/dev/null 2>&1; then for p in /usr/sbin /usr/bin /sbin /bin; do cp -a /oldroot/${p}/kexec $p >/dev/null 2>&1 && break done hash kexec fi trap "emergency_shell --shutdown shutdown Signal caught!" 0 getarg 'rd.break=pre-shutdown' && emergency_shell --shutdown pre-shutdown "Break before pre-shutdown" source_hook pre-shutdown warn "Killing all remaining processes" killall_proc_mountpoint /oldroot umount_a() { local _did_umount="n" while read a mp a; do if strstr "$mp" oldroot; then if umount "$mp"; then _did_umount="y" warn "Unmounted $mp." fi fi done /dev/null || break _cnt=$(($_cnt+1)) done [ $_cnt -ge 40 ] && umount_a if strstr "$(cat /proc/mounts)" "/oldroot"; then warn "Cannot umount /oldroot" for _pid in /proc/*; do _pid=${_pid##/proc/} case $_pid in *[!0-9]*) continue;; esac [ $_pid -eq $$ ] && continue [ -e "/proc/$_pid/exe" ] || continue [ -e "/proc/$_pid/root" ] || continue if strstr "$(ls -l /proc/$_pid /proc/$_pid/fd 2>/dev/null)" "oldroot"; then warn "Blocking umount of /oldroot [$_pid] $(cat /proc/$_pid/cmdline)" else warn "Still running [$_pid] $(cat /proc/$_pid/cmdline)" fi ls -l "/proc/$_pid/exe" 2>&1 | vwarn ls -l "/proc/$_pid/fd" 2>&1 | vwarn done fi _check_shutdown() { local __f local __s=1 for __f in $hookdir/shutdown/*.sh; do [ -e "$__f" ] || continue ( . "$__f" $1 ) if [ $? -eq 0 ]; then rm -f -- $__f __s=0 fi done return $__s } while _check_shutdown; do : done _check_shutdown final getarg 'rd.break=shutdown' && emergency_shell --shutdown shutdown "Break before shutdown" case "$ACTION" in reboot|poweroff|halt) $ACTION -f -d -n warn "$ACTION failed!" ;; kexec) kexec -e warn "$ACTION failed!" reboot -f -d -n ;; *) warn "Shutdown called with argument '$ACTION'. Rebooting!" reboot -f -d -n ;; esac emergency_shell --shutdown shutdown modules.d/50plymouth/module-setup.sh000075500000001546150252660340013457 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { [[ "$mount_needs" ]] && return 1 require_binaries plymouthd plymouth } depends() { echo drm } install() { if grep -q nash /usr/libexec/plymouth/plymouth-populate-initrd \ || [ ! -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then . "$moddir"/plymouth-populate-initrd.sh else PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$dracutfunctions" \ /usr/libexec/plymouth/plymouth-populate-initrd -t "$initdir" fi inst_hook emergency 50 "$moddir"/plymouth-emergency.sh inst_multiple readlink if ! dracut_module_included "systemd"; then inst_hook pre-trigger 10 "$moddir"/plymouth-pretrigger.sh inst_hook pre-pivot 90 "$moddir"/plymouth-newroot.sh fi } modules.d/50plymouth/plymouth-newroot.sh000075500000000337150252660340014405 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh if type plymouth >/dev/null 2>&1 && [ -z "$DRACUT_SYSTEMD" ]; then plymouth --newroot=$NEWROOT fi modules.d/50plymouth/plymouth-emergency.sh000075500000000240150252660340014657 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh plymouth --hide-splash 2>/dev/null || : modules.d/50plymouth/plymouth-populate-initrd.sh000075500000002742150252660340016032 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh PLYMOUTH_LOGO_FILE="/usr/share/pixmaps/system-logo-white.png" PLYMOUTH_THEME=$(plymouth-set-default-theme) inst_multiple plymouthd plymouth \ "${PLYMOUTH_LOGO_FILE}" \ /etc/system-release mkdir -m 0755 -p "${initdir}/usr/share/plymouth" inst_libdir_file "plymouth/text.so" "plymouth/details.so" if [[ $hostonly ]]; then inst_multiple \ "/usr/share/plymouth/themes/details/details.plymouth" \ "/usr/share/plymouth/themes/text/text.plymouth" \ if [[ -d /usr/share/plymouth/themes/${PLYMOUTH_THEME} ]]; then for x in "/usr/share/plymouth/themes/${PLYMOUTH_THEME}"/* ; do [[ -f "$x" ]] || break inst $x done fi if [ -L /usr/share/plymouth/themes/default.plymouth ]; then inst /usr/share/plymouth/themes/default.plymouth # Install plugin for this theme PLYMOUTH_PLUGIN=$(grep "^ModuleName=" /usr/share/plymouth/themes/default.plymouth | while read a b c; do echo $b; done;) inst_libdir_file "plymouth/${PLYMOUTH_PLUGIN}.so" fi else for x in /usr/share/plymouth/themes/{text,details}/* ; do [[ -f "$x" ]] || continue THEME_DIR=$(dirname "$x") mkdir -m 0755 -p "${initdir}/$THEME_DIR" inst_multiple "$x" done ( cd ${initdir}/usr/share/plymouth/themes; ln -s text/text.plymouth default.plymouth 2>&1; ) fi modules.d/50plymouth/plymouth-pretrigger.sh000075500000002251150252660340015057 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh 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 # first trigger graphics subsystem udevadm trigger --action=add --attr-match=class=0x030000 >/dev/null 2>&1 # first trigger graphics and tty subsystem udevadm trigger --action=add --subsystem-match=graphics --subsystem-match=drm --subsystem-match=tty >/dev/null 2>&1 udevadm settle --timeout=30 2>&1 | vinfo info "Starting plymouth daemon" mkdir -m 0755 /run/plymouth read consoledev rest < /sys/class/tty/console/active consoledev=${consoledev:-tty0} [ -x /lib/udev/console_init -a -e "/dev/$consoledev" ] && /lib/udev/console_init "/dev/$consoledev" plymouthd --attach-to-session --pid-file /run/plymouth/pid plymouth --show-splash 2>&1 | vinfo # reset tty after plymouth messed with it [ -x /lib/udev/console_init -a -e "/dev/$consoledev" ] && /lib/udev/console_init "/dev/$consoledev" fi fi modules.d/95zfcp/module-setup.sh000075500000001251150252660340012542 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { arch=$(uname -m) [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1 require_binaries zfcp_cio_free grep sed seq || return 1 return 0 } depends() { arch=$(uname -m) [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1 return 0 } installkernel() { instmods zfcp } install() { inst_hook cmdline 30 "$moddir/parse-zfcp.sh" inst_multiple zfcp_cio_free grep sed seq inst_script /sbin/zfcpconf.sh inst_rules 56-zfcp.rules if [[ $hostonly ]]; then inst_simple /etc/zfcp.conf fi } modules.d/95zfcp/parse-zfcp.sh000075500000000535150252660340012175 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh getargbool 1 rd.zfcp.conf -d -n rd_NO_ZFCPCONF || rm /etc/zfcp.conf for zfcp_arg in $(getargs rd.zfcp -d 'rd_ZFCP='); do ( IFS="," set $zfcp_arg echo "$@" >> /etc/zfcp.conf ) done zfcp_cio_free modules.d/98syslog/module-setup.sh000075500000002326150252660340013127 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { # do not add this module by default return 255 } depends() { return 0 } install() { local _i local _installs if type -P rsyslogd >/dev/null; then _installs="rsyslogd" inst_libdir_file rsyslog/lmnet.so rsyslog/imklog.so rsyslog/imuxsock.so elif type -P syslogd >/dev/null; then _installs="syslogd" elif type -P syslog-ng >/dev/null; then _installs="syslog-ng" else derror "Could not find any syslog binary although the syslogmodule" \ "is selected to be installed. Please check." fi if [ -n "$_installs" ]; then inst_multiple cat $_installs inst_hook cmdline 90 "$moddir/parse-syslog-opts.sh" inst_hook pre-udev 61 "$moddir/syslog-genrules.sh" inst_hook cleanup 99 "$moddir/syslog-cleanup.sh" inst_simple "$moddir/rsyslogd-start.sh" /sbin/rsyslogd-start inst_simple "$moddir/rsyslogd-stop.sh" /sbin/rsyslogd-stop mkdir -m 0755 -p ${initdir}/etc/templates inst_simple "${moddir}/rsyslog.conf" /etc/templates fi dracut_need_initqueue } modules.d/98syslog/README000064400000001500150252660340011016 0ustar00Syslog support for dracut This module provides syslog functionality in the initrd. This is especially interesting when complex configuration being used to provide access to the device the rootfs resides on. When this module is installed into the ramfs it is triggered by the udev event from the nic being setup (online). Then if syslog is configured it is started and will forward all kernel messages to the given syslog server. The syslog implementation is detected automatically by finding the apropriate binary with the following order: rsyslogd syslogd syslog-ng Then if detected the syslog.conf is generated and syslog is started. Bootparameters: syslogserver=ip Where to syslog to sysloglevel=level What level has to be logged syslogtype=rsyslog|syslog|syslogng Don't auto detect syslog but set it modules.d/98syslog/parse-syslog-opts.sh000075500000001363150252660340014117 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # Parses the syslog commandline options # #Bootparameters: #syslogserver=ip Where to syslog to #sysloglevel=level What level has to be logged #syslogtype=rsyslog|syslog|syslogng # Don't auto detect syslog but set it type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh syslogserver=$(getarg syslog.server -d syslog) syslogfilters=$(getargs syslog.filter -d filter) syslogtype=$(getarg syslog.type -d syslogtype) [ -n "$syslogserver" ] && echo $syslogserver > /tmp/syslog.server [ -n "$syslogfilters" ] && echo "$syslogfilters" > /tmp/syslog.filters [ -n "$syslogtype" ] && echo "$syslogtype" > /tmp/syslog.type modules.d/98syslog/rsyslogd-stop.sh000075500000000526150252660340013335 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # Kills rsyslogd if [ -f /var/run/syslogd.pid ]; then read pid < /var/run/syslogd.pid kill $pid kill -0 $pid && kill -9 $pid else warn "rsyslogd-stop: Could not find a pid for rsyslogd. Won't kill it." fimodules.d/98syslog/syslog-genrules.sh000075500000002170150252660340013643 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # Creates the syslog udev rules to be triggered when interface becomes online. type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh detect_syslog() { syslogtype="" if [ -e /sbin/rsyslogd ]; then syslogtype="rsyslogd" elif [ -e /sbin/syslogd ]; then syslogtype="syslogd" elif [ /sbin/syslog-ng ]; then syslogtype="syslog-ng" else warn "Could not find any syslog binary although the syslogmodule is selected to be installed. Please check." fi echo "$syslogtype" [ -n "$syslogtype" ] } read syslogtype < /tmp/syslog.type if [ -z "$syslogtype" ]; then syslogtype=$(detect_syslog) echo $syslogtype > /tmp/syslog.type fi if [ -e "/sbin/${syslogtype}-start" ]; then printf 'ACTION=="online", SUBSYSTEM=="net", RUN+="/sbin/initqueue --onetime /sbin/'${syslogtype}'-start $env{INTERFACE}"\n' > /etc/udev/rules.d/70-syslog.rules else warn "syslog-genrules: Could not find binary to start syslog of type \"$syslogtype\". Syslog will not be started." fi modules.d/98syslog/syslog-cleanup.sh000075500000001005150252660340013442 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # Just cleans up a previously started syslogd type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh if [ -f /tmp/syslog.server ]; then read syslogtype < /tmp/syslog.type if command -v "${syslogtype}-stop" >/dev/null; then ${syslogtype}-stop else warn "syslog-cleanup: Could not find script to stop syslog of type \"$syslogtype\". Syslog will not be stopped." fi fimodules.d/98syslog/rsyslogd-start.sh000075500000001530150252660340013501 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # Triggered by udev and starts rsyslogd with bootparameters type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh rsyslog_config() { local server=$1 shift local syslog_template=$1 shift local filters=$* local filter= cat $syslog_template for filter in $filters; do echo "${filter} @${server}" done # echo "*.* /tmp/syslog" } read server < /tmp/syslog.server read filters < /tmp/syslog.filters [ -z "$filters" ] && filters="kern.*" read conf < /tmp/syslog.conf [ -z "$conf" ] && conf="/etc/rsyslog.conf" && echo "$conf" > /tmp/syslog.conf template=/etc/templates/rsyslog.conf if [ -n "$server" ]; then rsyslog_config "$server" "$template" "$filters" > $conf rsyslogd -c3 fi modules.d/98syslog/rsyslog.conf000064400000001464150252660340012520 0ustar00#rsyslog v3 config file # if you experience problems, check # http://www.rsyslog.com/troubleshoot for assistance #### MODULES #### $ModLoad imuxsock.so # provides support for local system logging (e.g. via logger command) $ModLoad imklog.so # provides kernel logging support (previously done by rklogd) #$ModLoad immark.so # provides --MARK-- message capability # Provides UDP syslog reception #$ModLoad imudp.so #$UDPServerRun 514 # Provides TCP syslog reception #$ModLoad imtcp.so #$InputTCPServerRun 514 #### GLOBAL DIRECTIVES #### # Use default timestamp format $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat # File syncing capability is disabled by default. This feature is usually not required, # not useful and an extreme performance hit #$ActionFileEnableSync on #### RULES #### modules.d/95nbd/module-setup.sh000075500000001600150252660340012341 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { local _rootdev # if an nbd device is not somewhere in the chain of devices root is # mounted on, fail the hostonly check. [[ $hostonly ]] || [[ $mount_needs ]] && { is_nbd() { [[ -b /dev/block/$1 && $1 == 43:* ]] ;} _rootdev=$(find_root_block_device) [[ -b /dev/block/$_rootdev ]] || return 1 check_block_and_slaves is_nbd "$_rootdev" || return 255 } require_binaries nbd-client || return 1 return 0 } depends() { # We depend on network modules being loaded echo network rootfs-block } installkernel() { instmods nbd } install() { inst nbd-client inst_hook cmdline 90 "$moddir/parse-nbdroot.sh" inst_script "$moddir/nbdroot.sh" "/sbin/nbdroot" dracut_need_initqueue } modules.d/95nbd/parse-nbdroot.sh000075500000003230150252660340012476 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # Preferred format: # root=nbd:srv:port[:fstype[:rootflags[:nbdopts]]] # [root=*] netroot=nbd:srv:port[:fstype[:rootflags[:nbdopts]]] # # nbdopts is a comma separated list of options to give to nbd-client # # root= takes precedence over netroot= if root=nbd[...] # # Sadly there's no easy way to split ':' separated lines into variables netroot_to_var() { local v=${1}: set -- while [ -n "$v" ]; do set -- "$@" "${v%%:*}" v=${v#*:} done unset server port server=$2; port=$3; } # This script is sourced, so root should be set. But let's be paranoid [ -z "$root" ] && root=$(getarg root=) if [ -z "$netroot" ]; then for netroot in $(getargs netroot=); do [ "${netroot%%:*}" = "nbd" ] && break done [ "${netroot%%:*}" = "nbd" ] || unset netroot fi # Root takes precedence over netroot if [ "${root%%:*}" = "nbd" ] ; then if [ -n "$netroot" ] ; then warn "root takes precedence over netroot. Ignoring netroot" fi netroot=$root unset root fi # If it's not nbd we don't continue [ "${netroot%%:*}" = "nbd" ] || return # Check required arguments netroot_to_var $netroot [ -z "$server" ] && die "Argument server for nbdroot is missing" [ -z "$port" ] && die "Argument port for nbdroot is missing" # NBD actually supported? incol2 /proc/devices nbd || modprobe nbd || die "nbdroot requested but kernel/initrd does not support nbd" # Done, all good! rootok=1 # Shut up init error check if [ -z "$root" ]; then root=block:/dev/root wait_for_dev -n /dev/root fi modules.d/95nbd/nbdroot.sh000075500000006052150252660340011373 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh PATH=/usr/sbin:/usr/bin:/sbin:/bin # Huh? Empty $1? [ -z "$1" ] && exit 1 # Huh? Empty $2? [ -z "$2" ] && exit 1 # Huh? Empty $3? [ -z "$3" ] && exit 1 # root is in the form root=nbd:srv:port[:fstype[:rootflags[:nbdopts]]] netif="$1" nroot="$2" NEWROOT="$3" # If it's not nbd we don't continue [ "${nroot%%:*}" = "nbd" ] || return nroot=${nroot#nbd:} nbdserver=${nroot%%:*}; nroot=${nroot#*:} nbdport=${nroot%%:*}; nroot=${nroot#*:} nbdfstype=${nroot%%:*}; nroot=${nroot#*:} nbdflags=${nroot%%:*} nbdopts=${nroot#*:} # If nbdport not an integer, then assume name based import if [ ! -z $(echo "$nbdport" | sed 's/[0-9]//g') ]; then nbdport="-N $nbdport" fi if [ "$nbdopts" = "$nbdflags" ]; then unset nbdopts fi if [ "$nbdflags" = "$nbdfstype" ]; then unset nbdflags fi if [ "$nbdfstype" = "$nbdport" ]; then unset nbdfstype fi if [ -z "$nbdfstype" ]; then nbdfstype=auto fi # look through the NBD options and pull out the ones that need to # go before the host etc. Append a ',' so we know we terminate the loop nbdopts=${nbdopts}, while [ -n "$nbdopts" ]; do f=${nbdopts%%,*} nbdopts=${nbdopts#*,} if [ -z "$f" ]; then break fi if [ -z "${f%bs=*}" -o -z "${f%timeout=*}" ]; then preopts="$preopts $f" continue fi opts="$opts $f" done # look through the flags and see if any are overridden by the command line nbdflags=${nbdflags}, while [ -n "$nbdflags" ]; do f=${nbdflags%%,*} nbdflags=${nbdflags#*,} if [ -z "$f" ]; then break fi if [ "$f" = "ro" -o "$f" = "rw" ]; then nbdrw=$f continue fi fsopts=${fsopts:+$fsopts,}$f done getarg ro && nbdrw=ro getarg rw && nbdrw=rw fsopts=${fsopts:+$fsopts,}${nbdrw} # XXX better way to wait for the device to be made? i=0 while [ ! -b /dev/nbd0 ]; do [ $i -ge 20 ] && exit 1 if [ $UDEVVERSION -ge 143 ]; then udevadm settle --exit-if-exists=/dev/nbd0 else sleep 0.1 fi i=$(($i + 1)) done # If we didn't get a root= on the command line, then we need to # add the udev rules for mounting the nbd0 device if [ "$root" = "block:/dev/root" -o "$root" = "dhcp" ]; then printf 'KERNEL=="nbd0", ENV{DEVTYPE}!="partition", ENV{ID_FS_TYPE}=="?*", SYMLINK+="root"\n' >> /etc/udev/rules.d/99-nbd-root.rules udevadm control --reload type write_fs_tab >/dev/null 2>&1 || . /lib/fs-lib.sh write_fs_tab /dev/root "$nbdfstype" "$fsopts" wait_for_dev -n /dev/root if [ -z "$DRACUT_SYSTEMD" ]; then printf '/bin/mount %s\n' \ "$NEWROOT" \ > $hookdir/mount/01-$$-nbd.sh fi fi if strstr "$(nbd-client --help 2>&1)" "systemd-mark"; then preopts="--systemd-mark $preopts" fi nbd-client $preopts "$nbdserver" $nbdport /dev/nbd0 $opts || exit 1 # NBD doesn't emit uevents when it gets connected, so kick it echo change > /sys/block/nbd0/uevent udevadm settle need_shutdown exit 0 modules.d/90qemu-net/module-setup.sh000075500000001353150252660340013331 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { if type -P systemd-detect-virt >/dev/null 2>&1; then vm=$(systemd-detect-virt --vm >/dev/null 2>&1) (($? != 0)) && return 255 [[ $vm = "qemu" ]] && return 0 [[ $vm = "kvm" ]] && return 0 [[ $vm = "bochs" ]] && return 0 fi for i in /sys/class/dmi/id/*_vendor; do [[ -f $i ]] || continue read vendor < $i [[ "$vendor" == "QEMU" ]] && return 0 [[ "$vendor" == "Bochs" ]] && return 0 done return 255 } installkernel() { # qemu specific modules hostonly='' instmods virtio_net e1000 8139cp pcnet32 e100 ne2k_pci } modules.d/90qemu/module-setup.sh000075500000001643150252660340012547 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { if type -P systemd-detect-virt >/dev/null 2>&1; then vm=$(systemd-detect-virt --vm 2>/dev/null) (($? != 0)) && return 255 [[ $vm = "qemu" ]] && return 0 [[ $vm = "kvm" ]] && return 0 [[ $vm = "bochs" ]] && return 0 fi for i in /sys/class/dmi/id/*_vendor; do [[ -f $i ]] || continue read vendor < $i [[ "$vendor" == "QEMU" ]] && return 0 [[ "$vendor" == "Red Hat" ]] && return 0 [[ "$vendor" == "Bochs" ]] && return 0 done return 255 } installkernel() { # qemu specific modules hostonly='' instmods \ ata_piix ata_generic pata_acpi cdrom sr_mod ahci \ virtio_blk virtio virtio_ring virtio_pci \ virtio_scsi virtio_console spapr-vscsi ibmvscsi } modules.d/97biosdevname/module-setup.sh000075500000000524150252660340014100 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { [[ "$mount_needs" ]] && return 1 require_binaries biosdevname || return 1 return 0 } depends() { return 0 } install() { inst_multiple biosdevname inst_rules 71-biosdevname.rules } modules.d/97biosdevname/parse-biosdevname.sh000075500000000642150252660340015062 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh if ! getargbool 1 biosdevname; then info "biosdevname=0: removing biosdevname network renaming" udevproperty UDEV_BIOSDEVNAME= rm -f -- /etc/udev/rules.d/71-biosdevname.rules else info "biosdevname=1: activating biosdevname network renaming" udevproperty UDEV_BIOSDEVNAME=1 fi modules.d/95znet/module-setup.sh000075500000001053150252660340012560 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { arch=$(uname -m) [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1 require_binaries znet_cio_free grep sed seq readlink || return 1 return 0 } depends() { return 0 } installkernel() { instmods ctcm lcs qeth qeth_l2 qeth_l3 } install() { inst_hook cmdline 30 "$moddir/parse-ccw.sh" inst_rules 81-ccw.rules inst_multiple znet_cio_free grep sed seq readlink /lib/udev/ccw_init } modules.d/95znet/parse-ccw.sh000075500000001727150252660340012031 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh for ccw_arg in $(getargs rd.ccw -d 'rd_CCW=') $(getargs rd.znet -d 'rd_ZNET='); do echo $ccw_arg >> /etc/ccw.conf done for ifname in $(getargs rd.znet_ifname); do IFS=: read ifname_if ifname_subchannels _rest <<< "$ifname" if [ -z "$ifname_if" ] || [ -z "$ifname_subchannels" ] || [ -n "$_rest" ]; then warn "Invalid arguments for rd.znet_ifname=" else { ifname_subchannels=${ifname_subchannels//,/|} echo 'ACTION!="add|change", GOTO="ccw_ifname_end"' echo 'ATTR{type}!="1", GOTO="ccw_ifname_end"' echo 'SUBSYSTEM!="net", GOTO="ccw_ifname_end"' echo "SUBSYSTEMS==\"ccwgroup\", KERNELS==\"$ifname_subchannels\", DRIVERS==\"?*\" NAME=\"$ifname_if\"" echo 'LABEL="ccw_ifname_end"' } > /etc/udev/rules.d/81-ccw-ifname.rules fi done znet_cio_free modules.d/98pollcdrom/module-setup.sh000075500000000374150252660340013603 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { return 255 } depends() { return 0 } install() { inst_hook initqueue/settled 99 "$moddir/pollcdrom.sh" } modules.d/98pollcdrom/pollcdrom.sh000075500000001351150252660340013147 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # Licensed under the GPLv2 # # Copyright 2008-2012, Red Hat, Inc. # Harald Hoyer if [ ! -e /sys/module/block/parameters/events_dfl_poll_msecs ]; then # if the kernel does not support autopolling # then we have to do a # dirty hack for some cdrom drives, # which report no medium for quiet # some time. for cdrom in /sys/block/sr*; do [ -e "$cdrom" ] || continue # skip, if cdrom medium was already found strstr "$(udevadm info --query=env --path=${cdrom##/sys})" \ ID_CDROM_MEDIA && continue echo change > "$cdrom/uevent" done fi modules.d/95udev-rules/module-setup.sh000075500000006002150252660340013672 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh install() { local _i # Fixme: would be nice if we didn't have to guess, which rules to grab.... # ultimately, /lib/initramfs/rules.d or somesuch which includes links/copies # of the rules we want so that we just copy those in would be best inst_multiple udevadm cat uname blkid \ /etc/udev/udev.conf [ -d ${initdir}/$systemdutildir ] || mkdir -p ${initdir}/$systemdutildir for _i in ${systemdutildir}/systemd-udevd ${udevdir}/udevd /sbin/udevd; do [ -x "$_i" ] || continue inst "$_i" if ! [[ -f ${initdir}${systemdutildir}/systemd-udevd ]]; then ln -fs "$_i" ${initdir}${systemdutildir}/systemd-udevd fi break done if ! [[ -e ${initdir}${systemdutildir}/systemd-udevd ]]; then derror "Cannot find [systemd-]udevd binary!" exit 1 fi inst_rules \ 40-redhat-cpu-hotplug.rules \ 40-redhat.rules \ 50-firmware.rules \ 50-udev-default.rules \ 50-udev.rules \ "$moddir/59-persistent-storage.rules" \ /59-persistent-storage.rules \ 60-pcmcia.rules \ 60-persistent-storage.rules \ 61-persistent-storage-edd.rules \ "$moddir/61-persistent-storage.rules" \ 70-uaccess.rules \ 71-seat.rules \ 73-seat-late.rules \ 75-net-description.rules \ 80-drivers.rules \ 80-net-name-slot.rules \ 95-late.rules \ 95-udev-late.rules \ ${NULL} prepare_udev_rules 59-persistent-storage.rules 61-persistent-storage.rules # debian udev rules inst_rules 91-permissions.rules { for i in cdrom tape dialout floppy; do if ! egrep -q "^$i:" "$initdir/etc/group" 2>/dev/null; then if ! egrep "^$i:" /etc/group 2>/dev/null; then case $i in cdrom) echo "$i:x:11:";; dialout) echo "$i:x:18:";; floppy) echo "$i:x:19:";; tape) echo "$i:x:33:";; esac fi fi done } >> "$initdir/etc/group" inst_multiple -o \ ${udevdir}/ata_id \ ${udevdir}/cdrom_id \ ${udevdir}/create_floppy_devices \ ${udevdir}/edd_id \ ${udevdir}/firmware.sh \ ${udevdir}/firmware \ ${udevdir}/firmware.agent \ ${udevdir}/hotplug.functions \ ${udevdir}/fw_unit_symlinks.sh \ ${udevdir}/hid2hci \ ${udevdir}/path_id \ ${udevdir}/input_id \ ${udevdir}/scsi_id \ ${udevdir}/usb_id \ ${udevdir}/pcmcia-socket-startup \ ${udevdir}/pcmcia-check-broken-cis inst_multiple -o /etc/pcmcia/config.opts [ -f /etc/arch-release ] && \ inst_script "$moddir/load-modules.sh" /lib/udev/load-modules.sh inst_libdir_file "libnss_files*" } modules.d/95udev-rules/load-modules.sh000075500000000274150252660340013641 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # Implement blacklisting for udev-loaded modules modprobe -b "$@" modules.d/95udev-rules/59-persistent-storage.rules000064400000000424150252660340016063 0ustar00SUBSYSTEM!="block", GOTO="ps_end" ACTION!="add|change", GOTO="ps_end" # Also don't process disks that are slated to be a multipath device ENV{DM_MULTIPATH_DEVICE_PATH}=="?*", GOTO="ps_end" KERNEL=="cciss[0-9]*", IMPORT BLKID KERNEL=="nbd[0-9]*", IMPORT BLKID LABEL="ps_end" modules.d/95udev-rules/61-persistent-storage.rules000064400000001774150252660340016065 0ustar00SUBSYSTEM!="block", GOTO="pss_end" ACTION!="add|change", GOTO="pss_end" # Also don't process disks that are slated to be a multipath device ENV{DM_MULTIPATH_DEVICE_PATH}=="?*", GOTO="pss_end" ACTION=="change", KERNEL=="dm-[0-9]*", ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}!="1", GOTO="do_pss" KERNEL=="cciss[0-9]*", GOTO="do_pss" KERNEL=="nbd[0-9]*", GOTO="do_pss" KERNEL=="md[0-9]*|md_d[0-9]*|md/*", GOTO="do_pss" GOTO="pss_end" LABEL="do_pss" # by-path (parent device path) ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="", DEVPATH!="*/virtual/*", IMPORT PATH_ID ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}" ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n" # by-label/by-uuid links (filesystem metadata) ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}" ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}" LABEL="pss_end" modules.d/95fcoe-uefi/module-setup.sh000075500000001335150252660340013445 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # called by dracut check() { local _fcoe_ctlr [[ $hostonly ]] || [[ $mount_needs ]] && { for c in /sys/bus/fcoe/devices/ctlr_* ; do [ -L $c ] || continue _fcoe_ctlr=$c done [ -z "$_fcoe_ctlr" ] && return 255 } [[ $hostonly ]] || [[ $mount_needs ]] && { [ -d /sys/firmware/efi ] || return 255 } require_binaries dcbtool fipvlan lldpad ip readlink || return 1 return 0 } # called by dracut depends() { echo fcoe uefi-lib return 0 } # called by dracut install() { inst_hook cmdline 20 "$moddir/parse-uefifcoe.sh" } modules.d/95fcoe-uefi/parse-uefifcoe.sh000075500000002010150252660340013706 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh command -v getarg >/dev/null || . /lib/dracut-lib.sh command -v get_fcoe_boot_mac >/dev/null || . /lib/uefi-lib.sh command -v set_ifname >/dev/null || . /lib/net-lib.sh print_fcoe_uefi_conf() { local mac dev vlan mac=$(get_fcoe_boot_mac "$1") [ -z "$mac" ] && return 1 dev=$(set_ifname fcoe $mac) vlan=$(get_fcoe_boot_vlan "$1") if [ "$vlan" -ne "0" ]; then case "$vlan" in [0-9]*) printf "%s\n" "vlan=$dev.$vlan:$dev" dev="$dev.$vlan" ;; *) printf "%s\n" "vlan=$vlan:$dev" dev="$vlan" ;; esac fi # fcoe=eth0:nodcb printf "fcoe=%s\n" "$dev:nodcb" return 0 } for i in /sys/firmware/efi/vars/FcoeBootDevice-*/data; do [ -e "$i" ] || continue print_fcoe_uefi_conf $i > /etc/cmdline.d/40-fcoe-uefi.conf && break done modules.d/98usrmount/module-setup.sh000075500000000704150252660340013501 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { local _init [[ $mount_needs ]] && return 1 _init=$(readlink -f /sbin/init) [[ "$_init" == "${_init##/usr}" ]] && return 255 return 0 } depends() { echo 'fs-lib' } install() { if ! dracut_module_included "systemd"; then inst_hook pre-pivot 50 "$moddir/mount-usr.sh" fi : } modules.d/98usrmount/mount-usr.sh000075500000007160150252660340013032 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type info >/dev/null 2>&1 || . /lib/dracut-lib.sh type fsck_single >/dev/null 2>&1 || . /lib/fs-lib.sh filtersubvol() { local _oldifs _oldifs="$IFS" IFS="," set $* IFS="$_oldifs" while [ $# -gt 0 ]; do case $1 in subvol\=*) :;; *) printf '%s' "${1}," ;; esac shift done } fsck_usr() { local _dev=$1 local _fs=$2 local _fsopts=$3 local _fsckoptions if [ -f "$NEWROOT"/fsckoptions ]; then _fsckoptions=$(cat "$NEWROOT"/fsckoptions) fi if [ -f "$NEWROOT"/forcefsck ] || getargbool 0 forcefsck ; then _fsckoptions="-f $_fsckoptions" elif [ -f "$NEWROOT"/.autofsck ]; then [ -f "$NEWROOT"/etc/sysconfig/autofsck ] && . "$NEWROOT"/etc/sysconfig/autofsck if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then AUTOFSCK_OPT="$AUTOFSCK_OPT -f" fi if [ -n "$AUTOFSCK_SINGLEUSER" ]; then warn "*** Warning -- the system did not shut down cleanly. " warn "*** Dropping you to a shell; the system will continue" warn "*** when you leave the shell." action_on_fail fi _fsckoptions="$AUTOFSCK_OPT $_fsckoptions" fi fsck_single "$_dev" "$_fs" "$_fsopts" "$_fsckoptions" } mount_usr() { local _dev _mp _fs _opts _rest _usr_found _ret _freq _passno # check, if we have to mount the /usr filesystem while read _dev _mp _fs _opts _freq _passno; do [ "${_dev%%#*}" != "$_dev" ] && continue if [ "$_mp" = "/usr" ]; then case "$_dev" in LABEL=*) _dev="$(echo $_dev | sed 's,/,\\x2f,g')" _dev="/dev/disk/by-label/${_dev#LABEL=}" ;; UUID=*) _dev="${_dev#block:}" _dev="/dev/disk/by-uuid/${_dev#UUID=}" ;; esac if strstr "$_opts" "subvol=" && \ [ "${root#block:}" -ef $_dev ] && \ [ -n "$rflags" ]; then # for btrfs subvolumes we have to mount /usr with the same rflags rflags=$(filtersubvol "$rflags") rflags=${rflags%%,} _opts="${_opts:+${_opts},}${rflags}" elif getargbool 0 ro; then # if "ro" is specified, we want /usr to be mounted read-only _opts="${_opts:+${_opts},}ro" elif getargbool 0 rw; then # if "rw" is specified, we want /usr to be mounted read-write _opts="${_opts:+${_opts},}rw" fi echo "$_dev ${NEWROOT}${_mp} $_fs ${_opts} $_freq $_passno" _usr_found="1" break fi done < "$NEWROOT/etc/fstab" >> /etc/fstab if [ "$_usr_found" != "" ]; then # we have to mount /usr _fsck_ret=0 if ! getargbool 0 rd.skipfsck; then if [ "0" != "${_passno:-0}" ]; then fsck_usr "$_dev" "$_fs" "$_opts" _fsck_ret=$? [ $_fsck_ret -ne 255 ] && echo $_fsck_ret >/run/initramfs/usr-fsck fi fi info "Mounting /usr with -o $_opts" mount "$NEWROOT/usr" 2>&1 | vinfo if ! ismounted "$NEWROOT/usr"; then warn "Mounting /usr to $NEWROOT/usr failed" warn "*** Dropping you to a shell; the system will continue" warn "*** when you leave the shell." action_on_fail fi fi } if [ -f "$NEWROOT/etc/fstab" ]; then mount_usr fi modules.d/80cms/module-setup.sh000075500000001611150252660340012354 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { arch=$(uname -m) [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1 return 255 } depends() { arch=$(uname -m) [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1 echo znet zfcp dasd dasd_mod return 0 } installkernel() { instmods zfcp } install() { inst_hook pre-trigger 30 "$moddir/cmssetup.sh" inst_hook pre-pivot 95 "$moddir/cms-write-ifcfg.sh" inst_script "$moddir/cmsifup.sh" /sbin/cmsifup inst_multiple /etc/cmsfs-fuse/filetypes.conf /etc/udev/rules.d/99-fuse.rules /etc/fuse.conf \ cmsfs-fuse fusermount ulockmgr_server bash insmod rmmod cat normalize_dasd_arg sed \ $(rpm -ql s390utils-base) inst_libdir_file "gconv/*" #inst /usr/lib/locale/locale-archive dracut_need_initqueue } modules.d/80cms/cmsifup.sh000075500000001577150252660340011412 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh DEVICE=$1 . /tmp/cms.conf strstr "$IPADDR" '*:*:*' && ipv6=1 if [ "$ipv6" ] && ! str_starts "$IPADDR" "["; then IPADDR="[$IPADDR]" fi if [ "$ipv6" ] && ! str_starts "$GATEWAY" "["; then GATEWAY="[$GATEWAY]" fi if [ "$ipv6" ]; then DNS1=$(set -- ${DNS/,/ }; echo $1) DNS2=$(set -- ${DNS/,/ }; echo $2) else DNS1=$(set -- ${DNS/:/ }; echo $1) DNS2=$(set -- ${DNS/:/ }; echo $2) fi { echo "ip=$IPADDR::$GATEWAY:$NETMASK:$HOSTNAME:$DEVICE:none:$MTU:$MACADDR" for i in $DNS1 $DNS2; do echo "nameserver=$i" done } > /etc/cmdline.d/80-cms.conf [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces IFACES="$IFACES $DEVICE" echo "$IFACES" >> /tmp/net.ifaces exec ifup "$DEVICE" modules.d/80cms/cmssetup.sh000075500000013636150252660340011606 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh function sysecho () { file="$1" shift local i=1 while [ $i -le 10 ] ; do if [ ! -f "$file" ]; then sleep 1 i=$((i+1)) else break fi done local status read status < "$file" if [[ ! $status == $* ]]; then [ -f "$file" ] && echo $* > "$file" fi } function dasd_settle() { local dasd_status=/sys/bus/ccw/devices/$1/status if [ ! -f $dasd_status ]; then return 1 fi local i=1 while [ $i -le 60 ] ; do local status read status < $dasd_status case $status in online|unformatted) return 0 ;; *) sleep 0.1 i=$((i+1)) ;; esac done return 1 } function dasd_settle_all() { for dasdccw in $(while read line; do echo "${line%%(*}"; done < /proc/dasd/devices) ; do if ! dasd_settle $dasdccw ; then echo $"Could not access DASD $dasdccw in time" return 1 fi done return 0 } # prints a canonocalized device bus ID for a given devno of any format function canonicalize_devno() { case ${#1} in 3) echo "0.0.0${1}" ;; 4) echo "0.0.${1}" ;; *) echo "${1}" ;; esac return 0 } # read file from CMS and write it to /tmp function readcmsfile() # $1=dasdport $2=filename { local dev local numcpus local devname local ret=0 if [ $# -ne 2 ]; then return; fi # precondition: udevd created dasda block device node if ! dasd_cio_free -d $1 ; then echo $"DASD $1 could not be cleared from device blacklist" return 1 fi modprobe dasd_mod dasd=$CMSDASD modprobe dasd_eckd_mod udevadm settle # precondition: dasd_eckd_mod driver incl. dependencies loaded, # dasd_mod must be loaded without setting any DASD online dev=$(canonicalize_devno $1) numcpus=$( while read line; do if strstr "$line" "# processors"; then echo ${line##*:}; break; fi; done < /proc/cpuinfo ) if [ ${numcpus} -eq 1 ]; then echo 1 > /sys/bus/ccw/devices/$dev/online else if ! sysecho /sys/bus/ccw/devices/$dev/online 1; then echo $"DASD $dev could not be set online" return 1 fi udevadm settle if ! dasd_settle $dev ; then echo $"Could not access DASD $dev in time" return 1 fi fi udevadm settle devname=$(cd /sys/bus/ccw/devices/$dev/block; set -- *; [ -b /dev/$1 ] && echo $1) devname=${devname:-dasda} [[ -d /mnt ]] || mkdir /mnt if cmsfs-fuse --to=UTF-8 -a /dev/$devname /mnt; then cat /mnt/$2 > /run/initramfs/$2 umount /mnt || umount -l /mnt udevadm settle else echo $"Could not read conf file $2 on CMS DASD $1." ret=1 fi if ! sysecho /sys/bus/ccw/devices/$dev/online 0; then echo $"DASD $dev could not be set offline again" #return 1 fi udevadm settle # 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) udevadm settle modprobe -r dasd_eckd_mod udevadm settle modprobe -r dasd_diag_mod udevadm settle modprobe -r dasd_mod udevadm settle return $ret } processcmsfile() { source /tmp/cms.conf SUBCHANNELS="$(echo $SUBCHANNELS | sed 'y/ABCDEF/abcdef/')" if [[ $NETTYPE ]]; then ( echo -n $NETTYPE,$SUBCHANNELS [[ $PORTNAME ]] && echo -n ",portname=$PORTNAME" [[ $LAYER2 ]] && echo -n ",layer2=$LAYER2" [[ "$NETTYPE" = "ctc" ]] && [[ $CTCPROT ]] && echo -n ",protocol=$CTCPROT" echo ) >> /etc/ccw.conf OLDIFS=$IFS IFS=, read -a subch_array <<< "indexzero,$SUBCHANNELS" IFS=$OLDIFS devbusid=${subch_array[1]} if [ "$NETTYPE" = "ctc" ]; then driver="ctcm" else driver=$NETTYPE fi printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="%s", KERNELS=="%s", ENV{INTERFACE}=="?*", RUN+="/sbin/initqueue --onetime --unique --name cmsifup-$env{INTERFACE} /sbin/cmsifup $env{INTERFACE}"\n' "$driver" "$devbusid" > /etc/udev/rules.d/99-cms.rules # remove the default net rules rm -f -- /etc/udev/rules.d/91-default-net.rules [[ -f /etc/udev/rules.d/90-net.rules ]] \ || printf 'SUBSYSTEM=="net", ACTION=="online", RUN+="/sbin/initqueue --onetime --env netif=$env{INTERFACE} source_hook initqueue/online"\n' >> /etc/udev/rules.d/99-cms.rules udevadm control --reload znet_cio_free fi if [[ $DASD ]] && [[ $DASD != "none" ]]; then echo $DASD | normalize_dasd_arg > /etc/dasd.conf echo "options dasd_mod dasd=$DASD" > /etc/modprobe.d/dasd_mod.conf dasd_cio_free fi unset _do_zfcp for i in ${!FCP_*}; do echo "${!i}" | while read port rest; do case $port in *.*.*) ;; *.*) port="0.$port" ;; *) port="0.0.$port" ;; esac echo $port $rest >> /etc/zfcp.conf done _do_zfcp=1 done [[ $_do_zfcp ]] && zfcp_cio_free unset _do_zfcp } [[ $CMSDASD ]] || CMSDASD=$(getarg "CMSDASD=") [[ $CMSCONFFILE ]] || CMSCONFFILE=$(getarg "CMSCONFFILE=") # Parse configuration if [ -n "$CMSDASD" -a -n "$CMSCONFFILE" ]; then if readcmsfile $CMSDASD $CMSCONFFILE; then ln -s /run/initramfs/$CMSCONFFILE /tmp/$CMSCONFFILE ln -s /run/initramfs/$CMSCONFFILE /tmp/cms.conf processcmsfile fi fi modules.d/80cms/cms-write-ifcfg.sh000075500000006305150252660340012724 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh mkdir -m 0755 -p /run/initramfs/state/etc/sysconfig/network-scripts function cms_write_config() { . /tmp/cms.conf SUBCHANNELS="$(echo $SUBCHANNELS | sed 'y/ABCDEF/abcdef/')" OLDIFS=$IFS IFS=, read -a subch_array <<< "indexzero,$SUBCHANNELS" IFS=$OLDIFS devbusid=${subch_array[1]} if [ "$NETTYPE" = "ctc" ]; then driver="ctcm" else driver=$NETTYPE fi DEVICE=$(cd /sys/devices/${driver}/$devbusid/net/ && set -- * && [ "$1" != "*" ] && echo $1) uuid=$(cat /proc/sys/kernel/random/uuid) IFCFGFILE=/run/initramfs/state/etc/sysconfig/network-scripts/ifcfg-$DEVICE strstr "$IPADDR" '*:*:*' && ipv6=1 # to please NetworkManager on startup in loader before loader reconfigures net cat > /etc/sysconfig/network << EOF HOSTNAME=$HOSTNAME EOF echo "$HOSTNAME" > /etc/hostname if [ "$ipv6" ]; then echo "NETWORKING_IPV6=yes" >> /etc/sysconfig/network else echo "NETWORKING=yes" >> /etc/sysconfig/network fi cat > $IFCFGFILE << EOF DEVICE=$DEVICE UUID=$uuid ONBOOT=yes BOOTPROTO=static MTU=$MTU SUBCHANNELS=$SUBCHANNELS EOF if [ "$ipv6" ]; then cat >> $IFCFGFILE << EOF IPV6INIT=yes IPV6_AUTOCONF=no IPV6ADDR=$IPADDR/$NETMASK IPV6_DEFAULTGW=$GATEWAY EOF else cat >> $IFCFGFILE << EOF IPADDR=$IPADDR NETMASK=$NETMASK BROADCAST=$BROADCAST GATEWAY=$GATEWAY EOF fi if [ "$ipv6" ]; then DNS1=$(set -- ${DNS/,/ }; echo $1) DNS2=$(set -- ${DNS/,/ }; echo $2) else DNS1=$(set -- ${DNS/:/ }; echo $1) DNS2=$(set -- ${DNS/:/ }; echo $2) fi # real DNS config for NetworkManager to generate /etc/resolv.conf [ "$DNS1" != "" ] && echo "DNS1=$DNS1" >> $IFCFGFILE [ "$DNS2" != "" ] && echo "DNS2=$DNS2" >> $IFCFGFILE # just to please loader's readNetInfo && writeEnabledNetInfo # which eats DNS1,DNS2,... and generates it themselves based on DNS if [ "$ipv6" ]; then [ "$DNS" != "" ] && echo "DNS=\"$DNS\"" >> $IFCFGFILE else [ "$DNS" != "" ] && echo "DNS=\"${DNS/:/,}\"" >> $IFCFGFILE fi # colons in SEARCHDNS already replaced with spaces above for /etc/resolv.conf [ "$SEARCHDNS" != "" ] && echo "DOMAIN=\"$SEARCHDNS\"" >> $IFCFGFILE [ "$NETTYPE" != "" ] && echo "NETTYPE=$NETTYPE" >> $IFCFGFILE [ "$PEERID" != "" ] && echo "PEERID=$PEERID" >> $IFCFGFILE [ "$PORTNAME" != "" ] && echo "PORTNAME=$PORTNAME" >> $IFCFGFILE [ "$CTCPROT" != "" ] && echo "CTCPROT=$CTCPROT" >> $IFCFGFILE [ "$MACADDR" != "" ] && echo "MACADDR=$MACADDR" >> $IFCFGFILE optstr="" for option in LAYER2 PORTNO; do [ -z "${!option}" ] && continue [ -n "$optstr" ] && optstr=${optstr}" " optstr=${optstr}$(echo ${option} | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')"="${!option} done # write single quotes since network.py removes double quotes but we need quotes echo "OPTIONS='$optstr'" >> $IFCFGFILE unset option unset optstr unset DNS1 unset DNS2 echo "files /etc/sysconfig/network-scripts" >> /run/initramfs/rwtab echo "files /var/lib/dhclient" >> /run/initramfs/rwtab } [ -f /tmp/cms.conf ] && cms_write_config modules.d/90multipath/module-setup.sh000075500000007320150252660340013605 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh is_mpath() { local _dev=$1 [ -e /sys/dev/block/$_dev/dm/uuid ] || return 1 [[ $(cat /sys/dev/block/$_dev/dm/uuid) =~ mpath- ]] && return 0 return 1 } majmin_to_mpath_dev() { local _dev for i in /dev/mapper/*; do [[ $i == /dev/mapper/control ]] && continue _dev=$(get_maj_min $i) if [ "$_dev" = "$1" ]; then echo $i return fi done } check() { local _rootdev # if there's no multipath binary, no go. require_binaries multipath || return 1 [[ $hostonly ]] || [[ $mount_needs ]] && { for_each_host_dev_and_slaves is_mpath || return 255 } return 0 } depends() { echo rootfs-block echo dm return 0 } installkernel() { local _ret local _arch=$(uname -m) mp_mod_filter() { local _funcs='scsi_register_device_handler|dm_dirty_log_type_register|dm_register_path_selector|dm_register_target' # subfunctions inherit following FDs local _merge=8 _side2=9 function bmf1() { local _f while read _f; do case "$_f" in *.ko) [[ $(< $_f) =~ $_funcs ]] && echo "$_f" ;; *.ko.gz) [[ $(gzip -dc <$_f) =~ $_funcs ]] && echo "$_f" ;; *.ko.xz) [[ $(xz -dc <$_f) =~ $_funcs ]] && echo "$_f" ;; esac done return 0 } function rotor() { local _f1 _f2 while read _f1; do echo "$_f1" if read _f2; then echo "$_f2" 1>&${_side2} fi done | bmf1 1>&${_merge} return 0 } # Use two parallel streams to filter alternating modules. set +x eval "( ( rotor ) ${_side2}>&1 | bmf1 ) ${_merge}>&1" [[ $debug ]] && set -x return 0 } ( find_kernel_modules_by_path drivers/scsi; if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then find_kernel_modules_by_path drivers/s390/scsi; fi; find_kernel_modules_by_path drivers/md ) | mp_mod_filter | hostonly='' instmods } install() { local _f _allow add_hostonly_mpath_conf() { is_mpath $1 && { local _dev _dev=$(majmin_to_mpath_dev $1) [ -z "$_dev" ] && return strstr "$_allow" "$_dev" && return _allow="$_allow --allow $_dev" } } inst_multiple -o \ dmsetup \ kpartx \ mpath_wait \ multipath \ multipathd \ mpathpersist \ xdrgetuid \ xdrgetprio \ /etc/xdrdevices.conf \ /etc/multipath.conf \ /etc/multipath/* [[ $hostonly ]] && [[ $hostonly_mode = "strict" ]] && { for_each_host_dev_and_slaves_all add_hostonly_mpath_conf [ -n "$_allow" ] && mpathconf $_allow --outfile ${initdir}/etc/multipath.conf } inst $(command -v partx) /sbin/partx inst_libdir_file "libmultipath*" "multipath/*" if dracut_module_included "systemd"; then inst_multiple \ $systemdsystemunitdir/multipathd.service mkdir -p "${initdir}${systemdsystemconfdir}/sysinit.target.wants" ln -rfs "${initdir}${systemdsystemunitdir}/multipathd.service" "${initdir}${systemdsystemconfdir}/sysinit.target.wants/multipathd.service" else inst_hook pre-trigger 02 "$moddir/multipathd.sh" inst_hook cleanup 02 "$moddir/multipathd-stop.sh" fi inst_hook cleanup 80 "$moddir/multipathd-needshutdown.sh" inst_rules 40-multipath.rules 62-multipath.rules 65-multipath.rules 66-kpartx.rules } modules.d/90multipath/multipathd-stop.sh000075500000000533150252660340014317 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh if [ -e /etc/multipath.conf ]; then HARD="" while pidof multipathd >/dev/null 2>&1; do for pid in $(pidof multipathd); do kill $HARD $pid >/dev/null 2>&1 done HARD="-9" done fi modules.d/90multipath/multipathd.sh000075500000000455150252660340013337 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh if [ -e /etc/multipath.conf ]; then modprobe dm-multipath multipathd -B || multipathd need_shutdown else rm -- /etc/udev/rules.d/??-multipath.rules 2>/dev/null fi modules.d/90multipath/multipathd-needshutdown.sh000075500000000326150252660340016041 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh for i in /dev/mapper/mpath*; do [ -b "$i" ] || continue need_shutdown break done modules.d/40network/dhclient-script.sh000075500000020506150252660340013734 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh PATH=/usr/sbin:/usr/bin:/sbin:/bin type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh # We already need a set netif here netif=$interface setup_interface() { ip=$new_ip_address mtu=$new_interface_mtu mask=$new_subnet_mask bcast=$new_broadcast_address gw=${new_routers%%,*} domain=$new_domain_name search=$(printf -- "$new_domain_search") namesrv=$new_domain_name_servers hostname=$new_host_name [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time [ -n "$new_max_life" ] && lease_time=$new_max_life preferred_lft=$lease_time [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override # Taken from debian dhclient-script: # The 576 MTU is only used for X.25 and dialup connections # where the admin wants low latency. Such a low MTU can cause # problems with UDP traffic, among other things. As such, # disallow MTUs from 576 and below by default, so that broken # MTUs are ignored, but higher stuff is allowed (1492, 1500, etc). if [ -n "$mtu" ] && [ $mtu -gt 576 ] ; then if ! ip link set $netif mtu $mtu ; then ip link set $netif down ip link set $netif mtu $mtu linkup $netif fi fi ip addr add $ip${mask:+/$mask} ${bcast:+broadcast $bcast} dev $netif \ ${lease_time:+valid_lft $lease_time} \ ${preferred_lft:+preferred_lft ${preferred_lft}} if [ -n "$gw" ] ; then if [ "$mask" == "255.255.255.255" ] ; then # point-to-point connection => set explicit route to gateway echo ip route add $gw dev $netif > /tmp/net.$netif.gw fi echo ip route replace default via $gw dev $netif >> /tmp/net.$netif.gw fi [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf if [ -n "$namesrv" ] ; then for s in $namesrv; do echo nameserver $s done fi >> /tmp/net.$netif.resolv.conf # Note: hostname can be fqdn OR short hostname, so chop off any # trailing domain name and explicity add any domain if set. [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname } setup_interface6() { domain=$new_domain_name search=$(printf -- "$new_domain_search") namesrv=$new_domain_name_servers hostname=$new_host_name [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time [ -n "$new_max_life" ] && lease_time=$new_max_life preferred_lft=$lease_time [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life [ -f /tmp/net.$netif.override ] && . /tmp/net.$netif.override ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \ dev ${netif} scope global \ ${lease_time:+valid_lft $lease_time} \ ${preferred_lft:+preferred_lft ${preferred_lft}} [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf if [ -n "$namesrv" ] ; then for s in $namesrv; do echo nameserver $s done fi >> /tmp/net.$netif.resolv.conf # Note: hostname can be fqdn OR short hostname, so chop off any # trailing domain name and explicity add any domain if set. [ -n "$hostname" ] && echo "echo ${hostname%.$domain}${domain:+.$domain} > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname } function parse_option_121() { while [ $# -ne 0 ]; do mask="$1" shift # Is the destination a multicast group? if [ $1 -ge 224 -a $1 -lt 240 ]; then multicast=1 else multicast=0 fi # Parse the arguments into a CIDR net/mask string if [ $mask -gt 24 ]; then destination="$1.$2.$3.$4/$mask" shift; shift; shift; shift elif [ $mask -gt 16 ]; then destination="$1.$2.$3.0/$mask" shift; shift; shift elif [ $mask -gt 8 ]; then destination="$1.$2.0.0/$mask" shift; shift else destination="$1.0.0.0/$mask" shift fi # Read the gateway gateway="$1.$2.$3.$4" shift; shift; shift; shift # Multicast routing on Linux # - If you set a next-hop address for a multicast group, this breaks with Cisco switches # - If you simply leave it link-local and attach it to an interface, it works fine. if [ $multicast -eq 1 ]; then temp_result="$destination dev $interface" else temp_result="$destination via $gateway dev $interface" fi echo "/sbin/ip route add $temp_result" done } case $reason in PREINIT) echo "dhcp: PREINIT $netif up" linkup $netif ;; PREINIT6) echo "dhcp: PREINIT6 $netif up" linkup $netif wait_for_ipv6_dad_link $netif ;; BOUND) echo "dhcp: BOND setting $netif" unset layer2 if [ -f /sys/class/net/$netif/device/layer2 ]; then read layer2 < /sys/class/net/$netif/device/layer2 fi if [ "$layer2" != "0" ]; 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" exit 1 fi fi unset layer2 setup_interface set | while read line; do [ "${line#new_}" = "$line" ] && continue echo "$line" done >/tmp/dhclient.$netif.dhcpopts { echo '. /lib/net-lib.sh' echo "setup_net $netif" if [ -n "$new_classless_static_routes" ]; then parse_option_121 $new_classless_static_routes fi echo "source_hook initqueue/online $netif" [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif" echo "rm -f -- $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 >/tmp/net.$netif.up if [ -e /sys/class/net/${netif}/address ]; then > /tmp/net.$(cat /sys/class/net/${netif}/address).up fi ;; RENEW|REBIND) unset lease_time [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time [ -n "$new_max_life" ] && lease_time=$new_max_life preferred_lft=$lease_time [ -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} \ ${lease_time:+valid_lft $lease_time} ${preferred_lft:+preferred_lft ${preferred_lft}} \ >/dev/null 2>&1 ;; BOUND6) echo "dhcp: BOND6 setting $netif" setup_interface6 set | while read line; do [ "${line#new_}" = "$line" ] && continue echo "$line" done >/tmp/dhclient.$netif.dhcpopts { echo '. /lib/net-lib.sh' echo "setup_net $netif" echo "source_hook initqueue/online $netif" [ -e /tmp/net.$netif.manualup ] || echo "/sbin/netroot $netif" echo "rm -f -- $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 >/tmp/net.$netif.up if [ -e /sys/class/net/${netif}/address ]; then > /tmp/net.$(cat /sys/class/net/${netif}/address).up fi ;; RENEW6|REBIND6) unset lease_time [ -n "$new_dhcp_lease_time" ] && lease_time=$new_dhcp_lease_time [ -n "$new_max_life" ] && lease_time=$new_max_life preferred_lft=$lease_time [ -n "$new_preferred_life" ] && preferred_lft=$new_preferred_life 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}} \ >/dev/null 2>&1 ;; *) echo "dhcp: $reason";; esac exit 0 modules.d/40network/module-setup.sh000075500000011336150252660340013264 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { local _program require_binaries ip arping dhclient || return 1 return 255 } depends() { return 0 } installkernel() { # Include wired net drivers, excluding wireless net_module_filter() { local _net_drivers='eth_type_trans|register_virtio_device|usbnet_open' local _unwanted_drivers='/(wireless|isdn|uwb|net/ethernet|net/phy|net/team)/' local _ret # subfunctions inherit following FDs local _merge=8 _side2=9 function nmf1() { local _fname _fcont while read _fname; do [[ $_fname =~ $_unwanted_drivers ]] && continue case "$_fname" in *.ko) _fcont="$(< $_fname)" ;; *.ko.gz) _fcont="$(gzip -dc $_fname)" ;; *.ko.xz) _fcont="$(xz -dc $_fname)" ;; esac [[ $_fcont =~ $_net_drivers && ! $_fcont =~ iw_handler_get_spy ]] \ && echo "$_fname" done return 0 } function rotor() { local _f1 _f2 while read _f1; do echo "$_f1" if read _f2; then echo "$_f2" 1>&${_side2} fi done | nmf1 1>&${_merge} return 0 } # Use two parallel streams to filter alternating modules. set +x eval "( ( rotor ) ${_side2}>&1 | nmf1 ) ${_merge}>&1" [[ $debug ]] && set -x return 0 } { find_kernel_modules_by_path drivers/net; if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then find_kernel_modules_by_path drivers/s390/net; fi; } \ | net_module_filter | instmods #instmods() will take care of hostonly instmods \ =drivers/net/phy \ =drivers/net/team \ =drivers/net/ethernet \ ecb arc4 bridge stp llc ipv6 bonding 8021q af_packet virtio_net hostonly="" instmods iscsi_ibft crc32c iscsi_boot_sysfs } install() { local _arch _i _dir inst_multiple ip arping dhclient sed awk inst_multiple -o ping ping6 inst_multiple -o teamd teamdctl teamnl inst_simple /etc/libnl/classid inst_script "$moddir/ifup.sh" "/sbin/ifup" inst_script "$moddir/netroot.sh" "/sbin/netroot" inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script" inst_simple "$moddir/net-lib.sh" "/lib/net-lib.sh" inst_simple "$moddir/dhclient.conf" "/etc/dhclient.conf" inst_hook pre-udev 50 "$moddir/ifname-genrules.sh" inst_hook pre-udev 60 "$moddir/net-genrules.sh" inst_hook cmdline 91 "$moddir/dhcp-root.sh" inst_hook cmdline 92 "$moddir/parse-ibft.sh" inst_hook cmdline 95 "$moddir/parse-vlan.sh" inst_hook cmdline 96 "$moddir/parse-bond.sh" inst_hook cmdline 96 "$moddir/parse-team.sh" inst_hook cmdline 97 "$moddir/parse-bridge.sh" inst_hook cmdline 98 "$moddir/parse-ip-opts.sh" inst_hook cmdline 99 "$moddir/parse-ifname.sh" inst_hook cleanup 10 "$moddir/kill-dhclient.sh" # Special network nameing for idrac USB devs inst_rules 73-idrac.rules # install all config files for teaming unset TEAM_MASTER unset TEAM_CONFIG unset TEAM_PORT_CONFIG unset HWADDR unset SUBCHANNELS for i in /etc/sysconfig/network-scripts/ifcfg-*; do [ -e "$i" ] || continue case "$i" in *~ | *.bak | *.orig | *.rpmnew | *.rpmorig | *.rpmsave) continue ;; esac ( . "$i" if ! [ "${ONBOOT}" = "no" -o "${ONBOOT}" = "NO" ] \ && [ -n "${TEAM_MASTER}${TEAM_CONFIG}${TEAM_PORT_CONFIG}" ]; then if [ -n "$TEAM_CONFIG" ] && [ -n "$DEVICE" ]; then mkdir -p $initdir/etc/teamd printf -- "%s" "$TEAM_CONFIG" > "$initdir/etc/teamd/${DEVICE}.conf" elif [ -n "$TEAM_PORT_CONFIG" ]; then inst_simple "$i" HWADDR="$(echo $HWADDR | sed 'y/ABCDEF/abcdef/')" if [ -n "$HWADDR" ]; then ln_r "$i" "/etc/sysconfig/network-scripts/mac-${HWADDR}.conf" fi SUBCHANNELS="$(echo $SUBCHANNELS | sed 'y/ABCDEF/abcdef/')" if [ -n "$SUBCHANNELS" ]; then ln_r "$i" "/etc/sysconfig/network-scripts/ccw-${SUBCHANNELS}.conf" fi fi fi ) done _arch=$(uname -m) inst_libdir_file {"tls/$_arch/",tls/,"$_arch/",}"libnss_dns.so.*" \ {"tls/$_arch/",tls/,"$_arch/",}"libnss_mdns4_minimal.so.*" dracut_need_initqueue } modules.d/40network/ifname-genrules.sh000075500000002315150252660340013717 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # if there are no ifname parameters, just use NAME=KERNEL if ! getarg ifname= >/dev/null ; then return fi command -v parse_ifname_opts >/dev/null || . /lib/net-lib.sh { for p in $(getargs ifname=); do parse_ifname_opts $p if [ -f /tmp/ifname-$ifname_mac ]; then read oldif < /tmp/ifname-$ifname_mac fi if [ -f /tmp/ifname-$ifname_if ]; then read oldmac < /tmp/ifname-$ifname_if fi if [ -n "$oldif" -a -n "$oldmac" -a "$oldif" = "$ifname_if" -a "$oldmac" = "$ifname_mac" ]; then # skip same ifname= declaration continue fi [ -n "$oldif" ] && warn "Multiple interface names specified for MAC $ifname_mac: $oldif" [ -n "$oldmac" ] && warn "Multiple MAC specified for $ifname_if: $oldmac" printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", ATTR{type}=="1", NAME="%s"\n' "$ifname_mac" "$ifname_if" echo $ifname_if > /tmp/ifname-$ifname_mac echo $ifname_mac > /tmp/ifname-$ifname_if done } >> /etc/udev/rules.d/80-ifname.rules modules.d/40network/dhcp-root.sh000075500000001636150252660340012542 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # This script is sourced, so root should be set. But let's be paranoid [ -z "$root" ] && root=$(getarg root=) if [ -z "$netroot" ]; then for netroot in $(getargs netroot=); do [ "$netroot" = "dhcp" ] && break [ "$netroot" = "dhcp6" ] && break done [ "$netroot" = "dhcp" ] || [ "$netroot" = "dhcp6" ] || unset netroot fi if [ "$root" = "dhcp" ] || [ "$root" = "dhcp6" ] || [ "$netroot" = "dhcp" ] || [ "$netroot" = "dhcp6" ]; then # Tell ip= checker that we need dhcp NEEDDHCP="1" # Done, all good! rootok=1 if [ "$netroot" != "dhcp" ] && [ "$netroot" != "dhcp6" ]; then netroot=$root fi # Shut up init error check [ -z "$root" ] && root="dhcp" echo '[ -d $NEWROOT/proc -o -e /dev/root ]' > $hookdir/initqueue/finished/dhcp.sh fi modules.d/40network/parse-team.sh000075500000001727150252660340012702 0ustar00#!/bin/sh # # Format: # team=: # # teamslaves is a comma-separated list of physical (ethernet) interfaces # parseteam() { local v=${1}: set -- while [ -n "$v" ]; do set -- "$@" "${v%%:*}" v=${v#*:} done case $# in 2) teammaster=$1; teamslaves=$(str_replace "$2" "," " ") ;; *) die "team= requires two parameters" ;; esac } for team in $(getargs team=); do unset teammaster teamslaves parseteam "$(getarg team=)" echo "teammaster=$teammaster" > /tmp/team.${teammaster}.info echo "teamslaves=\"$teamslaves\"" >> /tmp/team.${teammaster}.info if ! [ -e /etc/teamd/${teammaster}.conf ]; then warn "Team master $teammaster specified, but no /etc/teamd/$teammaster.conf present. Using activebackup." mkdir -p /etc/teamd printf -- "%s" '{"runner": {"name": "activebackup"}, "link_watch": {"name": "ethtool"}}' > "/etc/teamd/${teammaster}.conf" fi done modules.d/40network/net-lib.sh000075500000060202150252660340012167 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh is_ip() { echo "$1" | { IFS=. read a b c d test "$a" -ge 0 -a "$a" -le 255 \ -a "$b" -ge 0 -a "$b" -le 255 \ -a "$c" -ge 0 -a "$c" -le 255 \ -a "$d" -ge 0 -a "$d" -le 255 \ 2> /dev/null } && return 0 return 1 } get_ip() { local iface="$1" ip="" ip=$(ip -o -f inet addr show $iface) ip=${ip%%/*} ip=${ip##* } } iface_for_remote_addr() { set -- $(ip -o route get to $1) echo $5 } iface_for_ip() { set -- $(ip -o addr show to $1) echo $2 } iface_for_mac() { local interface="" mac="$(echo $1 | sed 'y/ABCDEF/abcdef/')" for interface in /sys/class/net/*; do if [ $(cat $interface/address) = "$mac" ]; then echo ${interface##*/} fi done } # get the iface name for the given identifier - either a MAC, IP, or iface name iface_name() { case $1 in ??:??:??:??:??:??|??-??-??-??-??-??) iface_for_mac $1 ;; *:*:*|*.*.*.*) iface_for_ip $1 ;; *) echo $1 ;; esac } # list the configured interfaces configured_ifaces() { local IFACES="" iface_id="" rv=1 [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces if { pidof udevd || pidof systemd-udevd; } > /dev/null; then for iface_id in $IFACES; do echo $(iface_name $iface_id) rv=0 done else warn "configured_ifaces called before udev is running" echo $IFACES [ -n "$IFACES" ] && rv=0 fi return $rv } all_ifaces_up() { local iface="" IFACES="" [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces for iface in $IFACES; do [ -e /tmp/net.$iface.up ] || return 1 done } all_ifaces_setup() { local iface="" IFACES="" [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces for iface in $IFACES; do [ -e /tmp/net.$iface.did-setup ] || return 1 done } get_netroot_ip() { local prefix="" server="" rest="" splitsep "$1" ":" prefix server rest case $server in [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*) echo "$server"; return 0 ;; esac return 1 } ip_is_local() { strstr "$(ip route get $1 2>/dev/null)" " via " } ifdown() { local netif="$1" # ip down/flush ensures that routing info goes away as well ip link set $netif down ip addr flush dev $netif echo "#empty" > /etc/resolv.conf rm -f -- /tmp/net.$netif.did-setup [ -z "$DO_VLAN" ] && \ [ -e /sys/class/net/$netif/address ] && \ rm -f -- /tmp/net.$(cat /sys/class/net/$netif/address).did-setup # TODO: send "offline" uevent? } setup_net() { local netif="$1" f="" gw_ip="" netroot_ip="" iface="" IFACES="" local _p [ -e /tmp/net.$netif.did-setup ] && return [ -z "$DO_VLAN" ] && \ [ -e /sys/class/net/$netif/address ] && \ [ -e /tmp/net.$(cat /sys/class/net/$netif/address).did-setup ] && return [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces [ -z "$IFACES" ] && IFACES="$netif" # run the scripts written by ifup [ -e /tmp/net.$netif.hostname ] && . /tmp/net.$netif.hostname [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts # set up resolv.conf [ -e /tmp/net.$netif.resolv.conf ] && \ awk '!array[$0]++' /tmp/net.$netif.resolv.conf > /etc/resolv.conf [ -e /tmp/net.$netif.gw ] && . /tmp/net.$netif.gw # add static route for _p in $(getargs rd.route); do route_to_var "$_p" || continue [ -n "$route_dev" ] && [ "$route_dev" != "$netif" ] && continue ip route add "$route_mask" ${route_gw:+via "$route_gw"} ${route_dev:+dev "$route_dev"} if strstr "$route_mask" ":"; then printf -- "%s\n" "$route_mask ${route_gw:+via $route_gw} ${route_dev:+dev $route_dev}" \ > /tmp/net.route6."$netif" else printf -- "%s\n" "$route_mask ${route_gw:+via $route_gw} ${route_dev:+dev $route_dev}" \ > /tmp/net.route."$netif" fi done # Handle STP Timeout: arping the default gateway. # (or the root server, if a) it's local or b) there's no gateway.) # Note: This assumes that if no router is present the # root server is on the same subnet. # Get DHCP-provided router IP, or the cmdline-provided "gw=" argument [ -n "$new_routers" ] && gw_ip=${new_routers%%,*} [ -n "$gw" ] && gw_ip=$gw # Get the "netroot" IP (if there's an IP address in there) netroot_ip=$(get_netroot_ip $netroot) # try netroot if it's local (or there's no gateway) if ip_is_local $netroot_ip || [ -z "$gw_ip" ]; then dest="$netroot_ip" else dest="$gw_ip" fi unset layer2 if [ -f /sys/class/net/$netif/device/layer2 ]; then read layer2 < /sys/class/net/$netif/device/layer2 fi if [ "$layer2" != "0" ] && [ -n "$dest" ] && ! strstr "$dest" ":"; then arping -q -f -w 60 -I $netif $dest || info "Resolving $dest via ARP on $netif failed" fi unset layer2 > /tmp/net.$netif.did-setup [ -z "$DO_VLAN" ] && \ [ -e /sys/class/net/$netif/address ] && \ > /tmp/net.$(cat /sys/class/net/$netif/address).did-setup } save_netinfo() { local netif="$1" IFACES="" f="" i="" [ -e /tmp/net.ifaces ] && read IFACES < /tmp/net.ifaces # Add $netif to the front of IFACES (if it's not there already). set -- "$netif" for i in $IFACES; do [ "$i" != "$netif" ] && set -- "$@" "$i"; done IFACES="$*" for i in $IFACES; do for f in /tmp/dhclient.$i.*; do [ -f $f ] && cp -f $f /tmp/net.${f#/tmp/dhclient.} done done echo $IFACES > /tmp/.net.ifaces.new mv /tmp/.net.ifaces.new /tmp/net.ifaces } set_ifname() { local name="$1" mac="$2" num=-1 n="" # if it's already set, return the existing name for n in $(getargs ifname=); do strstr "$n" "$mac" && echo ${n%%:*} && return done # otherwise, pick a new name and use that while :; do num=$(($num+1)); [ -e /sys/class/net/$name$num ] && continue for n in $(getargs ifname=); do [ "$name$num" = "${n%%:*}" ] && continue 2 done break done echo "ifname=$name$num:$mac" >> /etc/cmdline.d/45-ifname.conf echo "$name$num" } # pxelinux provides macaddr '-' separated, but we need ':' fix_bootif() { local macaddr=${1} local IFS='-' macaddr=$(printf '%s:' ${macaddr}) macaddr=${macaddr%:} # strip hardware type field from pxelinux [ -n "${macaddr%??:??:??:??:??:??}" ] && macaddr=${macaddr#??:} # return macaddr with lowercase alpha characters expected by udev echo $macaddr | sed 'y/ABCDEF/abcdef/' } ibft_to_cmdline() { local iface="" modprobe -q iscsi_ibft ( for iface in /sys/firmware/ibft/ethernet*; do local mac="" dev="" local dhcp="" ip="" gw="" mask="" hostname="" local dns1 dns2 [ -e ${iface}/mac ] || continue mac=$(read a < ${iface}/mac; echo $a) [ -z "$mac" ] && continue dev=$(set_ifname ibft $mac) [ -e /tmp/net.${dev}.has_ibft_config ] && continue [ -e ${iface}/flags ] && flags=$(read a < ${iface}/flags; echo $a) # Skip invalid interfaces (( $flags & 1 )) || continue [ -e ${iface}/dhcp ] && dhcp=$(read a < ${iface}/dhcp; echo $a) [ -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 *.*.*.*) family=ipv4 ;; *:*) family=ipv6 ;; esac fi if [ -n "$dhcp" ] || [ "$origin" -eq 3 ]; then if [ "$family" = "ipv6" ] ; then echo "ip=$dev:dhcp6" else echo "ip=$dev:dhcp" fi elif [ -e ${iface}/ip-addr ]; then # skip not assigned ip adresses [ "$ip" = "0.0.0.0" ] && continue [ -e ${iface}/gateway ] && gw=$(read a < ${iface}/gateway; echo $a) [ "$gateway" = "0.0.0.0" ] && unset $gateway [ -e ${iface}/subnet-mask ] && mask=$(read a < ${iface}/subnet-mask; 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 [ -e ${iface}/secondary-dns ] && dns2=$(read a < ${iface}/secondary-dns; echo $a) [ "$dns2" = "0.0.0.0" ] && unset $dns2 [ -e ${iface}/hostname ] && hostname=$(read a < ${iface}/hostname; echo $a) if [ "$family" = "ipv6" ] ; then if [ -n "$ip" ] ; then ip="[$ip]" [ -n "$prefix" ] || prefix=64 mask="$prefix" fi if [ -n "$gw" ] ; then gw="[${gw}]" fi fi if [ -n "$ip" ] && [ -n "$mask" ]; then echo "ip=$ip::$gw:$mask:$hostname:$dev:none${dns1:+:$dns1}${dns2:+:$dns2}" else warn "${iface} does not contain a valid iBFT configuration" warn "ip-addr=$ip" warn "gateway=$gw" warn "subnet-mask=$mask" warn "hostname=$hostname" fi else info "${iface} does not contain a valid iBFT configuration" ls -l ${iface} | vinfo fi if [ -e ${iface}/vlan ]; then vlan=$(read a < ${iface}/vlan; echo $a) if [ "$vlan" -ne "0" ]; then case "$vlan" in [0-9]*) echo "vlan=$dev.$vlan:$dev" echo $mac > /tmp/net.${dev}.${vlan}.has_ibft_config ;; *) echo "vlan=$vlan:$dev" echo $mac > /tmp/net.${vlan}.has_ibft_config ;; esac else echo $mac > /tmp/net.${dev}.has_ibft_config fi else echo $mac > /tmp/net.${dev}.has_ibft_config fi done ) >> /etc/cmdline.d/40-ibft.conf } parse_iscsi_root() { local v v=${1#iscsi:} # extract authentication info case "$v" in *@*:*:*:*:*) authinfo=${v%%@*} v=${v#*@} # allow empty authinfo to allow having an @ in iscsi_target_name like this: # netroot=iscsi:@192.168.1.100::3260::iqn.2009-01.com.example:testdi@sk if [ -n "$authinfo" ]; then OLDIFS="$IFS" IFS=: set $authinfo IFS="$OLDIFS" if [ $# -gt 4 ]; then warn "Wrong authentication info in iscsi: parameter!" return 1 fi iscsi_username=$1 iscsi_password=$2 if [ $# -gt 2 ]; then iscsi_in_username=$3 iscsi_in_password=$4 fi fi ;; esac # extract target ip case "$v" in [[]*[]]:*) iscsi_target_ip=${v#[[]} iscsi_target_ip=${iscsi_target_ip%%[]]*} v=${v#[[]$iscsi_target_ip[]]:} ;; *) iscsi_target_ip=${v%%[:]*} v=${v#$iscsi_target_ip:} ;; esac unset iscsi_target_name # extract target name case "$v" in *:iqn.*) iscsi_target_name=iqn.${v##*:iqn.} v=${v%:iqn.*}: ;; *:eui.*) iscsi_target_name=eui.${v##*:eui.} v=${v%:eui.*}: ;; *:naa.*) iscsi_target_name=naa.${v##*:naa.} v=${v%:naa.*}: ;; esac # parse the rest OLDIFS="$IFS" IFS=: set $v IFS="$OLDIFS" iscsi_protocol=$1; shift # ignored iscsi_target_port=$1; shift if [ -n "$iscsi_target_name" ]; then if [ $# -eq 3 ]; then iscsi_iface_name=$1; shift fi if [ $# -eq 2 ]; then iscsi_netdev_name=$1; shift fi iscsi_lun=$1; shift if [ $# -ne 0 ]; then warn "Invalid parameter in iscsi: parameter!" return 1 fi return 0 fi if [ $# -gt 3 ] && [ -n "$1$2" ]; then if [ -z "$3" ] || [ "$3" -ge 0 ] 2>/dev/null ; then iscsi_iface_name=$1; shift iscsi_netdev_name=$1; shift fi fi iscsi_lun=$1; shift iscsi_target_name=$(printf "%s:" "$@") iscsi_target_name=${iscsi_target_name%:} } ip_to_var() { local v=${1}: local i set -- while [ -n "$v" ]; do if [ "${v#\[*:*:*\]:}" != "$v" ]; then # handle IPv6 address i="${v%%\]:*}" i="${i##\[}" set -- "$@" "$i" v=${v#\[$i\]:} else set -- "$@" "${v%%:*}" v=${v#*:} fi done unset ip srv gw mask hostname dev autoconf macaddr mtu dns1 dns2 if [ $# -eq 0 ]; then autoconf="error" return 0 fi if [ $# -eq 1 ]; then # format: ip={dhcp|on|any|dhcp6|auto6|either6} # or # ip= means anaconda-style static config argument cluster autoconf="$1" if strstr "$autoconf" "*.*.*.*"; then # ip= means anaconda-style static config argument cluster: # ip= gateway= netmask= hostname= mtu= # ksdevice={link|bootif|ibft||} ip="$autoconf" gw=$(getarg gateway=) mask=$(getarg netmask=) hostname=$(getarg hostname=) dev=$(getarg ksdevice=) autoconf="none" mtu=$(getarg mtu=) # handle special values for ksdevice case "$dev" in bootif|BOOTIF) dev=$(fix_bootif $(getarg BOOTIF=)) ;; link) dev="" ;; # FIXME: do something useful with this ibft) dev="" ;; # ignore - ibft is handled elsewhere esac fi return 0 fi if [ "$2" = "dhcp" -o "$2" = "on" -o "$2" = "any" -o "$2" = "dhcp6" -o "$2" = "auto6" -o "$2" = "either6" ]; then # format: ip=:{dhcp|on|any|dhcp6|auto6}[:[][:]] [ -n "$1" ] && dev="$1" [ -n "$2" ] && autoconf="$2" [ -n "$3" ] && mtu=$3 if [ -z "$5" ]; then macaddr="$4" else macaddr="${4}:${5}:${6}:${7}:${8}:${9}" fi return 0 fi # format: ip=:[]:::::{none|off|dhcp|on|any|dhcp6|auto6|ibft}:[:[][:]] [ -n "$1" ] && ip=$1 [ -n "$2" ] && srv=$2 [ -n "$3" ] && gw=$3 [ -n "$4" ] && mask=$4 [ -n "$5" ] && hostname=$5 [ -n "$6" ] && dev=$6 [ -n "$7" ] && autoconf=$7 case "$8" in [0-9]*:*|[0-9]*.[0-9]*.[0-9]*.[0-9]*) dns1="$8" [ -n "$9" ] && dns2="$9" ;; [0-9]*) mtu="$8" if [ -n "${9}" -a -z "${10}" ]; then macaddr="${9}" 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}" fi ;; *) if [ -n "${9}" -a -z "${10}" ]; then macaddr="${9}" 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}" fi ;; esac return 0 } route_to_var() { local v=${1}: local i set -- while [ -n "$v" ]; do if [ "${v#\[*:*:*\]:}" != "$v" ]; then # handle IPv6 address i="${v%%\]:*}" i="${i##\[}" set -- "$@" "$i" v=${v#\[$i\]:} else set -- "$@" "${v%%:*}" v=${v#*:} fi done unset route_mask route_gw route_dev case $# in 2) [ -n "$1" ] && route_mask="$1"; [ -n "$2" ] && route_gw="$2" return 0;; 3) [ -n "$1" ] && route_mask="$1"; [ -n "$2" ] && route_gw="$2"; [ -n "$3" ] && route_dev="$3" return 0;; *) return 1;; esac } parse_ifname_opts() { local IFS=: set $1 case $# in 7) ifname_if=$1 # udev requires MAC addresses to be lower case ifname_mac=$(echo $2:$3:$4:$5:$6:$7 | sed 'y/ABCDEF/abcdef/') ;; 21) # infiniband MAC addrs are 20 bytes long not 6 ifname_if=$1 ifname_mac=$(echo $2:$3:$4:$5:$6:$7:$8:$9:$10:$11:$12:13:$14:$15$16:$17:$18:$19:$20:$21 | sed 'y/ABCDEF/abcdef/') ;; *) die "Invalid arguments for ifname=$1" ;; esac 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]) warn "ifname=$ifname_if uses the kernel name space for interfaces" warn "This can fail for multiple network interfaces and is discouraged!" warn "Please use a custom name like \"netboot\" or \"bluesocket\"" warn "or use the persistent interface names from udev or biosdevname and no ifname= at all." ;; esac } # some network driver need long time to initialize, wait before it's ready. wait_for_if_link() { local cnt=0 local li local timeout="$(getargs rd.net.timeout.iflink=)" timeout=${timeout:-60} timeout=$(($timeout*10)) while [ $cnt -lt $timeout ]; do li=$(ip -o link show dev $1 2>/dev/null) [ -n "$li" ] && return 0 sleep 0.1 cnt=$(($cnt+1)) done return 1 } wait_for_if_up() { local cnt=0 local li local timeout="$(getargs rd.net.timeout.ifup=)" timeout=${timeout:-20} timeout=$(($timeout*10)) while [ $cnt -lt $timeout ]; do li=$(ip -o link show up dev $1) if [ -n "$li" ]; then case "$li" in *\*) return 0;; *\<*,UP,*\>*) return 0;; esac fi if strstr "$li" "LOWER_UP" \ && strstr "$li" "state UNKNOWN" \ && ! strstr "$li" "DORMANT"; then return 0 fi sleep 0.1 cnt=$(($cnt+1)) done return 1 } wait_for_route_ok() { local cnt=0 local timeout="$(getargs rd.net.timeout.route=)" timeout=${timeout:-20} timeout=$(($timeout*10)) while [ $cnt -lt $timeout ]; do li=$(ip route show) [ -n "$li" ] && [ -z "${li##*$1*}" ] && return 0 sleep 0.1 cnt=$(($cnt+1)) done return 1 } wait_for_ipv6_dad_link() { local cnt=0 local timeout="$(getargs rd.net.timeout.ipv6dad=)" timeout=${timeout:-50} timeout=$(($timeout*10)) while [ $cnt -lt $timeout ]; do [ -n "$(ip -6 addr show dev "$1" scope link)" ] \ && [ -z "$(ip -6 addr show dev "$1" scope link tentative)" ] \ && return 0 [ -n "$(ip -6 addr show dev "$1" scope link dadfailed)" ] \ && return 1 sleep 0.1 cnt=$(($cnt+1)) done return 1 } wait_for_ipv6_dad() { local cnt=0 local timeout="$(getargs rd.net.timeout.ipv6dad=)" timeout=${timeout:-50} timeout=$(($timeout*10)) while [ $cnt -lt $timeout ]; do [ -n "$(ip -6 addr show dev "$1")" ] \ && [ -z "$(ip -6 addr show dev "$1" tentative)" ] \ && return 0 [ -n "$(ip -6 addr show dev "$1" dadfailed)" ] \ && return 1 sleep 0.1 cnt=$(($cnt+1)) done return 1 } wait_for_ipv6_auto() { local cnt=0 local timeout="$(getargs rd.net.timeout.ipv6auto=)" timeout=${timeout:-40} timeout=$(($timeout*10)) while [ $cnt -lt $timeout ]; do [ -z "$(ip -6 addr show dev "$1" tentative)" ] \ && [ -n "$(ip -6 route list proto ra dev "$1")" ] \ && return 0 sleep 0.1 cnt=$(($cnt+1)) done return 1 } linkup() { wait_for_if_link $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 || \ hostname() { cat /proc/sys/kernel/hostname } iface_has_carrier() { local cnt=0 local interface="$1" flags="" [ -n "$interface" ] || return 2 interface="/sys/class/net/$interface" [ -d "$interface" ] || return 2 local timeout="$(getargs rd.net.timeout.carrier=)" timeout=${timeout:-15} timeout=$(($timeout*10)) linkup "$1" li=$(ip -o link show up dev $1) strstr "$li" "NO-CARRIER" && _no_carrier_flag=1 while [ $cnt -lt $timeout ]; do if [ -n "$_no_carrier_flag" ]; then # NO-CARRIER flag was cleared strstr "$li" "NO-CARRIER" || return 0 fi # double check the syscfs carrier flag [ -e "$interface/carrier" ] && [ "$(cat $interface/carrier)" = 1 ] && return 0 sleep 0.1 cnt=$(($cnt+1)) done return 1 } iface_has_link() { iface_has_carrier "$@" } iface_is_enslaved() { local _li _li=$(ip -o link show dev $1) strstr "$li" " master " || return 1 return 0 } find_iface_with_link() { local iface_path="" iface="" for iface_path in /sys/class/net/*; do iface=${iface_path##*/} str_starts "$iface" "lo" && continue if iface_has_link $iface; then echo "$iface" return 0 fi done return 1 } is_persistent_ethernet_name() { local _netif="$1" local _name_assign_type="0" [ -f "/sys/class/net/$_netif/name_assign_type" ] \ && _name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type") # NET_NAME_ENUM 1 [ "$_name_assign_type" = "1" ] && return 1 # NET_NAME_PREDICTABLE 2 [ "$_name_assign_type" = "2" ] && return 0 case "$_netif" in # udev persistent interface names 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]*) ;; 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]*) ;; # biosdevname 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]*) ;; *) return 1 esac return 0 } is_kernel_ethernet_name() { local _netif="$1" local _name_assign_type="1" if [ -e "/sys/class/net/$_netif/name_assign_type" ]; then _name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type") case "$_name_assign_type" in 2|3|4) # NET_NAME_PREDICTABLE 2 # NET_NAME_USER 3 # NET_NAME_RENAMED 4 return 1 ;; 1|*) # NET_NAME_ENUM 1 return 0 ;; esac fi # fallback to error prone manual name check case "$_netif" in eth[0-9]|eth[0-9][0-9]|eth[0-9][0-9][0-9]*) return 0 ;; *) return 1 esac } iface_get_subchannels() { local _netif local _subchannels _netif="$1" _subchannels=$({ for i in /sys/class/net/$_netif/device/cdev[0-9]*; do [ -e $i ] || continue channel=$(readlink -f $i) printf -- "%s" "${channel##*/}," done }) [ -n "$_subchannels" ] || return 1 printf -- "%s" ${_subchannels%,} } modules.d/40network/parse-ip-opts.sh000075500000011460150252660340013342 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # Format: # ip=[dhcp|on|any] # # ip=:[dhcp|on|any][:[][:]] # # ip=::::::{dhcp|on|any|none|off}[:[][:]] # # When supplying more than only ip= line, is mandatory and # bootdev= must contain the name of the primary interface to use for # routing,dns,dhcp-options,etc. # command -v getarg >/dev/null || . /lib/dracut-lib.sh if [ -n "$netroot" ] && [ -z "$(getarg ip=)" ] && [ -z "$(getarg BOOTIF=)" ]; then # No ip= argument(s) for netroot provided, defaulting to DHCP return; fi # Count ip= lines to decide whether we need bootdev= or not if [ -z "$NEEDBOOTDEV" ] ; then count=0 for p in $(getargs ip=); do case "$p" in ibft) continue;; esac count=$(( $count + 1 )) done [ $count -gt 1 ] && NEEDBOOTDEV=1 fi unset count # If needed, check if bootdev= contains anything usable BOOTDEV=$(getarg bootdev=) if [ -n "$NEEDBOOTDEV" ] && ! getargbool 0 rd.neednet; then #[ -z "$BOOTDEV" ] && warn "Please supply bootdev argument for multiple ip= lines" echo "rd.neednet=1" > /etc/cmdline.d/dracut-neednet.conf info "Multiple ip= arguments: assuming rd.neednet=1" else unset NEEDBOOTDEV fi # Check ip= lines # XXX Would be nice if we could errorcheck ip addresses here as well for p in $(getargs ip=); do ip_to_var $p # make first device specified the BOOTDEV if [ -n "$NEEDBOOTDEV" ] && [ -z "$BOOTDEV" ] && [ -n "$dev" ]; then BOOTDEV="$dev" info "Setting bootdev to '$BOOTDEV'" fi # skip ibft since we did it above [ "$autoconf" = "ibft" ] && continue # Empty autoconf defaults to 'dhcp' if [ -z "$autoconf" ] ; then warn "Empty autoconf values default to dhcp" autoconf="dhcp" fi # Error checking for autoconf in combination with other values for autoopt in $(str_replace "$autoconf" "," " "); do case $autoopt in error) die "Error parsing option 'ip=$p'";; bootp|rarp|both) die "Sorry, ip=$autoopt is currenty unsupported";; none|off) [ -z "$ip" ] && \ die "For argument 'ip=$p'\nValue '$autoopt' without static configuration does not make sense" [ -z "$mask" ] && \ die "Sorry, automatic calculation of netmask is not yet supported" ;; auto6);; either6);; dhcp|dhcp6|on|any) \ #[ -n "$NEEDBOOTDEV" ] && [ -z "$dev" ] && \ # die "Sorry, 'ip=$p' does not make sense for multiple interface configurations" [ -n "$ip" ] && \ die "For argument 'ip=$p'\nSorry, setting client-ip does not make sense for '$autoopt'" ;; *) die "For argument 'ip=$p'\nSorry, unknown value '$autoopt'";; esac done if [ -n "$dev" ] ; then # We don't like duplicate device configs if [ -n "$IFACES" ] ; then for i in $IFACES ; do [ "$dev" = "$i" ] && die "For argument 'ip=$p'\nDuplication configurations for '$dev'" done fi # IFACES list for later use IFACES="$IFACES $dev" fi # Do we need to check for specific options? if [ -n "$NEEDDHCP" ] || [ -n "$DHCPORSERVER" ] ; then # Correct device? (Empty is ok as well) [ "$dev" = "$BOOTDEV" ] || continue # Server-ip is there? [ -n "$DHCPORSERVER" ] && [ -n "$srv" ] && continue # dhcp? (It's simpler to check for a set ip. Checks above ensure that if # ip is there, we're static [ -z "$ip" ] && continue # Not good! die "Server-ip or dhcp for netboot needed, but current arguments say otherwise" fi if str_starts "$dev" "enx" && [ ${#dev} -eq 15 ]; then printf -- "ifname=%s:%s:%s:%s:%s:%s:%s\n" \ "$dev" \ "${dev:3:2}" \ "${dev:5:2}" \ "${dev:7:2}" \ "${dev:9:2}" \ "${dev:11:2}" \ "${dev:13:2}" >> /etc/cmdline.d/80-enx.conf fi done # put BOOTIF in IFACES to make sure it comes up if getargbool 1 "rd.bootif" && BOOTIF="$(getarg BOOTIF=)"; then BOOTDEV=$(fix_bootif $BOOTIF) IFACES="$BOOTDEV $IFACES" fi # This ensures that BOOTDEV is always first in IFACES if [ -n "$BOOTDEV" ] && [ -n "$IFACES" ] ; then IFACES="${IFACES%$BOOTDEV*} ${IFACES#*$BOOTDEV}" IFACES="$BOOTDEV $IFACES" fi # Store BOOTDEV and IFACES for later use [ -n "$BOOTDEV" ] && echo $BOOTDEV > /tmp/net.bootdev [ -n "$IFACES" ] && echo $IFACES > /tmp/net.ifaces modules.d/40network/netroot.sh000075500000005345150252660340012336 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh PATH=/usr/sbin:/usr/bin:/sbin:/bin command -v getarg >/dev/null || . /lib/dracut-lib.sh command -v setup_net >/dev/null || . /lib/net-lib.sh # Huh? Empty $1? [ -z "$1" ] && exit 1 # [ ! -z $2 ] means this is for manually bringing up network # instead of real netroot; If It's called without $2, then there's # no sense in doing something if no (net)root info is available # or root is already there [ -d $NEWROOT/proc ] && exit 0 if [ -z "$netroot" ]; then netroot=$(getarg netroot=) fi [ -z "$netroot" ] && exit 1 # Set or override primary interface netif=$1 [ -e "/tmp/net.bootdev" ] && read netif < /tmp/net.bootdev case "$netif" in ??:??:??:??:??:??) # MAC address for i in /sys/class/net/*/address; do mac=$(cat $i) if [ "$mac" = "$netif" ]; then i=${i%/address} netif=${i##*/} break fi done esac # Figure out the handler for root=dhcp by recalling all netroot cmdline # handlers when this is not called from manually network bringing up. if [ -z "$2" ]; then if getarg "root=dhcp" || getarg "netroot=dhcp" || getarg "root=dhcp6" || getarg "netroot=dhcp6"; then # Load dhcp options [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts # If we have a specific bootdev with no dhcpoptions or empty root-path, # we die. Otherwise we just warn if [ -z "$new_root_path" ] ; then [ -n "$BOOTDEV" ] && die "No dhcp root-path received for '$BOOTDEV'" warn "No dhcp root-path received for '$BOOTDEV' trying other interfaces if available" exit 1 fi rm -f -- $hookdir/initqueue/finished/dhcp.sh # Set netroot to new_root_path, so cmdline parsers don't call netroot=$new_root_path # FIXME! unset rootok for f in $hookdir/cmdline/90*.sh; do [ -f "$f" ] && . "$f"; done else rootok="1" fi # Check: do we really know how to handle (net)root? [ -z "$root" ] && die "No or empty root= argument" [ -z "$rootok" ] && die "Don't know how to handle 'root=$root'" handler=${netroot%%:*} handler=${handler%%4} handler=$(command -v ${handler}root) if [ -z "$netroot" ] || [ ! -e "$handler" ] ; then die "No handler for netroot type '$netroot'" fi fi # Source netroot hooks before we start the handler source_hook netroot $netif # Run the handler; don't store the root, it may change from device to device # XXX other variables to export? [ -n "$handler" ] && "$handler" "$netif" "$netroot" "$NEWROOT" save_netinfo $netif exit 0 modules.d/40network/parse-vlan.sh000075500000001024150252660340012702 0ustar00#!/bin/sh # # Format: # vlan=: # parsevlan() { local v=${1}: set -- while [ -n "$v" ]; do set -- "$@" "${v%%:*}" v=${v#*:} done unset vlanname phydevice case $# in 2) vlanname=$1; phydevice=$2 ;; *) die "vlan= requires two parameters" ;; esac } for vlan in $(getargs vlan=); do unset vlanname unset phydevice parsevlan "$vlan" echo "$phydevice" > /tmp/vlan.${phydevice}.phy echo "$vlanname" > /tmp/vlan.${vlanname}.${phydevice} done modules.d/40network/kill-dhclient.sh000075500000000552150252660340013362 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh for f in /tmp/dhclient.*.pid; do [ -e $f ] || continue read PID < $f; kill $PID >/dev/null 2>&1 done sleep 0.1 for f in /tmp/dhclient.*.pid; do [ -e $f ] || continue read PID < $f; kill -9 $PID >/dev/null 2>&1 done modules.d/40network/parse-bond.sh000075500000003730150252660340012672 0ustar00#!/bin/sh # # Format: # bond=[::[:[:]]] # # bondslaves is a comma-separated list of physical (ethernet) interfaces # options is a comma-separated list on bonding options (modinfo bonding for details) in format compatible with initscripts # if options include multi-valued arp_ip_target option, then its values should be separated by semicolon. # # bond without parameters assumes bond=bond0:eth0,eth1:mode=balance-rr # # if the mtu is specified, it will be set on the bond master # # We translate list of slaves to space-separated here to mwke it easier to loop over them in ifup # Ditto for bonding options parsebond() { local v=${1}: set -- while [ -n "$v" ]; do set -- "$@" "${v%%:*}" v=${v#*:} done case $# in 0) bondname=bond0; bondslaves="eth0 eth1" ;; 1) 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 } # Parse bond for bondname, bondslaves, bondmode, bondoptions and bondmtu for bond in $(getargs bond=); do unset bondname unset bondslaves unset bondoptions unset bondmtu if [ "$bond" != "bond" ]; then parsebond "$bond" fi # Simple default bond if [ -z "$bondname" ]; then bondname=bond0 bondslaves="eth0 eth1" fi # Make it suitable for initscripts export bondoptions=$(str_replace "$bondoptions" ";" ",") echo "bondname=$bondname" > /tmp/bond.${bondname}.info echo "bondslaves=\"$bondslaves\"" >> /tmp/bond.${bondname}.info echo "bondoptions=\"$bondoptions\"" >> /tmp/bond.${bondname}.info echo "bondmtu=\"$bondmtu\"" >> /tmp/bond.${bondname}.info done modules.d/40network/parse-bridge.sh000075500000002144150252660340013202 0ustar00#!/bin/sh # # Format: # bridge=: # # is a comma-separated list of physical (ethernet) interfaces # bridge without parameters assumes bridge=br0:eth0 # parsebridge() { local v=${1}: set -- while [ -n "$v" ]; do set -- "$@" "${v%%:*}" v=${v#*:} done case $# in 0) bridgename=br0; bridgeslaves=$iface ;; 1) die "bridge= requires two parameters" ;; 2) bridgename=$1; bridgeslaves=$(str_replace "$2" "," " ") ;; *) die "bridge= requires two parameters" ;; esac } # Parse bridge for bridgename and bridgeslaves for bridge in $(getargs bridge=); do unset bridgename unset bridgeslaves iface=eth0 # Read bridge= parameters if they exist if [ "$bridge" != "bridge" ]; then parsebridge $bridge fi # Simple default bridge if [ -z "$bridgename" ]; then bridgename=br0 bridgeslaves=$iface fi echo "bridgename=$bridgename" > /tmp/bridge.${bridgename}.info echo "bridgeslaves=\"$bridgeslaves\"" >> /tmp/bridge.${bridgename}.info done modules.d/40network/parse-ifname.sh000075500000001226150252660340013205 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # Format: # ifname=: # # Note letters in the macaddress must be lowercase! # # Examples: # ifname=eth0:4a:3f:4c:04:f8:d7 # # Note when using ifname= to get persistent interface names, you must specify # an ifname= argument for each interface used in an ip= or fcoe= argument # check if there are any ifname parameters if ! getarg ifname= >/dev/null ; then return fi command -v parse_ifname_opts >/dev/null || . /lib/net-lib.sh # Check ifname= lines for p in $(getargs ifname=); do parse_ifname_opts $p done modules.d/40network/net-genrules.sh000075500000007254150252660340013255 0ustar00#!/bin/sh getargbool 0 rd.neednet && NEEDNET=1 # Don't continue if we don't need network if [ -z "$netroot" ] && [ ! -e "/tmp/net.ifaces" ] && [ "$NEEDNET" != "1" ]; then return fi command -v fix_bootif >/dev/null || . /lib/net-lib.sh # Write udev rules { # bridge: attempt only the defined interface for i in /tmp/bridge.*.info; do [ -e "$i" ] || continue unset bridgeslaves unset bridgename . "$i" RAW_IFACES="$RAW_IFACES $bridgeslaves" MASTER_IFACES="$MASTER_IFACES $bridgename" done # bond: attempt only the defined interface (override bridge defines) for i in /tmp/bond.*.info; do [ -e "$i" ] || continue unset bondslaves unset bondname . "$i" # It is enough to fire up only one RAW_IFACES="$RAW_IFACES $bondslaves" MASTER_IFACES="$MASTER_IFACES ${bondname}" done for i in /tmp/team.*.info; do [ -e "$i" ] || continue unset teamslaves unset teammaster . "$i" RAW_IFACES="$RAW_IFACES ${teamslaves}" MASTER_IFACES="$MASTER_IFACES ${teammaster}" done for j in /tmp/vlan.*.phy; do [ -e "$j" ] || continue unset phydevice read phydevice < "$j" RAW_IFACES="$RAW_IFACES $phydevice" for i in /tmp/vlan.*.${phydevice}; do [ -e "$i" ] || continue unset vlanname read vlanname < "$i" MASTER_IFACES="$MASTER_IFACES ${vlanname}" done done MASTER_IFACES="$(trim "$MASTER_IFACES")" RAW_IFACES="$(trim "$RAW_IFACES")" if [ -z "$IFACES" ]; then [ -e /tmp/net.ifaces ] && read IFACES < /tmp/net.ifaces fi if [ -e /tmp/net.bootdev ]; then bootdev=$(cat /tmp/net.bootdev) fi ifup='/sbin/ifup $env{INTERFACE}' runcmd="RUN+=\"/sbin/initqueue --name ifup-\$env{INTERFACE} --unique --onetime $ifup\"" # We have some specific interfaces to handle if [ -n "${RAW_IFACES}${IFACES}" ]; then echo 'SUBSYSTEM!="net", GOTO="net_end"' echo 'ACTION!="add|change|move", GOTO="net_end"' for iface in $IFACES $RAW_IFACES; do case "$iface" in ??:??:??:??:??:??) # MAC address cond="ATTR{address}==\"$iface\"" echo "$cond, $runcmd, GOTO=\"net_end\"" ;; ??-??-??-??-??-??) # MAC address in BOOTIF form cond="ATTR{address}==\"$(fix_bootif $iface)\"" echo "$cond, $runcmd, GOTO=\"net_end\"" ;; *) # an interface name cond="ENV{INTERFACE}==\"$iface\"" echo "$cond, $runcmd, GOTO=\"net_end\"" cond="NAME==\"$iface\"" echo "$cond, $runcmd, GOTO=\"net_end\"" ;; esac # The GOTO prevents us from trying to ifup the same device twice done echo 'LABEL="net_end"' for iface in $IFACES; do if [ "$bootdev" = "$iface" ] || [ "$NEEDNET" = "1" ]; then echo "[ -f /tmp/net.${iface}.did-setup ]" >$hookdir/initqueue/finished/wait-$iface.sh fi done # Default: We don't know the interface to use, handle all # Fixme: waiting for the interface as well. else cond='ACTION=="add", SUBSYSTEM=="net", ENV{DEVTYPE}!="wlan|wwan"' # 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 fi # if you change the name of "90-net.rules", also change modules.d/80cms/cmssetup.sh } > /etc/udev/rules.d/90-net.rules modules.d/40network/dhclient.conf000064400000000406150252660340012737 0ustar00 option classless-static-routes code 121 = array of unsigned integer 8; request subnet-mask, broadcast-address, time-offset, routers, domain-name, domain-name-servers, domain-search, host-name, root-path, interface-mtu, classless-static-routes; modules.d/40network/ifup.sh000075500000033147150252660340011610 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # # We don't need to check for ip= errors here, that is handled by the # cmdline parser script # # without $2 means this is for real netroot case # or it is for manually bring up network ie. for kdump scp vmcore PATH=/usr/sbin:/usr/bin:/sbin:/bin type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh # Huh? No $1? [ -z "$1" ] && exit 1 # $netif reads easier than $1 netif=$1 # loopback is always handled the same way if [ "$netif" = "lo" ] ; then ip link set lo up ip addr add 127.0.0.1/8 dev lo exit 0 fi # Run dhclient do_dhcp() { # dhclient-script will mark the netif up and generate the online # event for nfsroot # XXX add -V vendor class and option parsing per kernel local _COUNT=0 local _timeout=$(getargs rd.net.timeout.dhcp=) local _DHCPRETRY=$(getargs rd.net.dhcp.retry=) _DHCPRETRY=${_DHCPRETRY:-1} [ -e /tmp/dhclient.$netif.pid ] && return 0 if ! iface_has_carrier $netif; then warn "No carrier detected on interface $netif" return 1 fi [ -n "$macaddr" ] && ip link set address $macaddr dev $netif [ -n "$mtu" ] && ip link set mtu $mtu dev $netif ip -4 addr flush dev $netif while [ $_COUNT -lt $_DHCPRETRY ]; do info "Starting dhcp for interface $netif" dhclient "$@" \ ${_timeout:+-timeout $_timeout} \ -q \ -cf /etc/dhclient.conf \ -pf /tmp/dhclient.$netif.pid \ -lf /tmp/dhclient.$netif.lease \ $netif \ && return 0 _COUNT=$(($_COUNT+1)) [ $_COUNT -lt $_DHCPRETRY ] && sleep 1 done warn "dhcp for interface $netif failed" return 1 } load_ipv6() { [ -d /proc/sys/net/ipv6 ] && return modprobe ipv6 i=0 while [ ! -d /proc/sys/net/ipv6 ]; do i=$(($i+1)) [ $i -gt 10 ] && break sleep 0.1 done } do_ipv6auto() { local ret load_ipv6 echo 0 > /proc/sys/net/ipv6/conf/$netif/forwarding echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_ra echo 1 > /proc/sys/net/ipv6/conf/$netif/accept_redirects linkup $netif [ -n "$macaddr" ] && ip link set address $macaddr dev $netif [ -n "$mtu" ] && ip link set mtu $mtu dev $netif wait_for_ipv6_auto $netif ret=$? [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname return $ret } # Handle static ip configuration do_static() { strstr $ip '*:*:*' && load_ipv6 if [ -z "$dev" ] && ! iface_has_carrier "$netif"; then warn "No carrier detected on interface $netif" return 1 elif ! linkup "$netif"; then warn "Could not bring interface $netif up!" return 1 fi ip route get "$ip" | { read a rest if [ "$a" = "local" ]; then warn "Not assigning $ip to interface $netif, cause it is already assigned!" return 1 fi return 0 } || return 1 [ -n "$macaddr" ] && ip link set address $macaddr dev $netif [ -n "$mtu" ] && ip link set mtu $mtu dev $netif if strstr $ip '*:*:*'; then # note no ip addr flush for ipv6 ip addr add $ip/$mask ${srv:+peer $srv} dev $netif wait_for_ipv6_dad $netif else if [ -z "$srv" ]; then if ! arping -f -q -D -c 2 -I $netif $ip; then warn "Duplicate address detected for $ip for interface $netif." return 1 fi fi ip -4 addr flush dev $netif ip addr add $ip/$mask ${srv:+peer $srv} brd + dev $netif fi [ -n "$gw" ] && echo ip route replace default via $gw dev $netif > /tmp/net.$netif.gw [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname return 0 } get_vid() { case "$1" in vlan*) echo ${1#vlan} ;; *.*) echo ${1##*.} ;; esac } # check, if we need VLAN's for this interface if [ -z "$DO_VLAN_PHY" ] && [ -e /tmp/vlan.${netif}.phy ]; then unset DO_VLAN NO_AUTO_DHCP=yes DO_VLAN_PHY=yes ifup "$netif" modprobe -b -q 8021q for i in /tmp/vlan.*.${netif}; do [ -e "$i" ] || continue read vlanname < "$i" if [ -n "$vlanname" ]; then linkup "$netif" ip link add dev "$vlanname" link "$netif" type vlan id "$(get_vid $vlanname)" ifup "$vlanname" fi done exit 0 fi # Check, if interface is VLAN interface if ! [ -e /tmp/vlan.${netif}.phy ]; then for i in /tmp/vlan.${netif}.*; do [ -e "$i" ] || continue export DO_VLAN=yes break done fi # bridge this interface? if [ -z "$NO_BRIDGE_MASTER" ]; then for i in /tmp/bridge.*.info; do [ -e "$i" ] || continue unset bridgeslaves unset bridgename . "$i" for ethname in $bridgeslaves ; do [ "$netif" != "$ethname" ] && continue NO_BRIDGE_MASTER=yes NO_AUTO_DHCP=yes ifup $ethname linkup $ethname if [ ! -e /tmp/bridge.$bridgename.up ]; then ip link add name $bridgename type bridge echo 0 > /sys/devices/virtual/net/$bridgename/bridge/forward_delay > /tmp/bridge.$bridgename.up fi ip link set dev $ethname master $bridgename ifup $bridgename exit 0 done done fi # enslave this interface to bond? if [ -z "$NO_BOND_MASTER" ]; then for i in /tmp/bond.*.info; do [ -e "$i" ] || continue unset bondslaves unset bondname . "$i" for slave in $bondslaves ; do [ "$netif" != "$slave" ] && continue # already setup [ -e /tmp/bond.$bondname.up ] && exit 0 # wait for all slaves to show up for slave in $bondslaves ; do # try to create the slave (maybe vlan or bridge) NO_BOND_MASTER=yes NO_AUTO_DHCP=yes ifup $slave if ! ip link show dev $slave >/dev/null 2>&1; then # wait for the last slave to show up exit 0 fi done modprobe -q -b bonding echo "+$bondname" > /sys/class/net/bonding_masters 2>/dev/null ip link set $bondname down # Stolen from ifup-eth # add the bits to setup driver parameters here for arg in $bondoptions ; do key=${arg%%=*}; value=${arg##*=}; # %{value:0:1} is replaced with non-bash specific construct if [ "${key}" = "arp_ip_target" -a "${#value}" != "0" -a "+${value%%+*}" != "+" ]; then OLDIFS=$IFS; IFS=','; for arp_ip in $value; do echo +$arp_ip > /sys/class/net/${bondname}/bonding/$key done IFS=$OLDIFS; else echo $value > /sys/class/net/${bondname}/bonding/$key fi done linkup $bondname for slave in $bondslaves ; do cat /sys/class/net/$slave/address > /tmp/net.${bondname}.${slave}.hwaddr ip link set $slave down echo "+$slave" > /sys/class/net/$bondname/bonding/slaves linkup $slave done # Set mtu on bond master [ -n "$bondmtu" ] && ip link set mtu $bondmtu dev $bondname # add the bits to setup the needed post enslavement parameters for arg in $bondoptions ; do key=${arg%%=*}; value=${arg##*=}; if [ "${key}" = "primary" ]; then echo $value > /sys/class/net/${bondname}/bonding/$key fi done > /tmp/bond.$bondname.up NO_BOND_MASTER=yes ifup $bondname exit $? done done fi if [ -z "$NO_TEAM_MASTER" ]; then for i in /tmp/team.*.info; do [ -e "$i" ] || continue unset teammaster unset teamslaves . "$i" for slave in $teamslaves ; do [ "$netif" != "$slave" ] && continue [ -e /tmp/team.$teammaster.up ] && exit 0 # wait for all slaves to show up for slave in $teamslaves ; do # try to create the slave (maybe vlan or bridge) NO_TEAM_MASTER=yes NO_AUTO_DHCP=yes ifup $slave if ! ip link show dev $slave >/dev/null 2>&1; then # wait for the last slave to show up exit 0 fi done if [ ! -e /tmp/team.$teammaster.up ] ; then # We shall only bring up those _can_ come up # in case of some slave is gone in active-backup mode working_slaves="" for slave in $teamslaves ; do ip link set $slave up 2>/dev/null if wait_for_if_up $slave; then working_slaves="$working_slaves$slave " fi done # Do not add slaves now teamd -d -U -n -N -t $teammaster -f /etc/teamd/$teammaster.conf for slave in $working_slaves; do # team requires the slaves to be down before joining team ip link set $slave down teamdctl $teammaster port add $slave done ip link set $teammaster up > /tmp/team.$teammaster.up NO_TEAM_MASTER=yes ifup $teammaster exit $? fi done done fi # all synthetic interfaces done.. now check if the interface is available if ! ip link show dev $netif >/dev/null 2>&1; then exit 1 fi # disable manual ifup while netroot is set for simplifying our logic # in netroot case we prefer netroot to bringup $netif automaticlly [ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2" if [ -n "$manualup" ]; then >/tmp/net.$netif.manualup rm -f /tmp/net.${netif}.did-setup else [ -e /tmp/net.${netif}.did-setup ] && exit 0 [ -z "$DO_VLAN" ] && \ [ -e /sys/class/net/$netif/address ] && \ [ -e /tmp/net.$(cat /sys/class/net/$netif/address).did-setup ] && exit 0 fi # No ip lines default to dhcp ip=$(getarg ip) if [ -z "$NO_AUTO_DHCP" ] && [ -z "$ip" ]; then if [ "$netroot" = "dhcp6" ]; then do_dhcp -6 else do_dhcp -4 fi for s in $(getargs nameserver); do [ -n "$s" ] || continue echo nameserver $s >> /tmp/net.$netif.resolv.conf done fi # Specific configuration, spin through the kernel command line # looking for ip= lines for p in $(getargs ip=); do ip_to_var $p # skip ibft [ "$autoconf" = "ibft" ] && continue case "$dev" in ??:??:??:??:??:??) # MAC address _dev=$(iface_for_mac $dev) [ -n "$_dev" ] && dev="$_dev" ;; ??-??-??-??-??-??) # MAC address in BOOTIF form _dev=$(iface_for_mac $(fix_bootif $dev)) [ -n "$_dev" ] && dev="$_dev" ;; esac # If this option isn't directed at our interface, skip it if [ -n "$dev" ]; then [ "$dev" != "$netif" ] && \ [ "$use_bridge" != 'true' ] && \ [ "$use_vlan" != 'true' ] && continue else iface_is_enslaved "$netif" && continue fi # Store config for later use for i in ip srv gw mask hostname macaddr mtu dns1 dns2; do eval '[ "$'$i'" ] && echo '$i'="$'$i'"' done > /tmp/net.$netif.override for autoopt in $(str_replace "$autoconf" "," " "); do case $autoopt in dhcp|on|any) do_dhcp -4 ;; dhcp6) load_ipv6 do_dhcp -6 ;; auto6) do_ipv6auto ;; either6) do_ipv6auto || do_dhcp -6 ;; *) do_static ;; esac done ret=$? # setup nameserver for s in "$dns1" "$dns2" $(getargs nameserver); do [ -n "$s" ] || continue echo nameserver $s >> /tmp/net.$netif.resolv.conf done if [ $ret -eq 0 ]; then > /tmp/net.${netif}.up if [ -z "$DO_VLAN" ] && [ -e /sys/class/net/${netif}/address ]; then > /tmp/net.$(cat /sys/class/net/${netif}/address).up fi case $autoconf in dhcp|on|any|dhcp6) ;; *) if [ $ret -eq 0 ]; then setup_net $netif source_hook initqueue/online $netif if [ -z "$manualup" ]; then /sbin/netroot $netif fi fi ;; esac exit $ret fi done # netif isn't the top stack? Then we should exit here. # eg. netif is bond0. br0 is on top of it. dhcp br0 is correct but dhcp # bond0 doesn't make sense. if [ -n "$DO_BOND_SETUP" -o -n "$DO_TEAM_SETUP" -o -n "$DO_VLAN_SETUP" ]; then exit 0 fi # no ip option directed at our interface? if [ -z "$NO_AUTO_DHCP" ] && [ ! -e /tmp/net.${netif}.up ]; then if [ -e /tmp/net.bootdev ]; then BOOTDEV=$(cat /tmp/net.bootdev) if [ "$netif" = "$BOOTDEV" ] || [ "$BOOTDEV" = "$(cat /sys/class/net/${netif}/address)" ]; then load_ipv6 do_dhcp fi else if getargs 'ip=dhcp6'; then load_ipv6 do_dhcp -6 fi if getargs 'ip=dhcp'; then do_dhcp -4 fi fi fi exit 0 modules.d/40network/parse-ibft.sh000075500000000611150252660340012667 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh command -v getarg >/dev/null || . /lib/dracut-lib.sh command -v ibft_to_cmdline >/dev/null || . /lib/net-lib.sh if getargbool 0 rd.iscsi.ibft -d "ip=ibft"; then modprobe -b -q iscsi_boot_sysfs 2>/dev/null modprobe -b -q iscsi_ibft ibft_to_cmdline fi modules.d/95virtfs/mount-virtfs.sh000075500000003644150252660340013157 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh filter_rootopts() { rootopts=$1 # strip ro and rw options local OLDIFS="$IFS" IFS=, set -- $rootopts IFS="$OLDIFS" local v while [ $# -gt 0 ]; do case $1 in rw|ro);; defaults);; *) v="$v,${1}";; esac shift done rootopts=${v#,} echo $rootopts } mount_root() { local _ret rootfs="9p" rflags="trans=virtio,version=9p2000.L" modprobe 9pnet_virtio mount -t ${rootfs} -o "$rflags",ro "${root#virtfs:}" "$NEWROOT" rootopts= if getargbool 1 rd.fstab -n rd_NO_FSTAB \ && ! getarg rootflags \ && [ -f "$NEWROOT/etc/fstab" ] \ && ! [ -L "$NEWROOT/etc/fstab" ]; then # if $NEWROOT/etc/fstab contains special mount options for # the root filesystem, # remount it with the proper options rootopts="defaults" while read dev mp fs opts rest; do # skip comments [ "${dev%%#*}" != "$dev" ] && continue if [ "$mp" = "/" ]; then rootopts=$opts break fi done < "$NEWROOT/etc/fstab" rootopts=$(filter_rootopts $rootopts) fi # we want rootflags (rflags) to take precedence so prepend rootopts to # them; rflags is guaranteed to not be empty rflags="${rootopts:+"${rootopts},"}${rflags}" umount "$NEWROOT" info "Remounting ${root#virtfs:} with -o ${rflags}" mount -t ${rootfs} -o "$rflags" "${root#virtfs:}" "$NEWROOT" 2>&1 | vinfo [ -f "$NEWROOT"/forcefsck ] && rm -f -- "$NEWROOT"/forcefsck 2>/dev/null [ -f "$NEWROOT"/.autofsck ] && rm -f -- "$NEWROOT"/.autofsck 2>/dev/null } if [ -n "$root" -a -z "${root%%virtfs:*}" ]; then mount_root fi : modules.d/95virtfs/module-setup.sh000075500000002235150252660340013120 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { [[ $hostonly ]] || [[ $mount_needs ]] && { for fs in "${host_fs_types[@]}"; do [[ "$fs" == "9p" ]] && return 0 done return 255 } if type -P systemd-detect-virt >/dev/null 2>&1; then vm=$(systemd-detect-virt --vm >/dev/null 2>&1) (($? != 0)) && return 255 [[ $vm = "qemu" ]] && return 0 [[ $vm = "kvm" ]] && return 0 [[ $vm = "bochs" ]] && return 0 fi for i in /sys/class/dmi/id/*_vendor; do [[ -f $i ]] || continue read vendor < $i [[ "$vendor" == "QEMU" ]] && return 0 [[ "$vendor" == "Bochs" ]] && return 0 done return 255 } depends() { return 0 } installkernel() { instmods 9p 9pnet_virtio virtio_pci } install() { inst_hook cmdline 95 "$moddir/parse-virtfs.sh" if ! dracut_module_included "systemd"; then inst_hook mount 99 "$moddir/mount-virtfs.sh" else inst_script "$moddir/virtfs-generator.sh" $systemdutildir/system-generators/dracut-virtfs-generator fi } modules.d/95virtfs/parse-virtfs.sh000075500000000345150252660340013122 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh if [ "${root%%:*}" = "virtfs" ] ; then initqueue --onetime modprobe -b -q 9pnet_virtio rootok=1 fi modules.d/95virtfs/virtfs-generator.sh000075500000001632150252660340013776 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh [ -z "$root" ] && root=$(getarg root=) [ "${root%%:*}" = "virtfs" ] || exit 0 GENERATOR_DIR="$2" [ -z "$GENERATOR_DIR" ] && exit 1 [ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR" ROOTFLAGS=$(getarg rootflags=) || ROOTFLAGS="trans=virtio,version=9p2000.L" ROOTFSTYPE=$(getarg rootfstype=) || ROOTFSTYPE="9p" root=${root#virtfs:} if getarg "ro"; then if [ -n "$ROOTFLAGS" ]; then ROOTFLAGS="$ROOTFLAGS,ro" else ROOTFLAGS="ro" fi fi { echo "[Unit]" echo "Before=initrd-root-fs.target" echo "[Mount]" echo "Where=/sysroot" echo "What=${root}" [ -n "$ROOTFSTYPE" ] && echo "Type=${ROOTFSTYPE}" [ -n "$ROOTFLAGS" ] && echo "Options=${ROOTFLAGS}" } > "$GENERATOR_DIR"/sysroot.mount exit 0 modules.d/91crypt-loop/module-setup.sh000064400000000640150252660340013702 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # called by dracut check() { require_binaries losetup || return 1 return 255 } depends() { echo crypt } installkernel() { instmods loop } install() { inst_multiple losetup inst "$moddir/crypt-loop-lib.sh" "/lib/dracut-crypt-loop-lib.sh" dracut_need_initqueue } modules.d/91crypt-loop/crypt-loop-lib.sh000075500000003117150252660340014140 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=4 sw=4 sts=0 et filetype=sh command -v ask_for_password >/dev/null || . /lib/dracut-crypt-lib.sh # loop_decrypt mnt_point keypath keydev device # # Decrypts symmetrically encrypted key to standard output. # # mnt_point - mount point where is already mounted # keypath - LUKS encrypted loop file path relative to # keydev - device on which key resides; only to display in prompt # device - device to be opened by cryptsetup; only to display in prompt loop_decrypt() { local mntp="$1" local keypath="$2" local keydev="$3" local device="$4" local key="/dev/mapper/${mntp##*/}" if [ ! -b $key ]; then info "Keyfile has .img suffix, treating it as LUKS-encrypted loop keyfile container to unlock $device" local loopdev=$(losetup -f "${mntp}/${keypath}" --show) local opts="-d - luksOpen $loopdev ${key##*/}" ask_for_password \ --cmd "cryptsetup $opts" \ --prompt "Password ($keypath on $keydev for $device)" \ --tty-echo-off [ -b $key ] || die "Tried setting it up, but keyfile block device was still not found!" initqueue --onetime --finished --unique --name "crypt-loop-cleanup-10-${key##*/}" \ $(command -v cryptsetup) "luksClose $key" initqueue --onetime --finished --unique --name "crypt-loop-cleanup-20-${loopdev##*/}" \ $(command -v losetup) "-d $loopdev" else info "Existing keyfile found, re-using it for $device" fi cat $key } modules.d/90mdraid/65-md-incremental-imsm.rules000064400000002704150252660340015223 0ustar00# This file causes block devices with Linux RAID (mdadm) signatures to # automatically cause mdadm to be run. # See udev(8) for syntax ACTION!="add|change", GOTO="md_end" SUBSYSTEM!="block", GOTO="md_end" ENV{rd_NO_MD}=="?*", GOTO="md_end" KERNEL=="md*", ENV{ID_FS_TYPE}!="linux_raid_member", GOTO="md_end" KERNEL=="md*", ACTION!="change", GOTO="md_end" # Also don't process disks that are slated to be a multipath device ENV{DM_MULTIPATH_DEVICE_PATH}=="?*", GOTO="md_end" ENV{ID_FS_TYPE}=="ddf_raid_member|isw_raid_member|linux_raid_member", GOTO="md_try" GOTO="md_end" LABEL="md_try" ENV{ID_FS_TYPE}=="isw_raid_member", ENV{rd_NO_MDIMSM}=="?*", GOTO="md_end" ENV{ID_FS_TYPE}=="ddf_raid_member", ENV{rd_NO_MDDDF}=="?*", GOTO="md_end" # already done ? PROGRAM="/bin/sh -c 'for i in $sys/$devpath/holders/md[0-9_]*; do [ -e $$i ] && exit 0; done; exit 1;' ", \ GOTO="md_end" # for native arrays - array's uuid has to be specified # for containers - container's uuid has to be specified # TODO : how to get embedded array's uuid having container's component ? # # UUID CHECK ENV{DEVTYPE}!="partition", \ RUN+="/sbin/partx -d --nr 1-1024 $env{DEVNAME}" RUN+="/sbin/initqueue --timeout --name 50-mdraid_start --onetime --unique /sbin/mdraid_start" # # Incrementally build the md array; this will automatically assemble # any eventual containers as well (imsm, ddf) # LABEL="md_incremental" RUN+="/sbin/mdadm $env{rd_MD_OFFROOT} -I $env{DEVNAME}" LABEL="md_end" modules.d/90mdraid/mdraid-cleanup.sh000075500000001304150252660340013274 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh _offroot=$(strstr "$(mdadm --help-options 2>&1)" offroot && echo --offroot) containers="" for md in /dev/md[0-9_]*; do [ -b "$md" ] || continue udevinfo="$(udevadm info --query=env --name=$md)" strstr "$udevinfo" "DEVTYPE=partition" && continue if strstr "$udevinfo" "MD_LEVEL=container"; then containers="$containers $md" continue fi mdadm $_offroot -S "$md" >/dev/null 2>&1 done for md in $containers; do mdadm $_offroot -S "$md" >/dev/null 2>&1 done unset containers udevinfo _offroot modules.d/90mdraid/mdmon-pre-shutdown.sh000075500000000522150252660340014157 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh _do_mdmon_takeover() { local ret mdmon --takeover --all ret=$? [ $ret -eq 0 ] && info "Taking over mdmon processes." return $ret } if command -v mdmon >/dev/null; then _do_mdmon_takeover $1 fi modules.d/90mdraid/module-setup.sh000075500000007770150252660340013047 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { local _rootdev # No mdadm? No mdraid support. require_binaries mdadm || return 1 [[ $hostonly ]] || [[ $mount_needs ]] && { for dev in "${!host_fs_types[@]}"; do [[ "${host_fs_types[$dev]}" != *_raid_member ]] && continue DEVPATH=$(get_devpath_block "$dev") for holder in "$DEVPATH"/holders/*; do [[ -e "$holder" ]] || continue [[ -e "$holder/md" ]] && return 0 break done done return 255 } return 0 } depends() { echo rootfs-block return 0 } installkernel() { instmods =drivers/md } cmdline() { local _activated dev line UUID declare -A _activated for dev in "${!host_fs_types[@]}"; do [[ "${host_fs_types[$dev]}" != *_raid_member ]] && continue UUID=$( /sbin/mdadm --examine --export $dev \ | while read line; do [[ ${line#MD_UUID=} = $line ]] && continue printf "%s" "${line#MD_UUID=} " done ) [[ -z "$UUID" ]] && continue if ! [[ ${_activated[${UUID}]} ]]; then printf "%s" " rd.md.uuid=${UUID}" _activated["${UUID}"]=1 fi done } install() { local rule rule_path inst_multiple cat inst_multiple -o mdmon inst $(command -v partx) /sbin/partx inst $(command -v mdadm) /sbin/mdadm if [[ $hostonly_cmdline == "yes" ]]; then cmdline >> "${initdir}/etc/cmdline.d/90mdraid.conf" echo >> "${initdir}/etc/cmdline.d/90mdraid.conf" fi # =mdadm-3.3 udev rules inst_rules 63-md-raid-arrays.rules 64-md-raid-assembly.rules # remove incremental assembly from stock rules, so they don't shadow # 65-md-inc*.rules and its fine-grained controls, or cause other problems # when we explicitly don't want certain components to be incrementally # assembled for rule in 64-md-raid.rules 64-md-raid-assembly.rules; do rule_path="${initdir}${udevdir}/rules.d/${rule}" [ -f "${rule_path}" ] && sed -i -r \ -e '/RUN\+?="[[:alpha:]/]*mdadm[[:blank:]]+(--incremental|-I)[[:blank:]]+(\$env\{DEVNAME\}|\$tempnode|\$devnode)/d' \ "${rule_path}" done inst_rules "$moddir/65-md-incremental-imsm.rules" inst_rules "$moddir/59-persistent-storage-md.rules" prepare_udev_rules 59-persistent-storage-md.rules # guard against pre-3.0 mdadm versions, that can't handle containers if ! mdadm -Q -e imsm /dev/null >/dev/null 2>&1; then inst_hook pre-trigger 30 "$moddir/md-noimsm.sh" fi if ! mdadm -Q -e ddf /dev/null >/dev/null 2>&1; then inst_hook pre-trigger 30 "$moddir/md-noddf.sh" fi if [[ $hostonly ]] || [[ $mdadmconf = "yes" ]]; then if [ -f /etc/mdadm.conf ]; then inst /etc/mdadm.conf else [ -f /etc/mdadm/mdadm.conf ] && inst /etc/mdadm/mdadm.conf /etc/mdadm.conf fi if [ -d /etc/mdadm.conf.d ]; then local f inst_dir /etc/mdadm.conf.d for f in /etc/mdadm.conf.d/*.conf; do [ -f "$f" ] || continue inst "$f" done fi fi inst_hook pre-udev 30 "$moddir/mdmon-pre-udev.sh" inst_hook pre-trigger 30 "$moddir/parse-md.sh" inst_hook pre-mount 10 "$moddir/mdraid-waitclean.sh" inst_hook cleanup 99 "$moddir/mdraid-needshutdown.sh" inst_hook shutdown 30 "$moddir/md-shutdown.sh" inst_script "$moddir/mdraid-cleanup.sh" /sbin/mdraid-cleanup inst_script "$moddir/mdraid_start.sh" /sbin/mdraid_start if dracut_module_included "systemd"; then if [ -e $systemdsystemunitdir/mdmon@.service ]; then inst_simple $systemdsystemunitdir/mdmon@.service fi fi inst_hook pre-shutdown 30 "$moddir/mdmon-pre-shutdown.sh" } modules.d/90mdraid/parse-md.sh000075500000004177150252660340012132 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh MD_UUID=$(getargs rd.md.uuid -d rd_MD_UUID=) if ( ! [ -n "$MD_UUID" ] && ! getargbool 0 rd.auto ) || ! getargbool 1 rd.md -d -n rd_NO_MD; then info "rd.md=0: removing MD RAID activation" udevproperty rd_NO_MD=1 else # rewrite the md rules to only process the specified raid array if [ -n "$MD_UUID" ]; then for f in /etc/udev/rules.d/65-md-incremental*.rules; do [ -e "$f" ] || continue while read line; do if [ "${line%%UUID CHECK}" != "$line" ]; then printf 'IMPORT{program}="/sbin/mdadm --examine --export $tempnode"\n' for uuid in $MD_UUID; do printf 'ENV{MD_UUID}=="%s", GOTO="md_uuid_ok"\n' $uuid done; printf 'GOTO="md_end"\n' printf 'LABEL="md_uuid_ok"\n' else echo "$line" fi done < "${f}" > "${f}.new" mv "${f}.new" "$f" done for uuid in $MD_UUID; do wait_for_dev "/dev/disk/by-id/md-uuid-${uuid}" done fi fi if [ -e /etc/mdadm.conf ] && getargbool 1 rd.md.conf -d -n rd_NO_MDADMCONF; then udevproperty rd_MDADMCONF=1 rm -f -- $hookdir/pre-pivot/*mdraid-cleanup.sh fi if ! getargbool 1 rd.md.conf -d -n rd_NO_MDADMCONF; then rm -f -- /etc/mdadm/mdadm.conf /etc/mdadm.conf ln -s $(command -v mdraid-cleanup) $hookdir/pre-pivot/31-mdraid-cleanup.sh 2>/dev/null fi # noiswmd nodmraid for anaconda / rc.sysinit compatibility # note nodmraid really means nobiosraid, so we don't want MDIMSM then either if ! getargbool 1 rd.md.imsm -d -n rd_NO_MDIMSM -n noiswmd -n nodmraid; then info "no MD RAID for imsm/isw raids" udevproperty rd_NO_MDIMSM=1 fi # same thing with ddf containers if ! getargbool 1 rd.md.ddf -n rd_NO_MDDDF -n noddfmd -n nodmraid; then info "no MD RAID for SNIA ddf raids" udevproperty rd_NO_MDDDF=1 fi strstr "$(mdadm --help-options 2>&1)" offroot && udevproperty rd_MD_OFFROOT=--offroot modules.d/90mdraid/md-noddf.sh000075500000000305150252660340012077 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh info "rd.md.ddf=0: no MD RAID for SNIA ddf raids" udevproperty rd_NO_MDDDF=1 modules.d/90mdraid/mdraid-waitclean.sh000075500000001616150252660340013622 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh if getargbool 0 rd.md.waitclean; then _offroot=$(strstr "$(mdadm --help-options 2>&1)" offroot && echo --offroot) type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh containers="" for md in /dev/md[0-9_]*; do [ -b "$md" ] || continue udevinfo="$(udevadm info --query=env --name=$md)" strstr "$udevinfo" "DEVTYPE=partition" && continue if strstr "$udevinfo" "MD_LEVEL=container"; then containers="$containers $md" continue fi info "Waiting for $md to become clean" mdadm $_offroot -W "$md" >/dev/null 2>&1 done for md in $containers; do info "Waiting for $md to become clean" mdadm $_offroot -W "$md" >/dev/null 2>&1 done unset containers udevinfo _offroot fi modules.d/90mdraid/mdraid_start.sh000075500000003637150252660340013077 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getargs >/dev/null 2>&1 || . /lib/dracut-lib.sh _md_start() { local _udevinfo local _path_s local _path_d local _md="$1" local _offroot="$2" _udevinfo="$(udevadm info --query=env --name="${_md}")" strstr "$_udevinfo" "MD_LEVEL=container" && continue strstr "$_udevinfo" "DEVTYPE=partition" && continue _path_s="/sys/$(udevadm info -q path -n "${_md}")/md/array_state" [ ! -r "$_path_s" ] && continue # inactive ? [ "$(cat "$_path_s")" != "inactive" ] && continue mdadm $_offroot -R "${_md}" 2>&1 | vinfo # still inactive ? [ "$(cat "$_path_s")" = "inactive" ] && continue _path_d="${_path_s%/*}/degraded" [ ! -r "$_path_d" ] && continue > $hookdir/initqueue/work } _md_force_run() { local _offroot local _md local _UUID local _MD_UUID=$(getargs rd.md.uuid -d rd_MD_UUID=) [ -n "$_MD_UUID" ] || getargbool 0 rd.auto || return _offroot=$(strstr "$(mdadm --help-options 2>&1)" offroot && echo --offroot) if [ -n "$_MD_UUID" ]; then for _md in /dev/md[0-9_]*; do [ -b "$_md" ] || continue _UUID=$( /sbin/mdadm -D --export "$_md" \ | while read line || [ -n "$line" ]; do str_starts "$line" "MD_UUID=" || continue printf "%s" "${line#MD_UUID=}" done ) [ -z "$_UUID" ] && continue # check if we should handle this device strstr " $_MD_UUID " " $_UUID " || continue _md_start "${_md}" "${_offroot}" done else # try to force-run anything not running yet for _md in /dev/md[0-9_]*; do [ -b "$_md" ] || continue _md_start "${_md}" "${_offroot}" done fi } _md_force_run modules.d/90mdraid/mdraid-needshutdown.sh000075500000000411150252660340014352 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh for md in /dev/md[0-9_]*; do [ -b "$md" ] || continue need_shutdown break done modules.d/90mdraid/mdmon-pre-udev.sh000075500000000360150252660340013247 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # save state dir for mdmon/mdadm for the real root [ -d /run/mdadm ] || mkdir -m 0755 /run/mdadm # backward compat link modules.d/90mdraid/59-persistent-storage-md.rules000064400000001513150252660340015621 0ustar00SUBSYSTEM!="block", GOTO="md_end" ACTION!="add|change", GOTO="md_end" # Also don't process disks that are slated to be a multipath device ENV{DM_MULTIPATH_DEVICE_PATH}=="?*", GOTO="md_end" KERNEL!="md[0-9]*|md_d[0-9]*|md/*", KERNEL!="md*", GOTO="md_end" # partitions have no md/{array_state,metadata_version} ENV{DEVTYPE}=="partition", GOTO="md_ignore_state" # container devices have a metadata version of e.g. 'external:ddf' and # never leave state 'inactive' ATTR{md/metadata_version}=="external:[A-Za-z]*", ATTR{md/array_state}=="inactive", GOTO="md_ignore_state" TEST!="md/array_state", GOTO="md_end" ATTR{md/array_state}=="|clear|inactive", GOTO="md_end" LABEL="md_ignore_state" IMPORT{program}="/sbin/mdadm --detail --export $tempnode" IMPORT BLKID OPTIONS+="link_priority=100" OPTIONS+="watch" OPTIONS+="db_persist" LABEL="md_end" modules.d/90mdraid/md-shutdown.sh000075500000001240150252660340012657 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh _do_md_shutdown() { local ret local final=$1 local _offroot=$(strstr "$(mdadm --help-options 2>&1)" offroot && echo --offroot) info "Waiting for mdraid devices to be clean." mdadm $_offroot -vv --wait-clean --scan| vinfo ret=$? info "Disassembling mdraid devices." mdadm $_offroot -vv --stop --scan | vinfo ret=$(($ret+$?)) if [ "x$final" != "x" ]; then info "/proc/mdstat:" vinfo < /proc/mdstat fi return $ret } if command -v mdadm >/dev/null; then _do_md_shutdown $1 else : fi modules.d/90mdraid/md-noimsm.sh000075500000000307150252660340012311 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh info "rd.md.imsm=0: no MD RAID for imsm/isw raids" udevproperty rd_NO_MDIMSM=1 modules.d/45ifcfg/module-setup.sh000075500000000501150252660340012646 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { [[ -d /etc/sysconfig/network-scripts ]] && return 0 return 255 } depends() { echo "network" return 0 } install() { inst_hook pre-pivot 85 "$moddir/write-ifcfg.sh" } modules.d/45ifcfg/write-ifcfg.sh000075500000020747150252660340012447 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # 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 udevadm settle --timeout=30 mkdir -m 0755 -p /tmp/ifcfg/ mkdir -m 0755 -p /tmp/ifcfg-leases/ get_config_line_by_subchannel() { local CHANNEL local line CHANNELS="$1" while read line || [ -n "$line" ]; do if strstr "$line" "$CHANNELS"; then echo $line return 0 fi done < /etc/ccw.conf return 1 } print_s390() { local _netif local SUBCHANNELS local OPTIONS local NETTYPE local CONFIG_LINE local i local channel local OLD_IFS _netif="$1" # if we find ccw channel, then use those, instead of # of the MAC SUBCHANNELS=$({ for i in /sys/class/net/$_netif/device/cdev[0-9]*; do [ -e $i ] || continue channel=$(readlink -f $i) printf '%s' "${channel##*/}," done }) [ -n "$SUBCHANNELS" ] || return 1 SUBCHANNELS=${SUBCHANNELS%,} echo "SUBCHANNELS=\"${SUBCHANNELS}\"" CONFIG_LINE=$(get_config_line_by_subchannel $SUBCHANNELS) [ $? -ne 0 -o -z "$CONFIG_LINE" ] && return 0 OLD_IFS=$IFS IFS="," set -- $CONFIG_LINE IFS=$OLD_IFS NETTYPE=$1 shift SUBCHANNELS="$1" OPTIONS="" shift while [ $# -gt 0 ]; do case $1 in *=*) OPTIONS="$OPTIONS $1";; esac shift done OPTIONS=${OPTIONS## } echo "NETTYPE=\"${NETTYPE}\"" echo "OPTIONS=\"${OPTIONS}\"" return 0 } hw_bind() { local _netif="$1" local _macaddr="$2" [ -n "$_macaddr" ] \ && echo "MACADDR=\"$_macaddr\"" print_s390 "$_netif" \ && return 0 [ -n "$_macaddr" ] && return 0 is_persistent_ethernet_name "$_netif" && return 0 [ -f "/sys/class/net/$_netif/addr_assign_type" ] \ && [ "$(cat "/sys/class/net/$_netif/addr_assign_type")" != "0" ] \ && return 1 [ -f "/sys/class/net/$_netif/address" ] \ || return 1 echo "HWADDR=\"$(cat /sys/class/net/$_netif/address)\"" } interface_bind() { local _netif="$1" local _macaddr="$2" # see, if we can bind it to some hw parms if hw_bind "$_netif" "$_macaddr"; then # only print out DEVICE, if it's user assigned is_kernel_ethernet_name "$_netif" && return 0 fi echo "DEVICE=\"$_netif\"" } for netup in /tmp/net.*.did-setup ; do [ -f $netup ] || continue netif=${netup%%.did-setup} netif=${netif##*/net.} strstr "$netif" ":*:*:*:*:" && continue [ -e /tmp/ifcfg/ifcfg-$netif ] && continue unset bridge unset bond unset team unset bondslaves unset bondname unset bondoptions unset bridgename unset bridgeslaves unset uuid unset ip unset gw unset mtu unset mask unset macaddr unset slave unset ethname unset vlan unset phydevice [ -e /tmp/bond.${netif}.info ] && . /tmp/bond.${netif}.info [ -e /tmp/bridge.${netif}.info ] && . /tmp/bridge.${netif}.info [ -e /tmp/team.${netif}.info ] && . /tmp/team.${netif}.info [ -e /tmp/net.${netif}.override ] && . /tmp/net.${netif}.override uuid=$(cat /proc/sys/kernel/random/uuid) if [ "$netif" = "$bridgename" ]; then bridge=yes elif [ "$netif" = "$teammaster" ]; then team=yes elif [ "$netif" = "$bondname" ]; then # $netif can't be bridge and bond at the same time bond=yes fi if ! [ -e /tmp/vlan.${netif}.phy ]; then for i in /tmp/vlan.${netif}.*; do [ ! -e "$i" ] && continue phydevice=${i##/tmp/vlan.${netif}.} vlan=yes break done fi # skip team interfaces for now, the host config must be in sync [ "$netif" = "$teammaster" ] && continue { echo "# Generated by dracut initrd" echo "NAME=\"$netif\"" [ -z "$vlan" ] && interface_bind "$netif" "$macaddr" echo "ONBOOT=yes" echo "NETBOOT=yes" echo "UUID=\"$uuid\"" strstr "$(ip -6 addr show dev $netif)" 'inet6' && echo "IPV6INIT=yes" if [ -f /tmp/dhclient.$netif.lease ]; then [ -f /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts if [ -f /tmp/net.$netif.has_ibft_config ]; then echo "BOOTPROTO=ibft" else echo "BOOTPROTO=dhcp" fi cp /tmp/dhclient.$netif.lease /tmp/ifcfg-leases/dhclient-$uuid-$netif.lease else if strstr "$ip" '*:*:*'; then echo "IPV6INIT=yes" echo "IPV6_AUTOCONF=no" echo "IPV6ADDR=\"$ip/$mask\"" else if [ -f /tmp/net.$netif.has_ibft_config ]; then echo "BOOTPROTO=ibft" else echo "BOOTPROTO=none" echo "IPADDR=\"$ip\"" if strstr "$mask" "."; then echo "NETMASK=\"$mask\"" else echo "PREFIX=\"$mask\"" fi fi fi if strstr "$gw" '*:*:*'; then echo "IPV6_DEFAULTGW=\"$gw\"" elif [ -n "$gw" ]; then echo "GATEWAY=\"$gw\"" fi fi [ -n "$mtu" ] && echo "MTU=\"$mtu\"" } > /tmp/ifcfg/ifcfg-$netif # bridge needs different things written to ifcfg if [ -z "$bridge" ] && [ -z "$bond" ] && [ -z "$vlan" ] && [ -z "$team" ]; then # standard interface echo "TYPE=Ethernet" >> /tmp/ifcfg/ifcfg-$netif fi if [ -n "$vlan" ] ; then { echo "TYPE=Vlan" echo "DEVICE=\"$netif\"" echo "VLAN=yes" echo "PHYSDEV=\"$phydevice\"" } >> /tmp/ifcfg/ifcfg-$netif fi if [ -n "$bond" ] ; then # bond interface { # This variable is an indicator of a bond interface for initscripts echo "BONDING_OPTS=\"$bondoptions\"" echo "NAME=\"$netif\"" echo "TYPE=Bond" } >> /tmp/ifcfg/ifcfg-$netif for slave in $bondslaves ; do # write separate ifcfg file for the raw eth interface ( echo "# Generated by dracut initrd" echo "NAME=\"$slave\"" echo "TYPE=Ethernet" echo "ONBOOT=yes" echo "NETBOOT=yes" echo "SLAVE=yes" echo "MASTER=\"$netif\"" echo "UUID=\"$(cat /proc/sys/kernel/random/uuid)\"" unset macaddr [ -e /tmp/net.${slave}.override ] && . /tmp/net.${slave}.override interface_bind "$slave" "$macaddr" ) >> /tmp/ifcfg/ifcfg-$slave done fi if [ -n "$bridge" ] ; then # bridge { echo "TYPE=Bridge" echo "NAME=\"$netif\"" } >> /tmp/ifcfg/ifcfg-$netif for slave in $bridgeslaves ; do # write separate ifcfg file for the raw eth interface ( echo "# Generated by dracut initrd" echo "NAME=\"$slave\"" echo "TYPE=Ethernet" echo "ONBOOT=yes" echo "NETBOOT=yes" echo "BRIDGE=\"$bridgename\"" echo "UUID=\"$(cat /proc/sys/kernel/random/uuid)\"" unset macaddr [ -e /tmp/net.${slave}.override ] && . /tmp/net.${slave}.override interface_bind "$slave" "$macaddr" ) >> /tmp/ifcfg/ifcfg-$slave done fi i=1 for ns in $(getargs nameserver); do echo "DNS${i}=\"${ns}\"" >> /tmp/ifcfg/ifcfg-$netif i=$((i+1)) done [ -f /tmp/net.route6."$netif" ] && cp /tmp/net.route6."$netif" /tmp/ifcfg/route6-"$netif" [ -f /tmp/net.route."$netif" ] && cp /tmp/net.route."$netif" /tmp/ifcfg/route-"$netif" done # Pass network opts mkdir -m 0755 -p /run/initramfs/state/etc/sysconfig/network-scripts mkdir -m 0755 -p /run/initramfs/state/var/lib/dhclient echo "files /etc/sysconfig/network-scripts" >> /run/initramfs/rwtab echo "files /var/lib/dhclient" >> /run/initramfs/rwtab { cp /tmp/net.* /run/initramfs/ cp /tmp/net.$netif.resolv.conf /run/initramfs/state/etc/resolv.conf copytree /tmp/ifcfg /run/initramfs/state/etc/sysconfig/network-scripts cp /tmp/ifcfg-leases/* /run/initramfs/state/var/lib/dhclient } > /dev/null 2>&1 modules.d/99base/module-setup.sh000075500000007426150252660350012531 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh check() { return 0 } depends() { echo udev-rules return 0 } install() { local _d inst_multiple mount mknod mkdir sleep chroot \ sed ls flock cp mv dmesg rm ln rmmod mkfifo umount readlink setsid inst $(command -v modprobe) /sbin/modprobe inst_multiple -o findmnt less kmod if [ ! -e "${initdir}/bin/sh" ]; then inst_multiple bash (ln -s bash "${initdir}/bin/sh" || :) fi #add common users in /etc/passwd, it will be used by nfs/ssh currently egrep '^root:' "$initdir/etc/passwd" 2>/dev/null || echo 'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd" egrep '^nobody:' /etc/passwd >> "$initdir/etc/passwd" # install our scripts and hooks inst_script "$moddir/init.sh" "/init" inst_script "$moddir/initqueue.sh" "/sbin/initqueue" inst_script "$moddir/loginit.sh" "/sbin/loginit" inst_script "$moddir/rdsosreport.sh" "/sbin/rdsosreport" inst_script "$moddir/memtrace-ko.sh" "/sbin/tracekomem" [ -e "${initdir}/lib" ] || mkdir -m 0755 -p ${initdir}/lib mkdir -m 0755 -p ${initdir}/lib/dracut mkdir -m 0755 -p ${initdir}/lib/dracut/hooks mkdir -p ${initdir}/tmp inst_simple "$moddir/dracut-lib.sh" "/lib/dracut-lib.sh" if ! dracut_module_included "systemd"; then inst_multiple switch_root || dfatal "Failed to install switch_root" inst_hook cmdline 10 "$moddir/parse-root-opts.sh" fi mkdir -p "${initdir}/var" if ! dracut_module_included "systemd"; then inst_multiple -o $systemdutildir/systemd-timestamp fi if [[ $realinitpath ]]; then for i in $realinitpath; do echo "rd.distroinit=$i" done > "${initdir}/etc/cmdline.d/distroinit.conf" fi ln -fs /proc/self/mounts "$initdir/etc/mtab" if [[ $ro_mnt = yes ]]; then echo ro >> "${initdir}/etc/cmdline.d/base.conf" fi if [ -e /etc/os-release ]; then . /etc/os-release VERSION+=" " PRETTY_NAME+=" " else VERSION="" PRETTY_NAME="" fi NAME=dracut ID=dracut VERSION+="dracut-$DRACUT_VERSION" PRETTY_NAME+="dracut-$DRACUT_VERSION (Initramfs)" VERSION_ID=$DRACUT_VERSION ANSI_COLOR="0;34" { echo NAME=\"$NAME\" echo VERSION=\"$VERSION\" echo ID=$ID echo VERSION_ID=$VERSION_ID echo PRETTY_NAME=\"$PRETTY_NAME\" echo ANSI_COLOR=\"$ANSI_COLOR\" } > $initdir/etc/initrd-release echo dracut-$DRACUT_VERSION > $initdir/lib/dracut/dracut-$DRACUT_VERSION ln -sf initrd-release $initdir/etc/os-release ## save host_devs which we need bring up if [[ $hostonly_cmdline == "yes" ]]; then if [[ -f "$initdir/lib/dracut/need-initqueue" ]] || ! dracut_module_included "systemd"; then ( if dracut_module_included "systemd"; then DRACUT_SYSTEMD=1 fi PREFIX="$initdir" . "$moddir/dracut-lib.sh" for _dev in "${host_devs[@]}"; do [[ "$_dev" == "$root_dev" ]] && continue # We only actually wait for real devs - swap is only needed # for resume and udev rules generated when parsing resume= # argument take care of the waiting for us for _dev2 in "${swap_devs[@]}"; do [[ "$_dev" == "$_dev2" ]] && continue 2 done _pdev=$(get_persistent_dev $_dev) case "$_pdev" in /dev/?*) wait_for_dev $_pdev;; *) ;; esac done ) fi fi } modules.d/99base/rdsosreport.sh000075500000001656150252660350012473 0ustar00#!/bin/sh echo 'Generating "/run/initramfs/rdsosreport.txt"' [ -d /run/initramfs ] || mkdir -p /run/initramfs exec >/run/initramfs/rdsosreport.txt 2>&1 set -x cat /lib/dracut/dracut-* cat /proc/cmdline [ -f /etc/cmdline ] && cat /etc/cmdline for _i in /etc/cmdline.d/*.conf; do [ -f "$_i" ] || break echo $_i cat $_i done cat /proc/self/mountinfo cat /proc/mounts blkid blkid -o udev ls -l /dev/disk/by* for _i in /etc/conf.d/*.conf; do [ -f "$_i" ] || break echo $_i cat $_i done if command -v lvm >/dev/null 2>/dev/null; then lvm pvdisplay lvm vgdisplay lvm lvdisplay fi command -v dmsetup >/dev/null 2>/dev/null && dmsetup ls --tree cat /proc/mdstat command -v ip >/dev/null 2>/dev/null && ip addr if command -v journalctl >/dev/null 2>/dev/null; then journalctl -ab --no-pager -o short-monotonic else dmesg [ -f /run/initramfs/init.log ] && cat /run/initramfs/init.log fi modules.d/99base/dracut-lib.sh000075500000100135150252660350012123 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh export DRACUT_SYSTEMD export NEWROOT if [ -n "$NEWROOT" ]; then [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT fi if ! [ -d /run/initramfs ]; then mkdir -p -m 0755 /run/initramfs/log ln -sfn /run/initramfs/log /var/log fi [ -d /run/lock ] || mkdir -p -m 0755 /run/lock [ -d /run/log ] || mkdir -p -m 0755 /run/log debug_off() { set +x } debug_on() { [ "$RD_DEBUG" = "yes" ] && set -x } # returns OK if $1 contains $2 strstr() { [ "${1#*$2*}" != "$1" ] } # returns OK if $1 contains $2 at the beginning str_starts() { [ "${1#$2*}" != "$1" ] } # returns OK if $1 contains $2 at the end str_ends() { [ "${1%*$2}" != "$1" ] } trim() { local var="$*" var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters echo -n "$var" } if [ -z "$DRACUT_SYSTEMD" ]; then warn() { check_quiet echo "<28>dracut Warning: $*" > /dev/kmsg echo "dracut Warning: $*" >&2 } info() { check_quiet echo "<30>dracut: $*" > /dev/kmsg [ "$DRACUT_QUIET" != "yes" ] && \ echo "dracut: $*" >&2 } else warn() { echo "Warning: $*" >&2 } info() { check_quiet [ "$DRACUT_QUIET" != "yes" ] && \ echo "$*" >&2 } fi vwarn() { while read line || [ -n "$line" ]; do warn $line; done } vinfo() { while read line || [ -n "$line" ]; do info $line; done } # replaces all occurrences of 'search' in 'str' with 'replacement' # # str_replace str search replacement # # example: # str_replace ' one two three ' ' ' '_' str_replace() { local in="$1"; local s="$2"; local r="$3" local out='' while strstr "${in}" "$s"; do chop="${in%%$s*}" out="${out}${chop}$r" in="${in#*$s}" done echo "${out}${in}" } killall_proc_mountpoint() { local _pid local _t for _pid in /proc/*; do _pid=${_pid##/proc/} case $_pid in *[!0-9]*) continue;; esac [ -e "/proc/$_pid/exe" ] || continue [ -e "/proc/$_pid/root" ] || continue strstr "$(ls -l -- "/proc/$_pid" "/proc/$_pid/fd" 2>/dev/null)" "$1" && kill -9 "$_pid" done } getcmdline() { local _line local _i local CMDLINE_ETC_D local CMDLINE_ETC local CMDLINE_PROC unset _line if [ -e /etc/cmdline ]; then while read -r _line; do CMDLINE_ETC="$CMDLINE_ETC $_line"; done ", we want the exact match if [ "$_o" = "$1" ]; then _val="1"; unset _doecho fi continue fi if [ "${_o#*=}" = "$_o" ]; then # if cmdline argument has no "=", we assume "=1" _val="1"; unset _doecho continue fi _val="${_o#*=}" _doecho=1 fi done if [ -n "$_val" ]; then [ "x$_doecho" != "x" ] && echo "$_val"; return 0; fi return 1; } getarg() { debug_off local _deprecated _newoption while [ $# -gt 0 ]; do case $1 in -d) _deprecated=1; shift;; -y) if _dogetarg $2 >/dev/null; then if [ "$_deprecated" = "1" ]; then [ -n "$_newoption" ] && warn "Kernel command line option '$2' is deprecated, use '$_newoption' instead." || warn "Option '$2' is deprecated." fi echo 1 debug_on return 0 fi _deprecated=0 shift 2;; -n) if _dogetarg $2 >/dev/null; then echo 0; if [ "$_deprecated" = "1" ]; then [ -n "$_newoption" ] && warn "Kernel command line option '$2' is deprecated, use '$_newoption=0' instead." || warn "Option '$2' is deprecated." fi debug_on return 1 fi _deprecated=0 shift 2;; *) if [ -z "$_newoption" ]; then _newoption="$1" fi if _dogetarg $1; then if [ "$_deprecated" = "1" ]; then [ -n "$_newoption" ] && warn "Kernel command line option '$1' is deprecated, use '$_newoption' instead." || warn "Option '$1' is deprecated." fi debug_on return 0; fi _deprecated=0 shift;; esac done debug_on return 1 } # getargbool # False if "getarg " returns "0", "no", or "off". # True if getarg returns any other non-empty string. # If not found, assumes - usually 0 for false, 1 for true. # example: getargbool 0 rd.info # true: rd.info, rd.info=1, rd.info=xxx # false: rd.info=0, rd.info=off, rd.info not present (default val is 0) getargbool() { local _b unset _b local _default _default="$1"; shift _b=$(getarg "$@") [ $? -ne 0 -a -z "$_b" ] && _b="$_default" if [ -n "$_b" ]; then [ $_b = "0" ] && return 1 [ $_b = "no" ] && return 1 [ $_b = "off" ] && return 1 fi return 0 } isdigit() { case "$1" in *[!0-9]*|"") return 1;; esac return 0 } # getargnum # Will echo the arg if it's in range [minval - maxval]. # If it's not set or it's not valid, will set it . # Note all values are required to be >= 0 here. # should be with [minval -maxval]. getargnum() { local _b unset _b local _default _min _max _default="$1"; shift _min="$1"; shift _max="$1"; shift _b=$(getarg "$1") [ $? -ne 0 -a -z "$_b" ] && _b=$_default if [ -n "$_b" ]; then isdigit "$_b" && _b=$(($_b)) && \ [ $_b -ge $_min ] && [ $_b -le $_max ] && echo $_b && return fi echo $_default } _dogetargs() { debug_off local _o _found _key unset _o unset _found CMDLINE=$(getcmdline) _key="$1" set -- for _o in $CMDLINE; do if [ "$_o" = "$_key" ]; then _found=1; elif [ "${_o%%=*}" = "${_key%=}" ]; then [ -n "${_o%%=*}" ] && set -- "$@" "${_o#*=}"; _found=1; fi done if [ -n "$_found" ]; then [ $# -gt 0 ] && printf '%s' "$*" return 0 fi return 1; } getargs() { debug_off local _val _i _args _gfound _deprecated unset _val unset _gfound _newoption="$1" _args="$@" set -- for _i in $_args; do if [ "$i" = "-d" ]; then _deprecated=1 continue fi _val="$(_dogetargs $_i)" if [ $? -eq 0 ]; then if [ "$_deprecated" = "1" ]; then [ -n "$_newoption" ] && warn "Option '$_i' is deprecated, use '$_newoption' instead." || warn "Option $_i is deprecated!" fi _gfound=1 fi [ -n "$_val" ] && set -- "$@" "$_val" _deprecated=0 done if [ -n "$_gfound" ]; then if [ $# -gt 0 ]; then printf '%s' "$*" else printf 1 fi debug_on return 0 fi debug_on return 1; } # Prints value of given option. If option is a flag and it's present, # it just returns 0. Otherwise 1 is returned. # $1 = options separated by commas # $2 = option we are interested in # # Example: # $1 = cipher=aes-cbc-essiv:sha256,hash=sha256,verify # $2 = hash # Output: # sha256 getoptcomma() { local line=",$1,"; local opt="$2"; local tmp case "${line}" in *,${opt}=*,*) tmp="${line#*,${opt}=}" echo "${tmp%%,*}" return 0 ;; *,${opt},*) return 0;; esac return 1 } # Splits given string 'str' with separator 'sep' into variables 'var1', 'var2', # 'varN'. If number of fields is less than number of variables, remaining are # not set. If number of fields is greater than number of variables, the last # variable takes remaining fields. In short - it acts similary to 'read'. # # splitsep sep str var1 var2 varN # # example: # splitsep ':' 'foo:bar:baz' v1 v2 # in result: # v1='foo', v2='bar:baz' # # TODO: ':' inside fields. splitsep() { debug_off local sep="$1"; local str="$2"; shift 2 local tmp while [ -n "$str" -a "$#" -gt 1 ]; do tmp="${str%%$sep*}" eval "$1='${tmp}'" str="${str#"$tmp"}" str="${str#$sep}" shift done [ -n "$str" -a -n "$1" ] && eval "$1='$str'" debug_on return 0 } setdebug() { [ -f /etc/initrd-release ] || return if [ -z "$RD_DEBUG" ]; then if [ -e /proc/cmdline ]; then RD_DEBUG=no if getargbool 0 rd.debug -d -y rdinitdebug -d -y rdnetdebug; then RD_DEBUG=yes [ -n "$BASH" ] && \ export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): '; fi fi export RD_DEBUG fi debug_on } setdebug source_all() { local f local _dir _dir=$1; shift [ "$_dir" ] && [ -d "/$_dir" ] || return for f in "/$_dir"/*.sh; do [ -e "$f" ] && . "$f" "$@"; done } hookdir=/lib/dracut/hooks export hookdir source_hook() { local _dir _dir=$1; shift source_all "/lib/dracut/hooks/$_dir" "$@" } check_finished() { local f for f in $hookdir/initqueue/finished/*.sh; do [ "$f" = "$hookdir/initqueue/finished/*.sh" ] && return 0 { [ -e "$f" ] && ( . "$f" ) ; } || return 1 done return 0 } source_conf() { local f [ "$1" ] && [ -d "/$1" ] || return for f in "/$1"/*.conf; do [ -e "$f" ] && . "$f"; done } die() { { echo "<24>dracut: FATAL: $*"; echo "<24>dracut: Refusing to continue"; } > /dev/kmsg { echo "warn dracut: FATAL: \"$*\""; echo "warn dracut: Refusing to continue"; } >> $hookdir/emergency/01-die.sh [ -d /run/initramfs ] || mkdir -p -- /run/initramfs > /run/initramfs/.die getargbool 0 "rd.debug=" && emergency_shell if [ -n "$DRACUT_SYSTEMD" ]; then systemctl --no-block --force halt fi exit 1 } check_quiet() { if [ -z "$DRACUT_QUIET" ]; then DRACUT_QUIET="yes" getargbool 0 rd.info -d -y rdinfo && DRACUT_QUIET="no" getargbool 0 rd.debug -d -y rdinitdebug && DRACUT_QUIET="no" if [ -z "$DRACUT_SYSTEMD" ]; then getarg quiet || DRACUT_QUIET="yes" a=$(getarg loglevel=) [ -n "$a" ] && [ $a -ge 28 ] && DRACUT_QUIET="yes" fi export DRACUT_QUIET fi } check_occurances() { # Count the number of times the character $ch occurs in $str # Return 0 if the count matches the expected number, 1 otherwise local str="$1" local ch="$2" local expected="$3" local count=0 while [ "${str#*$ch}" != "${str}" ]; do str="${str#*$ch}" count=$(( $count + 1 )) done [ $count -eq $expected ] } incol2() { debug_off local dummy check; local file="$1"; local str="$2"; [ -z "$file" ] && return 1; [ -z "$str" ] && return 1; while read dummy check restofline; do if [ "$check" = "$str" ]; then debug_on return 0 fi done < $file debug_on return 1 } udevsettle() { [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version) if [ $UDEVVERSION -ge 143 ]; then udevadm settle --exit-if-exists=$hookdir/initqueue/work $settle_exit_if_exists else udevadm settle --timeout=30 fi } udevproperty() { [ -z "$UDEVVERSION" ] && export UDEVVERSION=$(udevadm --version) if [ $UDEVVERSION -ge 143 ]; then for i in "$@"; do udevadm control --property=$i; done else for i in "$@"; do udevadm control --env=$i; done fi } find_mount() { local dev mnt etc wanted_dev wanted_dev="$(readlink -e -q $1)" while read dev mnt etc; do [ "$dev" = "$wanted_dev" ] && echo "$dev" && return 0 done < /proc/mounts return 1 } # usage: ismounted # usage: ismounted /dev/ if command -v findmnt >/dev/null; then ismounted() { findmnt "$1" > /dev/null 2>&1 } else ismounted() { if [ -b "$1" ]; then find_mount "$1" > /dev/null && return 0 return 1 fi while read a m a; do [ "$m" = "$1" ] && return 0 done < /proc/mounts return 1 } fi # root=nfs:[:][:] # root=nfs4:[:][:] nfsroot_to_var() { # strip nfs[4]: local arg="$@:" nfs="${arg%%:*}" arg="${arg##$nfs:}" # check if we have a server if strstr "$arg" ':/*' ; then server="${arg%%:/*}" arg="/${arg##*:/}" fi path="${arg%%:*}" # rest are options options="${arg##$path}" # strip leading ":" options="${options##:}" # strip ":" options="${options%%:}" # Does it really start with '/'? [ -n "${path%%/*}" ] && path="error"; #Fix kernel legacy style separating path and options with ',' if [ "$path" != "${path#*,}" ] ; then options=${path#*,} path=${path%%,*} fi } # Create udev rule match for a device with its device name, or the udev property # ID_FS_UUID or ID_FS_LABEL # # example: # udevmatch LABEL=boot # prints: # ENV{ID_FS_LABEL}="boot" # # TOOD: symlinks udevmatch() { case "$1" in UUID=????????-????-????-????-????????????|LABEL=*|PARTLABEL=*|PARTUUID=????????-????-????-????-????????????) printf 'ENV{ID_FS_%s}=="%s"' "${1%%=*}" "${1#*=}" ;; UUID=*) printf 'ENV{ID_FS_UUID}=="%s*"' "${1#*=}" ;; PARTUUID=*) printf 'ENV{ID_FS_PARTUUID}=="%s*"' "${1#*=}" ;; /dev/?*) printf -- 'KERNEL=="%s"' "${1#/dev/}" ;; *) return 255 ;; esac } # Prints unique path for potential file inside specified directory. It consists # of specified directory, prefix and number at the end which is incremented # until non-existing file is found. # # funiq dir prefix # # example: # # ls /mnt # cdrom0 cdrom1 # # # funiq /mnt cdrom # /mnt/cdrom2 funiq() { local dir="$1"; local prefix="$2" local i=0 [ -d "${dir}" ] || return 1 while [ -e "${dir}/${prefix}$i" ]; do i=$(($i+1)) || return 1 done echo "${dir}/${prefix}$i" } # Creates unique directory and prints its path. It's using funiq to generate # path. # # mkuniqdir subdir new_dir_name mkuniqdir() { local dir="$1"; local prefix="$2" local retdir; local retdir_new [ -d "${dir}" ] || mkdir -m 0755 -p "${dir}" || return 1 retdir=$(funiq "${dir}" "${prefix}") || return 1 until mkdir -m 0755 "${retdir}" 2>/dev/null; do retdir_new=$(funiq "${dir}" "${prefix}") || return 1 [ "$retdir_new" = "$retdir" ] && return 1 retdir="$retdir_new" done echo "${retdir}" } # Copy the contents of SRC into DEST, merging the contents of existing # directories (kinda like rsync, or cpio -p). # Creates DEST if it doesn't exist. Overwrites files with the same names. # # copytree SRC DEST copytree() { local src="$1" dest="$2" mkdir -p "$dest"; dest=$(readlink -e -q "$dest") ( cd "$src"; cp -af . -t "$dest" ) } # Evaluates command for UUIDs either given as arguments for this function or all # listed in /dev/disk/by-uuid. UUIDs doesn't have to be fully specified. If # beginning is given it is expanded to all matching UUIDs. To pass full UUID to # your command use '$___' as a place holder. Remember to escape '$'! # # foreach_uuid_until [ -p prefix ] command UUIDs # # prefix - string to put just before $___ # command - command to be evaluated # UUIDs - list of UUIDs separated by space # # The function returns after *first successful evaluation* of the given command # with status 0. If evaluation fails for every UUID function returns with # status 1. # # Example: # foreach_uuid_until "mount -U \$___ /mnt; echo OK; umount /mnt" \ # "01234 f512 a235567f-12a3-c123-a1b1-01234567abcb" foreach_uuid_until() ( cd /dev/disk/by-uuid [ "$1" = -p ] && local prefix="$2" && shift 2 local cmd="$1"; shift; local uuids_list="$*" local uuid; local full_uuid; local ___ [ -n "${cmd}" ] || return 1 for uuid in ${uuids_list:-*}; do for full_uuid in ${uuid}*; do [ -e "${full_uuid}" ] || continue ___="${prefix}${full_uuid}" eval ${cmd} && return 0 done done return 1 ) # Get kernel name for given device. Device may be the name too (then the same # is returned), a symlink (full path), UUID (prefixed with "UUID=") or label # (prefixed with "LABEL="). If just a beginning of the UUID is specified or # even an empty, function prints all device names which UUIDs match - every in # single line. # # NOTICE: The name starts with "/dev/". # # Example: # devnames UUID=123 # May print: # /dev/dm-1 # /dev/sdb1 # /dev/sdf3 devnames() { local dev="$1"; local d; local names case "$dev" in UUID=*) dev="$(foreach_uuid_until '! blkid -U $___' "${dev#UUID=}")" \ && return 255 [ -z "$dev" ] && return 255 ;; LABEL=*) dev="$(blkid -L "${dev#LABEL=}")" || return 255 ;; /dev/?*) ;; *) return 255 ;; esac for d in $dev; do names="$names $(readlink -e -q "$d")" || return 255 done echo "${names# }" } usable_root() { local _i [ -d "$1" ] || return 1 for _i in "$1"/usr/lib*/ld-*.so "$1"/lib*/ld-*.so; do [ -e "$_i" ] && return 0 done for _i in proc sys dev; do [ -e "$1"/$_i ] || return 1 done return 0 } inst_hook() { local _hookname _unique _name _job _exe while [ $# -gt 0 ]; do case "$1" in --hook) _hookname="/$2";shift;; --unique) _unique="yes";; --name) _name="$2";shift;; *) break;; esac shift done if [ -z "$_unique" ]; then _job="${_name}$$" else _job="${_name:-$1}" _job=${_job##*/} fi _exe=$1 shift [ -x "$_exe" ] || _exe=$(command -v $_exe) if [ -n "$onetime" ]; then { echo '[ -e "$_job" ] && rm -f -- "$_job"' echo "$_exe $@" } > "/tmp/$$-${_job}.sh" else echo "$_exe $@" > "/tmp/$$-${_job}.sh" fi mv -f "/tmp/$$-${_job}.sh" "$hookdir/${_hookname}/${_job}.sh" } # inst_mount_hook