2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
7 if [ -n "$NEWROOT" ]; then
8 [ -d $NEWROOT ] || mkdir
-p -m 0755 $NEWROOT
11 [ -d /run
/initramfs
] || mkdir
-p -m 0755 /run
/initramfs
12 [ -d /run
/lock
] || mkdir
-p -m 0755 /run
/lock
13 [ -d /run
/log
] || mkdir
-p -m 0755 /run
/log
20 [ "$RD_DEBUG" = "yes" ] && set -x
23 # returns OK if $1 contains literal string $2 (and isn't empty)
25 [ "${1##*"$2"*}" != "$1" ]
28 # returns OK if $1 matches (completely) glob pattern $2
29 # An empty $1 will not be considered matched, even if $2 is * which technically
30 # matches; as it would match anything, it's not an interesting case.
32 [ -n "$1" -a -z "${1##$2}" ]
35 # returns OK if $1 contains (anywhere) a match of glob pattern $2
36 # An empty $1 will not be considered matched, even if $2 is * which technically
37 # matches; as it would match anything, it's not an interesting case.
39 [ -n "$1" -a -z "${1##*$2*}" ]
42 # returns OK if $1 contains literal string $2 at the beginning, and isn't empty
44 [ "${1#"$2"*}" != "$1" ]
47 # returns OK if $1 contains literal string $2 at the end, and isn't empty
49 [ "${1%*"$2"}" != "$1" ]
52 if [ -z "$DRACUT_SYSTEMD" ]; then
56 echo "<28>dracut Warning: $*" > /dev
/kmsg
57 echo "dracut Warning: $*" >&2
62 echo "<30>dracut: $*" > /dev
/kmsg
63 [ "$DRACUT_QUIET" != "yes" ] && \
70 echo "Warning: $*" >&2
91 # replaces all occurrences of 'search' in 'str' with 'replacement'
93 # str_replace str search replacement
96 # str_replace ' one two three ' ' ' '_'
98 local in="$1"; local s
="$2"; local r
="$3"
101 while strstr
"${in}" "$s"; do
103 out
="${out}${chop}$r"
109 killall_proc_mountpoint
() {
112 for _pid
in /proc
/*; do
117 [ -e "/proc/$_pid/exe" ] ||
continue
118 [ -e "/proc/$_pid/root" ] ||
continue
119 strstr
"$(ls -l -- "/proc
/$_pid" "/proc
/$_pid/fd
" 2>/dev/null)" "$1" && kill -9 "$_pid"
130 if [ -e /etc
/cmdline
]; then
131 while read -r _line
; do
132 CMDLINE_ETC
="$CMDLINE_ETC $_line";
135 for _i
in /etc
/cmdline.d
/*.conf
; do
136 [ -e "$_i" ] ||
continue
137 while read -r _line
; do
138 CMDLINE_ETC_D
="$CMDLINE_ETC_D $_line";
141 if [ -e /proc
/cmdline
]; then
142 read -r CMDLINE
</proc
/cmdline
;
143 CMDLINE
="$CMDLINE_ETC_D $CMDLINE_ETC $CMDLINE"
145 printf "%s" "$CMDLINE"
149 local _o _val _doecho
153 CMDLINE
=$
(getcmdline
)
155 for _o
in $CMDLINE; do
156 if [ "${_o%%=*}" = "${1%%=*}" ]; then
157 if [ -n "${1#*=}" -a "${1#*=*}" != "${1}" ]; then
158 # if $1 has a "=<value>", we want the exact match
159 if [ "$_o" = "$1" ]; then
166 if [ "${_o#*=}" = "$_o" ]; then
167 # if cmdline argument has no "=<value>", we assume "=1"
177 if [ -n "$_val" ]; then
178 [ "x$_doecho" != "x" ] && echo "$_val";
186 local _deprecated _newoption
187 while [ $# -gt 0 ]; do
189 -d) _deprecated
=1; shift;;
190 -y) if _dogetarg
$2 >/dev
/null
; then
191 if [ "$_deprecated" = "1" ]; then
192 [ -n "$_newoption" ] && warn
"Kernel command line option '$2' is deprecated, use '$_newoption' instead." || warn
"Option '$2' is deprecated."
200 -n) if _dogetarg
$2 >/dev
/null
; then
202 if [ "$_deprecated" = "1" ]; then
203 [ -n "$_newoption" ] && warn
"Kernel command line option '$2' is deprecated, use '$_newoption=0' instead." || warn
"Option '$2' is deprecated."
210 *) if [ -z "$_newoption" ]; then
213 if _dogetarg
$1; then
214 if [ "$_deprecated" = "1" ]; then
215 [ -n "$_newoption" ] && warn
"Kernel command line option '$1' is deprecated, use '$_newoption' instead." || warn
"Option '$1' is deprecated."
228 # getargbool <defaultval> <args...>
229 # False if "getarg <args...>" returns "0", "no", or "off".
230 # True if getarg returns any other non-empty string.
231 # If not found, assumes <defaultval> - usually 0 for false, 1 for true.
232 # example: getargbool 0 rd.info
233 # true: rd.info, rd.info=1, rd.info=xxx
234 # false: rd.info=0, rd.info=off, rd.info not present (default val is 0)
241 [ $?
-ne 0 -a -z "$_b" ] && _b
="$_default"
242 if [ -n "$_b" ]; then
243 [ $_b = "0" ] && return 1
244 [ $_b = "no" ] && return 1
245 [ $_b = "off" ] && return 1
252 *[!0-9]*|
"") return 1;;
258 # getargnum <defaultval> <minval> <maxval> <arg>
259 # Will echo the arg if it's in range [minval - maxval].
260 # If it's not set or it's not valid, will set it <defaultval>.
261 # Note all values are required to be >= 0 here.
262 # <defaultval> should be with [minval -maxval].
266 local _default _min _max
271 [ $?
-ne 0 -a -z "$_b" ] && _b
=$_default
272 if [ -n "$_b" ]; then
273 isdigit
"$_b" && _b
=$
(($_b)) && \
274 [ $_b -ge $_min ] && [ $_b -le $_max ] && echo $_b && return
284 CMDLINE
=$
(getcmdline
)
287 for _o
in $CMDLINE; do
288 if [ "$_o" = "$_key" ]; then
290 elif [ "${_o%%=*}" = "${_key%=}" ]; then
291 [ -n "${_o%%=*}" ] && set -- "$@" "${_o#*=}";
295 if [ -n "$_found" ]; then
296 [ $# -gt 0 ] && echo -n "$@"
304 local _val _i _args _gfound _deprecated
311 if [ "$i" = "-d" ]; then
315 _val
="$(_dogetargs $_i)"
316 if [ $?
-eq 0 ]; then
317 if [ "$_deprecated" = "1" ]; then
318 [ -n "$_newoption" ] && warn
"Option '$_i' is deprecated, use '$_newoption' instead." || warn
"Option $_i is deprecated!"
322 [ -n "$_val" ] && set -- "$@" "$_val"
325 if [ -n "$_gfound" ]; then
326 if [ $# -gt 0 ]; then
339 # Prints value of given option. If option is a flag and it's present,
340 # it just returns 0. Otherwise 1 is returned.
341 # $1 = options separated by commas
342 # $2 = option we are interested in
345 # $1 = cipher=aes-cbc-essiv:sha256,hash=sha256,verify
350 local line
=",$1,"; local opt
="$2"; local tmp
354 tmp
="${line#*,${opt}=}"
358 *,${opt},*) return 0;;
363 # Splits given string 'str' with separator 'sep' into variables 'var1', 'var2',
364 # 'varN'. If number of fields is less than number of variables, remaining are
365 # not set. If number of fields is greater than number of variables, the last
366 # variable takes remaining fields. In short - it acts similary to 'read'.
368 # splitsep sep str var1 var2 varN
371 # splitsep ':' 'foo:bar:baz' v1 v2
373 # v1='foo', v2='bar:baz'
375 # TODO: ':' inside fields.
378 local sep
="$1"; local str
="$2"; shift 2
381 while [ -n "$str" -a "$#" -gt 1 ]; do
388 [ -n "$str" -a -n "$1" ] && eval "$1='$str'"
394 [ -f /etc
/initrd-release
] ||
return
395 if [ -z "$RD_DEBUG" ]; then
396 if [ -e /proc
/cmdline
]; then
398 if getargbool
0 rd.debug
-d -y rdinitdebug
-d -y rdnetdebug
; then
401 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
415 [ "$_dir" ] && [ -d "/$_dir" ] ||
return
416 for f
in "/$_dir"/*.sh
; do [ -e "$f" ] && .
"$f" "$@"; done
419 hookdir
=/lib
/dracut
/hooks
425 source_all
"/lib/dracut/hooks/$_dir" "$@"
430 for f
in $hookdir/initqueue
/finished
/*.sh
; do
431 [ "$f" = "$hookdir/initqueue/finished/*.sh" ] && return 0
432 { [ -e "$f" ] && ( .
"$f" ) ; } ||
return 1
439 [ "$1" ] && [ -d "/$1" ] ||
return
440 for f
in "/$1"/*.conf
; do [ -e "$f" ] && .
"$f"; done
445 echo "<24>dracut: FATAL: $*";
446 echo "<24>dracut: Refusing to continue";
450 echo "warn dracut: FATAL: \"$*\"";
451 echo "warn dracut: Refusing to continue";
452 } >> $hookdir/emergency
/01-die.sh
453 [ -d /run
/initramfs
] || mkdir
-p -- /run
/initramfs
455 > /run
/initramfs
/.die
457 getargbool
0 "rd.debug=" && emergency_shell
459 if [ -n "$DRACUT_SYSTEMD" ]; then
460 systemctl
--no-block --force halt
467 if [ -z "$DRACUT_QUIET" ]; then
469 getargbool
0 rd.info
-d -y rdinfo
&& DRACUT_QUIET
="no"
470 getargbool
0 rd.debug
-d -y rdinitdebug
&& DRACUT_QUIET
="no"
471 getarg quiet || DRACUT_QUIET
="yes"
472 a
=$
(getarg loglevel
=)
473 [ -n "$a" ] && [ $a -ge 28 ] && DRACUT_QUIET
="yes"
480 # Count the number of times the character $ch occurs in $str
481 # Return 0 if the count matches the expected number, 1 otherwise
487 while [ "${str#*$ch}" != "${str}" ]; do
489 count
=$
(( $count + 1 ))
492 [ $count -eq $expected ]
501 [ -z "$file" ] && return 1;
502 [ -z "$str" ] && return 1;
504 while read dummy check restofline
; do
505 if [ "$check" = "$str" ]; then
515 [ -z "$UDEVVERSION" ] && export UDEVVERSION
=$
(udevadm
--version)
517 if [ $UDEVVERSION -ge 143 ]; then
518 udevadm settle
--exit-if-exists=$hookdir/initqueue
/work
$settle_exit_if_exists
520 udevadm settle
--timeout=30
525 [ -z "$UDEVVERSION" ] && export UDEVVERSION
=$
(udevadm
--version)
527 if [ $UDEVVERSION -ge 143 ]; then
528 for i
in "$@"; do udevadm control
--property=$i; done
530 for i
in "$@"; do udevadm control
--env=$i; done
535 local dev mnt etc wanted_dev
536 wanted_dev
="$(readlink -e -q $1)"
537 while read dev mnt etc
; do
538 [ "$dev" = "$wanted_dev" ] && echo "$dev" && return 0
543 # usage: ismounted <mountpoint>
544 # usage: ismounted /dev/<device>
545 if command -v findmnt
>/dev
/null
; then
547 findmnt
"$1" > /dev
/null
2>&1
552 find_mount
"$1" > /dev
/null
&& return 0
557 [ "$m" = "$1" ] && return 0
563 # root=nfs:[<server-ip>:]<root-dir>[:<nfs-options>]
564 # root=nfs4:[<server-ip>:]<root-dir>[:<nfs-options>]
571 # check if we have a server
572 if strstr
"$arg" ':/' ; then
580 options
="${arg##$path}"
582 options
="${options##:}"
584 options
="${options%%:}"
586 # Does it really start with '/'?
587 [ -n "${path%%/*}" ] && path
="error";
589 #Fix kernel legacy style separating path and options with ','
590 if [ "$path" != "${path#*,}" ] ; then
596 # Create udev rule match for a device with its device name, or the udev property
597 # ID_FS_UUID or ID_FS_LABEL
600 # udevmatch LABEL=boot
602 # ENV{ID_FS_LABEL}="boot"
607 UUID
=????????
-????
-????
-????
-????????????|LABEL
=*|PARTLABEL
=*|PARTUUID
=????????
-????
-????
-????
-????????????
)
608 printf 'ENV{ID_FS_%s}=="%s"' "${1%%=*}" "${1#*=}"
611 printf 'ENV{ID_FS_UUID}=="%s*"' "${1#*=}"
614 printf 'ENV{ID_FS_PARTUUID}=="%s*"' "${1#*=}"
616 /dev
/?
*) printf -- 'KERNEL=="%s"' "${1#/dev/}" ;;
621 # Prints unique path for potential file inside specified directory. It consists
622 # of specified directory, prefix and number at the end which is incremented
623 # until non-existing file is found.
634 local dir
="$1"; local prefix
="$2"
637 [ -d "${dir}" ] ||
return 1
639 while [ -e "${dir}/${prefix}$i" ]; do
640 i
=$
(($i+1)) ||
return 1
643 echo "${dir}/${prefix}$i"
646 # Creates unique directory and prints its path. It's using funiq to generate
649 # mkuniqdir subdir new_dir_name
651 local dir
="$1"; local prefix
="$2"
652 local retdir
; local retdir_new
654 [ -d "${dir}" ] || mkdir
-m 0755 -p "${dir}" ||
return 1
656 retdir
=$
(funiq
"${dir}" "${prefix}") ||
return 1
657 until mkdir
-m 0755 "${retdir}" 2>/dev
/null
; do
658 retdir_new
=$
(funiq
"${dir}" "${prefix}") ||
return 1
659 [ "$retdir_new" = "$retdir" ] && return 1
666 # Copy the contents of SRC into DEST, merging the contents of existing
667 # directories (kinda like rsync, or cpio -p).
668 # Creates DEST if it doesn't exist. Overwrites files with the same names.
672 local src
="$1" dest
="$2"
673 mkdir
-p "$dest"; dest
=$
(readlink
-e -q "$dest")
674 ( cd "$src"; cp -af .
-t "$dest" )
677 # Evaluates command for UUIDs either given as arguments for this function or all
678 # listed in /dev/disk/by-uuid. UUIDs doesn't have to be fully specified. If
679 # beginning is given it is expanded to all matching UUIDs. To pass full UUID to
680 # your command use '$___' as a place holder. Remember to escape '$'!
682 # foreach_uuid_until [ -p prefix ] command UUIDs
684 # prefix - string to put just before $___
685 # command - command to be evaluated
686 # UUIDs - list of UUIDs separated by space
688 # The function returns after *first successful evaluation* of the given command
689 # with status 0. If evaluation fails for every UUID function returns with
693 # foreach_uuid_until "mount -U \$___ /mnt; echo OK; umount /mnt" \
694 # "01234 f512 a235567f-12a3-c123-a1b1-01234567abcb"
695 foreach_uuid_until
() (
698 [ "$1" = -p ] && local prefix
="$2" && shift 2
699 local cmd
="$1"; shift; local uuids_list
="$*"
700 local uuid
; local full_uuid
; local ___
702 [ -n "${cmd}" ] ||
return 1
704 for uuid
in ${uuids_list:-*}; do
705 for full_uuid
in ${uuid}*; do
706 [ -e "${full_uuid}" ] ||
continue
707 ___
="${prefix}${full_uuid}"
708 eval ${cmd} && return 0
715 # Get kernel name for given device. Device may be the name too (then the same
716 # is returned), a symlink (full path), UUID (prefixed with "UUID=") or label
717 # (prefixed with "LABEL="). If just a beginning of the UUID is specified or
718 # even an empty, function prints all device names which UUIDs match - every in
721 # NOTICE: The name starts with "/dev/".
730 local dev
="$1"; local d
; local names
734 dev
="$(foreach_uuid_until '! blkid -U $___' "${dev#UUID=}")" \
736 [ -z "$dev" ] && return 255
738 LABEL
=*) dev
="$(blkid -L "${dev#LABEL=}")" ||
return 255 ;;
745 $(readlink -e -q "$d")" ||
return 255
755 [ -d $1 ] ||
return 1
756 for _d
in proc sys dev
; do
757 [ -e "$1"/$_d ] ||
return 1
763 local _hookname _unique _name _job _exe
764 while [ $# -gt 0 ]; do
767 _hookname
="/$2";shift;;
778 if [ -z "$_unique" ]; then
788 [ -x "$_exe" ] || _exe
=$
(command -v $_exe)
790 if [ -n "$onetime" ]; then
792 echo '[ -e "$_job" ] && rm -f -- "$_job"'
794 } > "/tmp/$$-${_job}.sh"
796 echo "$_exe $@" > "/tmp/$$-${_job}.sh"
799 mv -f "/tmp/$$-${_job}.sh" "$hookdir/${_hookname}/${_job}.sh"
802 # inst_mount_hook <mountpoint> <prio> <name> <script>
804 # Install a mount hook with priority <prio>,
805 # which executes <script> as soon as <mountpoint> is mounted.
807 local _prio
="$2" _jobname
="$3" _script
="$4"
808 local _hookname
="mount-$(str_replace "$1" '/' '\\x2f')"
809 [ -d "$hookdir/${_hookname}" ] || mkdir
-p "$hookdir/${_hookname}"
810 inst_hook
--hook "$_hookname" --unique --name "${_prio}-${_jobname}" "$_script"
813 # add_mount_point <dev> <mountpoint> <filesystem> <fsopts>
815 # Mount <dev> on <mountpoint> with <filesystem> and <fsopts>
816 # and call any mount hooks, as soon, as it is mounted
818 local _dev
="$1" _mp
="$2" _fs
="$3" _fsopts
="$4"
819 local _hookname
="mount-$(str_replace "$2" '/' '\\x2f')"
820 local _devname
="dev-$(str_replace "$1" '/' '\\x2f')"
821 echo "$_dev $_mp $_fs $_fsopts 0 0" >> /etc
/fstab
823 exec 7>/etc
/udev
/rules.d
/99-mount-${_devname}.rules
824 echo 'SUBSYSTEM!="block", GOTO="mount_end"' >&7
825 echo 'ACTION!="add|change", GOTO="mount_end"' >&7
826 if [ -n "$_dev" ]; then
827 udevmatch
"$_dev" >&7 ||
{
828 warn
"add_mount_point dev=$_dev incorrect!"
835 printf -- 'RUN+="%s --unique --onetime ' $
(command -v initqueue
)
836 printf -- '--name mount-%%k '
837 printf -- '%s %s"\n' "$(command -v mount_hook)" "${_mp}"
839 echo 'LABEL="mount_end"' >&7
843 # wait_for_mount <mountpoint>
845 # Installs a initqueue-finished script,
846 # which will cause the main loop only to exit,
847 # if <mountpoint> is mounted.
851 _name
="$(str_replace "$1" '/' '\\x2f')"
852 printf '. /lib/dracut-lib.sh\nismounted "%s"\n' $1 \
853 >> "$hookdir/initqueue/finished/ismounted-${_name}.sh"
855 printf 'ismounted "%s" || ' $1
856 printf 'warn "\"%s\" is not mounted"\n' $1
857 } >> "$hookdir/emergency/90-${_name}.sh"
864 _name
="$(str_replace "$_name" '-' '\x2d')"
865 _name
="$(str_replace "$_name" '/' '-')"
871 # Installs a initqueue-finished script,
872 # which will cause the main loop only to exit,
873 # if the device <dev> is recognized by the system.
880 if [ "$1" = "-n" ]; then
885 _name
="$(str_replace "$1" '/' '\x2f')"
887 [ -e "${PREFIX}$hookdir/initqueue/finished/devexists-${_name}.sh" ] && return 0
889 printf '[ -e "%s" ]\n' $1 \
890 >> "${PREFIX}$hookdir/initqueue/finished/devexists-${_name}.sh"
892 printf '[ -e "%s" ] || ' $1
893 printf 'warn "\"%s\" does not exist"\n' $1
894 } >> "${PREFIX}$hookdir/emergency/80-${_name}.sh"
896 if [ -n "$DRACUT_SYSTEMD" ]; then
897 _name
=$
(dev_unit_name
"$1")
898 if ! [ -L ${PREFIX}/etc
/systemd
/system
/initrd.target.wants
/${_name}.device
]; then
899 [ -d ${PREFIX}/etc
/systemd
/system
/initrd.target.wants
] || mkdir
-p ${PREFIX}/etc
/systemd
/system
/initrd.target.wants
900 ln -s ..
/${_name}.device ${PREFIX}/etc/systemd/system/initrd.target.wants/${_name}.device
904 if ! [ -f ${PREFIX}/etc
/systemd
/system
/${_name}.device.d
/timeout.conf
]; then
905 mkdir
-p ${PREFIX}/etc
/systemd
/system
/${_name}.device.d
908 echo "JobTimeoutSec=0"
909 } > ${PREFIX}/etc
/systemd
/system
/${_name}.device.d
/timeout.conf
913 if [ -z "$PREFIX" ] && [ "$_needreload" = 1 ] && [ -z "$_noreload" ]; then
914 /sbin
/initqueue
--onetime --unique --name daemon-reload systemctl daemon-reload
919 cancel_wait_for_dev
()
922 _name
="$(str_replace "$1" '/' '\\x2f')"
923 rm -f -- "$hookdir/initqueue/finished/devexists-${_name}.sh"
924 rm -f -- "$hookdir/emergency/80-${_name}.sh"
925 if [ -n "$DRACUT_SYSTEMD" ]; then
926 _name
=$
(dev_unit_name
"$1")
927 rm -f -- ${PREFIX}/etc
/systemd
/system
/initrd.target.wants
/${_name}.device
928 rm -f -- ${PREFIX}/etc
/systemd
/system
/${_name}.device.d
/timeout.conf
929 /sbin
/initqueue
--onetime --unique --name daemon-reload systemctl daemon-reload
935 local _exe
="$(command -v $1)"
938 [ -x "$_exe" ] ||
return 1
939 for _i
in /proc
/[0-9]*; do
940 [ "$_i" = "/proc/1" ] && continue
941 if [ -e "$_i"/_exe
] && [ "$_i/_exe" -ef "$_exe" ] ; then
949 >/run
/initramfs
/.need_shutdown
954 [ "$RD_DEBUG" = "yes" ] ||
return
955 [ -e /run
/initramfs
/loginit.pipe
] ||
return
957 echo "DRACUT_LOG_END"
958 exec 0<>/dev
/console
1<>/dev
/console
2<>/dev
/console
961 while [ $i -lt 10 ]; do
962 if [ ! -e /run
/initramfs
/loginit.pipe
]; then
965 [ -z "${j##*Running*}" ] ||
break
971 if [ $i -eq 10 ]; then
972 kill %1 >/dev
/null
2>&1
973 kill $
(while read line
;do echo $line;done</run
/initramfs
/loginit.pid
)
977 rm -f -- /run
/initramfs
/loginit.pipe
/run
/initramfs
/loginit.pid
980 # pidof version for root
981 if ! command -v pidof
>/dev
/null
2>/dev
/null
; then
988 [ -z "$_cmd" ] && return 1
990 for i
in /proc
/*/exe
; do
991 [ -e "$i" ] ||
continue
992 if [ -n "$_exe" ]; then
993 [ "$i" -ef "$_exe" ] ||
continue
995 _rl
=$
(readlink
-f "$i");
996 [ "${_rl%/$_cmd}" != "$_rl" ] ||
continue
1008 if [ -n "$DRACUT_SYSTEMD" ]; then
1010 echo "PS1=\"$_name:\\\${PWD}# \"" >/etc
/profile
1011 systemctl start dracut-emergency.service
1012 rm -f -- /etc
/profile
1013 rm -f -- /.console_lock
1018 echo 'You might want to save "/run/initramfs/rdsosreport.txt" to a USB stick or /boot'
1019 echo 'after mounting them and attach it to a bug report.'
1020 if ! RD_DEBUG
= getargbool
0 rd.debug
-d -y rdinitdebug
-d -y rdnetdebug
; then
1022 echo 'To get more debug information in the report,'
1023 echo 'reboot with "rd.debug" added to the kernel command line.'
1026 echo 'Dropping to debug shell.'
1028 export PS1
="$_name:\${PWD}# "
1029 [ -e /.profile
] ||
>/.profile
1031 _ctty
="$(RD_DEBUG= getarg rd.ctty=)" && _ctty
="/dev/${_ctty##*/}"
1032 if [ -z "$_ctty" ]; then
1034 while [ -f /sys
/class
/tty
/$_ctty/active
]; do
1035 _ctty
=$
(cat /sys
/class
/tty
/$_ctty/active
)
1036 _ctty
=${_ctty##* } # last one in the list
1040 [ -c "$_ctty" ] || _ctty
=/dev
/tty1
1041 case "$(/usr/bin/setsid --help 2>&1)" in *--ctty*) CTTY
="--ctty";; esac
1042 setsid
$CTTY /bin
/sh
-i -l 0<>$_ctty 1<>$_ctty 2<>$_ctty
1050 local _rdshell_name
="dracut" action
="Boot" hook
="emergency"
1051 if [ "$1" = "-n" ]; then
1054 elif [ "$1" = "--shutdown" ]; then
1055 _rdshell_name
=$2; action
="Shutdown"; hook
="shutdown-emergency"
1056 if type plymouth
>/dev
/null
2>&1; then
1057 plymouth
--hide-splash
1058 elif [ -x /oldroot
/bin
/plymouth
]; then
1059 /oldroot
/bin
/plymouth
--hide-splash
1069 if getargbool
1 rd.shell
-d -y rdshell || getarg rd.
break -d rdbreak
; then
1070 _emergency_shell
$_rdshell_name
1072 warn
"$action has failed. To debug this issue add \"rd.shell rd.debug\" to the kernel command line."
1073 # cause a kernel panic
1077 if [ -e /run
/initramfs
/.die
]; then
1078 if [ -n "$DRACUT_SYSTEMD" ]; then
1079 systemctl
--no-block --force halt
1087 if [ -f "$initdir/lib/dracut/no-emergency-shell" ]; then
1088 [ "$1" = "-n" ] && shift 2
1089 [ "$1" = "--shutdown" ] && shift 2
1091 warn
"Not dropping to emergency shell, because $initdir/lib/dracut/no-emergency-shell exists."
1099 # Retain the values of these variables but ensure that they are unexported
1100 # This is a POSIX-compliant equivalent of bash's "export -n"
1108 [ -n "$val" ] && eval $var=\"$val\"
1112 # returns OK if list1 contains all elements of list2, i.e. checks if list2 is a
1113 # sublist of list1. An order and a duplication doesn't matter.
1118 # $4 = ignore values, separated by $1
1121 local _list
="${_sep}${2}${_sep}"
1123 [ -n "$4" ] && local _iglist
="${_sep}${4}${_sep}"
1127 [ "$_list" = "$_sublist" ] && return 0
1129 for _v
in $_sublist; do
1130 if [ -n "$_v" ] && ! ( [ -n "$_iglist" ] && strstr
"$_iglist" "$_v" )
1132 strstr
"$_list" "$_v" ||
return 1
1139 # returns OK if both lists contain the same values. An order and a duplication
1145 # $4 = ignore values, separated by $1
1147 listlist
"$1" "$2" "$3" "$4" && listlist
"$1" "$3" "$2" "$4"
1151 if [ -z "$DEBUG_MEM_LEVEL" ]; then
1152 export DEBUG_MEM_LEVEL
=$
(getargnum
0 0 3 rd.memdebug
)
1158 # parameters: msg [trace_level:trace]...
1164 if [ -n "$DEBUG_MEM_LEVEL" ] && [ "$DEBUG_MEM_LEVEL" -gt 0 ]; then
1165 make_trace show_memstats
$DEBUG_MEM_LEVEL "[debug_mem]" "$msg" "$@" >&2
1169 # parameters: func log_level prefix msg [trace_level:trace]...
1172 local func log_level prefix msg msg_printed
1173 local trace trace_level trace_in_higher_levels insert_trace
1187 if [ -z "$log_level" ]; then
1194 while [ $# -gt 0 ]; do
1196 trace_level
=${trace%%+}
1197 [ "$trace" != "$trace_level" ] && trace_in_higher_levels
="yes"
1200 if [ -z "$trace_level" ]; then
1205 if [ -n "$trace_in_higher_levels" ]; then
1206 if [ "$log_level" -ge "$trace_level" ]; then
1210 if [ "$log_level" -eq "$trace_level" ]; then
1215 if [ $insert_trace -eq 1 ]; then
1216 if [ $msg_printed -eq 0 ]; then
1231 cat /proc
/meminfo |
grep -e "^MemFree" -e "^Cached" -e "^Slab"