8889841cmodules.d/90crypt/crypt-run-generator.sh000075500000001567150526573730014264 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 type crypttab_contains >/dev/null 2>&1 || . /lib/dracut-crypt-lib.sh dev=$1 luks=$2 crypttab_contains "$luks" && exit 0 allowdiscards="-" # parse for allow-discards if strstr "$(cryptsetup --help)" "allow-discards"; then if discarduuids=$(getargs "rd.luks.allow-discards"); then discarduuids=$(str_replace "$discarduuids" 'luks-' '') if strstr " $discarduuids " " ${luks##luks-}"; then allowdiscards="allow-discards" fi elif getargbool 0 rd.luks.allow-discards; then allowdiscards="allow-discards" fi fi echo "$luks $dev - timeout=0,$allowdiscards" >> /etc/crypttab if command -v systemctl >/dev/null; then systemctl daemon-reload systemctl start cryptsetup.target fi exit 0 modules.d/90crypt/cryptroot-ask.sh000075500000010272150526573730013147 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 NEWROOT=${NEWROOT:-"/sysroot"} # do not ask, if we already have root [ -f $NEWROOT/proc ] && exit 0 # check if destination already exists [ -b /dev/mapper/$2 ] && exit 0 # we already asked for this device [ -f /tmp/cryptroot-asked-$2 ] && exit 0 # load dm_crypt if it is not already loaded [ -d /sys/module/dm_crypt ] || modprobe dm_crypt . /lib/dracut-crypt-lib.sh # default luksname - luks-UUID luksname=$2 # fallback to passphrase ask_passphrase=1 # if device name is /dev/dm-X, convert to /dev/mapper/name if [ "${1##/dev/dm-}" != "$1" ]; then device="/dev/mapper/$(dmsetup info -c --noheadings -o name "$1")" else device="$1" fi # number of tries numtries=${3:-10} # TODO: improve to support what cmdline does if [ -f /etc/crypttab ] && getargbool 1 rd.luks.crypttab -d -n rd_NO_CRYPTTAB; then while read name dev luksfile luksoptions; do # ignore blank lines and comments if [ -z "$name" -o "${name#\#}" != "$name" ]; then continue fi # UUID used in crypttab if [ "${dev%%=*}" = "UUID" ]; then if [ "luks-${dev##UUID=}" = "$2" ]; then luksname="$name" break fi # path used in crypttab else cdev=$(readlink -f $dev) mdev=$(readlink -f $device) if [ "$cdev" = "$mdev" ]; then luksname="$name" break fi fi done < /etc/crypttab unset name dev fi # # Open LUKS device # info "luksOpen $device $luksname $luksfile $luksoptions" OLD_IFS="$IFS" IFS=, set -- $luksoptions IFS="$OLD_IFS" while [ $# -gt 0 ]; do case $1 in noauto) # skip this exit 0 ;; swap) # skip this exit 0 ;; tmp) # skip this exit 0 ;; allow-discards) allowdiscards="--allow-discards" esac shift done # parse for allow-discards if strstr "$(cryptsetup --help)" "allow-discards"; then if discarduuids=$(getargs "rd.luks.allow-discards"); then discarduuids=$(str_replace "$discarduuids" 'luks-' '') if strstr " $discarduuids " " ${luksdev##luks-}"; then allowdiscards="--allow-discards" fi elif getargbool 0 rd.luks.allow-discards; then allowdiscards="--allow-discards" fi fi if strstr "$(cryptsetup --help)" "allow-discards"; then cryptsetupopts="$cryptsetupopts $allowdiscards" fi unset allowdiscards if [ -n "$luksfile" -a "$luksfile" != "none" -a -e "$luksfile" ]; then if cryptsetup --key-file "$luksfile" $cryptsetupopts luksOpen "$device" "$luksname"; then ask_passphrase=0 fi else while [ -n "$(getarg rd.luks.key)" ]; do if tmp=$(getkey /tmp/luks.keys $device); then keydev="${tmp%%:*}" keypath="${tmp#*:}" else if [ $numtries -eq 0 ]; then warn "No key found for $device. Fallback to passphrase mode." break fi sleep 1 info "No key found for $device. Will try $numtries time(s) more later." initqueue --unique --onetime --settled \ --name cryptroot-ask-$luksname \ $(command -v cryptroot-ask) "$device" "$luksname" "$(($numtries-1))" exit 0 fi unset tmp info "Using '$keypath' on '$keydev'" readkey "$keypath" "$keydev" "$device" \ | cryptsetup -d - $cryptsetupopts luksOpen "$device" "$luksname" unset keypath keydev ask_passphrase=0 break done fi if [ $ask_passphrase -ne 0 ]; then luks_open="$(command -v cryptsetup) $cryptsetupopts luksOpen" ask_for_password --ply-tries 5 \ --ply-cmd "$luks_open -T1 $device $luksname" \ --ply-prompt "Password ($device)" \ --tty-tries 1 \ --tty-cmd "$luks_open -T5 $device $luksname" unset luks_open fi unset device luksname luksfile # mark device as asked >> /tmp/cryptroot-asked-$2 need_shutdown udevsettle exit 0 modules.d/90crypt/crypt-cleanup.sh000075500000001047150526573730013114 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # close everything which is not busy rm -f -- /etc/udev/rules.d/70-luks.rules >/dev/null 2>&1 if ! getarg rd.luks.uuid -d rd_LUKS_UUID >/dev/null 2>&1 && getargbool 1 rd.luks -d -n rd_NO_LUKS >/dev/null 2>&1; then while true; do local do_break="y" for i in /dev/mapper/luks-*; do cryptsetup luksClose $i >/dev/null 2>&1 && do_break=n done [ "$do_break" = "y" ] && break done fi modules.d/90crypt/crypt-lib.sh000075500000015362150526573730012240 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 # check if the crypttab contains an entry for a LUKS UUID crypttab_contains() { local luks="$1" local l d rest if [ -f /etc/crypttab ]; then while read l d rest; do strstr "${l##luks-}" "${luks##luks-}" && return 0 strstr "$d" "${luks##luks-}" && return 0 done < /etc/crypttab fi return 1 } # ask_for_password # # Wraps around plymouth ask-for-password and adds fallback to tty password ask # if plymouth is not present. # # --cmd command # Command to execute. Required. # --prompt prompt # Password prompt. Note that function already adds ':' at the end. # Recommended. # --tries n # How many times repeat command on its failure. Default is 3. # --ply-[cmd|prompt|tries] # Command/prompt/tries specific for plymouth password ask only. # --tty-[cmd|prompt|tries] # Command/prompt/tries specific for tty password ask only. # --tty-echo-off # Turn off input echo before tty command is executed and turn on after. # It's useful when password is read from stdin. ask_for_password() { local cmd; local prompt; local tries=3 local ply_cmd; local ply_prompt; local ply_tries=3 local tty_cmd; local tty_prompt; local tty_tries=3 local ret while [ $# -gt 0 ]; do case "$1" in --cmd) ply_cmd="$2"; tty_cmd="$2" shift;; --ply-cmd) ply_cmd="$2"; shift;; --tty-cmd) tty_cmd="$2"; shift;; --prompt) ply_prompt="$2"; tty_prompt="$2" shift;; --ply-prompt) ply_prompt="$2"; shift;; --tty-prompt) tty_prompt="$2"; shift;; --tries) ply_tries="$2"; tty_tries="$2"; shift;; --ply-tries) ply_tries="$2"; shift;; --tty-tries) tty_tries="$2"; shift;; --tty-echo-off) tty_echo_off=yes;; esac shift done { flock -s 9; # Prompt for password with plymouth, if installed and running. if type plymouth >/dev/null 2>&1 && plymouth --ping 2>/dev/null; then plymouth ask-for-password \ --prompt "$ply_prompt" --number-of-tries=$ply_tries \ --command="$ply_cmd" ret=$? else if [ "$tty_echo_off" = yes ]; then stty_orig="$(stty -g)" stty -echo fi local i=1 while [ $i -le $tty_tries ]; do [ -n "$tty_prompt" ] && \ printf "$tty_prompt [$i/$tty_tries]:" >&2 eval "$tty_cmd" && ret=0 && break ret=$? i=$(($i+1)) [ -n "$tty_prompt" ] && printf '\n' >&2 done [ "$tty_echo_off" = yes ] && stty $stty_orig fi } 9>/.console_lock [ $ret -ne 0 ] && echo "Wrong password" >&2 return $ret } # Try to mount specified device (by path, by UUID or by label) and check # the path with 'test'. # # example: # test_dev -f LABEL="nice label" /some/file1 test_dev() { local test_op=$1; local dev="$2"; local f="$3" local ret=1; local mount_point=$(mkuniqdir /mnt testdev) local path [ -n "$dev" -a -n "$*" ] || return 1 [ -d "$mount_point" ] || die 'Mount point does not exist!' if mount -r "$dev" "$mount_point" >/dev/null 2>&1; then test $test_op "${mount_point}/${f}" ret=$? umount "$mount_point" fi rmdir "$mount_point" return $ret } # match_dev devpattern dev # # Returns true if 'dev' matches 'devpattern'. Both 'devpattern' and 'dev' are # expanded to kernel names and then compared. If name of 'dev' is on list of # names of devices matching 'devpattern', the test is positive. 'dev' and # 'devpattern' may be anything which function 'devnames' recognizes. # # If 'devpattern' is empty or '*' then function just returns true. # # Example: # match_dev UUID=123 /dev/dm-1 # Returns true if /dev/dm-1 UUID starts with "123". match_dev() { [ -z "$1" -o "$1" = '*' ] && return 0 local devlist; local dev devlist="$(devnames "$1")" || return 255 dev="$(devnames "$2")" || return 255 strstr " $devlist " " $dev " } # getkey keysfile for_dev # # Reads file produced by probe-keydev and looks for first line to # which device matches. The successful result is printed in format # ":". When nothing found, just false is returned. # # Example: # getkey /tmp/luks.keys /dev/sdb1 # May print: # /dev/sdc1:/keys/some.key getkey() { local keys_file="$1"; local for_dev="$2" local luks_dev; local key_dev; local key_path [ -z "$keys_file" -o -z "$for_dev" ] && die 'getkey: wrong usage!' [ -f "$keys_file" ] || return 1 local IFS=: while read luks_dev key_dev key_path; do if match_dev "$luks_dev" "$for_dev"; then echo "${key_dev}:${key_path}" return 0 fi done < "$keys_file" return 1 } # readkey keypath keydev device # # Mounts , reads key from file , optionally processes it (e.g. # if encrypted with GPG) and prints to standard output which is supposed to be # read by cryptsetup. is just passed to helper function for # informational purpose. readkey() { local keypath="$1" local keydev="$2" local device="$3" # This creates a unique single mountpoint for *, or several for explicitly # given LUKS devices. It accomplishes unlocking multiple LUKS devices with # a single password entry. local mntp="/mnt/$(str_replace "keydev-$keydev-$keypath" '/' '-')" if [ ! -d "$mntp" ]; then mkdir "$mntp" mount -r "$keydev" "$mntp" || die 'Mounting rem. dev. failed!' fi case "${keypath##*.}" in gpg) if [ -f /lib/dracut-crypt-gpg-lib.sh ]; then . /lib/dracut-crypt-gpg-lib.sh gpg_decrypt "$mntp" "$keypath" "$keydev" "$device" else die "No GPG support to decrypt '$keypath' on '$keydev'." fi ;; img) if [ -f /lib/dracut-crypt-loop-lib.sh ]; then . /lib/dracut-crypt-loop-lib.sh loop_decrypt "$mntp" "$keypath" "$keydev" "$device" initqueue --onetime --finished --unique --name "crypt-loop-cleanup-99-${mntp##*/}" \ $(command -v umount) "$mntp; " $(command -v rmdir) "$mntp" return 0 else die "No loop file support to decrypt '$keypath' on '$keydev'." fi ;; *) cat "$mntp/$keypath" ;; esac # General unmounting mechanism, modules doing custom cleanup should return earlier # and install a pre-pivot cleanup hook umount "$mntp" rmdir "$mntp" } modules.d/90crypt/parse-keydev.sh000075500000002354150526573730012727 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 rd.luks -n rd_NO_LUKS && \ [ -n "$(getarg rd.luks.key)" ]; then exec 7>/etc/udev/rules.d/65-luks-keydev.rules echo 'SUBSYSTEM!="block", GOTO="luks_keydev_end"' >&7 echo 'ACTION!="add|change", GOTO="luks_keydev_end"' >&7 for arg in $(getargs rd.luks.key); do unset keypath keydev luksdev splitsep : "$arg" keypath keydev luksdev info "rd.luks.key: keypath='$keypath' keydev='$keydev' luksdev='$luksdev'" if [ -z "$keypath" ]; then warn 'keypath required!' continue fi if [ -n "$keydev" ]; then udevmatch "$keydev" >&7 || { warn 'keydev incorrect!' continue } printf ', ' >&7 fi { printf -- 'RUN+="%s --unique --onetime ' $(command -v initqueue) printf -- '--name probe-keydev-%%k ' printf -- '%s /dev/%%k %s %s"\n' \ $(command -v probe-keydev) "${keypath}" "${luksdev}" } >&7 done unset arg keypath keydev luksdev echo 'LABEL="luks_keydev_end"' >&7 exec 7>&- fi modules.d/90crypt/parse-crypt.sh000075500000006314150526573730012601 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 crypttab_contains >/dev/null 2>&1 || . /lib/dracut-crypt-lib.sh if ! getargbool 1 rd.luks -d -n rd_NO_LUKS; then info "rd.luks=0: removing cryptoluks activation" rm -f -- /etc/udev/rules.d/70-luks.rules else { echo 'SUBSYSTEM!="block", GOTO="luks_end"' echo 'ACTION!="add|change", GOTO="luks_end"' } > /etc/udev/rules.d/70-luks.rules.new LUKS=$(getargs rd.luks.uuid -d rd_LUKS_UUID) tout=$(getarg rd.luks.key.tout) if [ -n "$LUKS" ]; then for luksid in $LUKS; do luksid=${luksid##luks-} if [ -z "$DRACUT_SYSTEMD" ]; then { printf -- 'ENV{ID_FS_TYPE}=="crypto_LUKS", ' printf -- 'ENV{ID_FS_UUID}=="*%s*", ' $luksid printf -- 'RUN+="%s --settled --unique --onetime ' $(command -v initqueue) printf -- '--name cryptroot-ask-%%k %s ' $(command -v cryptroot-ask) printf -- '$env{DEVNAME} luks-$env{ID_FS_UUID} %s"\n' $tout } >> /etc/udev/rules.d/70-luks.rules.new else if ! crypttab_contains "$luksid"; then { printf -- 'ENV{ID_FS_TYPE}=="crypto_LUKS", ' printf -- 'ENV{ID_FS_UUID}=="*%s*", ' $luksid printf -- 'RUN+="%s --settled --unique --onetime ' $(command -v initqueue) printf -- '--name systemd-cryptsetup-%%k %s start ' $(command -v systemctl) printf -- 'systemd-cryptsetup@luks$$(dev_unit_name -$env{ID_FS_UUID}).service"\n' } >> /etc/udev/rules.d/70-luks.rules.new fi fi uuid=$luksid while [ "$uuid" != "${uuid#*-}" ]; do uuid=${uuid%%-*}${uuid#*-}; done printf -- '[ -e /dev/disk/by-id/dm-uuid-CRYPT-LUKS?-*%s*-* ] || exit 1\n' $uuid \ >> $hookdir/initqueue/finished/90-crypt.sh { printf -- '[ -e /dev/disk/by-uuid/*%s* ] || ' $luksid printf -- 'warn "crypto LUKS UUID "%s" not found"\n' $luksid } >> $hookdir/emergency/90-crypt.sh done elif getargbool 0 rd.auto; then if [ -z "$DRACUT_SYSTEMD" ]; then { printf -- 'ENV{ID_FS_TYPE}=="crypto_LUKS", RUN+="%s ' $(command -v initqueue) printf -- '--unique --settled --onetime --name cryptroot-ask-%%k ' printf -- '%s $env{DEVNAME} luks-$env{ID_FS_UUID} %s"\n' $(command -v cryptroot-ask) $tout } >> /etc/udev/rules.d/70-luks.rules.new else { printf -- 'ENV{ID_FS_TYPE}=="crypto_LUKS", RUN+="%s ' $(command -v initqueue) printf -- '--unique --settled --onetime --name crypt-run-generator-%%k ' printf -- '%s $env{DEVNAME} luks-$env{ID_FS_UUID}"\n' $(command -v crypt-run-generator) } >> /etc/udev/rules.d/70-luks.rules.new fi fi echo 'LABEL="luks_end"' >> /etc/udev/rules.d/70-luks.rules.new mv /etc/udev/rules.d/70-luks.rules.new /etc/udev/rules.d/70-luks.rules fi modules.d/90crypt/probe-keydev.sh000075500000000754150526573730012726 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-crypt-lib.sh real_keydev="$1"; keypath="$2"; luksdev="$3" [ -z "$real_keydev" -o -z "$keypath" ] && die 'probe-keydev: wrong usage!' [ -z "$luksdev" ] && luksdev='*' info "Probing $real_keydev for $keypath..." test_dev -f "$real_keydev" "$keypath" || exit 1 info "Found $keypath on $real_keydev" echo "$luksdev:$real_keydev:$keypath" >> /tmp/luks.keys modules.d/90crypt/module-setup.sh000075500000005717150526573730012761 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 cryptsetup is not installed, then we cannot support encrypted devices. require_binaries cryptsetup || return 1 [[ $hostonly ]] || [[ $mount_needs ]] && { for fs in "${host_fs_types[@]}"; do [[ $fs = "crypto_LUKS" ]] && return 0 done return 255 } return 0 } depends() { echo dm rootfs-block return 0 } installkernel() { instmods dm_crypt =crypto hostonly="" instmods drbg } cmdline() { local dev UUID for dev in "${!host_fs_types[@]}"; do [[ "${host_fs_types[$dev]}" != "crypto_LUKS" ]] && continue UUID=$( blkid -u crypto -o export $dev \ | while read line; do [[ ${line#UUID} = $line ]] && continue printf "%s" "${line#UUID=}" break done ) [[ ${UUID} ]] || continue printf "%s" " rd.luks.uuid=luks-${UUID}" done } install() { if [[ $hostonly_cmdline == "yes" ]]; then cmdline >> "${initdir}/etc/cmdline.d/90crypt.conf" echo >> "${initdir}/etc/cmdline.d/90crypt.conf" fi inst_multiple cryptsetup rmdir readlink umount inst_script "$moddir"/cryptroot-ask.sh /sbin/cryptroot-ask inst_script "$moddir"/probe-keydev.sh /sbin/probe-keydev inst_hook cmdline 10 "$moddir/parse-keydev.sh" inst_hook cmdline 30 "$moddir/parse-crypt.sh" if ! dracut_module_included "systemd"; then inst_hook cleanup 30 "$moddir/crypt-cleanup.sh" fi if [[ $hostonly ]] && [[ -f /etc/crypttab ]]; then # filter /etc/crypttab for the devices we need while read _mapper _dev _rest || [ -n "$_mapper" ]; do [[ $_mapper = \#* ]] && continue [[ $_dev ]] || continue [[ $_dev == UUID=* ]] && \ _dev="/dev/disk/by-uuid/${_dev#UUID=}" for _hdev in "${!host_fs_types[@]}"; do [[ ${host_fs_types[$_hdev]} == "crypto_LUKS" ]] || continue if [[ $_hdev -ef $_dev ]] || [[ /dev/block/$_hdev -ef $_dev ]]; then echo "$_mapper $_dev $_rest" break fi done done < /etc/crypttab > $initdir/etc/crypttab fi inst_simple "$moddir/crypt-lib.sh" "/lib/dracut-crypt-lib.sh" inst_multiple -o \ $systemdutildir/system-generators/systemd-cryptsetup-generator \ $systemdutildir/systemd-cryptsetup \ $systemdsystemunitdir/systemd-ask-password-console.path \ $systemdsystemunitdir/systemd-ask-password-console.service \ $systemdsystemunitdir/cryptsetup.target \ $systemdsystemunitdir/sysinit.target.wants/cryptsetup.target \ systemd-ask-password systemd-tty-ask-password-agent inst_script "$moddir"/crypt-run-generator.sh /sbin/crypt-run-generator dracut_need_initqueue } modules.d/98ecryptfs/ecryptfs-mount.sh000075500000005444150526573730014040 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 (C) 2011 Politecnico di Torino, Italy # TORSEC group -- http://security.polito.it # Roberto Sassu ECRYPTFSCONFIG="${NEWROOT}/etc/sysconfig/ecryptfs" ECRYPTFSKEYTYPE="encrypted" ECRYPTFSKEYDESC="1000100010001000" ECRYPTFSKEYID="" ECRYPTFSSRCDIR="/secret" ECRYPTFS_EXTRA_MOUNT_OPTS="" load_ecryptfs_key() { # override the eCryptfs key path name from the 'ecryptfskey=' parameter in the kernel # command line ECRYPTFSKEYARG=$(getarg ecryptfskey=) [ $? -eq 0 ] && \ ECRYPTFSKEY=${ECRYPTFSKEYARG} # set the default value [ -z "${ECRYPTFSKEY}" ] && \ ECRYPTFSKEY="/etc/keys/ecryptfs-trusted.blob"; # set the eCryptfs key path name ECRYPTFSKEYPATH="${NEWROOT}${ECRYPTFSKEY}" # check for eCryptfs encrypted key's existence if [ ! -f "${ECRYPTFSKEYPATH}" ]; then if [ "${RD_DEBUG}" = "yes" ]; then info "eCryptfs: key file not found: ${ECRYPTFSKEYPATH}" fi return 1 fi # read the eCryptfs encrypted key blob KEYBLOB=$(cat ${ECRYPTFSKEYPATH}) # load the eCryptfs encrypted key blob ECRYPTFSKEYID=$(keyctl add ${ECRYPTFSKEYTYPE} ${ECRYPTFSKEYDESC} "load ${KEYBLOB}" @u) [ $? -eq 0 ] || { info "eCryptfs: failed to load the eCryptfs key: ${ECRYPTFSKEYDESC}"; return 1; } return 0 } unload_ecryptfs_key() { # unlink the eCryptfs encrypted key keyctl unlink ${ECRYPTFSKEYID} @u || { info "eCryptfs: failed to unlink the eCryptfs key: ${ECRYPTFSKEYDESC}"; return 1; } return 0 } mount_ecryptfs() { # read the configuration from the config file [ -f "${ECRYPTFSCONFIG}" ] && \ . ${ECRYPTFSCONFIG} # load the eCryptfs encrypted key load_ecryptfs_key || return 1 # set the default value for ECRYPTFSDSTDIR [ -z "${ECRYPTFSDSTDIR}" ] && \ ECRYPTFSDSTDIR=${ECRYPTFSSRCDIR} # set the eCryptfs filesystem mount point ECRYPTFSSRCMNT="${NEWROOT}${ECRYPTFSSRCDIR}" ECRYPTFSDSTMNT="${NEWROOT}${ECRYPTFSDSTDIR}" # build the mount options variable ECRYPTFS_MOUNT_OPTS="ecryptfs_sig=${ECRYPTFSKEYDESC}" [ ! -z "${ECRYPTFS_EXTRA_MOUNT_OPTS}" ] && \ ECRYPTFS_MOUNT_OPTS="${ECRYPTFS_MOUNT_OPTS},${ECRYPTFS_EXTRA_MOUNT_OPTS}" # mount the eCryptfs filesystem info "Mounting the configured eCryptfs filesystem" mount -i -t ecryptfs -o${ECRYPTFS_MOUNT_OPTS} ${ECRYPTFSSRCMNT} ${ECRYPTFSDSTMNT} >/dev/null || { info "eCryptfs: mount of the eCryptfs filesystem failed"; return 1; } # unload the eCryptfs encrypted key unload_ecryptfs_key || return 1 return 0 } mount_ecryptfs modules.d/98ecryptfs/README000064400000004447150526573730011364 0ustar00# Directions for creating the encrypted key that will be used to mount an # eCryptfs filesystem # Create the eCryptfs key (encrypted key type) # # The encrypted key type supports two formats: the 'default' format allows # to generate a random symmetric key of the length specified, the 'ecryptfs' # format generates an authentication token for the eCryptfs filesystem, # which contains a randomly generated key. Two requirements for the latter # format is that the key description must contain exactly 16 hexadecimal # characters and that the encrypted key length must be equal to 64. $ keyctl add encrypted 1000100010001000 "new ecryptfs trusted:kmk-trusted 64" @u 782117972 # Save the encrypted key $ su -c 'keyctl pipe `keyctl search @u encrypted 1000100010001000` > /etc/keys/ecryptfs-trusted.blob' # The eCryptfs key path name can be set in one of the following ways (specified in # the order in which the variable is overwritten): 1) use the default value: -------------------------------------------------------------------------- ECRYPTFSKEY="/etc/keys/ecryptfs-trusted.blob" -------------------------------------------------------------------------- 2) create the configuration file '/etc/sysconfig/ecryptfs' and set the ECRYPTFSKEY variable; 3) specify the eCryptfs key path name in the 'ecryptfskey=' parameter of the kernel command line. # The configuration file '/etc/sysconfig/ecryptfs' is also used to specify # more options for mounting the eCryptfs filesystem: ECRYPTFSSRCDIR: existent directory in the lower root filesystem; ECRYPTFSDSTDIR: mount point directory for the eCryptfs filesystem (the directory must be created in the root filesystem before rebooting the platform); ECRYPTFS_EXTRA_MOUNT_OPTS: extra mount options for the eCryptfs filesystem (the 'ecryptfs_sig' option is automatically added by the dracut script). # Example of the configuration file: ----------- '/etc/sysconfig/ecryptfs' (with default values) ----------- ECRYPTFS_KEY="/etc/keys/ecryptfs-trusted.blob" ECRYPTFSSRCDIR="/secret" ECRYPTFSDSTDIR="${ECRYPTFSSRCDIR}" ECRYPTFS_EXTRA_MOUNT_OPTS="" ----------------------------------------------------------------------- # If the variable ECRYPTFSDSTDIR is not specified in the configuration file, # its value will be equal to that of ECRYPTFSSRCDIR. modules.d/98ecryptfs/module-setup.sh000075500000000466150526573730013463 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() { echo masterkey return 0 } installkernel() { instmods ecryptfs } install() { inst_hook pre-pivot 63 "$moddir/ecryptfs-mount.sh" } modules.d/95iscsi/parse-iscsiroot.sh000075500000012306150526573730013432 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/iscsiroot.sh000075500000023511150526573730012322 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/95iscsi/mount-lun.sh000075500000000672150526573730012245 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/module-setup.sh000075500000012756150526573730012740 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/cleanup-iscsi.sh000075500000000306150526573730013040 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/50drm/module-setup.sh000075500000003724150526573730012372 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 } installkernel() { local _modname # Include KMS capable drm drivers drm_module_filter() { local _drm_drivers='drm_crtc_init' local _ret # subfunctions inherit following FDs local _merge=8 _side2=9 function nmf1() { local _fname _fcont while read _fname; do case "$_fname" in *.ko) _fcont="$(< $_fname)" ;; *.ko.gz) _fcont="$(gzip -dc $_fname)" ;; *.ko.xz) _fcont="$(xz -dc $_fname)" ;; esac [[ $_fcont =~ $_drm_drivers && ! $_fcont =~ iw_handler_get_spy ]] \ && echo "$_fname" done } function rotor() { local _f1 _f2 while read _f1; do echo "$_f1" if read _f2; then echo "$_f2" 1>&${_side2} fi done | nmf1 1>&${_merge} } # Use two parallel streams to filter alternating modules. set +x eval "( ( rotor ) ${_side2}>&1 | nmf1 ) ${_merge}>&1" [[ $debug ]] && set -x return 0 } instmods amdkfd hyperv_fb for _modname in $(find_kernel_modules_by_path drivers/gpu/drm \ | drm_module_filter) ; do # if the hardware is present, include module even if it is not currently loaded, # as we could e.g. be in the installer; nokmsboot boot parameter will disable # loading of the driver if needed if [[ $hostonly ]] && modinfo -F alias $_modname | sed -e 's,\?,\.,g' -e 's,\*,\.\*,g' \ | grep -qxf - /sys/bus/pci/devices/*/modalias 2>/dev/null; then hostonly='' instmods $_modname continue fi instmods $_modname done } modules.d/95rootfs-block/mount-root.sh000075500000010642150526573730013722 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 type det_fs >/dev/null 2>&1 || . /lib/fs-lib.sh mount_root() { local _ret local _rflags_ro # sanity - determine/fix fstype rootfs=$(det_fs "${root#block:}" "$fstype") journaldev=$(getarg "root.journaldev=") if [ -n "$journaldev" ]; then case "$rootfs" in xfs) rflags="${rflags:+${rflags},}logdev=$journaldev" ;; reiserfs) fsckoptions="-j $journaldev $fsckoptions" rflags="${rflags:+${rflags},}jdev=$journaldev" ;; *);; esac fi _rflags_ro="$rflags,ro" _rflags_ro="${_rflags_ro##,}" while ! mount -t ${rootfs} -o "$_rflags_ro" "${root#block:}" "$NEWROOT"; do warn "Failed to mount -t ${rootfs} -o $_rflags_ro ${root#block:} $NEWROOT" fsck_ask_err done READONLY= fsckoptions= if [ -f "$NEWROOT"/etc/sysconfig/readonly-root ]; then . "$NEWROOT"/etc/sysconfig/readonly-root fi if getargbool 0 "readonlyroot=" -y readonlyroot; then READONLY=yes fi if getarg noreadonlyroot ; then READONLY=no fi if [ -f "$NEWROOT"/fastboot ] || getargbool 0 fastboot ; then fastboot=yes fi if ! getargbool 0 rd.skipfsck; then 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 fi rootopts= if getargbool 1 rd.fstab -d -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 dump fsck; do # skip comments [ "${dev%%#*}" != "$dev" ] && continue if [ "$mp" = "/" ]; then # sanity - determine/fix fstype rootfs=$(det_fs "${root#block:}" "$fs") rootopts=$opts rootfsck=$fsck break fi done < "$NEWROOT/etc/fstab" fi # we want rootflags (rflags) to take precedence so prepend rootopts to # them rflags="${rootopts},${rflags}" rflags="${rflags#,}" rflags="${rflags%,}" # backslashes are treated as escape character in fstab # esc_root=$(echo ${root#block:} | sed 's,\\,\\\\,g') # printf '%s %s %s %s 1 1 \n' "$esc_root" "$NEWROOT" "$rootfs" "$rflags" >/etc/fstab ran_fsck=0 if fsck_able "$rootfs" && \ [ "$rootfsck" != "0" -a -z "$fastboot" -a "$READONLY" != "yes" ] && \ ! strstr "${rflags}" _netdev && \ ! getargbool 0 rd.skipfsck; then umount "$NEWROOT" fsck_single "${root#block:}" "$rootfs" "$rflags" "$fsckoptions" _ret=$? ran_fsck=1 fi echo "${root#block:} $NEWROOT $rootfs ${rflags:-defaults} 0 $rootfsck" >> /etc/fstab if ! ismounted "$NEWROOT"; then info "Mounting ${root#block:} with -o ${rflags}" mount "$NEWROOT" 2>&1 | vinfo elif ! are_lists_eq , "$rflags" "$_rflags_ro" defaults; then info "Remounting ${root#block:} with -o ${rflags}" mount -o remount "$NEWROOT" 2>&1 | vinfo fi if ! getargbool 0 rd.skipfsck; then [ -f "$NEWROOT"/forcefsck ] && rm -f -- "$NEWROOT"/forcefsck 2>/dev/null [ -f "$NEWROOT"/.autofsck ] && rm -f -- "$NEWROOT"/.autofsck 2>/dev/null fi } if [ -n "$root" -a -z "${root%%block:*}" ]; then mount_root fi modules.d/95rootfs-block/parse-block.sh000075500000002012150526573730013771 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 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="${root#UUID=}" root="$(echo $root | tr "[:upper:]" "[:lower:]")" root="block:/dev/disk/by-uuid/${root#UUID=}" rootok=1 ;; block:PARTUUID=*|PARTUUID=*) root="${root#block:}" root="${root#PARTUUID=}" root="$(echo $root | tr "[:upper:]" "[:lower:]")" root="block:/dev/disk/by-partuuid/${root}" rootok=1 ;; block:PARTLABEL=*|PARTLABEL=*) root="${root#block:}" root="block:/dev/disk/by-partlabel/${root#PARTLABEL=}" rootok=1 ;; /dev/*) root="block:${root}" rootok=1 ;; esac [ "${root%%:*}" = "block" ] && wait_for_dev "${root#block:}" modules.d/95rootfs-block/rootfallback.sh000075500000002510150526573730014235 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 root in $(getargs rootfallback=); do case "$root" in block:LABEL=*|LABEL=*) root="${root#block:}" root="$(echo $root | sed 's,/,\\x2f,g')" root="/dev/disk/by-label/${root#LABEL=}" ;; block:UUID=*|UUID=*) root="${root#block:}" root="${root#UUID=}" root="$(echo $root | tr "[:upper:]" "[:lower:]")" root="/dev/disk/by-uuid/${root#UUID=}" ;; block:PARTUUID=*|PARTUUID=*) root="${root#block:}" root="${root#PARTUUID=}" root="$(echo $root | tr "[:upper:]" "[:lower:]")" root="/dev/disk/by-partuuid/${root}" ;; block:PARTLABEL=*|PARTLABEL=*) root="${root#block:}" root="/dev/disk/by-partlabel/${root#PARTLABEL=}" ;; esac if ! [ -b "$root" ]; then warn "Could not find rootfallback $root" continue fi if mount "$root" /sysroot; then info "Mounted rootfallback $root" exit 0 else warn "Failed to mount rootfallback $root" exit 1 fi done [ -e "$job" ] && rm -f "$job" modules.d/95rootfs-block/module-setup.sh000075500000003267150526573730014227 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 fs-lib } cmdline_journal() { if [[ $hostonly ]]; then for dev in "${!host_fs_types[@]}"; do [[ ${host_fs_types[$dev]} = "reiserfs" ]] || [[ ${host_fs_types[$dev]} = "xfs" ]] || continue rootopts=$(find_dev_fsopts "$dev") if [[ ${host_fs_types[$dev]} = "reiserfs" ]]; then journaldev=$(fs_get_option $rootopts "jdev") elif [[ ${host_fs_types[$dev]} = "xfs" ]]; then journaldev=$(fs_get_option $rootopts "logdev") fi if [ -n "$journaldev" ]; then printf " root.journaldev=%s" "$journaldev" fi done fi return 0 } cmdline() { local dev=/dev/block/$(find_root_block_device) if [ -e $dev ] && [ -n "$root_dev" ] ; then printf " root=%s" "$(shorten_persistent_dev "$(get_persistent_dev "$dev")")" printf " rootflags=%s" "$(find_mp_fsopts /)" printf " rootfstype=%s" "$(find_mp_fstype /)" fi cmdline_journal } install() { if [[ $hostonly_cmdline == "yes" ]]; then journaldev=$(cmdline_journal) [[ $journaldev ]] && printf "%s\n" "$journaldev" >> "${initdir}/etc/cmdline.d/95root-journaldev.conf" fi inst_multiple umount inst_multiple tr if ! dracut_module_included "systemd"; then inst_hook cmdline 95 "$moddir/parse-block.sh" inst_hook pre-udev 30 "$moddir/block-genrules.sh" inst_hook mount 99 "$moddir/mount-root.sh" fi inst_hook initqueue/timeout 99 "$moddir/rootfallback.sh" } modules.d/95rootfs-block/block-genrules.sh000075500000001103150526573730014503 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%%:*}" = "block" ]; then { printf 'KERNEL=="%s", SYMLINK+="root"\n' \ ${root#block:/dev/} printf 'SYMLINK=="%s", SYMLINK+="root"\n' \ ${root#block:/dev/} } >> /etc/udev/rules.d/99-root.rules printf '[ -e "%s" ] && { ln -s "%s" /dev/root 2>/dev/null; rm "$job"; }\n' \ "${root#block:}" "${root#block:}" > $hookdir/initqueue/settled/blocksymlink.sh wait_for_dev "${root#block:}" fi modules.d/95debug/module-setup.sh000075500000000645150526573730012706 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/00systemd-bootchart/module-setup.sh000075500000000577150526573730015261 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/95fcoe-uefi/module-setup.sh000075500000001335150526573730013457 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.sh000075500000002010150526573730013720 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/95ssh-client/module-setup.sh000075500000003446150526573730013673 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/90bcache/module-setup.sh000075500000001426150526573730013016 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 ! blkid -k | { while read line; do [[ $line == bcache ]] && exit 0; done; exit 1; } \ && ! type -P probe-bcache >/dev/null; then return 1 fi [[ $hostonly ]] || [[ $mount_needs ]] && { for fs in "${host_fs_types[@]}"; do [[ $fs = "bcache" ]] && return 0 done return 255 } return 0 } depends() { return 0 } installkernel() { instmods bcache } install() { blkid -k | { while read line; do [[ $line == bcache ]] && exit 0; done; exit 1; } || inst_multiple -o probe-bcache inst_multiple -o ${udevdir}/bcache-register inst_rules 61-bcache.rules 69-bcache.rules } modules.d/95nbd/parse-nbdroot.sh000075500000003230150526573730012510 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.sh000075500000006052150526573730011405 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/95nbd/module-setup.sh000075500000001600150526573730012353 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/90mdraid/mdraid-cleanup.sh000075500000001304150526573730013306 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/mdraid-waitclean.sh000075500000001616150526573730013634 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/parse-md.sh000075500000004177150526573730012144 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-noimsm.sh000075500000000307150526573730012323 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/90mdraid/md-noddf.sh000075500000000305150526573730012111 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/65-md-incremental-imsm.rules000064400000002704150526573730015235 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/mdmon-pre-shutdown.sh000075500000000522150526573730014171 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/mdraid_start.sh000075500000003637150526573730013111 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/md-shutdown.sh000075500000001240150526573730012671 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/mdmon-pre-udev.sh000075500000000360150526573730013261 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/mdraid-needshutdown.sh000075500000000411150526573730014364 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/59-persistent-storage-md.rules000064400000001513150526573730015633 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/module-setup.sh000075500000007770150526573730013061 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/00bash/module-setup.sh000075500000000636150526573730012517 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 /bin/bash } depends() { return 0 } install() { # If another shell is already installed, do not use bash [[ -x $initdir/bin/sh ]] && return # Prefer bash as /bin/sh if it is available. inst /bin/bash && ln -sf bash "${initdir}/bin/sh" } modules.d/90dmraid/61-dmraid-imsm.rules000064400000001732150526573730013572 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/parse-dm.sh000075500000001647150526573730012143 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.sh000075500000002603150526573730011664 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/90dmraid/module-setup.sh000075500000004106150526573730013047 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/99kdumpbase/monitor_dd_progress000064400000000742150526573730014620 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-error-handler.service000064400000001741150526573730016057 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/99kdumpbase/kdump.sh000075500000011234150526573730012270 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.sh000075500000000221150526573730015024 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-emergency.service000064400000001611150526573730015265 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-capture.service000064400000001655150526573730014762 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.target000064400000000703150526573730015114 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/module-setup.sh000075500000063432150526573730013602 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/03rescue/module-setup.sh000075500000000644150526573730013072 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/91crypt-loop/crypt-loop-lib.sh000075500000003117150526573730014152 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/91crypt-loop/module-setup.sh000064400000000640150526573730013714 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/95udev-rules/59-persistent-storage.rules000064400000000424150526573730016075 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/load-modules.sh000075500000000274150526573730013653 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/61-persistent-storage.rules000064400000001774150526573730016077 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/95udev-rules/module-setup.sh000075500000006002150526573730013704 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/99shutdown/shutdown.sh000075500000006055150526573730012730 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/99shutdown/module-setup.sh000075500000001170150526573730013471 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/30convertfs/do-convertfs.sh000075500000000460150526573730013577 0ustar00#!/bin/bash # -*- 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.convertfs; then if getargbool 0 rd.debug; then bash -x convertfs "$NEWROOT" 2>&1 | vinfo else convertfs "$NEWROOT" 2>&1 | vinfo fi fi modules.d/30convertfs/convertfs.sh000075500000013741150526573730013205 0ustar00#!/bin/bash # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh ROOT="$1" if [[ ! -d "$ROOT" ]]; then echo "Usage: $0 " exit 1 fi if [[ "$ROOT" -ef / ]]; then echo "Can't convert the running system." echo "Please boot with 'rd.convertfs' on the kernel command line," echo "to update with the help of the initramfs," echo "or run this script from a rescue system." exit 1 fi while [[ "$ROOT" != "${ROOT%/}" ]]; do ROOT=${ROOT%/} done if [ ! -L $ROOT/var/run -a -e $ROOT/var/run ]; then echo "Converting /var/run to symlink" mv -f $ROOT/var/run $ROOT/var/run.runmove~ ln -sfn ../run $ROOT/var/run fi if [ ! -L $ROOT/var/lock -a -e $ROOT/var/lock ]; then echo "Converting /var/lock to symlink" mv -f $ROOT/var/lock $ROOT/var/lock.lockmove~ ln -sfn ../run/lock $ROOT/var/lock fi needconvert() { for dir in "$ROOT/bin" "$ROOT/sbin" "$ROOT/lib" "$ROOT/lib64"; do if [[ -e "$dir" ]]; then [[ -L "$dir" ]] || return 0 fi done return 1 } if ! [ -e "$ROOT/usr/bin" ]; then echo "$ROOT/usr/bin does not exist!" echo "Make sure, the kernel command line has enough information" echo "to mount /usr (man dracut.cmdline)" exit 1 fi if ! needconvert; then echo "Your system is already converted." exit 0 fi testfile="$ROOT/.usrmovecheck$$" rm -f -- "$testfile" > "$testfile" if [[ ! -e "$testfile" ]]; then echo "Cannot write to $ROOT/" exit 1 fi rm -f -- "$testfile" testfile="$ROOT/usr/.usrmovecheck$$" rm -f -- "$testfile" > "$testfile" if [[ ! -e "$testfile" ]]; then echo "Cannot write to $ROOT/usr/" exit 1 fi rm -f -- "$testfile" 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 # clean up after ourselves no matter how we die. cleanup() { echo "Something failed. Move back to the original state" for dir in "$ROOT/bin" "$ROOT/sbin" "$ROOT/lib" "$ROOT/lib64" \ "$ROOT/usr/bin" "$ROOT/usr/sbin" "$ROOT/usr/lib" \ "$ROOT/usr/lib64"; do [[ -d "${dir}.usrmove-new" ]] && rm -fr -- "${dir}.usrmove-new" if [[ -d "${dir}.usrmove-old" ]]; then mv "$dir" "${dir}.del~" mv "${dir}.usrmove-old" "$dir" rm -fr -- "${dir}.del~" fi done } trap 'ret=$?; [[ $ret -ne 0 ]] && cleanup;exit $ret;' EXIT trap 'exit 1;' SIGINT ismounted "$ROOT/usr" || CP_HARDLINK="-l" set -e # merge / and /usr in new dir in /usr for dir in bin sbin lib lib64; do rm -rf -- "$ROOT/usr/${dir}.usrmove-new" [[ -L "$ROOT/$dir" ]] && continue [[ -d "$ROOT/$dir" ]] || continue echo "Make a copy of \`$ROOT/usr/$dir'." [[ -d "$ROOT/usr/$dir" ]] \ && cp -ax -l "$ROOT/usr/$dir" "$ROOT/usr/${dir}.usrmove-new" echo "Merge the copy with \`$ROOT/$dir'." [[ -d "$ROOT/usr/${dir}.usrmove-new" ]] \ || mkdir -p "$ROOT/usr/${dir}.usrmove-new" cp -axT $CP_HARDLINK --backup --suffix=.usrmove~ "$ROOT/$dir" "$ROOT/usr/${dir}.usrmove-new" echo "Clean up duplicates in \`$ROOT/usr/$dir'." # delete all symlinks that have been backed up find "$ROOT/usr/${dir}.usrmove-new" -type l -name '*.usrmove~' -delete || : # replace symlink with backed up binary find "$ROOT/usr/${dir}.usrmove-new" \ -name '*.usrmove~' \ -type f \ -exec bash -c 'p="{}";o=${p%%%%.usrmove~}; [[ -L "$o" ]] && mv -f "$p" "$o"' ';' || : done # switch over merged dirs in /usr for dir in bin sbin lib lib64; do [[ -d "$ROOT/usr/${dir}.usrmove-new" ]] || continue echo "Switch to new \`$ROOT/usr/$dir'." rm -fr -- "$ROOT/usr/${dir}.usrmove-old" mv "$ROOT/usr/$dir" "$ROOT/usr/${dir}.usrmove-old" mv "$ROOT/usr/${dir}.usrmove-new" "$ROOT/usr/$dir" done # replace dirs in / with links to /usr for dir in bin sbin lib lib64; do [[ -L "$ROOT/$dir" ]] && continue [[ -d "$ROOT/$dir" ]] || continue echo "Create \`$ROOT/$dir' symlink." rm -fr -- "$ROOT/${dir}.usrmove-old" || : mv "$ROOT/$dir" "$ROOT/${dir}.usrmove-old" ln -sfn usr/$dir "$ROOT/$dir" done echo "Clean up backup files." # everything seems to work; cleanup for dir in bin sbin lib lib64; do # if we get killed in the middle of "rm -rf", ensure not to leave # an incomplete directory, which is moved back by cleanup() [[ -d "$ROOT/usr/${dir}.usrmove-old" ]] \ && mv "$ROOT/usr/${dir}.usrmove-old" "$ROOT/usr/${dir}.usrmove-old~" [[ -d "$ROOT/${dir}.usrmove-old" ]] \ && mv "$ROOT/${dir}.usrmove-old" "$ROOT/${dir}.usrmove-old~" done for dir in bin sbin lib lib64; do [[ -d "$ROOT/usr/${dir}.usrmove-old~" ]] \ && rm -rf -- "$ROOT/usr/${dir}.usrmove-old~" || : [[ -d "$ROOT/${dir}.usrmove-old~" ]] \ && rm -rf -- "$ROOT/${dir}.usrmove-old~" || : done for dir in lib lib64; do [[ -d "$ROOT/$dir" ]] || continue for lib in "$ROOT"/usr/${dir}/lib*.so*.usrmove~; do [[ -f $lib ]] || continue mv $lib ${lib/.so/_so} done done set +e echo "Run ldconfig." ldconfig -r "$ROOT" . $ROOT/etc/selinux/config if [ -n "$(command -v setfiles)" ] && [ "$SELINUX" != "disabled" ] && [ -f /etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts ]; then echo "Fixing SELinux labels" setfiles -r $ROOT -p /etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts $ROOT/sbin $ROOT/bin $ROOT/lib $ROOT/lib64 $ROOT/usr/lib $ROOT/usr/lib64 $ROOT/etc/ld.so.cache $ROOT/var/cache/ldconfig || : fi echo "Done." exit 0 modules.d/30convertfs/module-setup.sh000075500000000605150526573730013612 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 return 255 } depends() { return 0 } install() { inst_multiple bash find ldconfig mv rm cp ln inst_hook pre-pivot 99 "$moddir/do-convertfs.sh" inst_script "$moddir/convertfs.sh" /usr/bin/convertfs } modules.d/04watchdog/watchdog-stop.sh000075500000000075150526573730013543 0ustar00#!/bin/sh [ -c /dev/watchdog ] && printf 'V' > /dev/watchdog modules.d/04watchdog/watchdog.sh000075500000000365150526573730012562 0ustar00#!/bin/sh if [ -e /dev/watchdog ]; then if [ ! -e /tmp/watchdog_timeout ]; then wdctl -s 60 /dev/watchdog >/dev/null 2>&1 > /tmp/watchdog_timeout fi info "Triggering watchdog" >/dev/watchdog else modprobe ib700wdt modprobe i6300esb fi modules.d/04watchdog/module-setup.sh000075500000005561150526573730013410 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() { # Do not add watchdog hooks if systemd module is included # In that case, systemd will manage watchdog kick if ! dracut_module_included "systemd"; then inst_hook cmdline 00 "$moddir/watchdog.sh" inst_hook cmdline 50 "$moddir/watchdog.sh" inst_hook pre-trigger 00 "$moddir/watchdog.sh" inst_hook initqueue 00 "$moddir/watchdog.sh" inst_hook mount 00 "$moddir/watchdog.sh" inst_hook mount 50 "$moddir/watchdog.sh" inst_hook mount 99 "$moddir/watchdog.sh" inst_hook pre-pivot 00 "$moddir/watchdog.sh" inst_hook pre-pivot 99 "$moddir/watchdog.sh" inst_hook cleanup 00 "$moddir/watchdog.sh" inst_hook cleanup 99 "$moddir/watchdog.sh" fi inst_hook emergency 02 "$moddir/watchdog-stop.sh" inst_multiple -o wdctl } installkernel() { local -A _drivers local _alldrivers _active _wdtdrv _wdtppath _dir [[ -d /sys/class/watchdog/ ]] || return for _dir in /sys/class/watchdog/*; do [[ -d "$_dir" ]] || continue [[ -f "$_dir/state" ]] || continue _active=$(< "$_dir/state") ! [[ $hostonly ]] || [[ "$_active" = "active" ]] || continue # device/modalias will return driver of this device _wdtdrv=$(< "$_dir/device/modalias") # There can be more than one module represented by same # modalias. Currently load all of them. # TODO: Need to find a way to avoid any unwanted module # represented by modalias _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null) if [[ $_wdtdrv ]]; then instmods $_wdtdrv for i in $_wdtdrv; do _drivers[$i]=1 done fi # however in some cases, we also need to check that if there is # a specific driver for the parent bus/device. In such cases # we also need to enable driver for parent bus/device. _wdtppath=$(readlink -f "$_dir/device") while [[ -d "$_wdtppath" ]] && [[ "$_wdtppath" != "/sys" ]]; do _wdtppath=$(readlink -f "$_wdtppath/..") [[ -f "$_wdtppath/modalias" ]] || continue _wdtdrv=$(< "$_wdtppath/modalias") _wdtdrv=$(modprobe --set-version "$kernel" -R $_wdtdrv 2>/dev/null) if [[ $_wdtdrv ]]; then instmods $_wdtdrv for i in $_wdtdrv; do _drivers[$i]=1 done fi done done # ensure that watchdog module is loaded as early as possible _alldrivers="${!_drivers[*]}" [[ $_alldrivers ]] && echo "rd.driver.pre=${_alldrivers// /,}" > ${initdir}/etc/cmdline.d/00-watchdog.conf return 0 } modules.d/99fs-lib/fs-lib.sh000075500000014313150526573730011526 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 fsck_ask_reboot() { info "note - fsck suggests reboot, if you" info "leave shell, booting will continue normally" action_on_fail -n "(reboot ?)" } fsck_ask_err() { warn "*** An error occurred during the file system check." warn "*** Dropping you to a shell; the system will try" warn "*** to mount the filesystem(s), when you leave the shell." action_on_fail -n "(Repair filesystem)" } # inherits: _ret _drv _out fsck_tail() { [ $_ret -gt 0 ] && warn "$_drv returned with $_ret" if [ $_ret -ge 4 ]; then [ -n "$_out" ] && echo "$_out"|vwarn fsck_ask_err else [ -n "$_out" ] && echo "$_out"|vinfo [ $_ret -ge 2 ] && fsck_ask_reboot fi } # note: this function sets _drv of the caller fsck_able() { case "$1" in xfs) # { # type xfs_db && # type xfs_repair && # type xfs_check && # type mount && # type umount # } >/dev/null 2>&1 && # _drv="_drv=none fsck_drv_xfs" && # return 0 return 1 ;; ext?) type e2fsck >/dev/null 2>&1 && _drv="_drv=e2fsck fsck_drv_com" && return 0 ;; jfs) type jfs_fsck >/dev/null 2>&1 && _drv="_drv=jfs_fsck fsck_drv_com" && return 0 ;; reiserfs) type reiserfsck >/dev/null 2>&1 && _drv="_drv=reiserfsck fsck_drv_com" && return 0 ;; btrfs) # type btrfsck >/dev/null 2>&1 && # _drv="_drv=none fsck_drv_btrfs" && # return 0 return 1 ;; nfs*) # nfs can be a nop, returning success _drv="_drv=none :" && return 0 ;; *) type fsck >/dev/null 2>&1 && _drv="_drv=fsck fsck_drv_std" && return 0 ;; esac return 1 } # note: all drivers inherit: _drv _fop _dev fsck_drv_xfs() { # xfs fsck is not necessary... Either it mounts or not return 0 } fsck_drv_btrfs() { # btrfs fsck is not necessary... Either it mounts or not return 0 } # common code for checkers that follow usual subset of options and return codes fsck_drv_com() { local _ret local _out if ! strstr "$_fop" "-[ynap]"; then _fop="-a ${_fop}" fi info "issuing $_drv $_fop $_dev" # we enforce non-interactive run, so $() is fine _out=$($_drv $_fop "$_dev") _ret=$? fsck_tail return $_ret } # code for generic fsck, if the filesystem checked is "unknown" to us fsck_drv_std() { local _ret local _out unset _out info "issuing fsck $_fop $_dev" # note, we don't enforce -a here, thus fsck is being run (in theory) # interactively; otherwise some tool might complain about lack of terminal # (and using -a might not be safe) fsck $_fop "$_dev" >/dev/console 2>&1 _ret=$? fsck_tail return $_ret } # checks single filesystem, relying on specific "driver"; we don't rely on # automatic checking based on fstab, so empty one is passed; # takes 4 arguments - device, filesystem, filesystem options, additional fsck options; # first 2 arguments are mandatory (fs may be auto or "") # returns 255 if filesystem wasn't checked at all (e.g. due to lack of # necessary tools or insufficient options) fsck_single() { local FSTAB_FILE=/etc/fstab.empty local _dev="$1" local _fs="${2:-auto}" local _fsopts="$3" local _fop="$4" local _drv [ $# -lt 2 ] && return 255 # if UUID= marks more than one device, take only the first one [ -e "$_dev" ] || _dev=$(devnames "$_dev"| while read line; do if [ -n "$line" ]; then echo $line; break;fi;done) [ -e "$_dev" ] || return 255 _fs=$(det_fs "$_dev" "$_fs") fsck_able "$_fs" || return 255 info "Checking $_fs: $_dev" export FSTAB_FILE eval "$_drv" return $? } # takes list of filesystems to check in parallel; we don't rely on automatic # checking based on fstab, so empty one is passed fsck_batch() { local FSTAB_FILE=/etc/fstab.empty local _drv=fsck local _dev local _ret local _out [ $# -eq 0 ] || ! type fsck >/dev/null 2>&1 && return 255 info "Checking filesystems (fsck -M -T -a):" for _dev in "$@"; do info " $_dev" done export FSTAB_FILE _out="$(fsck -M -T "$@" -- -a)" _ret=$? fsck_tail return $_ret } # verify supplied filesystem type: # if user provided the fs and we couldn't find it, assume user is right # if we found the fs, assume we're right det_fs() { local _dev="$1" local _orig="${2:-auto}" local _fs _fs=$(udevadm info --query=env --name="$_dev" | \ while read line; do if str_starts $line "ID_FS_TYPE="; then echo ${line#ID_FS_TYPE=} break fi done) _fs=${_fs:-auto} if [ "$_fs" = "auto" ]; then _fs="$_orig" fi echo "$_fs" } write_fs_tab() { local _o local _rw local _root local _rootfstype local _rootflags local _fspassno _fspassno="0" _root="$1" _rootfstype="$2" _rootflags="$3" [ -z "$_rootfstype" ] && _rootfstype=$(getarg rootfstype=) [ -z "$_rootflags" ] && _rootflags=$(getarg rootflags=) [ -z "$_rootfstype" ] && _rootfstype="auto" if [ -z "$_rootflags" ]; then _rootflags="ro,x-initrd.mount" else _rootflags="ro,$_rootflags,x-initrd.mount" fi _rw=0 CMDLINE=$(getcmdline) for _o in $CMDLINE; do case $_o in rw) _rw=1;; ro) _rw=0;; esac done if [ "$_rw" = "1" ]; then _rootflags="$_rootflags,rw" if ! getargbool 0 rd.skipfsck; then _fspassno="1" fi fi echo "$_root /sysroot $_rootfstype $_rootflags $_fspassno 0" >> /etc/fstab if type systemctl >/dev/null 2>/dev/null; then systemctl daemon-reload systemctl --no-block start initrd-root-fs.target fi } modules.d/99fs-lib/module-setup.sh000075500000003212150526573730012771 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() { return 0 } echo_fs_helper() { local dev=$1 fs=$2 case "$fs" in xfs) echo -n " xfs_db xfs_repair xfs_check xfs_metadump" ;; ext?) echo -n " e2fsck " ;; jfs) echo -n " jfs_fsck " ;; reiserfs) echo -n " reiserfsck " ;; btrfs) echo -n " btrfsck " ;; esac echo -n " fsck.$fs " return 0 } include_fs_helper_modules() { local dev=$1 fs=$2 case "$fs" in xfs|btrfs) instmods crc32c ;; esac } installkernel() { # xfs and btrfs needs crc32c... if [[ $hostonly ]]; then for_each_host_dev_fs include_fs_helper_modules : else instmods crc32c fi } install() { local _helpers inst "$moddir/fs-lib.sh" "/lib/fs-lib.sh" > ${initdir}/etc/fstab.empty [[ "$nofscks" = "yes" ]] && return if [[ "$fscks" = "${fscks#*[^ ]*}" ]]; then _helpers="\ umount mount /sbin/fsck* xfs_db xfs_check xfs_repair xfs_metadump e2fsck jfs_fsck reiserfsck btrfsck " if [[ $hostonly ]]; then _helpers="umount mount " _helpers+=$(for_each_host_dev_fs echo_fs_helper) fi else _helpers="$fscks" fi if [[ "$_helpers" == *e2fsck* ]] && [ -e /etc/e2fsck.conf ]; then inst_simple /etc/e2fsck.conf fi inst_multiple -o $_helpers fsck } modules.d/95resume/resume.sh000075500000001236150526573730011772 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 [ -s /.resume -a -b "$resume" ] && { # First try user level resume; it offers splash etc case "$splash" in quiet ) a_splash="-P splash=y" ;; * ) a_splash="-P splash=n" ;; esac [ -x "$(command -v resume)" ] && command resume $a_splash "$resume" # parsing the output of ls is Bad, but until there is a better way... ls -lH "$resume" | ( read x x x x maj min x; echo "${maj%,}:$min"> /sys/power/resume) >/.resume } modules.d/95resume/parse-resume.sh000075500000006346150526573730013111 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 resume=$(getarg resume=) && ! getarg noresume; then export resume echo "$resume" >/.resume else unset resume fi case "$resume" in LABEL=*) \ resume="$(echo $resume | sed 's,/,\\x2f,g')" resume="/dev/disk/by-label/${resume#LABEL=}" ;; UUID=*) \ resume="/dev/disk/by-uuid/${resume#UUID=}" ;; PARTUUID=*) \ resume="/dev/disk/by-partuuid/${resume#PARTUUID=}" ;; PARTLABEL=*) \ resume="/dev/disk/by-partlabel/${resume#PARTLABEL=}" ;; esac if splash=$(getarg splash=); then export splash else unset splash fi case "$splash" in quiet ) a_splash="-P splash=y" ;; * ) a_splash="-P splash=n" ;; esac if [ -n "$resume" ]; then { printf "KERNEL==\"%s\", ACTION==\"add|change\", SYMLINK+=\"/dev/resume\"\n" \ ${resume#/dev/}; printf "SYMLINK==\"%s\", ACTION==\"add|change\", SYMLINK+=\"/dev/resume\"\n" \ ${resume#/dev/}; } >> /etc/udev/rules.d/99-resume-link.rules { if [ -x /usr/sbin/resume ]; then printf "KERNEL==\"%s\", ACTION==\"add|change\", ENV{ID_FS_TYPE}==\"suspend|swsuspend|swsupend\", RUN+=\"/sbin/initqueue --finished --unique --name 00resume /usr/sbin/resume %s \'%s\'\"\n" \ ${resume#/dev/} "$a_splash" "$resume"; printf "SYMLINK==\"%s\", ACTION==\"add|change\", ENV{ID_FS_TYPE}==\"suspend|swsuspend|swsupend\", RUN+=\"/sbin/initqueue --finished --unique --name 00resume /usr/sbin/resume %s \'%s\'\"\n" \ ${resume#/dev/} "$a_splash" "$resume"; fi printf "KERNEL==\"%s\", ACTION==\"add|change\", ENV{ID_FS_TYPE}==\"suspend|swsuspend|swsupend\", RUN+=\"/sbin/initqueue --finished --unique --name 00resume echo %%M:%%m > /sys/power/resume\"\n" \ ${resume#/dev/}; printf "SYMLINK==\"%s\", ACTION==\"add|change\", ENV{ID_FS_TYPE}==\"suspend|swsuspend|swsupend\", RUN+=\"/sbin/initqueue --finished --unique --name 00resume echo %%M:%%m > /sys/power/resume\"\n" \ ${resume#/dev/}; } >> /etc/udev/rules.d/99-resume.rules printf '[ -e "%s" ] && { ln -s "%s" /dev/resume; rm -f -- "$job" "%s/initqueue/timeout/resume.sh"; }\n' \ "$resume" "$resume" "$hookdir" >> $hookdir/initqueue/settled/resume.sh printf 'warn "Cancelling resume operation. Device not found."; cancel_wait_for_dev /dev/resume; rm -f -- "$job" "%s/initqueue/settled/resume.sh";' \ "$hookdir" >> $hookdir/initqueue/timeout/resume.sh wait_for_dev "/dev/resume" mv /lib/dracut/resume.sh /lib/dracut/hooks/pre-mount/10-resume.sh elif ! getarg noresume; then { if [ -x /usr/sbin/resume ]; then printf "SUBSYSTEM==\"block\", ACTION==\"add|change\", ENV{ID_FS_TYPE}==\"suspend|swsuspend|swsupend\", RUN+=\"/sbin/initqueue --finished --unique --name 00resume /usr/sbin/resume %s \$tempnode\"\n" "$a_splash" fi echo "SUBSYSTEM==\"block\", ACTION==\"add|change\", ENV{ID_FS_TYPE}==\"suspend|swsuspend|swsupend\"," \ " RUN+=\"/sbin/initqueue --finished --unique --name 00resume echo %M:%m > /sys/power/resume\""; } >> /etc/udev/rules.d/99-resume.rules fi modules.d/95resume/module-setup.sh000075500000001741150526573730013116 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() { # No point trying to support resume, if no swap partition exist [[ $hostonly ]] || [[ $mount_needs ]] && { for fs in "${host_fs_types[@]}"; do [[ $fs =~ ^(swap|swsuspend|swsupend)$ ]] && return 0 done return 255 } return 0 } install() { local _bin # Optional uswsusp support for _bin in /usr/sbin/resume /usr/lib/suspend/resume /usr/lib/uswsusp/resume do [[ -x "${_bin}" ]] && { inst "${_bin}" /usr/sbin/resume [[ -f /etc/suspend.conf ]] && inst /etc/suspend.conf break } done if ! dracut_module_included "systemd"; then inst_hook cmdline 10 "$moddir/parse-resume.sh" else inst_script "$moddir/parse-resume.sh" /lib/dracut/parse-resume.sh fi inst_script "$moddir/resume.sh" /lib/dracut/resume.sh } modules.d/95zfcp/parse-zfcp.sh000075500000000535150526573730012207 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/95zfcp/module-setup.sh000075500000001251150526573730012554 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/99microcode_ctl-fw_dir_override/module-setup.sh000075500000010022150526573730017567 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/90livenet/livenetroot.sh000075500000001240150526573730013200 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/parse-livenet.sh000075500000001716150526573730013414 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/fetch-liveupdate.sh000075500000001531150526573730014062 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/90livenet/module-setup.sh000075500000000554150526573730013260 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/95dasd_mod/parse-dasd-mod.sh000075500000000713150526573730013543 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh mod_args="" for dasd_arg in $(getargs rd.dasd= -d rd_DASD= DASD=); do mod_args="$mod_args,$dasd_arg" done mod_args="${mod_args#*,}" if [ -n "$mod_args" ]; then [ -d /etc/modprobe.d ] || mkdir -m 0755 -p /etc/modprobe.d echo "options dasd_mod dasd=$mod_args" >> /etc/modprobe.d/dasd_mod.conf fi unset dasd_arg dasd_cio_free modules.d/95dasd_mod/module-setup.sh000075500000000761150526573730013371 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 _arch=$(uname -m) [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1 require_binaries grep sed seq return 0 } depends() { return 0 } installkernel() { instmods dasd_mod dasd_eckd_mod dasd_fba_mod dasd_diag_mod } install() { inst_hook cmdline 31 "$moddir/parse-dasd-mod.sh" inst_multiple dasd_cio_free grep sed seq } modules.d/05busybox/module-setup.sh000075500000001360150526573730013275 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/90qemu/module-setup.sh000075500000001643150526573730012561 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/98systemd/dracut-pre-trigger.sh000075500000001114150526573730014367 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-pre-udev.service.8000064400000002777150526573730015100 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-pre-pivot.service.8.asc000064400000000655150526573730016034 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.service.8.asc000064400000000650150526573730015631 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/emergency.service000064400000001724150526573730013670 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-pre-mount.service.8000064400000003010150526573730015254 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-trigger.service.8.asc000064400000000670150526573730016333 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-mount.service000064400000002002150526573730014322 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.8000064400000007027150526573730015215 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-pre-pivot.service000064400000002042150526573730015111 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.service.8.asc000064400000000640150526573730015243 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-pre-udev.sh000075500000002763150526573730013702 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-initqueue.sh000075500000004257150526573730014163 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-pivot.sh000075500000002227150526573730014073 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-shutdown.service.8.asc000064400000003231150526573730015753 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.service.8000064400000003021150526573730014743 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.8000064400000003014150526573730015561 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/dracut-pre-udev.service000064400000002262150526573730014717 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-cmdline.service.8.asc000064400000000672150526573730015521 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/rescue.service000064400000001555150526573730013202 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-initqueue.service.8000064400000003014150526573730015342 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/initrd.target000064400000000367150526573730013033 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/dracut-pre-mount.service.8.asc000064400000000662150526573730016033 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/dracut-pre-mount.service000064400000002042150526573730015112 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-pre-trigger.service000064400000002222150526573730015413 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-initqueue.service.8.asc000064400000000667150526573730016122 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-cmdline-ask.sh000075500000000646150526573730014340 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/dracut-initqueue.service000064400000002567150526573730015210 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-pivot.service.8000064400000003003150526573730015255 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-mount.sh000075500000002222150526573730013303 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-mount.service.8000064400000002771150526573730014505 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-emergency.service000064400000001716150526573730015151 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-tmpfiles.conf000064400000000207150526573730014275 0ustar00d /run/initramfs 0755 root root - d /run/initramfs/log 0755 root root - L /var/log - - - - ../run/initramfs/log modules.d/98systemd/dracut-cmdline.service000064400000002210150526573730014574 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-shutdown.service000064400000001245150526573730015043 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/rootfs-generator.sh000075500000007160150526573730014167 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-mount.sh000075500000001156150526573730014074 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/dracut-cmdline.sh000075500000005232150526573730013560 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-emergency.sh000075500000002476150526573730014132 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-cmdline-ask.service000064400000001722150526573730015357 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/98systemd/module-setup.sh000075500000023761150526573730013317 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/98selinux/selinux-loadpolicy.sh000075500000004440150526573730014510 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/98selinux/module-setup.sh000075500000000432150526573730013304 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/90lvm/lvm_scan.sh000075500000007126150526573730011571 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh # run lvm scan if udev has settled extraargs="$@" type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh VGS=$(getargs rd.lvm.vg -d rd_LVM_VG=) LVS=$(getargs rd.lvm.lv -d rd_LVM_LV=) SNAPSHOT=$(getargs rd.lvm.snapshot -d rd_LVM_SNAPSHOT=) SNAPSIZE=$(getargs rd.lvm.snapsize -d rd_LVM_SNAPSIZE=) [ -d /etc/lvm ] || mkdir -m 0755 -p /etc/lvm # build a list of devices to scan lvmdevs=$( for f in /tmp/.lvm_scan-*; do [ -e "$f" ] || continue printf '%s' "${f##/tmp/.lvm_scan-} " done ) if [ ! -e /etc/lvm/lvm.conf ]; then { echo 'devices {'; printf ' filter = [ ' for dev in $lvmdevs; do printf '"a|^/dev/%s$|", ' $dev; done; echo '"r/.*/" ]'; echo '}'; # establish LVM locking if [ -n $SNAPSHOT ]; then echo 'global {'; echo ' locking_type = 1'; echo ' use_lvmetad = 0'; echo '}'; else echo 'global {'; echo ' locking_type = 4'; echo ' use_lvmetad = 0'; echo '}'; fi } > /etc/lvm/lvm.conf lvmwritten=1 fi check_lvm_ver() { maj=$1 min=$2 ver=$3 # --poll is supported since 2.2.57 [ $4 -lt $maj ] && return 1 [ $4 -gt $maj ] && return 0 [ $5 -lt $min ] && return 1 [ $5 -gt $min ] && return 0 [ $6 -ge $ver ] && return 0 return 1 } # hopefully this output format will never change, e.g.: # LVM version: 2.02.53(1) (2009-09-25) OLDIFS=$IFS IFS=. set $(lvm version 2>/dev/null) IFS=$OLDIFS maj=${1##*:} min=$2 sub=${3%% *} sub=${sub%%\(*}; check_lvm_ver 2 2 57 $maj $min $sub && \ nopoll="--poll n" if check_lvm_ver 2 2 65 $maj $min $sub; then sysinit=" --sysinit $extraargs" fi unset extraargs export LVM_SUPPRESS_LOCKING_FAILURE_MESSAGES=1 if [ -n "$SNAPSHOT" ] ; then # HACK - this should probably be done elsewhere or turned into a function # Enable read-write LVM locking sed -i -e 's/\(^[[:space:]]*\)locking_type[[:space:]]*=[[:space:]]*[[:digit:]]/\1locking_type = 1/' ${initdir}/etc/lvm/lvm.conf # Expected SNAPSHOT format ":" ORIG_LV=${SNAPSHOT%%:*} SNAP_LV=${SNAPSHOT##*:} info "Removing existing LVM snapshot $SNAP_LV" lvm lvremove --force $SNAP_LV 2>&1| vinfo # Determine snapshot size if [ -z "$SNAPSIZE" ] ; then SNAPSIZE=$(lvm lvs --noheadings --units m --options lv_size $ORIG_LV) info "No LVM snapshot size provided, using size of $ORIG_LV ($SNAPSIZE)" fi info "Creating LVM snapshot $SNAP_LV ($SNAPSIZE)" lvm lvcreate -s -n $SNAP_LV -L $SNAPSIZE $ORIG_LV 2>&1| vinfo fi if [ -n "$LVS" ] ; then info "Scanning devices $lvmdevs for LVM logical volumes $LVS" lvm lvscan --ignorelockingfailure 2>&1 | vinfo for LV in $LVS; do if [ -z "$sysinit" ]; then lvm lvchange --yes -K -ay --ignorelockingfailure $nopoll --ignoremonitoring $LV 2>&1 | vinfo else lvm lvchange --yes -K -ay $sysinit $LV 2>&1 | vinfo fi done fi if [ -z "$LVS" -o -n "$VGS" ]; then info "Scanning devices $lvmdevs for LVM volume groups $VGS" lvm vgscan --ignorelockingfailure 2>&1 | vinfo if [ -z "$sysinit" ]; then lvm vgchange -ay --ignorelockingfailure $nopoll --ignoremonitoring $VGS 2>&1 | vinfo else lvm vgchange -ay $sysinit $VGS 2>&1 | vinfo fi fi if [ "$lvmwritten" ]; then rm -f -- /etc/lvm/lvm.conf fi unset lvmwritten udevadm settle need_shutdown modules.d/90lvm/parse-lvm.sh000075500000001124150526573730011665 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/lvm/lvm.conf ] && ! getargbool 1 rd.lvm.conf -d -n rd_NO_LVMCONF; then rm -f -- /etc/lvm/lvm.conf fi LV_DEVS="$(getargs rd.lvm.vg -d rd_LVM_VG=) $(getargs rd.lvm.lv -d rd_LVM_LV=)" if ! getargbool 1 rd.lvm -d -n rd_NO_LVM \ || ( [ -z "$LV_DEVS" ] && ! getargbool 0 rd.auto ); then info "rd.lvm=0: removing LVM activation" rm -f -- /etc/udev/rules.d/64-lvm*.rules else for dev in $LV_DEVS; do wait_for_dev -n "/dev/$dev" done fi modules.d/90lvm/64-lvm.rules000064400000001410150526573730011517 0ustar00# hacky rules to try to activate lvm when we get new block devs... # # Copyright 2008, Red Hat, Inc. # Jeremy Katz SUBSYSTEM!="block", GOTO="lvm_end" ACTION!="add|change", GOTO="lvm_end" # Also don't process disks that are slated to be a multipath device ENV{DM_MULTIPATH_DEVICE_PATH}=="?*", GOTO="lvm_end" KERNEL=="dm-[0-9]*", ACTION=="add", GOTO="lvm_end" ENV{ID_FS_TYPE}!="LVM?_member", GOTO="lvm_end" PROGRAM=="/bin/sh -c 'for i in $sys/$devpath/holders/dm-[0-9]*; do [ -e $$i ] && exit 0; done; exit 1;' ", \ GOTO="lvm_end" RUN+="/sbin/initqueue --settled --onetime --unique /sbin/lvm_scan" RUN+="/sbin/initqueue --timeout --name 51-lvm_scan --onetime --unique /sbin/lvm_scan --partial" RUN+="/bin/sh -c '>/tmp/.lvm_scan-%k;'" LABEL="lvm_end" modules.d/90lvm/module-setup.sh000075500000011412150526573730012403 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() { # No point trying to support lvm if the binaries are missing require_binaries lvm || return 1 [[ $hostonly ]] || [[ $mount_needs ]] && { for fs in "${host_fs_types[@]}"; do [[ $fs = LVM*_member ]] && return 0 done return 255 } return 0 } depends() { # We depend on dm_mod being loaded echo rootfs-block dm return 0 } # called by dracut cmdline() { local _activated declare -A _activated for dev in "${!host_fs_types[@]}"; do [ -e /sys/block/${dev#/dev/}/dm/name ] || continue [ -e /sys/block/${dev#/dev/}/dm/uuid ] || continue uuid=$(/dev/null) [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] || return 1 if ! [[ ${_activated[${DM_VG_NAME}/${DM_LV_NAME}]} ]]; then printf " rd.lvm.lv=%s\n" "${DM_VG_NAME}/${DM_LV_NAME} " _activated["${DM_VG_NAME}/${DM_LV_NAME}"]=1 fi done } installkernel() { hostonly='' instmods dm-snapshot } # called by dracut install() { local _i inst lvm if [[ $hostonly_cmdline == "yes" ]]; then cmdline >> "${initdir}/etc/cmdline.d/90lvm.conf" echo >> "${initdir}/etc/cmdline.d/90lvm.conf" fi inst_rules "$moddir/64-lvm.rules" if [[ $hostonly ]] || [[ $lvmconf = "yes" ]]; then for f in /etc/lvm/lvm.conf /etc/lvm/lvm_*.conf; do [ -e "$f" ] || continue inst_simple "$f" if [ -f "${initdir}/$f" ]; then # FIXME: near-term hack to establish read-only locking; # use command-line lvm.conf editor once it is available sed -i -e 's/\(^[[:space:]]*\)locking_type[[:space:]]*=[[:space:]]*[[:digit:]]/\1locking_type = 4/' "${initdir}/$f" sed -i -e 's/\(^[[:space:]]*\)use_lvmetad[[:space:]]*=[[:space:]]*[[:digit:]]/\1use_lvmetad = 0/' "${initdir}/$f" fi done fi if ! [[ -e ${initdir}/etc/lvm/lvm.conf ]]; then mkdir -p "${initdir}/etc/lvm" { echo 'global {' echo 'locking_type = 4' echo 'use_lvmetad = 0' echo '}' } > "${initdir}/etc/lvm/lvm.conf" fi inst_rules 11-dm-lvm.rules 69-dm-lvm-metad.rules # Do not run lvmetad update via pvscan in udev rule - lvmetad is not running yet in dracut! if [[ -f ${initdir}/lib/udev/rules.d/69-dm-lvm-metad.rules ]]; then if grep -q SYSTEMD_WANTS ${initdir}/lib/udev/rules.d/69-dm-lvm-metad.rules; then sed -i -e 's/^ENV{SYSTEMD_ALIAS}=.*/# No LVM pvscan in dracut - lvmetad is not running yet/' \ ${initdir}/lib/udev/rules.d/69-dm-lvm-metad.rules sed -i -e 's/^ENV{ID_MODEL}=.*//' ${initdir}/lib/udev/rules.d/69-dm-lvm-metad.rules sed -i -e 's/^ENV{SYSTEMD_WANTS}=.*//' ${initdir}/lib/udev/rules.d/69-dm-lvm-metad.rules else sed -i -e 's/.*lvm pvscan.*/# No LVM pvscan for in dracut - lvmetad is not running yet/' \ ${initdir}/lib/udev/rules.d/69-dm-lvm-metad.rules fi fi # Gentoo ebuild for LVM2 prior to 2.02.63-r1 doesn't install above rules # files, but provides the one below: inst_rules 64-device-mapper.rules # debian udev rules inst_rules 56-lvm.rules 60-persistent-storage-lvm.rules inst_script "$moddir/lvm_scan.sh" /sbin/lvm_scan inst_hook cmdline 30 "$moddir/parse-lvm.sh" inst_libdir_file "libdevmapper-event-lvm*.so" if [[ $hostonly ]] && type -P lvs &>/dev/null; then for dev in "${!host_fs_types[@]}"; do [ -e /sys/block/${dev#/dev/}/dm/name ] || continue dev=$(/dev/null) [[ ${DM_VG_NAME} ]] && [[ ${DM_LV_NAME} ]] || continue case "$(lvs --noheadings -o segtype ${DM_VG_NAME} 2>/dev/null)" in *thin*|*cache*|*era*) inst_multiple -o thin_dump thin_restore thin_check thin_repair \ cache_dump cache_restore cache_check cache_repair \ era_check era_dump era_invalidate era_restore break;; esac done fi if ! [[ $hostonly ]]; then inst_multiple -o thin_dump thin_restore thin_check thin_repair \ cache_dump cache_restore cache_check cache_repair \ era_check era_dump era_invalidate era_restore fi } modules.d/90dm/11-dm.rules000064400000000216150526573730011116 0ustar00SUBSYSTEM!="block", GOTO="dm_end" KERNEL!="dm-[0-9]*", GOTO="dm_end" ACTION!="add|change", GOTO="dm_end" OPTIONS+="db_persist" LABEL="dm_end" modules.d/90dm/59-persistent-storage-dm.rules000064400000001236150526573730014775 0ustar00SUBSYSTEM!="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" KERNEL!="dm-[0-9]*", GOTO="dm_end" ACTION=="add", GOTO="dm_end" IMPORT{program}="/sbin/dmsetup info -c --nameprefixes --unquoted --rows --noheadings -o name,uuid,suspended,readonly,major,minor,open,tables_loaded,names_using_dev -j%M -m%m" ENV{DM_NAME}!="?*", GOTO="dm_end" ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="dm_end" ENV{DM_UUID}=="CRYPT-TEMP-?*", GOTO="dm_end" ENV{DM_UUID}!="?*", ENV{DM_NAME}=="temporary-cryptsetup-?*", GOTO="dm_end" IMPORT BLKID LABEL="dm_end" modules.d/90dm/dm-shutdown.sh000075500000000721150526573730012034 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_dm_shutdown() { local ret local final=$1 info "Disassembling device-mapper devices" dmsetup -v remove_all ret=$? if [ "x$final" != "x" ]; then info "dmsetup ls --tree" dmsetup ls --tree 2>&1 | vinfo fi return $ret } if command -v dmsetup >/dev/null; then _do_dm_shutdown $1 else : fi modules.d/90dm/dm-pre-udev.sh000075500000000323150526573730011706 0ustar00#!/bin/sh # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh strstr "$(cat /proc/misc)" device-mapper || modprobe dm_mod modprobe dm_mirror 2>/dev/null modules.d/90dm/module-setup.sh000075500000002034150526573730012205 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 dmsetup || return 1 return 255 } depends() { return 0 } installkernel() { instmods =drivers/md instmods dm_mod dm-cache dm-cache-mq dm-cache-cleaner } install() { modinfo -k $kernel dm_mod >/dev/null 2>&1 && \ inst_hook pre-udev 30 "$moddir/dm-pre-udev.sh" inst_multiple dmsetup inst_multiple -o dmeventd inst_libdir_file "libdevmapper-event.so*" inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules # Gentoo ebuild for LVM2 prior to 2.02.63-r1 doesn't install above rules # files, but provides the one below: inst_rules 64-device-mapper.rules # debian udev rules inst_rules 60-persistent-storage-dm.rules 55-dm.rules inst_rules "$moddir/11-dm.rules" inst_rules "$moddir/59-persistent-storage-dm.rules" prepare_udev_rules 59-persistent-storage-dm.rules inst_hook shutdown 30 "$moddir/dm-shutdown.sh" } modules.d/40network/net-lib.sh000075500000060202150526573730012201 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/net-genrules.sh000075500000007254150526573730013267 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/kill-dhclient.sh000075500000000552150526573730013374 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/dhclient-script.sh000075500000020506150526573730013746 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/parse-ibft.sh000075500000000611150526573730012701 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/40network/parse-ifname.sh000075500000001226150526573730013217 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/dhclient.conf000064400000000406150526573730012751 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.sh000075500000033147150526573730011622 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-team.sh000075500000001727150526573730012714 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/parse-bridge.sh000075500000002144150526573730013214 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/dhcp-root.sh000075500000001636150526573730012554 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/netroot.sh000075500000005345150526573730012350 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-bond.sh000075500000003730150526573730012704 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-ip-opts.sh000075500000011460150526573730013354 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/parse-vlan.sh000075500000001024150526573730012714 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/module-setup.sh000075500000011336150526573730013276 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.sh000075500000002315150526573730013731 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/45ifcfg/write-ifcfg.sh000075500000020747150526573730012461 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/45ifcfg/module-setup.sh000075500000000501150526573730012660 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/03modsign/load-modsign-keys.sh000075500000000530150526573730014141 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/03modsign/module-setup.sh000075500000001426150526573730013243 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/45url-lib/url-lib.sh000075500000007657150526573730012116 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/45url-lib/module-setup.sh000075500000002014150526573730013151 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/95virtfs/parse-virtfs.sh000075500000000345150526573730013134 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/mount-virtfs.sh000075500000003644150526573730013171 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/virtfs-generator.sh000075500000001632150526573730014010 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/95virtfs/module-setup.sh000075500000002235150526573730013132 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/90dmsquash-live-ntfs/module-setup.sh000075500000000454150526573730015343 0ustar00#!/bin/bash command -v check() { require_binaries ntfs-3g || return 1 return 255 } depends() { echo dmsquash-live return 0 } install() { inst_multiple fusermount ulockmgr_server mount.fuse ntfs-3g dracut_need_initqueue } installkernel() { hostonly='' instmods fuse } modules.d/90btrfs/80-btrfs.rules000064400000000416150526573730012366 0ustar00SUBSYSTEM!="block", GOTO="btrfs_end" ACTION!="add|change", GOTO="btrfs_end" ENV{ID_FS_TYPE}!="btrfs", GOTO="btrfs_end" RUN+="/sbin/btrfs device scan $env{DEVNAME}" RUN+="/sbin/initqueue --finished --unique --name btrfs_finished /sbin/btrfs_finished" LABEL="btrfs_end" modules.d/90btrfs/btrfs_finished.sh000075500000001303150526573730013271 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 btrfs_check_complete() { local _rootinfo _dev _dev="${1:-/dev/root}" [ -e "$_dev" ] || return 0 _rootinfo=$(udevadm info --query=env "--name=$_dev" 2>/dev/null) if strstr "$_rootinfo" "ID_FS_TYPE=btrfs"; then info "Checking, if btrfs device complete" unset __btrfs_mount mount -o ro "$_dev" /tmp >/dev/null 2>&1 __btrfs_mount=$? [ $__btrfs_mount -eq 0 ] && umount "$_dev" >/dev/null 2>&1 return $__btrfs_mount fi return 0 } btrfs_check_complete $1 exit $? modules.d/90btrfs/btrfs_device_ready.sh000075500000001101150526573730014117 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 btrfs_check_complete() { local _rootinfo _dev _dev="${1:-/dev/root}" [ -e "$_dev" ] || return 0 _rootinfo=$(udevadm info --query=env "--name=$_dev" 2>/dev/null) if strstr "$_rootinfo" "ID_FS_TYPE=btrfs"; then info "Checking, if btrfs device complete" btrfs device ready "$_dev" >/dev/null 2>&1 return $? fi return 0 } btrfs_check_complete $1 exit $? modules.d/90btrfs/btrfs_timeout.sh000075500000000374150526573730013175 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 info "Scanning for all btrfs devices" /sbin/btrfs device scan >/dev/null 2>&1 modules.d/90btrfs/module-setup.sh000075500000002207150526573730012727 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 btrfs installed on the host system, # no point in trying to support it in the initramfs. require_binaries btrfs || return 1 [[ $hostonly ]] || [[ $mount_needs ]] && { for fs in "${host_fs_types[@]}"; do [[ "$fs" == "btrfs" ]] && return 0 done return 255 } return 0 } depends() { echo udev-rules return 0 } installkernel() { instmods btrfs } install() { if ! inst_rules 64-btrfs.rules; then inst_rules "$moddir/80-btrfs.rules" case "$(btrfs --help)" in *device\ ready*) inst_script "$moddir/btrfs_device_ready.sh" /sbin/btrfs_finished ;; *) inst_script "$moddir/btrfs_finished.sh" /sbin/btrfs_finished ;; esac fi if ! dracut_module_included "systemd"; then inst_hook initqueue/timeout 10 "$moddir/btrfs_timeout.sh" fi inst_multiple -o btrfsck btrfs-zero-log inst $(command -v btrfs) /sbin/btrfs } modules.d/50plymouth/plymouth-emergency.sh000075500000000240150526573730014671 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.sh000075500000002742150526573730016044 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-newroot.sh000075500000000337150526573730014417 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-pretrigger.sh000075500000002251150526573730015071 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/50plymouth/module-setup.sh000075500000001546150526573730013471 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/90multipath/multipathd-stop.sh000075500000000533150526573730014331 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-needshutdown.sh000075500000000326150526573730016053 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/90multipath/multipathd.sh000075500000000455150526573730013351 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/module-setup.sh000075500000007320150526573730013617 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/91crypt-gpg/crypt-gpg-lib.sh000075500000002064150526573730013562 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.sh000075500000000534150526573730013525 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/95terminfo/module-setup.sh000075500000001203150526573730013432 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 _terminfodir # terminfo bits make things work better if you fall into interactive mode for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do [ -f ${_terminfodir}/l/linux ] && break done if [ -d ${_terminfodir} ]; then for i in "l/linux" "v/vt100" "v/vt102" "v/vt220"; do inst_dir "$_terminfodir/${i%/*}" cp --reflink=auto --sparse=auto -prfL -t "${initdir}/${_terminfodir}/${i%/*}" "$_terminfodir/$i" done fi } modules.d/95fcoe/fcoe-up.sh000075500000004464150526573730011452 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/parse-fcoe.sh000075500000003407150526573730012134 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.sh000064400000000553150526573730012445 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/95fcoe/fcoe-edd.sh000075500000002371150526573730011555 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/lldpad.sh000064400000000553150526573730011344 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-genrules.sh000075500000001461150526573730012644 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/module-setup.sh000075500000005676150526573730012545 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/98pollcdrom/pollcdrom.sh000075500000001351150526573730013161 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/98pollcdrom/module-setup.sh000075500000000374150526573730013615 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/95dasd/parse-dasd.sh000075500000000445150526573730012131 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 dasd_arg in $(getargs rd.dasd= -d rd_DASD= DASD=); do ( IFS="," set -- $dasd_arg echo "$@" | normalize_dasd_arg >> /etc/dasd.conf ) done modules.d/95dasd/module-setup.sh000075500000001205150526573730012524 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 _arch=$(uname -m) [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1 require_binaries normalize_dasd_arg || return 1 return 0 } depends() { return 0 } installkernel() { instmods dasd_mod dasd_eckd_mod dasd_fba_mod dasd_diag_mod } install() { inst_hook cmdline 30 "$moddir/parse-dasd.sh" inst_multiple dasdinfo dasdconf.sh normalize_dasd_arg if [[ $hostonly ]]; then inst /etc/dasd.conf fi inst_rules 56-dasd.rules inst_rules 59-dasd.rules } modules.d/98syslog/parse-syslog-opts.sh000075500000001363150526573730014131 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.sh000075500000000526150526573730013347 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/rsyslog.conf000064400000001464150526573730012532 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/98syslog/syslog-cleanup.sh000075500000001005150526573730013454 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/syslog-genrules.sh000075500000002170150526573730013655 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/README000064400000001500150526573730011030 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/rsyslogd-start.sh000075500000001530150526573730013513 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/module-setup.sh000075500000002326150526573730013141 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/95nfs/nfsroot-cleanup.sh000075500000001673150526573730013104 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 incol2 >/dev/null 2>&1 || . /lib/dracut-lib.sh [ -f /tmp/nfs.rpc_pipefs_path ] && rpcpipefspath=`cat /tmp/nfs.rpc_pipefs_path` [ -z "$rpcpipefspath" ] && rpcpipefspath=var/lib/nfs/rpc_pipefs pid=$(pidof rpc.statd) [ -n "$pid" ] && kill $pid pid=$(pidof rpc.idmapd) [ -n "$pid" ] && kill $pid pid=$(pidof rpcbind) [ -n "$pid" ] && kill $pid if incol2 /proc/mounts /var/lib/nfs/rpc_pipefs; then # try to create the destination directory [ -d $NEWROOT/$rpcpipefspath ] || \ mkdir -m 0755 -p $NEWROOT/$rpcpipefspath 2>/dev/null if [ -d $NEWROOT/$rpcpipefspath ]; then # mount --move does not seem to work??? mount --bind /var/lib/nfs/rpc_pipefs $NEWROOT/$rpcpipefspath umount /var/lib/nfs/rpc_pipefs 2>/dev/null else umount /var/lib/nfs/rpc_pipefs 2>/dev/null fi fi modules.d/95nfs/nfs-lib.sh000075500000011225150526573730011311 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/net-lib.sh # TODO: make these things not pollute the calling namespace # nfs_to_var NFSROOT [NETIF] # use NFSROOT to set $nfs, $server, $path, and $options. # NFSROOT is something like: nfs[4]::/[:|,] # NETIF is used to get information from DHCP options, if needed. nfs_to_var() { # Unfortunately, there's multiple styles of nfs "URL" in use, so we need # extra functions to parse them into $nfs, $server, $path, and $options. # FIXME: local netif=${2:-$netif}? case "$1" in nfs://*) rfc2224_nfs_to_var "$1" ;; nfs:*[*) anaconda_nfsv6_to_var "$1" ;; nfs:*:*:/*) anaconda_nfs_to_var "$1" ;; *) nfsroot_to_var "$1" ;; esac # if anything's missing, try to fill it in from DHCP options if [ -z "$server" ] || [ -z "$path" ]; then nfsroot_from_dhcp $2; fi # if there's a "%s" in the path, replace it with the hostname/IP if strstr "$path" "%s"; then local node="" read node < /proc/sys/kernel/hostname [ "$node" = "(none)" ] && node=$(get_ip $2) path=${path%%%s*}$node${path#*%s} # replace only the first %s 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 } # RFC2224: nfs://[:]/ rfc2224_nfs_to_var() { nfs="nfs" server="${1#nfs://}" path="/${server#*/}" server="${server%%/*}" server="${server%%:}" # anaconda compat (nfs://:/) local port="${server##*:}" [ "$port" != "$server" ] && options="port=$port" } # Anaconda-style path with options: nfs:::/ # (without mount options, anaconda is the same as dracut) anaconda_nfs_to_var() { nfs="nfs" options="${1#nfs:}" server="${options#*:}" server="${server%:/*}" options="${options%%:*}" path="/${1##*:/}" } # IPv6 nfs path will be treated separately anaconda_nfsv6_to_var() { nfs="nfs" path="$1:" options="${path#*:/}" path="/${options%%:*}" server="${1#*nfs:}" if str_starts $server '['; then server="${server%:/*}" options="${options#*:*}" else server="${server%:/*}" options="${server%%:*}" server="${server#*:}" fi } # nfsroot_from_dhcp NETIF # fill in missing server/path from DHCP options. nfsroot_from_dhcp() { local f for f in /tmp/net.$1.override /tmp/dhclient.$1.dhcpopts; do [ -f $f ] && . $f done [ -n "$new_root_path" ] && nfsroot_to_var "$nfs:$new_root_path" [ -z "$path" ] && [ "$(getarg root=)" == "/dev/nfs" ] && path=/tftpboot/%s [ -z "$server" ] && server=$srv [ -z "$server" ] && server=$new_dhcp_server_identifier [ -z "$server" ] && server=$new_next_server [ -z "$server" ] && server=${new_root_path%%:*} } # Look through $options, fix "rw"/"ro", move "lock"/"nolock" to $nfslock munge_nfs_options() { local f="" flags="" nfsrw="ro" OLDIFS="$IFS" IFS=, for f in $options; do case $f in ro|rw) nfsrw=$f ;; lock|nolock) nfslock=$f ;; *) flags=${flags:+$flags,}$f ;; esac done IFS="$OLDIFS" # Override rw/ro if set on cmdline getarg ro >/dev/null && nfsrw=ro getarg rw >/dev/null && nfsrw=rw options=$nfsrw${flags:+,$flags} } # mount_nfs NFSROOT MNTDIR [NETIF] mount_nfs() { local nfsroot="$1" mntdir="$2" netif="$3" local nfs="" server="" path="" options="" nfs_to_var "$nfsroot" $netif munge_nfs_options if [ "$nfs" = "nfs4" ]; then options=$options${nfslock:+,$nfslock} else # NFSv{2,3} doesn't support using locks as it requires a helper to # transfer the rpcbind state to the new root [ "$nfslock" = "lock" ] \ && warn "Locks unsupported on NFSv{2,3}, using nolock" 1>&2 options=$options,nolock fi mount -t $nfs -o$options "$server:$path" "$mntdir" } modules.d/95nfs/nfsroot.sh000075500000001471150526573730011453 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/nfs-lib.sh [ "$#" = 3 ] || exit 1 # root is in the form root=nfs[4]:[server:]path[:options], either from # cmdline or dhcp root-path netif="$1" root="$2" NEWROOT="$3" nfs_to_var $root $netif [ -z "$server" ] && die "Required parameter 'server' is missing" mount_nfs $root $NEWROOT $netif && { [ -e /dev/root ] || ln -s null /dev/root ; [ -e /dev/nfs ] || ln -s null /dev/nfs; } [ -f $NEWROOT/etc/fstab ] && cat $NEWROOT/etc/fstab > /dev/null # inject new exit_if_exists echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm -- "$job"' > $hookdir/initqueue/nfs.sh # force udevsettle to break > $hookdir/initqueue/work need_shutdown modules.d/95nfs/nfs-start-rpc.sh000075500000001641150526573730012463 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 modprobe sunrpc || strstr "$(cat /proc/filesystems)" rpc_pipefs; then [ ! -d /var/lib/nfs/rpc_pipefs/nfs ] && \ mount -t rpc_pipefs rpc_pipefs /var/lib/nfs/rpc_pipefs # Start rpcbind or rpcbind # FIXME occasionally saw 'rpcbind: fork failed: No such device' -- why? command -v portmap >/dev/null && [ -z "$(pidof portmap)" ] && portmap command -v rpcbind >/dev/null && [ -z "$(pidof rpcbind)" ] && rpcbind # Start rpc.statd as mount won't let us use locks on a NFSv4 # filesystem without talking to it. NFSv4 does locks internally, # rpc.lockd isn't needed [ -z "$(pidof rpc.statd)" ] && rpc.statd [ -z "$(pidof rpc.idmapd)" ] && rpc.idmapd else warn 'Kernel module "sunrpc" not in the initramfs, or support for filesystem "rpc_pipefs" missing!' fi modules.d/95nfs/parse-nfsroot.sh000075500000006436150526573730012571 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=nfs[4]:[server:]path[:options] # # This syntax can come from DHCP root-path as well. # # Legacy format: # root=/dev/nfs nfsroot=[server:]path[,options] # # In Legacy root=/dev/nfs mode, if the 'nfsroot' parameter is not given # on the command line or is empty, the dhcp root-path is used as # [server:]path[:options] or the default "/tftpboot/%s" will be used. # # If server is unspecified it will be pulled from one of the following # sources, in order: # static ip= option on kernel command line # DHCP next-server option # DHCP server-id option # DHCP root-path option # # NFSv4 is only used if explicitly requested with nfs4: prefix, otherwise # NFSv3 is used. # type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh # This script is sourced, so root should be set. But let's be paranoid [ -z "$root" ] && root=$(getarg root=) [ -z "$nfsroot" ] && nfsroot=$(getarg nfsroot=) [ -n "$netroot" ] && oldnetroot="$netroot" # netroot= cmdline argument must be ignored, but must be used if # we're inside netroot to parse dhcp root-path if [ -n "$netroot" ] ; then for n in $(getargs netroot=); do [ "$n" = "$netroot" ] && break done if [ "$n" = "$netroot" ]; then #warn "Ignoring netroot argument for NFS" netroot=$root fi else netroot=$root; fi # LEGACY: nfsroot= is valid only if root=/dev/nfs if [ -n "$nfsroot" ] ; then # @deprecated warn "Argument nfsroot is deprecated and might be removed in a future release. See 'man dracut.kernel' for more information." if [ "$(getarg root=)" != "/dev/nfs" ]; then die "Argument nfsroot only accepted for legacy root=/dev/nfs" fi netroot=nfs:$nfsroot; fi case "$netroot" in /dev/nfs) netroot=nfs;; /dev/*) if [ -n "$oldnetroot" ]; then netroot="$oldnetroot" else unset netroot fi return ;; # LEGACY: root=:/> /etc/idmapd.conf fi nfsroot_to_var $netroot [ "$path" = "error" ] && die "Argument nfsroot must contain a valid path!" # Set fstype, might help somewhere fstype=${nfs#/dev/} # Rewrite root so we don't have to parse this uglyness later on again netroot="$fstype:$server:$path:$options" # If we don't have a server, we need dhcp if [ -z "$server" ] ; then DHCPORSERVER="1" fi; # Done, all good! rootok=1 # Shut up init error check or make sure that block parser wont get # confused by having /dev/nfs[4] root="$fstype" echo '[ -e $NEWROOT/proc ]' > $hookdir/initqueue/finished/nfsroot.sh modules.d/95nfs/module-setup.sh000075500000005100150526573730012375 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_any_binary rpcbind portmap || return 1 require_binaries rpc.statd mount.nfs mount.nfs4 umount || return 1 [[ $hostonly ]] || [[ $mount_needs ]] && { for fs in "${host_fs_types[@]}"; do [[ "$fs" == "nfs" ]] && return 0 [[ "$fs" == "nfs3" ]] && return 0 [[ "$fs" == "nfs4" ]] && return 0 done return 255 } return 0 } depends() { # We depend on network modules being loaded echo network } installkernel() { hostonly='' instmods =net/sunrpc =fs/nfs ipv6 nfs_acl nfs_layout_nfsv41_files } install() { local _i local _nsslibs inst_multiple -o portmap rpcbind rpc.statd mount.nfs \ mount.nfs4 umount rpc.idmapd sed /etc/netconfig inst_multiple /etc/services /etc/nsswitch.conf /etc/rpc /etc/protocols /etc/idmapd.conf if [ -f /lib/modprobe.d/nfs.conf ]; then inst_multiple /lib/modprobe.d/nfs.conf else [ -d $initdir/etc/modprobe.d/ ] || mkdir $initdir/etc/modprobe.d echo "alias nfs4 nfs" > $initdir/etc/modprobe.d/nfs.conf fi inst_libdir_file 'libnfsidmap_nsswitch.so*' 'libnfsidmap/*.so' 'libnfsidmap*.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-nfsroot.sh" inst_hook pre-udev 99 "$moddir/nfs-start-rpc.sh" inst_hook cleanup 99 "$moddir/nfsroot-cleanup.sh" inst "$moddir/nfsroot.sh" "/sbin/nfsroot" inst "$moddir/nfs-lib.sh" "/lib/nfs-lib.sh" mkdir -m 0755 -p "$initdir/var/lib/nfs/rpc_pipefs" mkdir -m 0755 -p "$initdir/var/lib/rpcbind" mkdir -m 0755 -p "$initdir/var/lib/nfs/statd/sm" # Rather than copy the passwd file in, just set a user for rpcbind # We'll save the state and restart the daemon from the root anyway egrep '^nfsnobody:|^rpc:|^rpcuser:' /etc/passwd >> "$initdir/etc/passwd" egrep '^nogroup:|^rpc:|^nobody:' /etc/group >> "$initdir/etc/group" # rpc user needs to be able to write to this directory to save the warmstart # file chmod 770 "$initdir/var/lib/rpcbind" egrep -q '^rpc:' /etc/passwd \ && egrep -q '^rpc:' /etc/group \ && chown rpc.rpc "$initdir/var/lib/rpcbind" dracut_need_initqueue } modules.d/99base/dracut-lib.sh000075500000100135150526573730012134 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