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/>.
30 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
31 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
32 . $dracutbasedir/dracut-version.sh
35 # 80x25 linebreak here ^
37 Usage: $0 [OPTION]... <initramfs> <kernel-version>
39 Version: $DRACUT_VERSION
41 Creates initial ramdisk images for preloading modules
43 -f, --force Overwrite existing initramfs file.
44 -m, --modules [LIST] Specify a space-separated list of dracut modules to
45 call when building the initramfs. Modules are located
46 in /usr/lib/dracut/modules.d.
47 -o, --omit [LIST] Omit a space-separated list of dracut modules.
48 -a, --add [LIST] Add a space-separated list of dracut modules.
49 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
50 exclusively include in the initramfs.
51 --add-drivers [LIST] Specify a space-separated list of kernel
52 modules to add to the initramfs.
53 --omit-drivers [LIST] Specify a space-separated list of kernel
54 modules not to add to the initramfs.
55 --filesystems [LIST] Specify a space-separated list of kernel filesystem
56 modules to exclusively include in the generic
58 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
60 --fwdir [DIR] Specify additional directories, where to look for
61 firmwares, separated by :
62 --kernel-only Only install kernel drivers and firmware files
63 --no-kernel Do not install kernel drivers and firmware files
64 --strip Strip binaries in the initramfs
65 --nostrip Do not strip binaries in the initramfs (default)
66 --prefix [DIR] Prefix initramfs files with [DIR]
67 --noprefix Do not prefix initramfs files (default)
68 --mdadmconf Include local /etc/mdadm.conf
69 --nomdadmconf Do not include local /etc/mdadm.conf
70 --lvmconf Include local /etc/lvm/lvm.conf
71 --nolvmconf Do not include local /etc/lvm/lvm.conf
72 --fscks [LIST] Add a space-separated list of fsck helpers.
73 --nofscks Inhibit installation of any fsck helpers.
74 -h, --help This message
75 --debug Output debug information of the build process
76 --profile Output profile information of the build process
77 -L, --stdlog [0-6] Specify logging level (to standard error)
78 0 - suppress any messages
83 5 - debug info (here starts lots of output)
84 6 - trace info (and even more)
85 -v, --verbose Increase verbosity level (default is info(4))
86 -q, --quiet Decrease verbosity level (default is info(4))
87 -c, --conf [FILE] Specify configuration file to use.
88 Default: /etc/dracut.conf
89 --confdir [DIR] Specify configuration directory to use *.conf files
90 from. Default: /etc/dracut.conf.d
91 --tmpdir [DIR] Temporary directory to be used instead of default
93 -l, --local Local mode. Use modules from the current working
94 directory instead of the system-wide installed in
95 /usr/lib/dracut/modules.d.
96 Useful when running dracut from a git checkout.
97 -H, --hostonly Host-Only mode: Install only what is needed for
98 booting the local host instead of a generic host.
99 --no-hostonly Disables Host-Only mode
100 --fstab Use /etc/fstab to determine the root device.
101 --add-fstab [FILE] Add file to the initramfs fstab
102 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
103 Mount device [DEV] on mountpoint [MP] with filesystem
104 [FSTYPE] and options [FSOPTS] in the initramfs
105 -i, --include [SOURCE] [TARGET]
106 Include the files in the SOURCE directory into the
107 Target directory in the final initramfs.
108 If SOURCE is a file, it will be installed to TARGET
109 in the final initramfs.
110 -I, --install [LIST] Install the space separated list of files into the
112 --gzip Compress the generated initramfs using gzip.
113 This will be done by default, unless another
114 compression option or --no-compress is passed.
115 --bzip2 Compress the generated initramfs using bzip2.
116 Make sure your kernel has bzip2 decompression support
117 compiled in, otherwise you will not be able to boot.
118 --lzma Compress the generated initramfs using lzma.
119 Make sure your kernel has lzma support compiled in,
120 otherwise you will not be able to boot.
121 --xz Compress the generated initramfs using xz.
122 Make sure that your kernel has xz support compiled
123 in, otherwise you will not be able to boot.
124 --compress [COMPRESSION] Compress the generated initramfs with the
125 passed compression program. Make sure your kernel
126 knows how to decompress the generated initramfs,
127 otherwise you will not be able to boot.
128 --no-compress Do not compress the generated initramfs. This will
129 override any other compression options.
130 --list-modules List all available dracut modules.
131 -M, --show-modules Print included module's name to standard output during
133 --keep Keep the temporary initramfs for debugging purposes
134 --printsize Print out the module install size
135 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
137 If [LIST] has multiple arguments, then you have to put these in quotes.
139 # dracut --add-drivers "module1 module2" ...
144 # push values to a stack
145 # $1 = stack variable
148 # push stack 1 2 "3 4"
150 local __stack=$1; shift
152 eval ${__stack}'[${#'${__stack}'[@]}]="$i"'
157 # pops the last value from a stack
158 # assigns value to second argument variable
159 # or echo to stdout, if no second argument
160 # $1 = stack variable
161 # $2 = optional variable to store the value
166 local __stack=$1; shift
169 # check for empty stack
170 eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
172 eval myresult='${'${__stack}'[${#'${__stack}'[@]}-1]}'
174 if [[ "$__resultvar" ]]; then
175 eval $__resultvar="'$myresult'"
179 eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
183 # Little helper function for reading args from the commandline.
184 # it automatically handles -a b and -a=b variants, and returns 1 if
185 # we need to shift $3.
190 local rematch='^[^=]*=(.*)$'
191 if [[ $2 =~ $rematch ]]; then
192 read "$1" <<< "${BASH_REMATCH[1]}"
195 # There is no way to shift our callers args, so
196 # return 1 to indicate they should do it instead.
201 # Little helper function for reading args from the commandline to a stack.
202 # it automatically handles -a b and -a=b variants, and returns 1 if
203 # we need to shift $3.
208 local rematch='^[^=]*=(.*)$'
209 if [[ $2 =~ $rematch ]]; then
210 push "$1" "${BASH_REMATCH[1]}"
213 # There is no way to shift our callers args, so
214 # return 1 to indicate they should do it instead.
223 -a|--add) push_arg add_dracutmodules_l "$@" || shift;;
224 --force-add) push_arg force_add_dracutmodules_l "$@" || shift;;
225 --add-drivers) push_arg add_drivers_l "$@" || shift;;
226 --omit-drivers) push_arg omit_drivers_l "$@" || shift;;
227 -m|--modules) push_arg dracutmodules_l "$@" || shift;;
228 -o|--omit) push_arg omit_dracutmodules_l "$@" || shift;;
229 -d|--drivers) push_arg drivers_l "$@" || shift;;
230 --filesystems) push_arg filesystems_l "$@" || shift;;
231 -I|--install) push_arg install_items_l "$@" || shift;;
232 --fwdir) push_arg fw_dir_l "$@" || shift;;
233 --libdirs) push_arg libdirs_l "$@" || shift;;
234 --fscks) push_arg fscks_l "$@" || shift;;
235 --add-fstab) push_arg add_fstab_l "$@" || shift;;
236 --mount) push_arg fstab_lines "$@" || shift;;
237 --nofscks) nofscks_l="yes";;
238 -k|--kmoddir) read_arg drivers_dir_l "$@" || shift;;
239 -c|--conf) read_arg conffile "$@" || shift;;
240 --confdir) read_arg confdir "$@" || shift;;
241 --tmpdir) read_arg tmpdir_l "$@" || shift;;
242 -L|--stdlog) read_arg stdloglvl_l "$@" || shift;;
243 --compress) read_arg compress_l "$@" || shift;;
244 --prefix) read_arg prefix_l "$@" || shift;;
245 -f|--force) force=yes;;
246 --kernel-only) kernel_only="yes"; no_kernel="no";;
247 --no-kernel) kernel_only="no"; no_kernel="yes";;
248 --strip) do_strip_l="yes";;
249 --nostrip) do_strip_l="no";;
250 --noprefix) prefix_l="/";;
251 --mdadmconf) mdadmconf_l="yes";;
252 --nomdadmconf) mdadmconf_l="no";;
253 --lvmconf) lvmconf_l="yes";;
254 --nolvmconf) lvmconf_l="no";;
255 --debug) debug="yes";;
256 --profile) profile="yes";;
257 --sshkey) read_arg sshkey "$@" || shift;;
258 -v|--verbose) ((verbosity_mod_l++));;
259 -q|--quiet) ((verbosity_mod_l--));;
262 [[ -f "$(readlink -f ${0%/*})/dracut-functions.sh" ]] \
263 && dracutbasedir="$(readlink -f ${0%/*})"
265 -H|--hostonly) hostonly_l="yes" ;;
266 --no-hostonly) hostonly_l="no" ;;
267 --fstab) use_fstab_l="yes" ;;
268 -h|--help) usage; exit 1 ;;
269 -i|--include) push include_src "$2"
270 push include_target "$3"
272 --bzip2) compress_l="bzip2";;
273 --lzma) compress_l="lzma";;
274 --xz) compress_l="xz";;
275 --no-compress) _no_compress_l="cat";;
276 --gzip) compress_l="gzip";;
284 --printsize) printsize="yes";;
285 -*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage; exit 1;;
287 if ! [[ ${outfile+x} ]]; then
289 elif ! [[ ${kernel+x} ]]; then
298 if ! [[ $kernel ]]; then
301 [[ $outfile ]] || outfile="/boot/initramfs-$kernel.img"
303 for i in /usr/sbin /sbin /usr/bin /bin; do
310 export PATH="${NPATH#:}"
312 unset LD_LIBRARY_PATH
316 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
321 export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
326 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
328 # if we were not passed a config file, try the default one
329 if [[ ! -f $conffile ]]; then
330 [[ $allowlocal ]] && conffile="$dracutbasedir/dracut.conf" || \
331 conffile="/etc/dracut.conf"
334 if [[ ! -d $confdir ]]; then
335 [[ $allowlocal ]] && confdir="$dracutbasedir/dracut.conf.d" || \
336 confdir="/etc/dracut.conf.d"
339 # source our config file
340 [[ -f $conffile ]] && . "$conffile"
342 # source our config dir
343 if [[ $confdir && -d $confdir ]]; then
344 for f in "$confdir"/*.conf; do
345 [[ -e $f ]] && . "$f"
349 # these optins add to the stuff in the config file
350 if (( ${#add_dracutmodules_l[@]} )); then
351 while pop add_dracutmodules_l val; do
352 add_dracutmodules+=" $val "
356 if (( ${#force_add_dracutmodules_l[@]} )); then
357 while pop force_add_dracutmodules_l val; do
358 force_add_dracutmodules+=" $val "
362 if (( ${#fscks_l[@]} )); then
363 while pop fscks_l val; do
368 if (( ${#add_fstab_l[@]} )); then
369 while pop add_fstab_l val; do
374 if (( ${#fstab_lines_l[@]} )); then
375 while pop fstab_lines_l val; do
376 push fstab_lines $val
380 if (( ${#install_items_l[@]} )); then
381 while pop install_items_l val; do
382 install_items+=" $val "
386 # these options override the stuff in the config file
387 if (( ${#dracutmodules_l[@]} )); then
389 while pop dracutmodules_l val; do
390 dracutmodules+="$val "
394 if (( ${#omit_dracutmodules_l[@]} )); then
395 omit_dracutmodules=''
396 while pop omit_dracutmodules_l val; do
397 omit_dracutmodules+="$val "
401 if (( ${#filesystems_l[@]} )); then
403 while pop filesystems_l val; do
408 if (( ${#fw_dir_l[@]} )); then
410 while pop fw_dir_l val; do
415 if (( ${#libdirs_l[@]} )); then
417 while pop libdirs_l val; do
422 [[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
423 [[ ! $stdloglvl ]] && stdloglvl=4
424 stdloglvl=$((stdloglvl + verbosity_mod_l))
425 ((stdloglvl > 6)) && stdloglvl=6
426 ((stdloglvl < 0)) && stdloglvl=0
428 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
429 [[ $do_strip_l ]] && do_strip=$do_strip_l
430 [[ $prefix_l ]] && prefix=$prefix_l
431 [[ $prefix = "/" ]] && unset prefix
432 [[ $hostonly_l ]] && hostonly=$hostonly_l
433 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
434 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
435 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
436 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
437 [[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
438 [[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
439 [[ $tmpdir ]] || tmpdir=/var/tmp
440 [[ $do_strip ]] || do_strip=no
441 [[ $compress_l ]] && compress=$compress_l
442 [[ $show_modules_l ]] && show_modules=$show_modules_l
443 [[ $nofscks_l ]] && nofscks="yes"
444 # eliminate IFS hackery when messing with fw_dir
445 fw_dir=${fw_dir//:/ }
447 # handle compression options.
448 [[ $compress ]] || compress="gzip"
450 bzip2) compress="bzip2 -9";;
451 lzma) compress="lzma -9";;
452 xz) compress="xz --check=crc32 --lzma2=dict=1MiB";;
453 gzip) command -v pigz > /dev/null 2>&1 && compress="pigz -9" || \
456 if [[ $_no_compress_l = "cat" ]]; then
460 [[ $hostonly = yes ]] && hostonly="-h"
461 [[ $hostonly != "-h" ]] && unset hostonly
463 if [[ -f $dracutbasedir/dracut-functions.sh ]]; then
464 . $dracutbasedir/dracut-functions.sh
466 echo "Cannot find $dracutbasedir/dracut-functions.sh." >&2
467 echo "Are you running from a git checkout?" >&2
468 echo "Try passing -l as an argument to $0" >&2
472 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
473 . $dracutbasedir/dracut-version.sh
476 # Verify bash version, curret minimum is 3.1
477 if (( ${BASH_VERSINFO[0]} < 3 ||
478 ( ${BASH_VERSINFO[0]} == 3 && ${BASH_VERSINFO[1]} < 1 ) )); then
479 dfatal 'You need at least Bash 3.1 to use dracut, sorry.'
483 dracutfunctions=$dracutbasedir/dracut-functions.sh
484 export dracutfunctions
486 if (( ${#drivers_l[@]} )); then
488 while pop drivers_l val; do
492 drivers=${drivers/-/_}
494 if (( ${#add_drivers_l[@]} )); then
495 while pop add_drivers_l val; do
496 add_drivers+=" $val "
499 add_drivers=${add_drivers/-/_}
501 if (( ${#omit_drivers_l[@]} )); then
502 while pop omit_drivers_l val; do
503 omit_drivers+=" $val "
506 omit_drivers=${omit_drivers/-/_}
508 omit_drivers_corrected=""
509 for d in $omit_drivers; do
510 strstr " $drivers $add_drivers " " $d " && continue
511 omit_drivers_corrected+="$d|"
513 omit_drivers="${omit_drivers_corrected%|}"
514 unset omit_drivers_corrected
517 ddebug "Executing $0 $dracut_args"
519 [[ $do_list = yes ]] && {
520 for mod in $dracutbasedir/modules.d/*; do
521 [[ -d $mod ]] || continue;
522 [[ -e $mod/install || -e $mod/installkernel || \
523 -e $mod/module-setup.sh ]] || continue
530 if ! [[ $libdir ]] || ! [[ $usrlibdir ]] ; then
531 if strstr "$(ldd /bin/sh)" "/lib64/" &>/dev/null \
532 && [[ -d /lib64 ]]; then
539 for i in $libdir $usrlibdir; do
543 dwarn 'No $i directory??!!'
548 # This is kinda legacy -- eventually it should go away.
549 case $dracutmodules in
550 ""|auto) dracutmodules="all" ;;
553 abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
555 srcmods="/lib/modules/$kernel/"
556 [[ $drivers_dir ]] && {
557 if vercmp $(modprobe --version | cut -d' ' -f3) lt 3.7; then
558 dfatal 'To use --kmoddir option module-init-tools >= 3.7 is required.'
561 srcmods="$drivers_dir"
565 if [[ -f $outfile && ! $force ]]; then
566 dfatal "Will not override existing initramfs ($outfile) without --force"
571 [[ $outdir ]] || outdir="/"
573 if [[ ! -d "$outdir" ]]; then
574 dfatal "Can't write $outfile: Directory $outdir does not exist."
576 elif [[ ! -w "$outdir" ]]; then
577 dfatal "No permission to write $outdir."
579 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
580 dfatal "No permission to write $outfile."
584 readonly TMPDIR="$tmpdir"
585 readonly initdir=$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)
586 [ -d "$initdir" ] || {
587 dfatal "mktemp failed."
591 # clean up after ourselves no matter how we die.
592 trap 'ret=$?;[[ $keep ]] && echo "Not removing $initdir." >&2 || rm -rf "$initdir";exit $ret;' EXIT
593 # clean up after ourselves no matter how we die.
594 trap 'exit 1;' SIGINT
596 # Need to be able to have non-root users read stuff (rpcbind etc)
599 for line in "${fstab_lines[@]}"; do
603 push host_fs_types "$1|$3"
606 for f in $add_fstab; do
607 [ -e $f ] || continue
608 while read dev rest; do
613 if [[ $hostonly ]]; then
614 # in hostonly mode, determine all devices, which have to be accessed
615 # and examine them for filesystem types
627 for mp in "${host_mp[@]}"; do
628 mountpoint "$mp" >/dev/null 2>&1 || continue
629 push host_devs $(readlink -f "/dev/block/$(find_block_device "$mp")")
635 if [[ -b $1 ]] && get_fs_env $1; then
636 echo "$(readlink -f $1)|$ID_FS_TYPE"
639 if [[ -b /dev/block/$1 ]] && get_fs_env /dev/block/$1; then
640 echo "$(readlink -f /dev/block/$1)|$ID_FS_TYPE"
643 if fstype=$(find_dev_fstype $1); then
650 for dev in "${host_devs[@]}"; do
652 for fstype in $(_get_fs_type $dev) \
653 $(check_block_and_slaves _get_fs_type $(get_maj_min $dev)); do
654 if ! strstr " ${host_fs_types[*]} " " $fstype ";then
655 push host_fs_types "$fstype"
660 export initdir dracutbasedir dracutmodules drivers \
661 fw_dir drivers_dir debug no_kernel kernel_only \
662 add_drivers omit_drivers mdadmconf lvmconf filesystems \
663 use_fstab fstab_lines libdir usrlibdir fscks nofscks \
664 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
665 debug host_fs_types host_devs sshkey add_fstab \
668 # Create some directory structure first
669 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
671 [[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
672 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
674 if [[ $prefix ]]; then
675 for d in bin etc lib "$libdir" sbin tmp usr var; do
676 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
680 if [[ $kernel_only != yes ]]; then
681 for d in usr/bin usr/sbin bin etc lib "$libdir" sbin tmp usr var var/log var/run var/lock; do
682 [[ -e "${initdir}${prefix}/$d" ]] && continue
683 if [ -L "/$d" ]; then
684 inst_symlink "/$d" "${prefix}/$d"
686 mkdir -m 0755 -p "${initdir}${prefix}/$d"
690 for d in dev proc sys sysroot root run run/lock run/initramfs; do
691 if [ -L "/$d" ]; then
694 mkdir -m 0755 -p "$initdir/$d"
698 ln -sfn /run "$initdir/var/run"
699 ln -sfn /run/lock "$initdir/var/lock"
701 for d in lib "$libdir"; do
702 [[ -e "${initdir}${prefix}/$d" ]] && continue
703 if [ -h "/$d" ]; then
704 inst "/$d" "${prefix}/$d"
706 mkdir -m 0755 -p "${initdir}${prefix}/$d"
711 if [[ $kernel_only != yes ]]; then
712 mkdir -p "${initdir}/etc/cmdline.d"
713 for _d in $hookdirs; do
714 mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d
718 mkdir -p "$initdir/.kernelmodseen"
721 # check all our modules to see if they should be sourced.
722 # This builds a list of modules that we will install next.
723 for_each_module_dir check_module
724 for_each_module_dir check_mount
726 _isize=0 #initramfs size
728 # source our modules.
729 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
730 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
731 if strstr "$mods_to_load" " $_d_mod "; then
732 [[ $show_modules = yes ]] && echo "$_d_mod" || \
733 dinfo "*** Including module: $_d_mod ***"
734 if [[ $kernel_only = yes ]]; then
735 module_installkernel $_d_mod || {
736 dfatal "installkernel failed in module $_d_mod"
740 module_install $_d_mod
741 if [[ $no_kernel != yes ]]; then
742 module_installkernel $_d_mod || {
743 dfatal "installkernel failed in module $_d_mod"
748 mods_to_load=${mods_to_load// $_d_mod /}
749 modules_loaded+="$_d_mod "
751 #print the module install size
752 if [ -n "$printsize" ]; then
753 _isize_new=$(du -sk ${initdir}|cut -f1)
754 _isize_delta=$(($_isize_new - $_isize))
755 echo "$_d_mod install size: ${_isize_delta}k"
762 for i in $modules_loaded; do
763 echo "$i" >> $initdir/lib/dracut/modules.txt
766 dinfo "*** Including modules done ***"
768 ## final stuff that has to happen
770 # generate module dependencies for the initrd
771 if [[ -d $initdir/lib/modules/$kernel ]] && \
772 ! depmod -a -b "$initdir" $kernel; then
773 dfatal "\"depmod -a $kernel\" failed."
777 while pop include_src src && pop include_target tgt; do
778 if [[ $src && $tgt ]]; then
779 if [[ -f $src ]]; then
782 ddebug "Including directory: $src"
783 mkdir -p "${initdir}/${tgt}"
784 # check for preexisting symlinks, so we can cope with the
785 # symlinks to $prefix
786 for i in "$src"/*; do
787 [[ -e "$i" || -h "$i" ]] || continue
788 s=${initdir}/${tgt}/${i#$src/}
789 if [[ -d "$i" ]]; then
790 if ! [[ -e "$s" ]]; then
791 mkdir -m 0755 -p "$s"
792 chmod --reference="$i" "$s"
803 if [[ $kernel_only != yes ]]; then
804 for item in $install_items; do
805 dracut_install "$item"
809 while pop fstab_lines line; do
810 echo "$line 0 0" >> "${initdir}/etc/fstab"
813 for f in $add_fstab; do
814 cat $f >> "${initdir}/etc/fstab"
817 # make sure that library links are correct and up to date
818 for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
819 [[ -f $f ]] && inst_simple "$f"
821 if ! ldconfig -r "$initdir"; then
822 if [[ $UID = 0 ]]; then
823 derror "ldconfig exited ungracefully"
825 derror "ldconfig might need uid=0 (root) for chroot()"
830 rm -fr "$initdir/.kernelmodseen"
833 if (($maxloglvl >= 5)); then
834 ddebug "Listing sizes of included files:"
835 du -c "$initdir" | sort -n | ddebug
839 if [[ $do_strip = yes ]] ; then
840 for p in strip grep find; do
841 if ! type -P $p >/dev/null; then
842 derror "Could not find '$p'. You should run $0 with '--nostrip'."
848 if [[ $do_strip = yes ]] ; then
849 for f in $(find "$initdir" -type f \
850 \( -perm -0100 -or -perm -0010 -or -perm -0001 \
851 -or -path '*/lib/modules/*.ko' \) ); do
853 strip -g "$f" 2>/dev/null|| :
857 type hardlink &>/dev/null && {
858 hardlink "$initdir" 2>&1
861 if strstr "$modules_loaded" " fips " && command -v prelink >/dev/null; then
862 for dir in "$initdir/bin" \
865 "$initdir/usr/sbin"; do
866 [[ -L "$dir" ]] && continue
867 for i in "$dir"/*; do
868 [[ -x $i ]] && prelink -u $i &>/dev/null
873 if ! ( cd "$initdir"; find . |cpio -R 0:0 -H newc -o --quiet| \
874 $compress > "$outfile"; ); then
875 dfatal "dracut: creation of $outfile failed"
879 dinfo "Wrote $outfile:"
880 dinfo "$(ls -l "$outfile")"