dracut.sh: do not strip in FIPS mode
[platform/upstream/dracut.git] / dracut.sh
1 #!/bin/bash
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4 #
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
8 #
9
10 # Copyright 2005-2013 Red Hat, Inc.  All rights reserved.
11 #
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.
16 #
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.
21 #
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/>.
24 #
25
26 # store for logging
27 dracut_args=( "$@" )
28
29 set -o pipefail
30
31 usage() {
32     [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
33     if [[ -f $dracutbasedir/dracut-version.sh ]]; then
34         . $dracutbasedir/dracut-version.sh
35     fi
36
37 #                                                       80x25 linebreak here ^
38     cat << EOF
39 Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
40
41 Version: $DRACUT_VERSION
42
43 Creates initial ramdisk images for preloading modules
44
45   -h, --help  Display all options
46
47 If a [LIST] has multiple arguments, then you have to put these in quotes.
48
49 For example:
50
51     # dracut --add-drivers "module1 module2"  ...
52
53 EOF
54 }
55
56 long_usage() {
57     [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
58     if [[ -f $dracutbasedir/dracut-version.sh ]]; then
59         . $dracutbasedir/dracut-version.sh
60     fi
61
62 #                                                       80x25 linebreak here ^
63     cat << EOF
64 Usage: $0 [OPTION]... [<initramfs> [<kernel-version>]]
65
66 Version: $DRACUT_VERSION
67
68 Creates initial ramdisk images for preloading modules
69
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   --force-add [LIST]    Force to add a space-separated list of dracut modules
78                          to the default set of modules, when -H is specified.
79   -d, --drivers [LIST]  Specify a space-separated list of kernel modules to
80                          exclusively include in the initramfs.
81   --add-drivers [LIST]  Specify a space-separated list of kernel
82                          modules to add to the initramfs.
83   --omit-drivers [LIST] Specify a space-separated list of kernel
84                          modules not to add to the initramfs.
85   --filesystems [LIST]  Specify a space-separated list of kernel filesystem
86                          modules to exclusively include in the generic
87                          initramfs.
88   -k, --kmoddir [DIR]   Specify the directory, where to look for kernel
89                          modules
90   --fwdir [DIR]         Specify additional directories, where to look for
91                          firmwares, separated by :
92   --kernel-only         Only install kernel drivers and firmware files
93   --no-kernel           Do not install kernel drivers and firmware files
94   --early-microcode     Combine early microcode with ramdisk
95   --no-early-microcode  Do not combine early microcode with ramdisk
96   --kernel-cmdline [PARAMETERS] Specify default kernel command line parameters
97   --strip               Strip binaries in the initramfs
98   --nostrip             Do not strip binaries in the initramfs
99   --hardlink            Hardlink files in the initramfs
100   --nohardlink          Do not hardlink files in the initramfs
101   --prefix [DIR]        Prefix initramfs files with [DIR]
102   --noprefix            Do not prefix initramfs files
103   --mdadmconf           Include local /etc/mdadm.conf
104   --nomdadmconf         Do not include local /etc/mdadm.conf
105   --lvmconf             Include local /etc/lvm/lvm.conf
106   --nolvmconf           Do not include local /etc/lvm/lvm.conf
107   --fscks [LIST]        Add a space-separated list of fsck helpers.
108   --nofscks             Inhibit installation of any fsck helpers.
109   --ro-mnt              Mount / and /usr read-only by default.
110   -h, --help            This message
111   --debug               Output debug information of the build process
112   --profile             Output profile information of the build process
113   -L, --stdlog [0-6]    Specify logging level (to standard error)
114                          0 - suppress any messages
115                          1 - only fatal errors
116                          2 - all errors
117                          3 - warnings
118                          4 - info
119                          5 - debug info (here starts lots of output)
120                          6 - trace info (and even more)
121   -v, --verbose         Increase verbosity level
122   -q, --quiet           Decrease verbosity level
123   -c, --conf [FILE]     Specify configuration file to use.
124                          Default: /etc/dracut.conf
125   --confdir [DIR]       Specify configuration directory to use *.conf files
126                          from. Default: /etc/dracut.conf.d
127   --tmpdir [DIR]        Temporary directory to be used instead of default
128                          /var/tmp.
129   -l, --local           Local mode. Use modules from the current working
130                          directory instead of the system-wide installed in
131                          /usr/lib/dracut/modules.d.
132                          Useful when running dracut from a git checkout.
133   -H, --hostonly        Host-Only mode: Install only what is needed for
134                          booting the local host instead of a generic host.
135   -N, --no-hostonly     Disables Host-Only mode
136   --fstab               Use /etc/fstab to determine the root device.
137   --add-fstab [FILE]    Add file to the initramfs fstab
138   --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
139                         Mount device [DEV] on mountpoint [MP] with filesystem
140                         [FSTYPE] and options [FSOPTS] in the initramfs
141   --add-device "[DEV]"  Bring up [DEV] in initramfs
142   -i, --include [SOURCE] [TARGET]
143                         Include the files in the SOURCE directory into the
144                          Target directory in the final initramfs.
145                         If SOURCE is a file, it will be installed to TARGET
146                          in the final initramfs.
147   -I, --install [LIST]  Install the space separated list of files into the
148                          initramfs.
149   --gzip                Compress the generated initramfs using gzip.
150                          This will be done by default, unless another
151                          compression option or --no-compress is passed.
152   --bzip2               Compress the generated initramfs using bzip2.
153                          Make sure your kernel has bzip2 decompression support
154                          compiled in, otherwise you will not be able to boot.
155   --lzma                Compress the generated initramfs using lzma.
156                          Make sure your kernel has lzma support compiled in,
157                          otherwise you will not be able to boot.
158   --xz                  Compress the generated initramfs using xz.
159                          Make sure that your kernel has xz support compiled
160                          in, otherwise you will not be able to boot.
161   --compress [COMPRESSION] Compress the generated initramfs with the
162                          passed compression program.  Make sure your kernel
163                          knows how to decompress the generated initramfs,
164                          otherwise you will not be able to boot.
165   --no-compress         Do not compress the generated initramfs.  This will
166                          override any other compression options.
167   --list-modules        List all available dracut modules.
168   -M, --show-modules    Print included module's name to standard output during
169                          build.
170   --keep                Keep the temporary initramfs for debugging purposes
171   --printsize           Print out the module install size
172   --sshkey [SSHKEY]     Add ssh key to initramfs (use with ssh-client module)
173
174 If [LIST] has multiple arguments, then you have to put these in quotes.
175
176 For example:
177
178     # dracut --add-drivers "module1 module2"  ...
179
180 EOF
181 }
182
183 # function push()
184 # push values to a stack
185 # $1 = stack variable
186 # $2.. values
187 # example:
188 # push stack 1 2 "3 4"
189 push() {
190     local _i
191     local __stack=$1; shift
192     for _i in "$@"; do
193         eval ${__stack}'[${#'${__stack}'[@]}]="$_i"'
194     done
195 }
196
197 # function pop()
198 # pops the last value from a stack
199 # assigns value to second argument variable
200 # or echo to stdout, if no second argument
201 # $1 = stack variable
202 # $2 = optional variable to store the value
203 # example:
204 # pop stack val
205 # val=$(pop stack)
206 pop() {
207     local __stack=$1; shift
208     local __resultvar=$1
209     local _value;
210     # check for empty stack
211     eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
212
213     eval _value='${'${__stack}'[${#'${__stack}'[@]}-1]}'
214
215     if [[ "$__resultvar" ]]; then
216         eval $__resultvar="'$_value'"
217     else
218         printf "%s" "$_value"
219     fi
220     eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
221     return 0
222 }
223
224 # Little helper function for reading args from the commandline.
225 # it automatically handles -a b and -a=b variants, and returns 1 if
226 # we need to shift $3.
227 read_arg() {
228     # $1 = arg name
229     # $2 = arg value
230     # $3 = arg parameter
231     local rematch='^[^=]*=(.*)$'
232     if [[ $2 =~ $rematch ]]; then
233         read "$1" <<< "${BASH_REMATCH[1]}"
234     else
235         read "$1" <<< "$3"
236         # There is no way to shift our callers args, so
237         # return 1 to indicate they should do it instead.
238         return 1
239     fi
240 }
241
242 dropindirs_sort()
243 {
244     local suffix=$1; shift
245     local -a files
246     local f d
247
248     for d in "$@"; do
249         for i in "$d/"*"$suffix"; do
250             if [[ -e "$i" ]]; then
251                 printf "%s\n" "${i##*/}"
252             fi
253         done
254     done | sort -Vu | {
255         readarray -t files
256
257         for f in "${files[@]}"; do
258             for d in "$@"; do
259                 if [[ -e "$d/$f" ]]; then
260                     printf "%s\n" "$d/$f"
261                     continue 2
262                 fi
263             done
264         done
265     }
266 }
267
268 verbosity_mod_l=0
269 unset kernel
270 unset outfile
271
272 # Workaround -i, --include taking 2 arguments
273 set -- "${@/--include/++include}"
274
275 # This prevents any long argument ending with "-i"
276 # -i, like --opt-i but I think we can just prevent that
277 set -- "${@/%-i/++include}"
278
279 TEMP=$(unset POSIXLY_CORRECT; getopt \
280     -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
281     --long kver: \
282     --long add: \
283     --long force-add: \
284     --long add-drivers: \
285     --long omit-drivers: \
286     --long modules: \
287     --long omit: \
288     --long drivers: \
289     --long filesystems: \
290     --long install: \
291     --long fwdir: \
292     --long libdirs: \
293     --long fscks: \
294     --long add-fstab: \
295     --long mount: \
296     --long device: \
297     --long nofscks: \
298     --long ro-mnt \
299     --long kmoddir: \
300     --long conf: \
301     --long confdir: \
302     --long tmpdir: \
303     --long stdlog: \
304     --long compress: \
305     --long prefix: \
306     --long force \
307     --long kernel-only \
308     --long no-kernel \
309     --long kernel-cmdline: \
310     --long strip \
311     --long nostrip \
312     --long hardlink \
313     --long nohardlink \
314     --long noprefix \
315     --long mdadmconf \
316     --long nomdadmconf \
317     --long lvmconf \
318     --long nolvmconf \
319     --long debug \
320     --long profile \
321     --long sshkey: \
322     --long verbose \
323     --long quiet \
324     --long local \
325     --long hostonly \
326     --long host-only \
327     --long no-hostonly \
328     --long no-host-only \
329     --long fstab \
330     --long help \
331     --long bzip2 \
332     --long lzma \
333     --long xz \
334     --long no-compress \
335     --long gzip \
336     --long list-modules \
337     --long show-modules \
338     --long keep \
339     --long printsize \
340     --long regenerate-all \
341     --long noimageifnotneeded \
342     -- "$@")
343
344 if (( $? != 0 )); then
345     usage
346     exit 1
347 fi
348
349 eval set -- "$TEMP"
350
351 while :; do
352     case $1 in
353         --kver)        kernel="$2"; shift;;
354         -a|--add)      push add_dracutmodules_l  "$2"; shift;;
355         --force-add)   push force_add_dracutmodules_l  "$2"; shift;;
356         --add-drivers) push add_drivers_l        "$2"; shift;;
357         --omit-drivers) push omit_drivers_l      "$2"; shift;;
358         -m|--modules)  push dracutmodules_l      "$2"; shift;;
359         -o|--omit)     push omit_dracutmodules_l "$2"; shift;;
360         -d|--drivers)  push drivers_l            "$2"; shift;;
361         --filesystems) push filesystems_l        "$2"; shift;;
362         -I|--install)  push install_items_l      "$2"; shift;;
363         --fwdir)       push fw_dir_l             "$2"; shift;;
364         --libdirs)     push libdirs_l            "$2"; shift;;
365         --fscks)       push fscks_l              "$2"; shift;;
366         --add-fstab)   push add_fstab_l          "$2"; shift;;
367         --mount)       push fstab_lines          "$2"; shift;;
368         --add-device|--device)
369                        push add_device_l         "$2"; shift;;
370         --kernel-cmdline) push kernel_cmdline_l  "$2"; shift;;
371         --nofscks)     nofscks_l="yes";;
372         --ro-mnt)      ro_mnt_l="yes";;
373         -k|--kmoddir)  drivers_dir_l="$2"; shift;;
374         -c|--conf)     conffile="$2"; shift;;
375         --confdir)     confdir="$2"; shift;;
376         --tmpdir)      tmpdir_l="$2"; shift;;
377         -L|--stdlog)   stdloglvl_l="$2"; shift;;
378         --compress)    compress_l="$2"; shift;;
379         --prefix)      prefix_l="$2"; shift;;
380         -f|--force)    force=yes;;
381         --kernel-only) kernel_only="yes"; no_kernel="no";;
382         --no-kernel)   kernel_only="no"; no_kernel="yes";;
383         --early-microcode) early_microcode="yes";;
384         --no-early-microcode) early_microcode="no";;
385         --strip)       do_strip_l="yes";;
386         --nostrip)     do_strip_l="no";;
387         --hardlink)    do_hardlink_l="yes";;
388         --nohardlink)  do_hardlink_l="no";;
389         --noprefix)    prefix_l="/";;
390         --mdadmconf)   mdadmconf_l="yes";;
391         --nomdadmconf) mdadmconf_l="no";;
392         --lvmconf)     lvmconf_l="yes";;
393         --nolvmconf)   lvmconf_l="no";;
394         --debug)       debug="yes";;
395         --profile)     profile="yes";;
396         --sshkey)      sshkey="$2"; shift;;
397         -v|--verbose)  ((verbosity_mod_l++));;
398         -q|--quiet)    ((verbosity_mod_l--));;
399         -l|--local)
400                        allowlocal="yes"
401                        [[ -f "$(readlink -f "${0%/*}")/dracut-functions.sh" ]] \
402                            && dracutbasedir="$(readlink -f "${0%/*}")"
403                        ;;
404         -H|--hostonly|--host-only)
405                        hostonly_l="yes" ;;
406         -N|--no-hostonly|--no-host-only)
407                        hostonly_l="no" ;;
408         --fstab)       use_fstab_l="yes" ;;
409         -h|--help)     long_usage; exit 1 ;;
410         -i|--include)  push include_src "$2"
411                        shift;;
412         --bzip2)       compress_l="bzip2";;
413         --lzma)        compress_l="lzma";;
414         --xz)          compress_l="xz";;
415         --no-compress) _no_compress_l="cat";;
416         --gzip)        compress_l="gzip";;
417         --list-modules) do_list="yes";;
418         -M|--show-modules)
419                        show_modules_l="yes"
420                        ;;
421         --keep)        keep="yes";;
422         --printsize)   printsize="yes";;
423         --regenerate-all) regenerate_all="yes";;
424         --noimageifnotneeded) noimageifnotneeded="yes";;
425
426         --) shift; break;;
427
428         *)  # should not even reach this point
429             printf "\n!Unknown option: '%s'\n\n" "$1" >&2; usage; exit 1;;
430     esac
431     shift
432 done
433
434 # getopt cannot handle multiple arguments, so just handle "-I,--include"
435 # the old fashioned way
436
437 while (($# > 0)); do
438     case ${1%%=*} in
439         ++include) push include_src "$2"
440                        push include_target "$3"
441                        shift 2;;
442         *)
443             if ! [[ ${outfile+x} ]]; then
444                 outfile=$1
445             elif ! [[ ${kernel+x} ]]; then
446                 kernel=$1
447             else
448                 printf "\nUnknown arguments: %s\n\n" "$*" >&2
449                 usage; exit 1;
450             fi
451             ;;
452     esac
453     shift
454 done
455
456 if [[ $regenerate_all == "yes" ]]; then
457     ret=0
458     if [[ $kernel ]]; then
459         printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
460         exit 1
461     fi
462
463     if [[ $outfile ]]; then
464         printf -- "--regenerate-all cannot be called with a image file\n" >&2
465         exit 1
466     fi
467
468     ((len=${#dracut_args[@]}))
469     for ((i=0; i < len; i++)); do
470         [[ ${dracut_args[$i]} == "--regenerate-all" ]] && \
471             unset dracut_args[$i]
472     done
473
474     cd /lib/modules
475     for i in *; do
476         [[ -f $i/modules.builtin ]] || continue
477         dracut --kver="$i" "${dracut_args[@]}"
478         ((ret+=$?))
479     done
480     exit $ret
481 fi
482
483 if ! [[ $kernel ]]; then
484     kernel=$(uname -r)
485 fi
486
487 if ! [[ $outfile ]]; then
488     [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
489
490     if [[ $MACHINE_ID ]] && ( [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]] ); then
491         outfile="/boot/${MACHINE_ID}/$kernel/initrd"
492     else
493         outfile="/boot/initramfs-$kernel.img"
494     fi
495 fi
496
497 for i in /usr/sbin /sbin /usr/bin /bin; do
498     rl=$i
499     if [ -L "$i" ]; then
500         rl=$(readlink -f $i)
501     fi
502     if [[ "$NPATH" != "*:$rl*" ]] ; then
503         NPATH+=":$rl"
504     fi
505 done
506 export PATH="${NPATH#:}"
507 unset LC_MESSAGES
508 unset LC_CTYPE
509 export LC_ALL=C
510 export LANG=C
511 unset NPATH
512 unset LD_LIBRARY_PATH
513 unset GREP_OPTIONS
514
515 export DRACUT_LOG_LEVEL=warning
516 [[ $debug ]] && {
517     export DRACUT_LOG_LEVEL=debug
518     export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
519     set -x
520 }
521
522 [[ $profile ]] && {
523     export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
524     set -x
525     debug=yes
526 }
527
528 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
529
530 # if we were not passed a config file, try the default one
531 if [[ ! -f $conffile ]]; then
532     if [[ $allowlocal ]]; then
533         conffile="$dracutbasedir/dracut.conf"
534     else
535         conffile="/etc/dracut.conf"
536     fi
537 fi
538
539 if [[ ! -d $confdir ]]; then
540     if [[ $allowlocal ]]; then
541         confdir="$dracutbasedir/dracut.conf.d"
542     else
543         confdir="/etc/dracut.conf.d"
544     fi
545 fi
546
547 # source our config file
548 [[ -f $conffile ]] && . "$conffile"
549
550 # source our config dir
551 for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); do
552     [[ -e $f ]] && . "$f"
553 done
554
555 # these optins add to the stuff in the config file
556 if (( ${#add_dracutmodules_l[@]} )); then
557     while pop add_dracutmodules_l val; do
558         add_dracutmodules+=" $val "
559     done
560 fi
561
562 if (( ${#force_add_dracutmodules_l[@]} )); then
563     while pop force_add_dracutmodules_l val; do
564         force_add_dracutmodules+=" $val "
565     done
566 fi
567
568 if (( ${#fscks_l[@]} )); then
569     while pop fscks_l val; do
570         fscks+=" $val "
571     done
572 fi
573
574 if (( ${#add_fstab_l[@]} )); then
575     while pop add_fstab_l val; do
576         add_fstab+=" $val "
577     done
578 fi
579
580 if (( ${#fstab_lines_l[@]} )); then
581     while pop fstab_lines_l val; do
582         push fstab_lines $val
583     done
584 fi
585
586 if (( ${#install_items_l[@]} )); then
587     while pop install_items_l val; do
588         install_items+=" $val "
589     done
590 fi
591
592 # these options override the stuff in the config file
593 if (( ${#dracutmodules_l[@]} )); then
594     dracutmodules=''
595     while pop dracutmodules_l val; do
596         dracutmodules+="$val "
597     done
598 fi
599
600 if (( ${#omit_dracutmodules_l[@]} )); then
601     omit_dracutmodules=''
602     while pop omit_dracutmodules_l val; do
603         omit_dracutmodules+="$val "
604     done
605 fi
606
607 if (( ${#filesystems_l[@]} )); then
608     filesystems=''
609     while pop filesystems_l val; do
610         filesystems+="$val "
611     done
612 fi
613
614 if (( ${#fw_dir_l[@]} )); then
615     fw_dir=''
616     while pop fw_dir_l val; do
617         fw_dir+="$val "
618     done
619 fi
620
621 if (( ${#libdirs_l[@]} )); then
622     libdirs=''
623     while pop libdirs_l val; do
624         libdirs+="$val "
625     done
626 fi
627
628 [[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
629 [[ ! $stdloglvl ]] && stdloglvl=4
630 stdloglvl=$((stdloglvl + verbosity_mod_l))
631 ((stdloglvl > 6)) && stdloglvl=6
632 ((stdloglvl < 0)) && stdloglvl=0
633
634 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
635 [[ $do_strip_l ]] && do_strip=$do_strip_l
636 [[ $do_strip ]] || do_strip=yes
637 [[ $do_hardlink_l ]] && do_hardlink=$do_hardlink_l
638 [[ $do_hardlink ]] || do_hardlink=yes
639 [[ $prefix_l ]] && prefix=$prefix_l
640 [[ $prefix = "/" ]] && unset prefix
641 [[ $hostonly_l ]] && hostonly=$hostonly_l
642 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
643 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
644 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
645 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
646 [[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
647 [[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
648 [[ $tmpdir ]] || tmpdir=/var/tmp
649 [[ $compress_l ]] && compress=$compress_l
650 [[ $show_modules_l ]] && show_modules=$show_modules_l
651 [[ $nofscks_l ]] && nofscks="yes"
652 [[ $ro_mnt_l ]] && ro_mnt="yes"
653 # eliminate IFS hackery when messing with fw_dir
654 fw_dir=${fw_dir//:/ }
655
656 # handle compression options.
657 [[ $compress ]] || compress="gzip"
658 case $compress in
659     bzip2) compress="bzip2 -9";;
660     lzma)  compress="lzma -9";;
661     xz)    compress="xz --check=crc32 --lzma2=dict=1MiB";;
662     gzip)  compress="gzip -9"; command -v pigz > /dev/null 2>&1 && compress="pigz -9";;
663 esac
664 if [[ $_no_compress_l = "cat" ]]; then
665     compress="cat"
666 fi
667
668 [[ $hostonly = yes ]] && hostonly="-h"
669 [[ $hostonly != "-h" ]] && unset hostonly
670
671 readonly TMPDIR="$tmpdir"
672 readonly initdir="$(mktemp --tmpdir="$TMPDIR/" -d -t initramfs.XXXXXX)"
673 [ -d "$initdir" ] || {
674     printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t initramfs.XXXXXX failed." >&2
675     exit 1
676 }
677
678 if [[ $early_microcode = yes ]]; then
679     readonly microcode_dir="$(mktemp --tmpdir="$TMPDIR/" -d -t early_microcode.XXXXXX)"
680     [ -d "$microcode_dir" ] || {
681         printf "%s\n" "dracut: mktemp --tmpdir=\"$TMPDIR/\" -d -t early_microcode.XXXXXX failed." >&2
682         exit 1
683     }
684 fi
685 # clean up after ourselves no matter how we die.
686 trap '
687     ret=$?;
688     [[ $outfile ]] && [[ -f $outfile.$$ ]] && rm -f -- "$outfile.$$";
689     [[ $keep ]] && echo "Not removing $initdir." >&2 || { [[ $initdir ]] && rm -rf -- "$initdir"; };
690     [[ $keep ]] && echo "Not removing $microcode_dir." >&2 || { [[ $microcode_dir ]] && rm -Rf -- "$microcode_dir"; };
691     [[ $_dlogdir ]] && rm -Rf -- "$_dlogdir";
692     exit $ret;
693     ' EXIT
694
695 # clean up after ourselves no matter how we die.
696 trap 'exit 1;' SIGINT
697
698 export DRACUT_KERNEL_LAZY="1"
699 export DRACUT_RESOLVE_LAZY="1"
700
701 if [[ -f $dracutbasedir/dracut-functions.sh ]]; then
702     . $dracutbasedir/dracut-functions.sh
703 else
704     printf "%s\n" "dracut: Cannot find $dracutbasedir/dracut-functions.sh." >&2
705     printf "%s\n" "dracut: Are you running from a git checkout?" >&2
706     printf "%s\n" "dracut: Try passing -l as an argument to $0" >&2
707     exit 1
708 fi
709
710 inst /bin/sh
711 if ! $DRACUT_INSTALL ${initdir+-D "$initdir"} -R "$initdir/bin/sh" &>/dev/null; then
712     unset DRACUT_RESOLVE_LAZY
713     export DRACUT_RESOLVE_DEPS=1
714 fi
715 rm -fr -- ${initdir}/*
716
717 if [[ -f $dracutbasedir/dracut-version.sh ]]; then
718     . $dracutbasedir/dracut-version.sh
719 fi
720
721 # Verify bash version, current minimum is 3.1
722 if (( BASH_VERSINFO[0] < 4 )); then
723     dfatal 'You need at least Bash 4 to use dracut, sorry.'
724     exit 1
725 fi
726
727 dracutfunctions=$dracutbasedir/dracut-functions.sh
728 export dracutfunctions
729
730 if (( ${#drivers_l[@]} )); then
731     drivers=''
732     while pop drivers_l val; do
733         drivers+="$val "
734     done
735 fi
736 drivers=${drivers/-/_}
737
738 if (( ${#add_drivers_l[@]} )); then
739     while pop add_drivers_l val; do
740         add_drivers+=" $val "
741     done
742 fi
743 add_drivers=${add_drivers/-/_}
744
745 if (( ${#omit_drivers_l[@]} )); then
746     while pop omit_drivers_l val; do
747         omit_drivers+=" $val "
748     done
749 fi
750 omit_drivers=${omit_drivers/-/_}
751
752 if (( ${#kernel_cmdline_l[@]} )); then
753     while pop kernel_cmdline_l val; do
754         kernel_cmdline+=" $val "
755     done
756 fi
757
758 omit_drivers_corrected=""
759 for d in $omit_drivers; do
760     [[ " $drivers $add_drivers " == *\ $d\ * ]] && continue
761     omit_drivers_corrected+="$d|"
762 done
763 omit_drivers="${omit_drivers_corrected%|}"
764 unset omit_drivers_corrected
765
766 # prepare args for logging
767 for ((i=0; i < ${#dracut_args[@]}; i++)); do
768     [[ "${dracut_args[$i]}" == *\ * ]] && \
769         dracut_args[$i]="\"${dracut_args[$i]}\""
770         #" keep vim happy
771 done
772 dinfo "Executing: $0 ${dracut_args[@]}"
773
774 [[ $do_list = yes ]] && {
775     for mod in $dracutbasedir/modules.d/*; do
776         [[ -d $mod ]] || continue;
777         [[ -e $mod/install || -e $mod/installkernel || \
778             -e $mod/module-setup.sh ]] || continue
779         printf "%s\n" "${mod##*/??}"
780     done
781     exit 0
782 }
783
784 # This is kinda legacy -- eventually it should go away.
785 case $dracutmodules in
786     ""|auto) dracutmodules="all" ;;
787 esac
788
789 abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
790
791 if [[ -d $srcmods ]]; then
792     [[ -f $srcmods/modules.dep ]] || {
793       dwarn "$srcmods/modules.dep is missing. Did you run depmod?"
794     }
795 fi
796
797 if [[ -f $outfile && ! $force ]]; then
798     dfatal "Will not override existing initramfs ($outfile) without --force"
799     exit 1
800 fi
801
802 outdir=${outfile%/*}
803 [[ $outdir ]] || outdir="/"
804
805 if [[ ! -d "$outdir" ]]; then
806     dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible."
807     exit 1
808 elif [[ ! -w "$outdir" ]]; then
809     dfatal "No permission to write to $outdir."
810     exit 1
811 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
812     dfatal "No permission to write $outfile."
813     exit 1
814 fi
815
816 # Need to be able to have non-root users read stuff (rpcbind etc)
817 chmod 755 "$initdir"
818
819 if [[ $hostonly ]]; then
820     for i in /sys /proc /run /dev; do
821         if ! findmnt --target "$i" &>/dev/null; then
822             dwarning "Turning off host-only mode: '$i' is not mounted!"
823             unset hostonly
824         fi
825     done
826     if ! [[ -d /run/udev/data ]]; then
827         dwarning "Turning off host-only mode: udev database not found!"
828         unset hostonly
829     fi
830 fi
831
832 declare -A host_fs_types
833
834 for line in "${fstab_lines[@]}"; do
835     set -- $line
836     #dev mp fs fsopts
837     push host_devs "$1"
838     host_fs_types["$1"]="$3"
839 done
840
841 for f in $add_fstab; do
842     [[ -e $f ]] || continue
843     while read dev rest; do
844         push host_devs "$dev"
845     done < "$f"
846 done
847
848 for dev in $add_device; do
849     push host_devs "$dev"
850 done
851
852 if (( ${#add_device_l[@]} )); then
853     while pop add_device_l val; do
854         add_device+=" $val "
855         push host_devs "$val"
856     done
857 fi
858
859 if [[ $hostonly ]]; then
860     # in hostonly mode, determine all devices, which have to be accessed
861     # and examine them for filesystem types
862
863     for mp in \
864         "/" \
865         "/etc" \
866         "/bin" \
867         "/sbin" \
868         "/lib" \
869         "/lib64" \
870         "/boot";
871     do
872         mp=$(readlink -f "$mp")
873         mountpoint "$mp" >/dev/null 2>&1 || continue
874         _dev=$(find_block_device "$mp")
875         _bdev=$(readlink -f "/dev/block/$dev")
876         [[ -b $_bdev ]] && _dev=$_bdev
877         push host_devs $_dev
878         [[ "$_mp" == "/" ]] && root_dev="$_dev"
879         push host_devs "$_dev"
880     done
881
882     if [[ -f /proc/swaps ]] && [[ -f /etc/fstab ]]; then
883         while read dev type rest; do
884             [[ -b $dev ]] || continue
885             [[ "$type" == "partition" ]] || continue
886
887             while read _d _m _t _o _r; do
888                 [[ "$_d" == \#* ]] && continue
889                 [[ $_d ]] || continue
890                 [[ $_t != "swap" ]] || [[ $_m != "swap" ]] && continue
891                 [[ "$_o" == *noauto* ]] && continue
892                 [[ "$_d" == UUID\=* ]] && _d="/dev/disk/by-uuid/${_d#UUID=}"
893                 [[ "$_d" == LABEL\=* ]] && _d="/dev/disk/by-label/$_d#LABEL=}"
894                 [[ "$_d" -ef "$dev" ]] || continue
895
896                 if [[ -f /etc/crypttab ]]; then
897                     while read _mapper _a _p _o; do
898                         [[ $_mapper = \#* ]] && continue
899                         [[ "$_d" -ef /dev/mapper/"$_mapper" ]] || continue
900                         [[ "$_o" ]] || _o="$_p"
901                 # skip mkswap swap
902                         [[ $_o == *swap* ]] && continue 2
903                     done < /etc/crypttab
904                 fi
905
906                 push host_devs "$(readlink -f "$dev")"
907                 break
908             done < /etc/fstab
909         done < /proc/swaps
910     fi
911 fi
912
913 _get_fs_type() {
914     [[ $1 ]] || return
915     if [[ -b /dev/block/$1 ]] && ID_FS_TYPE=$(get_fs_env "/dev/block/$1"); then
916         host_fs_types["$(readlink -f "/dev/block/$1")"]="$ID_FS_TYPE"
917         return 1
918     fi
919     if [[ -b $1 ]] && ID_FS_TYPE=$(get_fs_env "$1"); then
920         host_fs_types["$(readlink -f "$1")"]="$ID_FS_TYPE"
921         return 1
922     fi
923     if fstype=$(find_dev_fstype "$1"); then
924         host_fs_types["$1"]="$fstype"
925         return 1
926     fi
927     return 1
928 }
929
930 for dev in ${host_devs[@]}; do
931     _get_fs_type "$dev"
932     check_block_and_slaves_all _get_fs_type "$(get_maj_min "$dev")"
933 done
934
935 [[ -d $udevdir ]] \
936     || udevdir="$(pkg-config udev --variable=udevdir 2>/dev/null)"
937 if ! [[ -d "$udevdir" ]]; then
938     [[ -d /lib/udev ]] && udevdir=/lib/udev
939     [[ -d /usr/lib/udev ]] && udevdir=/usr/lib/udev
940 fi
941
942 [[ -d $systemdutildir ]] \
943     || systemdutildir=$(pkg-config systemd --variable=systemdutildir 2>/dev/null)
944
945 if ! [[ -d "$systemdutildir" ]]; then
946     [[ -d /lib/systemd ]] && systemdutildir=/lib/systemd
947     [[ -d /usr/lib/systemd ]] && systemdutildir=/usr/lib/systemd
948 fi
949
950 [[ -d $systemdsystemunitdir ]] \
951     || systemdsystemunitdir=$(pkg-config systemd --variable=systemdsystemunitdir 2>/dev/null)
952
953 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir=${systemdutildir}/system
954
955 [[ -d $systemdsystemconfdir ]] \
956     || systemdsystemconfdir=$(pkg-config systemd --variable=systemdsystemconfdir 2>/dev/null)
957
958 [[ -d "$systemdsystemconfdir" ]] || systemdsystemconfdir=/etc/systemd/system
959
960 export initdir dracutbasedir dracutmodules \
961     fw_dir drivers_dir debug no_kernel kernel_only \
962     omit_drivers mdadmconf lvmconf root_dev \
963     use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
964     stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
965     debug host_fs_types host_devs sshkey add_fstab \
966     DRACUT_VERSION udevdir prefix filesystems drivers \
967     systemdutildir systemdsystemunitdir systemdsystemconfdir
968
969 # Create some directory structure first
970 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
971
972 [[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
973 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
974
975 if [[ $prefix ]]; then
976     for d in bin etc lib sbin tmp usr var $libdirs; do
977         [[ "$d" == */* ]] && continue
978         ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
979     done
980 fi
981
982 if [[ $kernel_only != yes ]]; then
983     for d in usr/bin usr/sbin bin etc lib sbin tmp usr var $libdirs; do
984         [[ -e "${initdir}${prefix}/$d" ]] && continue
985         if [ -L "/$d" ]; then
986             inst_symlink "/$d" "${prefix}/$d"
987         else
988             mkdir -m 0755 -p "${initdir}${prefix}/$d"
989         fi
990     done
991
992     for d in dev proc sys sysroot root run run/lock run/initramfs; do
993         if [ -L "/$d" ]; then
994             inst_symlink "/$d"
995         else
996             mkdir -m 0755 -p "$initdir/$d"
997         fi
998     done
999
1000     ln -sfn ../run "$initdir/var/run"
1001     ln -sfn ../run/lock "$initdir/var/lock"
1002     ln -sfn ../run/log "$initdir/var/log"
1003 else
1004     for d in lib "$libdir"; do
1005         [[ -e "${initdir}${prefix}/$d" ]] && continue
1006         if [ -h "/$d" ]; then
1007             inst "/$d" "${prefix}/$d"
1008         else
1009             mkdir -m 0755 -p "${initdir}${prefix}/$d"
1010         fi
1011     done
1012 fi
1013
1014 if [[ $kernel_only != yes ]]; then
1015     mkdir -p "${initdir}/etc/cmdline.d"
1016     for _d in $hookdirs; do
1017         mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d
1018     done
1019     if [[ "$UID" = "0" ]]; then
1020         [ -c ${initdir}/dev/null ] || mknod ${initdir}/dev/null c 1 3
1021         [ -c ${initdir}/dev/kmsg ] || mknod ${initdir}/dev/kmsg c 1 11
1022         [ -c ${initdir}/dev/console ] || mknod ${initdir}/dev/console c 5 1
1023     fi
1024 fi
1025
1026 mods_to_load=""
1027 # check all our modules to see if they should be sourced.
1028 # This builds a list of modules that we will install next.
1029 for_each_module_dir check_module
1030 for_each_module_dir check_mount
1031
1032 [[ "$mods_to_load " == *01fips\ * ]] && export DRACUT_FIPS_MODE=1
1033
1034 _isize=0 #initramfs size
1035 modules_loaded=" "
1036 # source our modules.
1037 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
1038     _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
1039     if [[ "$mods_to_load" == *\ $_d_mod\ * ]]; then
1040         if [[ $show_modules = yes ]]; then
1041             printf "%s\n" "$_d_mod"
1042         else
1043             dinfo "*** Including module: $_d_mod ***"
1044         fi
1045         if [[ $kernel_only == yes ]]; then
1046             module_installkernel "$_d_mod" || {
1047                 dfatal "installkernel failed in module $_d_mod"
1048                 exit 1
1049             }
1050         else
1051             module_install "$_d_mod"
1052             if [[ $no_kernel != yes ]]; then
1053                 module_installkernel "$_d_mod" || {
1054                     dfatal "installkernel failed in module $_d_mod"
1055                     exit 1
1056                 }
1057             fi
1058         fi
1059         mods_to_load=${mods_to_load// $_d_mod /}
1060         modules_loaded+="$_d_mod "
1061
1062         #print the module install size
1063         if [ -n "$printsize" ]; then
1064             _isize_new=$(du -sk ${initdir}|cut -f1)
1065             _isize_delta=$((_isize_new - _isize))
1066             printf "%s\n" "$_d_mod install size: ${_isize_delta}k"
1067             _isize=$_isize_new
1068         fi
1069     fi
1070 done
1071 unset moddir
1072
1073 for i in $modules_loaded; do
1074     mkdir -p $initdir/lib/dracut
1075     printf "%s\n" "$i" >> $initdir/lib/dracut/modules.txt
1076 done
1077
1078 dinfo "*** Including modules done ***"
1079
1080 ## final stuff that has to happen
1081 if [[ $no_kernel != yes ]]; then
1082
1083     if [[ $drivers ]]; then
1084         hostonly='' instmods $drivers
1085     fi
1086
1087     if [[ $add_drivers ]]; then
1088         hostonly='' instmods -c $add_drivers
1089     fi
1090     if [[ $filesystems ]]; then
1091         hostonly='' instmods -c $filesystems
1092     fi
1093
1094     dinfo "*** Installing kernel module dependencies and firmware ***"
1095     dracut_kernel_post
1096     dinfo "*** Installing kernel module dependencies and firmware done ***"
1097
1098     if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
1099         if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
1100             [[ -f ${initdir}/lib/modules/$kernel/modules.dep && ! -s ${initdir}/lib/modules/$kernel/modules.dep ]]; then
1101             for i in ${initdir}/etc/cmdline.d/*.conf; do
1102                 # We need no initramfs image and do not generate one.
1103                 [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
1104             done
1105         fi
1106     fi
1107 fi
1108
1109 if [[ $kernel_only != yes ]]; then
1110     (( ${#install_items[@]} > 0 )) && inst_multiple ${install_items[@]}
1111
1112     [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
1113
1114     while pop fstab_lines line; do
1115         printf "%s\n" "$line 0 0" >> "${initdir}/etc/fstab"
1116     done
1117
1118     for f in $add_fstab; do
1119         cat "$f" >> "${initdir}/etc/fstab"
1120     done
1121
1122     if [ -d ${initdir}/$systemdutildir ]; then
1123         mkdir -p ${initdir}/etc/conf.d
1124         {
1125             printf "%s\n" "systemdutildir=\"$systemdutildir\""
1126             printf "%s\n" "systemdsystemunitdir=\"$systemdsystemunitdir\""
1127             printf "%s\n" "systemdsystemconfdir=\"$systemdsystemconfdir\""
1128         } > ${initdir}/etc/conf.d/systemd.conf
1129     fi
1130
1131     if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
1132         dinfo "*** Resolving executable dependencies ***"
1133         find "$initdir" -type f \
1134             '(' -perm -0100 -or -perm -0010 -or -perm -0001 ')' \
1135             -not -path '*.ko' -print0 \
1136         | xargs -r -0 $DRACUT_INSTALL ${initdir+-D "$initdir"} -R ${DRACUT_FIPS_MODE+-H} --
1137         dinfo "*** Resolving executable dependencies done***"
1138     fi
1139 fi
1140
1141 while pop include_src src && pop include_target tgt; do
1142     if [[ $src && $tgt ]]; then
1143         if [[ -f $src ]]; then
1144             inst $src $tgt
1145         else
1146             ddebug "Including directory: $src"
1147             mkdir -p "${initdir}/${tgt}"
1148             # check for preexisting symlinks, so we can cope with the
1149             # symlinks to $prefix
1150             for i in "$src"/*; do
1151                 [[ -e "$i" || -h "$i" ]] || continue
1152                 s=${initdir}/${tgt}/${i#$src/}
1153                 if [[ -d "$i" ]]; then
1154                     if ! [[ -e "$s" ]]; then
1155                         mkdir -m 0755 -p "$s"
1156                         chmod --reference="$i" "$s"
1157                     fi
1158                     cp --reflink=auto --sparse=auto -fa -t "$s" "$i"/*
1159                 else
1160                     cp --reflink=auto --sparse=auto -fa -t "$s" "$i"
1161                 fi
1162             done
1163         fi
1164     fi
1165 done
1166
1167 if [[ $kernel_only != yes ]]; then
1168     # make sure that library links are correct and up to date
1169     for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
1170         [[ -f $f ]] && inst_simple "$f"
1171     done
1172     if ! ldconfig -r "$initdir"; then
1173         if [[ $UID = 0 ]]; then
1174             derror "ldconfig exited ungracefully"
1175         else
1176             derror "ldconfig might need uid=0 (root) for chroot()"
1177         fi
1178     fi
1179 fi
1180
1181 PRELINK_BIN="$(command -v prelink)"
1182 if [[ $UID = 0 ]] && [[ $PRELINK_BIN ]]; then
1183     if [[ $DRACUT_FIPS_MODE ]]; then
1184         dinfo "*** Installing prelink files ***"
1185         inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf /etc/prelink.cache
1186     else
1187         dinfo "*** Pre-linking files ***"
1188         inst_multiple -o prelink /etc/prelink.conf /etc/prelink.conf.d/*.conf
1189         chroot "$initdir" "$PRELINK_BIN" -a
1190         rm -f -- "$initdir/$PRELINK_BIN"
1191         rm -fr -- "$initdir"/etc/prelink.*
1192         dinfo "*** Pre-linking files done ***"
1193     fi
1194 fi
1195
1196 if [[ $do_hardlink = yes ]] && command -v hardlink >/dev/null; then
1197     dinfo "*** Hardlinking files ***"
1198     hardlink "$initdir" 2>&1
1199     dinfo "*** Hardlinking files done ***"
1200 fi
1201
1202 # strip binaries
1203 if [[ $do_strip = yes ]] ; then
1204     for p in strip xargs find; do
1205         if ! type -P $p >/dev/null; then
1206             dinfo "Could not find '$p'. Not stripping the initramfs."
1207             do_strip=no
1208         fi
1209     done
1210 fi
1211
1212 if [[ $do_strip = yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
1213     dinfo "*** Stripping files ***"
1214     find "$initdir" -type f \
1215         -executable -not -path '*/lib/modules/*.ko' -print0 \
1216         | xargs -r -0 strip -g 2>/dev/null
1217
1218     # strip kernel modules, but do not touch signed modules
1219     find "$initdir" -type f -path '*/lib/modules/*.ko' -print0 \
1220         | while read -r -d $'\0' f; do
1221         SIG=$(tail -c 28 "$f")
1222         [[ $SIG == '~Module signature appended~' ]] || { printf "%s\000" "$f"; }
1223     done | xargs -r -0 strip -g
1224
1225     dinfo "*** Stripping files done ***"
1226 fi
1227 if [[ $early_microcode = yes ]]; then
1228     dinfo "*** Generating early-microcode cpio image ***"
1229     ucode_dir=(amd-ucode intel-ucode)
1230     ucode_dest=(AuthenticAMD.bin GenuineIntel.bin)
1231     _dest_dir="$microcode_dir/d/kernel/x86/microcode"
1232     _dest_idx="0 1"
1233     mkdir -p $_dest_dir
1234     if [[ $hostonly ]]; then
1235         [[ $(get_cpu_vendor) == "AMD" ]] && _dest_idx="0"
1236         [[ $(get_cpu_vendor) == "Intel" ]] && _dest_idx="1"
1237     fi
1238     for idx in $_dest_idx; do
1239         _fw=${ucode_dir[$idx]}
1240         for _fwdir in $fw_dir; do
1241             if [[ -d $_fwdir && -d $_fwdir/$_fw ]]; then
1242                 _src="*"
1243                 dinfo "*** Constructing ${ucode_dest[$idx]} ****"
1244                 if [[ $hostonly ]]; then
1245                     _src=$(get_ucode_file)
1246                 fi
1247                 cat $_fwdir/$_fw/$_src > $_dest_dir/${ucode_dest[$idx]}
1248             fi
1249         done
1250     done
1251     (cd "$microcode_dir/d"; find . -print0 | cpio --null -o -H newc --quiet >../ucode.cpio)
1252 fi
1253
1254 rm -f -- "$outfile"
1255 dinfo "*** Creating image file ***"
1256 if [[ $early_microcode = yes ]]; then
1257     # The microcode blob is _before_ the initramfs blob, not after
1258     mv $microcode_dir/ucode.cpio $outfile.$$
1259 fi
1260 if ! ( umask 077; cd "$initdir"; find . -print0 | cpio --null -R 0:0 -H newc -o --quiet| \
1261     $compress >> "$outfile.$$"; ); then
1262     dfatal "dracut: creation of $outfile.$$ failed"
1263     exit 1
1264 fi
1265 mv -- "$outfile.$$" "$outfile"
1266 dinfo "*** Creating image file done ***"
1267
1268 if (( maxloglvl >= 5 )); then
1269     lsinitrd "$outfile"| ddebug
1270 fi
1271
1272 exit 0