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.XXXXXXfailed." >&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]}\""
645 ddebug
"Executing: $0 ${dracut_args[@]}"
647 [[ $do_list = yes ]] && {
648 for mod
in $dracutbasedir/modules.d
/*; do
649 [[ -d $mod ]] ||
continue;
650 [[ -e $mod/install ||
-e $mod/installkernel || \
651 -e $mod/module-setup.sh
]] ||
continue
657 # This is kinda legacy -- eventually it should go away.
658 case $dracutmodules in
659 ""|auto
) dracutmodules
="all" ;;
662 abs_outfile
=$
(readlink
-f "$outfile") && outfile
="$abs_outfile"
664 [[ -f $srcmods/modules.dep
]] ||
{
665 dfatal
"$srcmods/modules.dep is missing. Did you run depmod?"
669 if [[ -f $outfile && ! $force ]]; then
670 dfatal
"Will not override existing initramfs ($outfile) without --force"
675 [[ $outdir ]] || outdir
="/"
677 if [[ ! -d "$outdir" ]]; then
678 dfatal
"Can't write $outfile: Directory $outdir does not exist."
680 elif [[ ! -w "$outdir" ]]; then
681 dfatal
"No permission to write to $outdir."
683 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
684 dfatal
"No permission to write $outfile."
688 # clean up after ourselves no matter how we die.
689 trap 'ret=$?;[[ $keep ]] && echo "Not removing $initdir." >&2 || rm -rf "$initdir";exit $ret;' EXIT
690 # clean up after ourselves no matter how we die.
691 trap 'exit 1;' SIGINT
693 # Need to be able to have non-root users read stuff (rpcbind etc)
696 for line
in "${fstab_lines[@]}"; do
700 push host_fs_types
"$1|$3"
703 for f
in $add_fstab; do
704 [ -e $f ] ||
continue
705 while read dev rest
; do
710 if [[ $hostonly ]]; then
711 # in hostonly mode, determine all devices, which have to be accessed
712 # and examine them for filesystem types
724 for mp
in "${host_mp[@]}"; do
725 mountpoint
"$mp" >/dev
/null
2>&1 ||
continue
726 push host_devs $
(readlink
-f "/dev/block/$(find_block_device "$mp")")
732 if [[ -b $1 ]] && get_fs_env
$1; then
733 echo "$(readlink -f $1)|$ID_FS_TYPE"
736 if [[ -b /dev
/block
/$1 ]] && get_fs_env
/dev
/block
/$1; then
737 echo "$(readlink -f /dev/block/$1)|$ID_FS_TYPE"
740 if fstype
=$
(find_dev_fstype
$1); then
747 for dev
in "${host_devs[@]}"; do
749 for fstype
in $
(_get_fs_type
$dev) \
750 $
(check_block_and_slaves _get_fs_type $
(get_maj_min
$dev)); do
751 if ! strstr
" ${host_fs_types[*]} " " $fstype ";then
752 push host_fs_types
"$fstype"
758 || udevdir
=$
(pkg-config udev
--variable=udevdir
2>/dev
/null
)
759 if ! [[ -d "$udevdir" ]]; then
760 [[ -d /lib
/udev
]] && udevdir
=/lib
/udev
761 [[ -d /usr
/lib
/udev
]] && udevdir
=/usr
/lib
/udev
764 [[ -d $systemdutildir ]] \
765 || systemdutildir
=$
(pkg-config systemd
--variable=systemdutildir
2>/dev
/null
)
766 [[ -d $systemdsystemunitdir ]] \
767 || systemdsystemunitdir
=$
(pkg-config systemd
--variable=systemdsystemunitdir
2>/dev
/null
)
769 if ! [[ -d "$systemdutildir" ]]; then
770 [[ -d /lib
/systemd
]] && systemdutildir
=/lib
/systemd
771 [[ -d /usr
/lib
/systemd
]] && systemdutildir
=/usr
/lib
/systemd
773 [[ -d "$systemdsystemunitdir" ]] || systemdsystemunitdir
=${systemdutildir}/system
775 export initdir dracutbasedir dracutmodules drivers \
776 fw_dir drivers_dir debug no_kernel kernel_only \
777 add_drivers omit_drivers mdadmconf lvmconf filesystems \
778 use_fstab fstab_lines libdirs fscks nofscks \
779 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
780 debug host_fs_types host_devs sshkey add_fstab \
781 DRACUT_VERSION udevdir systemdutildir systemdsystemunitdir
783 # Create some directory structure first
784 [[ $prefix ]] && mkdir
-m 0755 -p "${initdir}${prefix}"
786 [[ -h /lib
]] || mkdir
-m 0755 -p "${initdir}${prefix}/lib"
787 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
789 if [[ $prefix ]]; then
790 for d
in bin etc lib sbin tmp usr var
$libdirs; do
791 strstr
"$d" "/" && continue
792 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
796 if [[ $kernel_only != yes ]]; then
797 for d
in usr
/bin usr
/sbin bin etc lib sbin tmp usr var var
/log var
/run var
/lock
$libdirs; do
798 [[ -e "${initdir}${prefix}/$d" ]] && continue
799 if [ -L "/$d" ]; then
800 inst_symlink
"/$d" "${prefix}/$d"
802 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
806 for d
in dev proc sys sysroot root run run
/lock run
/initramfs
; do
807 if [ -L "/$d" ]; then
810 mkdir
-m 0755 -p "$initdir/$d"
814 ln -sfn /run
"$initdir/var/run"
815 ln -sfn /run
/lock
"$initdir/var/lock"
817 for d
in lib
"$libdir"; do
818 [[ -e "${initdir}${prefix}/$d" ]] && continue
819 if [ -h "/$d" ]; then
820 inst
"/$d" "${prefix}/$d"
822 mkdir
-m 0755 -p "${initdir}${prefix}/$d"
827 if [[ $kernel_only != yes ]]; then
828 mkdir
-p "${initdir}/etc/cmdline.d"
829 for _d
in $hookdirs; do
830 mkdir
-m 0755 -p ${initdir}/lib
/dracut
/hooks
/$_d
832 if [[ "$UID" = "0" ]]; then
833 [ -c ${initdir}/dev
/null
] || mknod
${initdir}/dev
/null c
1 3
834 [ -c ${initdir}/dev
/kmsg
] || mknod
${initdir}/dev
/kmsg c
1 11
835 [ -c ${initdir}/dev
/console
] || mknod
${initdir}/dev
/console c
5 1
840 # check all our modules to see if they should be sourced.
841 # This builds a list of modules that we will install next.
842 for_each_module_dir check_module
843 for_each_module_dir check_mount
845 strstr
"$mods_to_load" "fips" && export DRACUT_FIPS_MODE
=1
847 _isize
=0 #initramfs size
849 # source our modules.
850 for moddir
in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
851 _d_mod
=${moddir##*/}; _d_mod
=${_d_mod#[0-9][0-9]}
852 if strstr
"$mods_to_load" " $_d_mod "; then
853 [[ $show_modules = yes ]] && echo "$_d_mod" || \
854 dinfo
"*** Including module: $_d_mod ***"
855 if [[ $kernel_only = yes ]]; then
856 module_installkernel
$_d_mod ||
{
857 dfatal
"installkernel failed in module $_d_mod"
861 module_install
$_d_mod
862 if [[ $no_kernel != yes ]]; then
863 module_installkernel
$_d_mod ||
{
864 dfatal
"installkernel failed in module $_d_mod"
869 mods_to_load
=${mods_to_load// $_d_mod /}
870 modules_loaded
+="$_d_mod "
872 #print the module install size
873 if [ -n "$printsize" ]; then
874 _isize_new
=$
(du
-sk ${initdir}|cut
-f1)
875 _isize_delta
=$
(($_isize_new - $_isize))
876 echo "$_d_mod install size: ${_isize_delta}k"
883 for i
in $modules_loaded; do
884 mkdir
-p $initdir/lib
/dracut
885 echo "$i" >> $initdir/lib
/dracut
/modules.txt
888 dinfo
"*** Including modules done ***"
890 ## final stuff that has to happen
891 if [[ $no_kernel != yes ]]; then
892 dinfo
"*** Installing kernel module dependencies and firmware ***"
894 dinfo
"*** Installing kernel module dependencies and firmware done ***"
897 if [[ $kernel_only != yes ]]; then
898 (( ${#install_items[@]} > 0 )) && dracut_install
${install_items[@]}
900 while pop fstab_lines line
; do
901 echo "$line 0 0" >> "${initdir}/etc/fstab"
904 for f
in $add_fstab; do
905 cat $f >> "${initdir}/etc/fstab"
908 if [[ $DRACUT_RESOLVE_LAZY ]] && [[ $DRACUT_INSTALL ]]; then
909 dinfo
"*** Resolving executable dependencies ***"
910 find "$initdir" -type f \
911 '(' -perm -0100 -or -perm -0010 -or -perm -0001 ')' \
912 -not -path '*.ko' -print0 \
913 |
xargs -r -0 $DRACUT_INSTALL ${initdir+-D "$initdir"} -R ${DRACUT_FIPS_MODE+-H}
914 dinfo
"*** Resolving executable dependencies done***"
918 while pop include_src src
&& pop include_target tgt
; do
919 if [[ $src && $tgt ]]; then
920 if [[ -f $src ]]; then
923 ddebug
"Including directory: $src"
924 mkdir
-p "${initdir}/${tgt}"
925 # check for preexisting symlinks, so we can cope with the
926 # symlinks to $prefix
927 for i
in "$src"/*; do
928 [[ -e "$i" ||
-h "$i" ]] ||
continue
929 s
=${initdir}/${tgt}/${i#$src/}
930 if [[ -d "$i" ]]; then
931 if ! [[ -e "$s" ]]; then
932 mkdir
-m 0755 -p "$s"
933 chmod --reference="$i" "$s"
935 cp --reflink=auto
--sparse=auto
-pfLr -t "$s" "$i"/*
937 cp --reflink=auto
--sparse=auto
-pfLr -t "$s" "$i"
944 if [[ $kernel_only != yes ]]; then
945 # make sure that library links are correct and up to date
946 for f
in /etc
/ld.so.conf
/etc
/ld.so.conf.d
/*; do
947 [[ -f $f ]] && inst_simple
"$f"
949 if ! ldconfig
-r "$initdir"; then
950 if [[ $UID = 0 ]]; then
951 derror
"ldconfig exited ungracefully"
953 derror
"ldconfig might need uid=0 (root) for chroot()"
958 if (($maxloglvl >= 5)); then
959 ddebug
"Listing sizes of included files:"
960 du
-c "$initdir" |
sort -n | ddebug
964 if [[ $do_strip = yes ]] ; then
965 for p
in strip
xargs find; do
966 if ! type -P $p >/dev
/null
; then
967 derror
"Could not find '$p'. You should run $0 with '--nostrip'."
973 if strstr
"$modules_loaded" " fips " && command -v prelink
>/dev
/null
; then
974 dinfo
"*** pre-unlinking files ***"
975 for dir
in "$initdir/bin" \
978 "$initdir/usr/sbin"; do
979 [[ -L "$dir" ]] && continue
980 for i
in "$dir"/*; do
981 [[ -L $i ]] && continue
982 [[ -x $i ]] && prelink
-u $i &>/dev
/null
985 dinfo
"*** pre-unlinking files done ***"
988 if [[ $do_strip = yes ]] ; then
989 dinfo
"*** Stripping files ***"
990 find "$initdir" -type f \
991 '(' -perm -0100 -or -perm -0010 -or -perm -0001 \
992 -or -path '*/lib/modules/*.ko' ')' -print0 \
993 |
xargs -r -0 strip
-g 2>/dev
/null
994 dinfo
"*** Stripping files done ***"
997 if [[ $do_hardlink = yes ]] ; then
998 type hardlink
&>/dev
/null
&& {
999 dinfo
"*** hardlinking files ***"
1000 hardlink
"$initdir" 2>&1
1001 dinfo
"*** hardlinking files done ***"
1005 dinfo
"*** Creating image file ***"
1006 if ! ( cd "$initdir"; find . |
cpio -R 0:0 -H newc
-o --quiet| \
1007 $compress > "$outfile"; ); then
1008 dfatal
"dracut: creation of $outfile failed"
1011 dinfo
"*** Creating image file done ***"
1013 dinfo
"Wrote $outfile:"
1014 dinfo
"$(ls -l "$outfile")"