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 -f, --force Overwrite existing initramfs file.
71 -m, --modules [LIST] Specify a space-separated list of dracut modules to
72 call when building the initramfs. Modules are located
73 in /usr/lib/dracut/modules.d.
74 -o, --omit [LIST] Omit a space-separated list of dracut modules.
75 -a, --add [LIST] Add a space-separated list of dracut modules.
76 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
77 exclusively include in the initramfs.
78 --add-drivers [LIST] Specify a space-separated list of kernel
79 modules to add to the initramfs.
80 --omit-drivers [LIST] Specify a space-separated list of kernel
81 modules not to add to the initramfs.
82 --filesystems [LIST] Specify a space-separated list of kernel filesystem
83 modules to exclusively include in the generic
85 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
87 --fwdir [DIR] Specify additional directories, where to look for
88 firmwares, separated by :
89 --kernel-only Only install kernel drivers and firmware files
90 --no-kernel Do not install kernel drivers and firmware files
91 --strip Strip binaries in the initramfs
92 --nostrip Do not strip binaries in the initramfs (default)
93 --hardlink Hardlink files in the initramfs (default)
94 --nohardlink Do not hardlink files in the initramfs
95 --prefix [DIR] Prefix initramfs files with [DIR]
96 --noprefix Do not prefix initramfs files (default)
97 --mdadmconf Include local /etc/mdadm.conf
98 --nomdadmconf Do not include local /etc/mdadm.conf
99 --lvmconf Include local /etc/lvm/lvm.conf
100 --nolvmconf Do not include local /etc/lvm/lvm.conf
101 --fscks [LIST] Add a space-separated list of fsck helpers.
102 --nofscks Inhibit installation of any fsck helpers.
103 -h, --help This message
104 --debug Output debug information of the build process
105 --profile Output profile information of the build process
106 -L, --stdlog [0-6] Specify logging level (to standard error)
107 0 - suppress any messages
108 1 - only fatal errors
112 5 - debug info (here starts lots of output)
113 6 - trace info (and even more)
114 -v, --verbose Increase verbosity level (default is info(4))
115 -q, --quiet Decrease verbosity level (default is info(4))
116 -c, --conf [FILE] Specify configuration file to use.
117 Default: /etc/dracut.conf
118 --confdir [DIR] Specify configuration directory to use *.conf files
119 from. Default: /etc/dracut.conf.d
120 --tmpdir [DIR] Temporary directory to be used instead of default
122 -l, --local Local mode. Use modules from the current working
123 directory instead of the system-wide installed in
124 /usr/lib/dracut/modules.d.
125 Useful when running dracut from a git checkout.
126 -H, --hostonly Host-Only mode: Install only what is needed for
127 booting the local host instead of a generic host.
128 --no-hostonly Disables Host-Only mode
129 --fstab Use /etc/fstab to determine the root device.
130 --add-fstab [FILE] Add file to the initramfs fstab
131 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
132 Mount device [DEV] on mountpoint [MP] with filesystem
133 [FSTYPE] and options [FSOPTS] in the initramfs
134 -i, --include [SOURCE] [TARGET]
135 Include the files in the SOURCE directory into the
136 Target directory in the final initramfs.
137 If SOURCE is a file, it will be installed to TARGET
138 in the final initramfs.
139 -I, --install [LIST] Install the space separated list of files into the
141 --gzip Compress the generated initramfs using gzip.
142 This will be done by default, unless another
143 compression option or --no-compress is passed.
144 --bzip2 Compress the generated initramfs using bzip2.
145 Make sure your kernel has bzip2 decompression support
146 compiled in, otherwise you will not be able to boot.
147 --lzma Compress the generated initramfs using lzma.
148 Make sure your kernel has lzma support compiled in,
149 otherwise you will not be able to boot.
150 --xz Compress the generated initramfs using xz.
151 Make sure that your kernel has xz support compiled
152 in, otherwise you will not be able to boot.
153 --compress [COMPRESSION] Compress the generated initramfs with the
154 passed compression program. Make sure your kernel
155 knows how to decompress the generated initramfs,
156 otherwise you will not be able to boot.
157 --no-compress Do not compress the generated initramfs. This will
158 override any other compression options.
159 --list-modules List all available dracut modules.
160 -M, --show-modules Print included module's name to standard output during
162 --keep Keep the temporary initramfs for debugging purposes
163 --printsize Print out the module install size
164 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
166 If [LIST] has multiple arguments, then you have to put these in quotes.
170 # dracut --add-drivers "module1 module2" ...
176 # push values to a stack
177 # $1 = stack variable
180 # push stack 1 2 "3 4"
183 local __stack=$1; shift
185 eval ${__stack}'[${#'${__stack}'[@]}]="$_i"'
190 # pops the last value from a stack
191 # assigns value to second argument variable
192 # or echo to stdout, if no second argument
193 # $1 = stack variable
194 # $2 = optional variable to store the value
199 local __stack=$1; shift
202 # check for empty stack
203 eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
205 eval _value='${'${__stack}'[${#'${__stack}'[@]}-1]}'
207 if [[ "$__resultvar" ]]; then
208 eval $__resultvar="'$_value'"
212 eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
216 # Little helper function for reading args from the commandline.
217 # it automatically handles -a b and -a=b variants, and returns 1 if
218 # we need to shift $3.
223 local rematch='^[^=]*=(.*)$'
224 if [[ $2 =~ $rematch ]]; then
225 read "$1" <<< "${BASH_REMATCH[1]}"
228 # There is no way to shift our callers args, so
229 # return 1 to indicate they should do it instead.
238 # Workaround -i, --include taking 2 arguments
239 set -- "${@/--include/++include}"
241 # This prevents any long argument ending with "-i"
242 # -i, like --opt-i but I think we can just prevent that
243 set -- "${@/%-i/++include}"
245 TEMP=$(unset POSIXLY_CORRECT; getopt \
246 -o "a:m:o:d:I:k:c:L:fvqlHhM" \
249 --long add-drivers: \
250 --long omit-drivers: \
254 --long filesystems: \
296 --long list-modules \
297 --long show-modules \
302 if (( $? != 0 )); then
311 -a|--add) push add_dracutmodules_l "$2"; shift;;
312 --force-add) push force_add_dracutmodules_l "$2"; shift;;
313 --add-drivers) push add_drivers_l "$2"; shift;;
314 --omit-drivers) push omit_drivers_l "$2"; shift;;
315 -m|--modules) push dracutmodules_l "$2"; shift;;
316 -o|--omit) push omit_dracutmodules_l "$2"; shift;;
317 -d|--drivers) push drivers_l "$2"; shift;;
318 --filesystems) push filesystems_l "$2"; shift;;
319 -I|--install) push install_items_l "$2"; shift;;
320 --fwdir) push fw_dir_l "$2"; shift;;
321 --libdirs) push libdirs_l "$2"; shift;;
322 --fscks) push fscks_l "$2"; shift;;
323 --add-fstab) push add_fstab_l "$2"; shift;;
324 --mount) push fstab_lines "$2"; shift;;
325 --nofscks) nofscks_l="yes";;
326 -k|--kmoddir) drivers_dir_l="$2"; shift;;
327 -c|--conf) conffile="$2"; shift;;
328 --confdir) confdir="$2"; shift;;
329 --tmpdir) tmpdir_l="$2"; shift;;
330 -L|--stdlog) stdloglvl_l="$2"; shift;;
331 --compress) compress_l="$2"; shift;;
332 --prefix) prefix_l="$2"; shift;;
333 -f|--force) force=yes;;
334 --kernel-only) kernel_only="yes"; no_kernel="no";;
335 --no-kernel) kernel_only="no"; no_kernel="yes";;
336 --strip) do_strip_l="yes";;
337 --nostrip) do_strip_l="no";;
338 --hardlink) do_hardlink_l="yes";;
339 --nohardlink) do_hardlink_l="no";;
340 --noprefix) prefix_l="/";;
341 --mdadmconf) mdadmconf_l="yes";;
342 --nomdadmconf) mdadmconf_l="no";;
343 --lvmconf) lvmconf_l="yes";;
344 --nolvmconf) lvmconf_l="no";;
345 --debug) debug="yes";;
346 --profile) profile="yes";;
347 --sshkey) sshkey="$2"; shift;;
348 -v|--verbose) ((verbosity_mod_l++));;
349 -q|--quiet) ((verbosity_mod_l--));;
352 [[ -f "$(readlink -f ${0%/*})/dracut-functions.sh" ]] \
353 && dracutbasedir="$(readlink -f ${0%/*})"
355 -H|--hostonly) hostonly_l="yes" ;;
356 --no-hostonly) hostonly_l="no" ;;
357 --fstab) use_fstab_l="yes" ;;
358 -h|--help) long_usage; exit 1 ;;
359 -i|--include) push include_src "$2"
361 --bzip2) compress_l="bzip2";;
362 --lzma) compress_l="lzma";;
363 --xz) compress_l="xz";;
364 --no-compress) _no_compress_l="cat";;
365 --gzip) compress_l="gzip";;
366 --list-modules) do_list="yes";;
371 --printsize) printsize="yes";;
375 *) # should not even reach this point
376 printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage; exit 1;;
381 # getopt cannot handle multiple arguments, so just handle "-I,--include"
382 # the old fashioned way
386 ++include) push include_src "$2"
387 push include_target "$3"
390 if ! [[ ${outfile+x} ]]; then
392 elif ! [[ ${kernel+x} ]]; then
395 printf "\nUnknown arguments: %s\n\n" "$*" >&2
403 if ! [[ $kernel ]]; then
407 if ! [[ $outfile ]]; then
408 outfile="/boot/initramfs-$kernel.img"
411 for i in /usr/sbin /sbin /usr/bin /bin; do
416 if [[ "$NPATH" != "*:$rl*" ]] ; then
420 export PATH="${NPATH#:}"
422 unset LD_LIBRARY_PATH
425 export DRACUT_LOG_LEVEL=warning
427 export DRACUT_LOG_LEVEL=debug
428 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
433 export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
438 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
440 # if we were not passed a config file, try the default one
441 if [[ ! -f $conffile ]]; then
442 [[ $allowlocal ]] && conffile="$dracutbasedir/dracut.conf" || \
443 conffile="/etc/dracut.conf"
446 if [[ ! -d $confdir ]]; then
447 [[ $allowlocal ]] && confdir="$dracutbasedir/dracut.conf.d" || \
448 confdir="/etc/dracut.conf.d"
451 # source our config file
452 [[ -f $conffile ]] && . "$conffile"
454 # source our config dir
455 if [[ $confdir && -d $confdir ]]; then
456 for f in "$confdir"/*.conf; do
457 [[ -e $f ]] && . "$f"
461 # these optins add to the stuff in the config file
462 if (( ${#add_dracutmodules_l[@]} )); then
463 while pop add_dracutmodules_l val; do
464 add_dracutmodules+=" $val "
468 if (( ${#force_add_dracutmodules_l[@]} )); then
469 while pop force_add_dracutmodules_l val; do
470 force_add_dracutmodules+=" $val "
474 if (( ${#fscks_l[@]} )); then
475 while pop fscks_l val; do
480 if (( ${#add_fstab_l[@]} )); then
481 while pop add_fstab_l val; do
486 if (( ${#fstab_lines_l[@]} )); then
487 while pop fstab_lines_l val; do
488 push fstab_lines $val
492 if (( ${#install_items_l[@]} )); then
493 while pop install_items_l val; do
494 install_items+=" $val "
498 # these options override the stuff in the config file
499 if (( ${#dracutmodules_l[@]} )); then
501 while pop dracutmodules_l val; do
502 dracutmodules+="$val "
506 if (( ${#omit_dracutmodules_l[@]} )); then
507 omit_dracutmodules=''
508 while pop omit_dracutmodules_l val; do
509 omit_dracutmodules+="$val "
513 if (( ${#filesystems_l[@]} )); then
515 while pop filesystems_l val; do
520 if (( ${#fw_dir_l[@]} )); then
522 while pop fw_dir_l val; do
527 if (( ${#libdirs_l[@]} )); then
529 while pop libdirs_l val; do
534 [[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
535 [[ ! $stdloglvl ]] && stdloglvl=4
536 stdloglvl=$((stdloglvl + verbosity_mod_l))
537 ((stdloglvl > 6)) && stdloglvl=6
538 ((stdloglvl < 0)) && stdloglvl=0
540 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
541 [[ $do_strip_l ]] && do_strip=$do_strip_l
542 [[ $do_strip ]] || do_strip=no
543 [[ $do_hardlink_l ]] && do_hardlink=$do_hardlink_l
544 [[ $do_hardlink ]] || do_hardlink=yes
545 [[ $prefix_l ]] && prefix=$prefix_l
546 [[ $prefix = "/" ]] && unset prefix
547 [[ $hostonly_l ]] && hostonly=$hostonly_l
548 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
549 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
550 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
551 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
552 [[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
553 [[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
554 [[ $tmpdir ]] || tmpdir=/var/tmp
555 [[ $compress_l ]] && compress=$compress_l
556 [[ $show_modules_l ]] && show_modules=$show_modules_l
557 [[ $nofscks_l ]] && nofscks="yes"
558 # eliminate IFS hackery when messing with fw_dir
559 fw_dir=${fw_dir//:/ }
561 # handle compression options.
562 [[ $compress ]] || compress="gzip"
564 bzip2) compress="bzip2 -9";;
565 lzma) compress="lzma -9";;
566 xz) compress="xz --check=crc32 --lzma2=dict=1MiB";;
567 gzip) command -v pigz > /dev/null 2>&1 && compress="pigz -9" || \
570 if [[ $_no_compress_l = "cat" ]]; then
574 [[ $hostonly = yes ]] && hostonly="-h"
575 [[ $hostonly != "-h" ]] && unset hostonly
577 readonly TMPDIR="$tmpdir"
578 readonly initdir=$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)
579 [ -d "$initdir" ] || {
580 echo "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t initramfs.XXXXXX failed." >&2
584 export DRACUT_KERNEL_LAZY="1"
585 export DRACUT_RESOLVE_LAZY="1"
587 if [[ -f $dracutbasedir/dracut-functions.sh ]]; then
588 . $dracutbasedir/dracut-functions.sh
590 echo "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2
591 echo "dracut: Are you running from a git checkout?" >&2
592 echo "dracut: Try passing -l as an argument to $0" >&2
596 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
597 . $dracutbasedir/dracut-version.sh
600 # Verify bash version, curret minimum is 3.1
601 if (( ${BASH_VERSINFO[0]} < 3 ||
602 ( ${BASH_VERSINFO[0]} == 3 && ${BASH_VERSINFO[1]} < 1 ) )); then
603 dfatal 'You need at least Bash 3.1 to use dracut, sorry.'
607 dracutfunctions=$dracutbasedir/dracut-functions.sh
608 export dracutfunctions
610 if (( ${#drivers_l[@]} )); then
612 while pop drivers_l val; do
616 drivers=${drivers/-/_}
618 if (( ${#add_drivers_l[@]} )); then
619 while pop add_drivers_l val; do
620 add_drivers+=" $val "
623 add_drivers=${add_drivers/-/_}
625 if (( ${#omit_drivers_l[@]} )); then
626 while pop omit_drivers_l val; do
627 omit_drivers+=" $val "
630 omit_drivers=${omit_drivers/-/_}
632 omit_drivers_corrected=""
633 for d in $omit_drivers; do
634 strstr " $drivers $add_drivers " " $d " && continue
635 omit_drivers_corrected+="$d|"
637 omit_drivers="${omit_drivers_corrected%|}"
638 unset omit_drivers_corrected
640 # prepare args for logging
641 for ((i=0; i < ${#dracut_args[@]}; i++)); do
642 strstr "${dracut_args[$i]}" " " && \
643 dracut_args[$i]="\"${dracut_args[$i]}\""
646 ddebug "Executing: $0 ${dracut_args[@]}"
648 [[ $do_list = yes ]] && {
649 for mod in $dracutbasedir/modules.d/*; do
650 [[ -d $mod ]] || continue;
651 [[ -e $mod/install || -e $mod/installkernel || \
652 -e $mod/module-setup.sh ]] || continue
658 # This is kinda legacy -- eventually it should go away.
659 case $dracutmodules in
660 ""|auto) dracutmodules="all" ;;
663 abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
665 [[ -f $srcmods/modules.dep ]] || {
666 dfatal "$srcmods/modules.dep is missing. Did you run depmod?"
670 if [[ -f $outfile && ! $force ]]; then
671 dfatal "Will not override existing initramfs ($outfile) without --force"
676 [[ $outdir ]] || outdir="/"
678 if [[ ! -d "$outdir" ]]; then
679 dfatal "Can't write $outfile: Directory $outdir does not exist."
681 elif [[ ! -w "$outdir" ]]; then
682 dfatal "No permission to write to $outdir."
684 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
685 dfatal "No permission to write $outfile."
689 # clean up after ourselves no matter how we die.
690 trap 'ret=$?;[[ $keep ]] && echo "Not removing $initdir." >&2 || rm -rf "$initdir";exit $ret;' EXIT
691 # clean up after ourselves no matter how we die.
692 trap 'exit 1;' SIGINT
694 # Need to be able to have non-root users read stuff (rpcbind etc)
697 for line in "${fstab_lines[@]}"; do
701 push host_fs_types "$1|$3"
704 for f in $add_fstab; do
705 [ -e $f ] || continue
706 while read dev rest; do
711 if [[ $hostonly ]]; then
712 # in hostonly mode, determine all devices, which have to be accessed
713 # and examine them for filesystem types
725 for mp in "${host_mp[@]}"; do
726 mountpoint "$mp" >/dev/null 2>&1 || continue
727 push host_devs $(readlink -f "/dev/block/$(find_block_device "$mp")")
733 if [[ -b $1 ]] && get_fs_env $1; then
734 echo "$(readlink -f $1)|$ID_FS_TYPE"
737 if [[ -b /dev/block/$1 ]] && get_fs_env /dev/block/$1; then
738 echo "$(readlink -f /dev/block/$1)|$ID_FS_TYPE"
741 if fstype=$(find_dev_fstype $1); then
748 for dev in "${host_devs[@]}"; do
750 for fstype in $(_get_fs_type $dev) \
751 $(check_block_and_slaves _get_fs_type $(get_maj_min $dev)); do
752 if ! strstr " ${host_fs_types[*]} " " $fstype ";then
753 push host_fs_types "$fstype"
759 || udevdir=$(pkg-config udev --variable=udevdir 2>/dev/null)
760 if ! [[ -d "$udevdir" ]]; then
761 [[ -d /lib/udev ]] && udevdir=/lib/udev
762 [[ -d /usr/lib/udev ]] && udevdir=/usr/lib/udev
765 [[ -d $systemdutildir ]] \
766 || systemdutildir=$(pkg-config systemd --variable=systemdutildir 2>/dev/null)
767 [[ -d $systemdsystemunitdir ]] \
768 || systemdsystemunitdir=$(pkg-config systemd --variable=systemdsystemunitdir 2>/dev/null)
770 if ! [[ -d "$systemdutildir" ]]; then
771 [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd
772 [[ -d /usr/lib/systemd ]] && systemdutildir=/usr/lib/systemd
774 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system
776 export initdir dracutbasedir dracutmodules drivers \
777 fw_dir drivers_dir debug no_kernel kernel_only \
778 add_drivers omit_drivers mdadmconf lvmconf filesystems \
779 use_fstab fstab_lines libdirs fscks nofscks \
780 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
781 debug host_fs_types host_devs sshkey add_fstab \
782 DRACUT_VERSION udevdir systemdutildir systemdsystemunitdir \
785 # Create some directory structure first
786 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
788 [[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
789 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
791 if [[ $prefix ]]; then
792 for d in bin etc lib sbin tmp usr var $libdirs; do
793 strstr "$d" "/" && continue
794 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
798 if [[ $kernel_only != yes ]]; then
799 for d in usr/bin usr/sbin bin etc lib sbin tmp usr var var/log var/run var/lock $libdirs; do
800 [[ -e "${initdir}${prefix}/$d" ]] && continue
801 if [ -L "/$d" ]; then
802 inst_symlink "/$d" "${prefix}/$d"
804 mkdir -m 0755 -p "${initdir}${prefix}/$d"
808 for d in dev proc sys sysroot root run run/lock run/initramfs; do
809 if [ -L "/$d" ]; then
812 mkdir -m 0755 -p "$initdir/$d"
816 ln -sfn /run "$initdir/var/run"
817 ln -sfn /run/lock "$initdir/var/lock"
819 for d in lib "$libdir"; do
820 [[ -e "${initdir}${prefix}/$d" ]] && continue
821 if [ -h "/$d" ]; then
822 inst "/$d" "${prefix}/$d"
824 mkdir -m 0755 -p "${initdir}${prefix}/$d"
829 if [[ $kernel_only != yes ]]; then
830 mkdir -p "${initdir}/etc/cmdline.d"
831 for _d in $hookdirs; do
832 mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d
834 if [[ "$UID" = "0" ]]; then
835 [ -c ${initdir}/dev/null ] || mknod ${initdir}/dev/null c 1 3
836 [ -c ${initdir}/dev/kmsg ] || mknod ${initdir}/dev/kmsg c 1 11
837 [ -c ${initdir}/dev/console ] || mknod ${initdir}/dev/console c 5 1
842 # check all our modules to see if they should be sourced.
843 # This builds a list of modules that we will install next.
844 for_each_module_dir check_module
845 for_each_module_dir check_mount
847 strstr "$mods_to_load" "fips" && export DRACUT_FIPS_MODE=1
849 _isize=0 #initramfs size
851 # source our modules.
852 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
853 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
854 if strstr "$mods_to_load" " $_d_mod "; then
855 [[ $show_modules = yes ]] && echo "$_d_mod" || \
856 dinfo "*** Including module: $_d_mod ***"
857 if [[ $kernel_only = yes ]]; then
858 module_installkernel $_d_mod || {
859 dfatal "installkernel failed in module $_d_mod"
863 module_install $_d_mod
864 if [[ $no_kernel != yes ]]; then
865 module_installkernel $_d_mod || {
866 dfatal "installkernel failed in module $_d_mod"
871 mods_to_load=${mods_to_load// $_d_mod /}
872 modules_loaded+="$_d_mod "
874 #print the module install size
875 if [ -n "$printsize" ]; then
876 _isize_new=$(du -sk ${initdir}|cut -f1)
877 _isize_delta=$(($_isize_new - $_isize))
878 echo "$_d_mod install size: ${_isize_delta}k"
885 for i in $modules_loaded; do
886 mkdir -p $initdir/lib/dracut
887 echo "$i" >> $initdir/lib/dracut/modules.txt
890 dinfo "*** Including modules done ***"
892 ## final stuff that has to happen
893 if [[ $no_kernel != yes ]]; then
894 dinfo "*** Installing kernel module dependencies and firmware ***"
896 dinfo "*** Installing kernel module dependencies and firmware done ***"
899 if [[ $kernel_only != yes ]]; then
900 (( ${#install_items[@]} > 0 )) && dracut_install ${install_items[@]}
902 while pop fstab_lines line; do
903 echo "$line 0 0" >> "${initdir}/etc/fstab"
906 for f in $add_fstab; do
907 cat $f >> "${initdir}/etc/fstab"
910 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
911 dinfo "*** Resolving executable dependencies ***"
912 find "$initdir" -type f \
913 '(' -perm -0100 -or -perm -0010 -or -perm -0001 ')' \
914 -not -path '*.ko' -print0 \
915 | xargs -r -0 $DRACUT_INSTALL ${initdir+-D "$initdir"} -R ${DRACUT_FIPS_MODE+-H}
916 dinfo "*** Resolving executable dependencies done***"
920 while pop include_src src && pop include_target tgt; do
921 if [[ $src && $tgt ]]; then
922 if [[ -f $src ]]; then
925 ddebug "Including directory: $src"
926 mkdir -p "${initdir}/${tgt}"
927 # check for preexisting symlinks, so we can cope with the
928 # symlinks to $prefix
929 for i in "$src"/*; do
930 [[ -e "$i" || -h "$i" ]] || continue
931 s=${initdir}/${tgt}/${i#$src/}
932 if [[ -d "$i" ]]; then
933 if ! [[ -e "$s" ]]; then
934 mkdir -m 0755 -p "$s"
935 chmod --reference="$i" "$s"
937 cp --reflink=auto --sparse=auto -fa -t "$s" "$i"/*
939 cp --reflink=auto --sparse=auto -fa -t "$s" "$i"
946 if [[ $kernel_only != yes ]]; then
947 # make sure that library links are correct and up to date
948 for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
949 [[ -f $f ]] && inst_simple "$f"
951 if ! ldconfig -r "$initdir"; then
952 if [[ $UID = 0 ]]; then
953 derror "ldconfig exited ungracefully"
955 derror "ldconfig might need uid=0 (root) for chroot()"
960 if (($maxloglvl >= 5)); then
961 ddebug "Listing sizes of included files:"
962 du -c "$initdir" | sort -n | ddebug
966 if [[ $do_strip = yes ]] ; then
967 for p in strip xargs find; do
968 if ! type -P $p >/dev/null; then
969 derror "Could not find '$p'. You should run $0 with '--nostrip'."
975 if strstr "$modules_loaded" " fips " && command -v prelink >/dev/null; then
976 dinfo "*** pre-unlinking files ***"
977 for dir in "$initdir/bin" \
980 "$initdir/usr/sbin"; do
981 [[ -L "$dir" ]] && continue
982 for i in "$dir"/*; do
983 [[ -L $i ]] && continue
984 [[ -x $i ]] && prelink -u $i &>/dev/null
987 dinfo "*** pre-unlinking files done ***"
990 if [[ $do_strip = yes ]] ; then
991 dinfo "*** Stripping files ***"
992 find "$initdir" -type f \
993 '(' -perm -0100 -or -perm -0010 -or -perm -0001 \
994 -or -path '*/lib/modules/*.ko' ')' -print0 \
995 | xargs -r -0 strip -g 2>/dev/null
996 dinfo "*** Stripping files done ***"
999 if [[ $do_hardlink = yes ]] ; then
1000 type hardlink &>/dev/null && {
1001 dinfo "*** hardlinking files ***"
1002 hardlink "$initdir" 2>&1
1003 dinfo "*** hardlinking files done ***"
1007 dinfo "*** Creating image file ***"
1008 if ! ( cd "$initdir"; find . |cpio -R 0:0 -H newc -o --quiet| \
1009 $compress > "$outfile"; ); then
1010 dfatal "dracut: creation of $outfile failed"
1013 dinfo "*** Creating image file done ***"
1015 dinfo "Wrote $outfile:"
1016 dinfo "$(ls -l "$outfile")"