2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 # Generator script for a dracut initramfs
6 # Tries to retain some degree of compatibility with the command line
7 # of the various mkinitrd implementations out there
10 # Copyright 2005-2010 Red Hat, Inc. All rights reserved.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
32 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
33 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
34 .
$dracutbasedir/dracut-version.sh
37 # 80x25 linebreak here ^
39 Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
41 Version: $DRACUT_VERSION
43 Creates initial ramdisk images for preloading modules
45 -h, --help Display all options
47 If a [LIST] has multiple arguments, then you have to put these in quotes.
51 # dracut --add-drivers "module1 module2" ...
57 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
58 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
59 .
$dracutbasedir/dracut-version.sh
62 # 80x25 linebreak here ^
64 Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
66 Version: $DRACUT_VERSION
68 Creates initial ramdisk images for preloading modules
70 --kver [VERSION] Set kernel version to [VERSION].
71 -f, --force Overwrite existing initramfs file.
72 -a, --add [LIST] Add a space-separated list of dracut modules.
73 -m, --modules [LIST] Specify a space-separated list of dracut modules to
74 call when building the initramfs. Modules are located
75 in /usr/lib/dracut/modules.d.
76 -o, --omit [LIST] Omit a space-separated list of dracut modules.
77 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
78 exclusively include in the initramfs.
79 --add-drivers [LIST] Specify a space-separated list of kernel
80 modules to add to the initramfs.
81 --omit-drivers [LIST] Specify a space-separated list of kernel
82 modules not to add to the initramfs.
83 --filesystems [LIST] Specify a space-separated list of kernel filesystem
84 modules to exclusively include in the generic
86 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
88 --fwdir [DIR] Specify additional directories, where to look for
89 firmwares, separated by :
90 --kernel-only Only install kernel drivers and firmware files
91 --no-kernel Do not install kernel drivers and firmware files
92 --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
93 --strip Strip binaries in the initramfs
94 --nostrip Do not strip binaries in the initramfs
95 --hardlink Hardlink files in the initramfs
96 --nohardlink Do not hardlink files in the initramfs
97 --prefix [DIR] Prefix initramfs files with [DIR]
98 --noprefix Do not prefix initramfs files
99 --mdadmconf Include local /etc/mdadm.conf
100 --nomdadmconf Do not include local /etc/mdadm.conf
101 --lvmconf Include local /etc/lvm/lvm.conf
102 --nolvmconf Do not include local /etc/lvm/lvm.conf
103 --fscks [LIST] Add a space-separated list of fsck helpers.
104 --nofscks Inhibit installation of any fsck helpers.
105 --ro-mnt Mount / and /usr read-only by default.
106 -h, --help This message
107 --debug Output debug information of the build process
108 --profile Output profile information of the build process
109 -L, --stdlog [0-6] Specify logging level (to standard error)
110 0 - suppress any messages
111 1 - only fatal errors
115 5 - debug info (here starts lots of output)
116 6 - trace info (and even more)
117 -v, --verbose Increase verbosity level
118 -q, --quiet Decrease verbosity level
119 -c, --conf [FILE] Specify configuration file to use.
120 Default: /etc/dracut.conf
121 --confdir [DIR] Specify configuration directory to use *.conf files
122 from. Default: /etc/dracut.conf.d
123 --tmpdir [DIR] Temporary directory to be used instead of default
125 -l, --local Local mode. Use modules from the current working
126 directory instead of the system-wide installed in
127 /usr/lib/dracut/modules.d.
128 Useful when running dracut from a git checkout.
129 -H, --hostonly Host-Only mode: Install only what is needed for
130 booting the local host instead of a generic host.
131 -N, --no-hostonly Disables Host-Only mode
132 --fstab Use /etc/fstab to determine the root device.
133 --add-fstab [FILE] Add file to the initramfs fstab
134 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
135 Mount device [DEV] on mountpoint [MP] with filesystem
136 [FSTYPE] and options [FSOPTS] in the initramfs
137 --add-device "[DEV]" Bring up [DEV] in initramfs
138 -i, --include [SOURCE] [TARGET]
139 Include the files in the SOURCE directory into the
140 Target directory in the final initramfs.
141 If SOURCE is a file, it will be installed to TARGET
142 in the final initramfs.
143 -I, --install [LIST] Install the space separated list of files into the
145 --gzip Compress the generated initramfs using gzip.
146 This will be done by default, unless another
147 compression option or --no-compress is passed.
148 --bzip2 Compress the generated initramfs using bzip2.
149 Make sure your kernel has bzip2 decompression support
150 compiled in, otherwise you will not be able to boot.
151 --lzma Compress the generated initramfs using lzma.
152 Make sure your kernel has lzma support compiled in,
153 otherwise you will not be able to boot.
154 --xz Compress the generated initramfs using xz.
155 Make sure that your kernel has xz support compiled
156 in, otherwise you will not be able to boot.
157 --compress [COMPRESSION] Compress the generated initramfs with the
158 passed compression program. Make sure your kernel
159 knows how to decompress the generated initramfs,
160 otherwise you will not be able to boot.
161 --no-compress Do not compress the generated initramfs. This will
162 override any other compression options.
163 --list-modules List all available dracut modules.
164 -M, --show-modules Print included module's name to standard output during
166 --keep Keep the temporary initramfs for debugging purposes
167 --printsize Print out the module install size
168 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
170 If [LIST] has multiple arguments, then you have to put these in quotes.
174 # dracut --add-drivers "module1 module2" ...
180 # push values to a stack
181 # $1 = stack variable
184 # push stack 1 2 "3 4"
187 local __stack
=$1; shift
189 eval ${__stack}'[${#'${__stack}'[@]}]="$_i"'
194 # pops the last value from a stack
195 # assigns value to second argument variable
196 # or echo to stdout, if no second argument
197 # $1 = stack variable
198 # $2 = optional variable to store the value
203 local __stack=$1; shift
206 # check for empty stack
207 eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
209 eval _value='${'${__stack}'[${#'${__stack}'[@]}-1]}'
211 if [[ "$__resultvar" ]]; then
212 eval $__resultvar="'$_value'"
216 eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
220 # Little helper function for reading args from the commandline.
221 # it automatically handles -a b and -a=b variants, and returns 1 if
222 # we need to shift $3.
227 local rematch
='^[^=]*=(.*)$'
228 if [[ $2 =~
$rematch ]]; then
229 read "$1" <<< "${BASH_REMATCH[1]}"
232 # There is no way to shift our callers args, so
233 # return 1 to indicate they should do it instead.
244 while (( $# > 0 )); do
245 for i
in ${1}/*${suffix}; do
246 [[ -f $i ]] && echo ${i##*/}
253 for d
in "${args[@]}"; do
254 if [[ -f "$d/$f" ]]; then
266 # Workaround -i, --include taking 2 arguments
267 set -- "${@/--include/++include}"
269 # This prevents any long argument ending with "-i"
270 # -i, like --opt-i but I think we can just prevent that
271 set -- "${@/%-i/++include}"
273 TEMP
=$
(unset POSIXLY_CORRECT
; getopt \
274 -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
278 --long add-drivers
: \
279 --long omit-drivers
: \
283 --long filesystems
: \
303 --long kernel-cmdline
: \
328 --long list-modules \
329 --long show-modules \
334 if (( $?
!= 0 )); then
343 --kver) kernel
="$2"; shift;;
344 -a|
--add) push add_dracutmodules_l
"$2"; shift;;
345 --force-add) push force_add_dracutmodules_l
"$2"; shift;;
346 --add-drivers) push add_drivers_l
"$2"; shift;;
347 --omit-drivers) push omit_drivers_l
"$2"; shift;;
348 -m|
--modules) push dracutmodules_l
"$2"; shift;;
349 -o|
--omit) push omit_dracutmodules_l
"$2"; shift;;
350 -d|
--drivers) push drivers_l
"$2"; shift;;
351 --filesystems) push filesystems_l
"$2"; shift;;
352 -I|
--install) push install_items_l
"$2"; shift;;
353 --fwdir) push fw_dir_l
"$2"; shift;;
354 --libdirs) push libdirs_l
"$2"; shift;;
355 --fscks) push fscks_l
"$2"; shift;;
356 --add-fstab) push add_fstab_l
"$2"; shift;;
357 --mount) push fstab_lines
"$2"; shift;;
358 --add-device|
--device)
359 push add_device_l
"$2"; shift;;
360 --kernel-cmdline) push kernel_cmdline_l
"$2"; shift;;
361 --nofscks) nofscks_l
="yes";;
362 --ro-mnt) ro_mnt_l
="yes";;
363 -k|
--kmoddir) drivers_dir_l
="$2"; shift;;
364 -c|
--conf) conffile
="$2"; shift;;
365 --confdir) confdir
="$2"; shift;;
366 --tmpdir) tmpdir_l
="$2"; shift;;
367 -L|
--stdlog) stdloglvl_l
="$2"; shift;;
368 --compress) compress_l
="$2"; shift;;
369 --prefix) prefix_l
="$2"; shift;;
370 -f|
--force) force
=yes;;
371 --kernel-only) kernel_only
="yes"; no_kernel
="no";;
372 --no-kernel) kernel_only
="no"; no_kernel
="yes";;
373 --strip) do_strip_l
="yes";;
374 --nostrip) do_strip_l
="no";;
375 --hardlink) do_hardlink_l
="yes";;
376 --nohardlink) do_hardlink_l
="no";;
377 --noprefix) prefix_l
="/";;
378 --mdadmconf) mdadmconf_l
="yes";;
379 --nomdadmconf) mdadmconf_l
="no";;
380 --lvmconf) lvmconf_l
="yes";;
381 --nolvmconf) lvmconf_l
="no";;
382 --debug) debug
="yes";;
383 --profile) profile
="yes";;
384 --sshkey) sshkey
="$2"; shift;;
385 -v|
--verbose) ((verbosity_mod_l
++));;
386 -q|
--quiet) ((verbosity_mod_l--
));;
389 [[ -f "$(readlink -f ${0%/*})/dracut-functions.sh" ]] \
390 && dracutbasedir
="$(readlink -f ${0%/*})"
392 -H|
--hostonly) hostonly_l
="yes" ;;
393 -N|
--no-hostonly) hostonly_l
="no" ;;
394 --fstab) use_fstab_l
="yes" ;;
395 -h|
--help) long_usage
; exit 1 ;;
396 -i|
--include) push include_src
"$2"
398 --bzip2) compress_l
="bzip2";;
399 --lzma) compress_l
="lzma";;
400 --xz) compress_l
="xz";;
401 --no-compress) _no_compress_l
="cat";;
402 --gzip) compress_l
="gzip";;
403 --list-modules) do_list
="yes";;
408 --printsize) printsize
="yes";;
412 *) # should not even reach this point
413 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage
; exit 1;;
418 # getopt cannot handle multiple arguments, so just handle "-I,--include"
419 # the old fashioned way
423 ++include
) push include_src
"$2"
424 push include_target
"$3"
427 if ! [[ ${outfile+x} ]]; then
429 elif ! [[ ${kernel+x} ]]; then
432 printf "\nUnknown arguments: %s\n\n" "$*" >&2
440 if ! [[ $kernel ]]; then
444 if ! [[ $outfile ]]; then
445 [[ -f /etc
/machine-id
]] && read MACHINE_ID
< /etc
/machine-id
447 if [[ $MACHINE_ID ]] && ( [[ -d /boot
/${MACHINE_ID} ]] ||
[[ -L /boot
/${MACHINE_ID} ]] ); then
448 outfile
="/boot/${MACHINE_ID}/$kernel/initrd"
450 outfile
="/boot/initramfs-$kernel.img"
454 for i
in /usr
/sbin
/sbin
/usr
/bin
/bin
; do
459 if [[ "$NPATH" != "*:$rl*" ]] ; then
463 export PATH
="${NPATH#:}"
465 unset LD_LIBRARY_PATH
468 export DRACUT_LOG_LEVEL
=warning
470 export DRACUT_LOG_LEVEL
=debug
471 export PS4
='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
476 export PS4
='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
481 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
483 # if we were not passed a config file, try the default one
484 if [[ ! -f $conffile ]]; then
485 [[ $allowlocal ]] && conffile
="$dracutbasedir/dracut.conf" || \
486 conffile
="/etc/dracut.conf"
489 if [[ ! -d $confdir ]]; then
490 [[ $allowlocal ]] && confdir
="$dracutbasedir/dracut.conf.d" || \
491 confdir
="/etc/dracut.conf.d"
494 # source our config file
495 [[ -f $conffile ]] && .
"$conffile"
497 # source our config dir
498 for f
in $
(dropindirs_sort
".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
499 [[ -e $f ]] && .
"$f"
502 # these optins add to the stuff in the config file
503 if (( ${#add_dracutmodules_l[@]} )); then
504 while pop add_dracutmodules_l val
; do
505 add_dracutmodules
+=" $val "
509 if (( ${#force_add_dracutmodules_l[@]} )); then
510 while pop force_add_dracutmodules_l val
; do
511 force_add_dracutmodules
+=" $val "
515 if (( ${#fscks_l[@]} )); then
516 while pop fscks_l val
; do
521 if (( ${#add_fstab_l[@]} )); then
522 while pop add_fstab_l val
; do
527 if (( ${#fstab_lines_l[@]} )); then
528 while pop fstab_lines_l val
; do
529 push fstab_lines
$val
533 if (( ${#install_items_l[@]} )); then
534 while pop install_items_l val
; do
535 install_items
+=" $val "
539 # these options override the stuff in the config file
540 if (( ${#dracutmodules_l[@]} )); then
542 while pop dracutmodules_l val
; do
543 dracutmodules
+="$val "
547 if (( ${#omit_dracutmodules_l[@]} )); then
548 omit_dracutmodules
=''
549 while pop omit_dracutmodules_l val
; do
550 omit_dracutmodules
+="$val "
554 if (( ${#filesystems_l[@]} )); then
556 while pop filesystems_l val
; do
561 if (( ${#fw_dir_l[@]} )); then
563 while pop fw_dir_l val
; do
568 if (( ${#libdirs_l[@]} )); then
570 while pop libdirs_l val
; do
575 [[ $stdloglvl_l ]] && stdloglvl
=$stdloglvl_l
576 [[ ! $stdloglvl ]] && stdloglvl
=4
577 stdloglvl
=$
((stdloglvl
+ verbosity_mod_l
))
578 ((stdloglvl
> 6)) && stdloglvl
=6
579 ((stdloglvl
< 0)) && stdloglvl
=0
581 [[ $drivers_dir_l ]] && drivers_dir
=$drivers_dir_l
582 [[ $do_strip_l ]] && do_strip
=$do_strip_l
583 [[ $do_strip ]] || do_strip
=yes
584 [[ $do_hardlink_l ]] && do_hardlink
=$do_hardlink_l
585 [[ $do_hardlink ]] || do_hardlink
=yes
586 [[ $prefix_l ]] && prefix
=$prefix_l
587 [[ $prefix = "/" ]] && unset prefix
588 [[ $hostonly_l ]] && hostonly
=$hostonly_l
589 [[ $use_fstab_l ]] && use_fstab
=$use_fstab_l
590 [[ $mdadmconf_l ]] && mdadmconf
=$mdadmconf_l
591 [[ $lvmconf_l ]] && lvmconf
=$lvmconf_l
592 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
593 [[ $fw_dir ]] || fw_dir
="/lib/firmware/updates /lib/firmware"
594 [[ $tmpdir_l ]] && tmpdir
="$tmpdir_l"
595 [[ $tmpdir ]] || tmpdir
=/var
/tmp
596 [[ $compress_l ]] && compress=$compress_l
597 [[ $show_modules_l ]] && show_modules
=$show_modules_l
598 [[ $nofscks_l ]] && nofscks
="yes"
599 [[ $ro_mnt_l ]] && ro_mnt
="yes"
600 # eliminate IFS hackery when messing with fw_dir
601 fw_dir
=${fw_dir//:/ }
603 # handle compression options.
604 [[ $compress ]] ||
compress="gzip"
606 bzip2) compress="bzip2 -9";;
607 lzma
) compress="lzma -9";;
608 xz
) compress="xz --check=crc32 --lzma2=dict=1MiB";;
609 gzip) command -v pigz
> /dev
/null
2>&1 && compress="pigz -9" || \
612 if [[ $_no_compress_l = "cat" ]]; then
616 [[ $hostonly = yes ]] && hostonly
="-h"
617 [[ $hostonly != "-h" ]] && unset hostonly
619 readonly TMPDIR
="$tmpdir"
620 readonly initdir
=$
(mktemp
--tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX
)
621 [ -d "$initdir" ] ||
{
622 echo "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t initramfs.XXXXXX failed." >&2
626 # clean up after ourselves no matter how we die.
627 trap 'ret=$?;[[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf "$initdir";exit $ret; };' EXIT
628 # clean up after ourselves no matter how we die.
629 trap 'exit 1;' SIGINT
631 export DRACUT_KERNEL_LAZY
="1"
632 export DRACUT_RESOLVE_LAZY
="1"
634 if [[ -f $dracutbasedir/dracut-functions.sh
]]; then
635 .
$dracutbasedir/dracut-functions.sh
637 echo "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2
638 echo "dracut: Are you running from a git checkout?" >&2
639 echo "dracut: Try passing -l as an argument to $0" >&2
644 if ! $DRACUT_INSTALL ${initdir+-D "$initdir"} -R "$initdir/bin/sh" &>/dev
/null
; then
645 unset DRACUT_RESOLVE_LAZY
646 export DRACUT_RESOLVE_DEPS
=1
650 if [[ -f $dracutbasedir/dracut-version.sh
]]; then
651 .
$dracutbasedir/dracut-version.sh
654 # Verify bash version, current minimum is 3.1
655 if (( ${BASH_VERSINFO[0]} < 3 ||
656 ( ${BASH_VERSINFO[0]} == 3 && ${BASH_VERSINFO[1]} < 1 ) )); then
657 dfatal
'You need at least Bash 3.1 to use dracut, sorry.'
661 dracutfunctions
=$dracutbasedir/dracut-functions.sh
662 export dracutfunctions
664 if (( ${#drivers_l[@]} )); then
666 while pop drivers_l val
; do
670 drivers
=${drivers/-/_}
672 if (( ${#add_drivers_l[@]} )); then
673 while pop add_drivers_l val
; do
674 add_drivers
+=" $val "
677 add_drivers
=${add_drivers/-/_}
679 if (( ${#omit_drivers_l[@]} )); then
680 while pop omit_drivers_l val
; do
681 omit_drivers
+=" $val "
684 omit_drivers
=${omit_drivers/-/_}
686 if (( ${#kernel_cmdline_l[@]} )); then
687 while pop kernel_cmdline_l val
; do
688 kernel_cmdline
+=" $val "
692 omit_drivers_corrected
=""
693 for d
in $omit_drivers; do
694 strstr
" $drivers $add_drivers " " $d " && continue
695 omit_drivers_corrected
+="$d|"
697 omit_drivers
="${omit_drivers_corrected%|}"
698 unset omit_drivers_corrected
700 # prepare args for logging
701 for ((i
=0; i
< ${#dracut_args[@]}; i
++)); do
702 strstr
"${dracut_args[$i]}" " " && \
703 dracut_args
[$i]="\"${dracut_args[$i]}\""
706 ddebug
"Executing: $0 ${dracut_args[@]}"
708 [[ $do_list = yes ]] && {
709 for mod
in $dracutbasedir/modules.d
/*; do
710 [[ -d $mod ]] ||
continue;
711 [[ -e $mod/install ||
-e $mod/installkernel || \
712 -e $mod/module-setup.sh
]] ||
continue
718 # This is kinda legacy -- eventually it should go away.
719 case $dracutmodules in
720 ""|auto
) dracutmodules
="all" ;;
723 abs_outfile
=$
(readlink
-f "$outfile") && outfile
="$abs_outfile"
725 if [[ -d $srcmods ]]; then
726 [[ -f $srcmods/modules.dep
]] ||
{
727 dwarn
"$srcmods/modules.dep is missing. Did you run depmod?"
731 if [[ -f $outfile && ! $force ]]; then
732 dfatal
"Will not override existing initramfs ($outfile) without --force"
737 [[ $outdir ]] || outdir
="/"
739 if [[ ! -d "$outdir" ]]; then
740 dfatal
"Can't write to $outdir: Directory $outdir does not exist or is not accessible."
742 elif [[ ! -w "$outdir" ]]; then
743 dfatal
"No permission to write to $outdir."
745 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
746 dfatal
"No permission to write $outfile."
750 # Need to be able to have non-root users read stuff (rpcbind etc)
753 declare -A host_fs_types
755 for line
in "${fstab_lines[@]}"; do
759 host_fs_types
["$1"]="$3"
762 for f
in $add_fstab; do
763 [ -e $f ] ||
continue
764 while read dev rest
; do
769 if (( ${#add_device_l[@]} )); then
770 while pop add_device_l val
; do
775 for dev
in $add_device; do
779 if [[ $hostonly ]]; then
780 # in hostonly mode, determine all devices, which have to be accessed
781 # and examine them for filesystem types
793 for mp
in "${host_mp[@]}"; do
794 mountpoint
"$mp" >/dev
/null
2>&1 ||
continue
795 push host_devs $
(readlink
-f "/dev/block/$(find_block_device "$mp")")
798 while read dev
type rest
; do
799 [[ -b $dev ]] ||
continue
800 [[ "$type" == "partition" ]] ||
continue
801 while read _d _m _t _o _r
; do
802 [[ "$_d" == \
#* ]] && continue
803 [[ $_d ]] ||
continue
804 [[ $_t != "swap" ]] ||
[[ $_m != "swap" ]] && continue
805 [[ "$_o" == *noauto
* ]] && continue
806 [[ "$_d" == UUID\
=* ]] && _d
="/dev/disk/by-uuid/${_d#UUID=}"
807 [[ "$_d" == LABEL\
=* ]] && _d
="/dev/disk/by-label/$_d#LABEL=}"
808 [[ "$_d" -ef "$dev" ]] ||
continue
809 push host_devs $
(readlink
-f $dev)
818 if [[ -b $1 ]] && get_fs_env
$1; then
819 echo "$(readlink -f $1) $ID_FS_TYPE"
822 if [[ -b /dev
/block
/$1 ]] && get_fs_env
/dev
/block
/$1; then
823 echo "$(readlink -f /dev/block/$1) $ID_FS_TYPE"
826 if fstype
=$
(find_dev_fstype
$1); then
833 for dev
in "${host_devs[@]}"; do
834 while read key val
; do
835 host_fs_types
["$key"]="$val"
838 check_block_and_slaves_all _get_fs_type $
(get_maj_min
$dev)
843 || udevdir
=$
(pkg-config udev
--variable=udevdir
2>/dev
/null
)
844 if ! [[ -d "$udevdir" ]]; then
845 [[ -d /lib
/udev
]] && udevdir
=/lib
/udev
846 [[ -d /usr
/lib
/udev
]] && udevdir
=/usr
/lib
/udev
849 [[ -d $systemdutildir ]] \
850 || systemdutildir
=$
(pkg-config systemd
--variable=systemdutildir
2>/dev
/null
)
851 [[ -d $systemdsystemunitdir ]] \
852 || systemdsystemunitdir
=$
(pkg-config systemd
--variable=systemdsystemunitdir
2>/dev
/null
)
854 if ! [[ -d "$systemdutildir" ]]; then
855 [[ -d /lib
/systemd
]] && systemdutildir
=/lib
/systemd
856 [[ -d /usr
/lib
/systemd
]] && systemdutildir
=/usr
/lib
/systemd
858 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir
=${systemdutildir}/system
860 export initdir dracutbasedir dracutmodules \
861 fw_dir drivers_dir debug no_kernel kernel_only \
862 omit_drivers mdadmconf lvmconf \
863 use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
864 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
865 debug host_fs_types host_devs sshkey add_fstab \
866 DRACUT_VERSION udevdir systemdutildir systemdsystemunitdir \
867 prefix filesystems drivers
869 # Create some directory structure first
870 [[ $prefix ]] && mkdir
-m 0755 -p "${initdir}${prefix}"
872 [[ -h /lib
]] || mkdir
-m 0755 -p "${initdir}${prefix}/lib"
873 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
875 if [[ $prefix ]]; then
876 for d
in bin etc lib sbin tmp usr var
$libdirs; do
877 strstr
"$d" "/" && continue
878 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
882 if [[ $kernel_only != yes ]]; then
883 for d
in usr
/bin usr
/sbin bin etc lib sbin tmp usr var
$libdirs; do
884 [[ -e "${initdir}${prefix}/$d" ]] && continue
885 if [ -L "/$d" ]; then
886 inst_symlink
"/$d" "${prefix}/$d"
888 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
892 for d
in dev proc sys sysroot root run run
/lock run
/initramfs
; do
893 if [ -L "/$d" ]; then
896 mkdir
-m 0755 -p "$initdir/$d"
900 ln -sfn ..
/run
"$initdir/var/run"
901 ln -sfn ..
/run
/lock
"$initdir/var/lock"
902 ln -sfn ..
/run
/log
"$initdir/var/log"
904 for d
in lib
"$libdir"; do
905 [[ -e "${initdir}${prefix}/$d" ]] && continue
906 if [ -h "/$d" ]; then
907 inst
"/$d" "${prefix}/$d"
909 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
914 if [[ $kernel_only != yes ]]; then
915 mkdir
-p "${initdir}/etc/cmdline.d"
916 for _d
in $hookdirs; do
917 mkdir
-m 0755 -p ${initdir}/lib
/dracut
/hooks
/$_d
919 if [[ "$UID" = "0" ]]; then
920 [ -c ${initdir}/dev
/null
] || mknod
${initdir}/dev
/null c
1 3
921 [ -c ${initdir}/dev
/kmsg
] || mknod
${initdir}/dev
/kmsg c
1 11
922 [ -c ${initdir}/dev
/console
] || mknod
${initdir}/dev
/console c
5 1
927 # check all our modules to see if they should be sourced.
928 # This builds a list of modules that we will install next.
929 for_each_module_dir check_module
930 for_each_module_dir check_mount
932 strstr
"$mods_to_load" "fips" && export DRACUT_FIPS_MODE
=1
934 _isize
=0 #initramfs size
936 # source our modules.
937 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
938 _d_mod
=${moddir##*/}; _d_mod
=${_d_mod#[0-9][0-9]}
939 if strstr
"$mods_to_load" " $_d_mod "; then
940 [[ $show_modules = yes ]] && echo "$_d_mod" || \
941 dinfo
"*** Including module: $_d_mod ***"
942 if [[ $kernel_only = yes ]]; then
943 module_installkernel
$_d_mod ||
{
944 dfatal
"installkernel failed in module $_d_mod"
948 module_install
$_d_mod
949 if [[ $no_kernel != yes ]]; then
950 module_installkernel
$_d_mod ||
{
951 dfatal
"installkernel failed in module $_d_mod"
956 mods_to_load
=${mods_to_load// $_d_mod /}
957 modules_loaded
+="$_d_mod "
959 #print the module install size
960 if [ -n "$printsize" ]; then
961 _isize_new
=$
(du
-sk ${initdir}|cut
-f1)
962 _isize_delta
=$
(($_isize_new - $_isize))
963 echo "$_d_mod install size: ${_isize_delta}k"
970 for i
in $modules_loaded; do
971 mkdir
-p $initdir/lib
/dracut
972 echo "$i" >> $initdir/lib
/dracut
/modules.txt
975 dinfo
"*** Including modules done ***"
977 ## final stuff that has to happen
978 if [[ $no_kernel != yes ]]; then
980 if [[ $drivers ]]; then
981 hostonly
='' instmods
$drivers
984 if [[ $add_drivers ]]; then
985 hostonly
='' instmods
-c $add_drivers
987 if [[ $filesystems ]]; then
988 hostonly
='' instmods
-c $filesystems
991 dinfo
"*** Installing kernel module dependencies and firmware ***"
993 dinfo
"*** Installing kernel module dependencies and firmware done ***"
996 if [[ $kernel_only != yes ]]; then
997 (( ${#install_items[@]} > 0 )) && dracut_install
${install_items[@]}
999 [[ $kernel_cmdline ]] && echo "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1001 while pop fstab_lines line
; do
1002 echo "$line 0 0" >> "${initdir}/etc/fstab"
1005 for f
in $add_fstab; do
1006 cat $f >> "${initdir}/etc/fstab"
1009 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1010 dinfo
"*** Resolving executable dependencies ***"
1011 find "$initdir" -type f \
1012 '(' -perm -0100 -or -perm -0010 -or -perm -0001 ')' \
1013 -not -path '*.ko' -print0 \
1014 |
xargs -r -0 $DRACUT_INSTALL ${initdir+-D "$initdir"} -R ${DRACUT_FIPS_MODE+-H}
1015 dinfo
"*** Resolving executable dependencies done***"
1019 while pop include_src src
&& pop include_target tgt
; do
1020 if [[ $src && $tgt ]]; then
1021 if [[ -f $src ]]; then
1024 ddebug
"Including directory: $src"
1025 mkdir
-p "${initdir}/${tgt}"
1026 # check for preexisting symlinks, so we can cope with the
1027 # symlinks to $prefix
1028 for i
in "$src"/*; do
1029 [[ -e "$i" ||
-h "$i" ]] ||
continue
1030 s
=${initdir}/${tgt}/${i#$src/}
1031 if [[ -d "$i" ]]; then
1032 if ! [[ -e "$s" ]]; then
1033 mkdir
-m 0755 -p "$s"
1034 chmod --reference="$i" "$s"
1036 cp --reflink=auto
--sparse=auto
-fa -t "$s" "$i"/*
1038 cp --reflink=auto
--sparse=auto
-fa -t "$s" "$i"
1045 if [[ $kernel_only != yes ]]; then
1046 # make sure that library links are correct and up to date
1047 for f
in /etc
/ld.so.conf
/etc
/ld.so.conf.d
/*; do
1048 [[ -f $f ]] && inst_simple
"$f"
1050 if ! ldconfig
-r "$initdir"; then
1051 if [[ $UID = 0 ]]; then
1052 derror
"ldconfig exited ungracefully"
1054 derror
"ldconfig might need uid=0 (root) for chroot()"
1059 if (($maxloglvl >= 5)); then
1060 ddebug
"Listing sizes of included files:"
1061 du
-c "$initdir" |
sort -n | ddebug
1064 PRELINK_BIN
=$
(command -v prelink
)
1065 if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then
1066 if [[ $DRACUT_FIPS_MODE ]]; then
1067 dinfo
"*** Pre-unlinking files ***"
1068 dracut_install
-o prelink
/etc
/prelink.conf
/etc
/prelink.conf.d
/*.conf
/etc
/prelink.cache
1069 chroot
"$initdir" $PRELINK_BIN -u -a
1070 rm -f "$initdir"/$PRELINK_BIN
1071 rm -fr "$initdir"/etc
/prelink.
*
1072 dinfo
"*** Pre-unlinking files done ***"
1074 dinfo
"*** Pre-linking files ***"
1075 dracut_install
-o prelink
/etc
/prelink.conf
/etc
/prelink.conf.d
/*.conf
1076 chroot
"$initdir" $PRELINK_BIN -a
1077 rm -f "$initdir"/$PRELINK_BIN
1078 rm -fr "$initdir"/etc
/prelink.
*
1079 dinfo
"*** Pre-linking files done ***"
1083 if [[ $do_hardlink = yes ]] && command -v hardlink
>/dev
/null
; then
1084 dinfo
"*** Hardlinking files ***"
1085 hardlink
"$initdir" 2>&1
1086 dinfo
"*** Hardlinking files done ***"
1090 if [[ $do_strip = yes ]] ; then
1091 for p
in strip
xargs find; do
1092 if ! type -P $p >/dev
/null
; then
1093 dwarn
"Could not find '$p'. Not stripping the initramfs."
1099 if [[ $do_strip = yes ]] ; then
1100 dinfo
"*** Stripping files ***"
1101 if [[ $DRACUT_FIPS_MODE ]]; then
1102 find "$initdir" -type f \
1103 -executable -not -path '*/lib/modules/*.ko' -print0 \
1104 |
while read -r -d $
'\0' f
; do
1105 if ! [[ -e "${f%/*}/.${f##*/}.hmac" ]] \
1106 && ! [[ -e "/lib/fipscheck/${f##*/}.hmac" ]] \
1107 && ! [[ -e "/lib64/fipscheck/${f##*/}.hmac" ]]; then
1108 echo -n "$f"; echo -n -e "\000"
1110 done |
xargs -r -0 strip
-g 2>/dev
/null
1112 find "$initdir" -type f \
1113 -executable -not -path '*/lib/modules/*.ko' -print0 \
1114 |
xargs -r -0 strip
-g 2>/dev
/null
1117 # strip kernel modules, but do not touch signed modules
1118 find "$initdir" -type f
-path '*/lib/modules/*.ko' -print0 \
1119 |
while read -r -d $
'\0' f
; do
1120 SIG
=$
(tail -c 28 "$f")
1121 [[ $SIG == '~Module signature appended~' ]] ||
{ echo -n "$f"; echo -n -e "\000"; }
1122 done |
xargs -r -0 strip
-g
1124 dinfo
"*** Stripping files done ***"
1128 dinfo
"*** Creating image file ***"
1129 if ! ( umask 077; cd "$initdir"; find . |
cpio -R 0:0 -H newc
-o --quiet| \
1130 $compress > "$outfile.$$"; ); then
1131 dfatal
"dracut: creation of $outfile.$$ failed"
1134 mv $outfile.$$
$outfile
1135 dinfo
"*** Creating image file done ***"
1137 dinfo
"Wrote $outfile:"
1138 dinfo
"$(ls -l "$outfile")"