]> git.ipfire.org Git - thirdparty/dracut.git/blob - dracut.sh
remove --ctty
[thirdparty/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-2010 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 usage() {
30 # 80x25 linebreak here ^
31 cat << EOF
32 Usage: $0 [OPTION]... <initramfs> <kernel-version>
33 Creates initial ramdisk images for preloading modules
34
35 -f, --force Overwrite existing initramfs file.
36 -m, --modules [LIST] Specify a space-separated list of dracut modules to
37 call when building the initramfs. Modules are located
38 in /usr/lib/dracut/modules.d.
39 -o, --omit [LIST] Omit a space-separated list of dracut modules.
40 -a, --add [LIST] Add a space-separated list of dracut modules.
41 -d, --drivers [LIST] Specify a space-separated list of kernel modules to
42 exclusively include in the initramfs.
43 --add-drivers [LIST] Specify a space-separated list of kernel
44 modules to add to the initramfs.
45 --omit-drivers [LIST] Specify a space-separated list of kernel
46 modules not to add to the initramfs.
47 --filesystems [LIST] Specify a space-separated list of kernel filesystem
48 modules to exclusively include in the generic
49 initramfs.
50 -k, --kmoddir [DIR] Specify the directory, where to look for kernel
51 modules
52 --fwdir [DIR] Specify additional directories, where to look for
53 firmwares, separated by :
54 --kernel-only Only install kernel drivers and firmware files
55 --no-kernel Do not install kernel drivers and firmware files
56 --strip Strip binaries in the initramfs
57 --nostrip Do not strip binaries in the initramfs (default)
58 --prefix [DIR] Prefix initramfs files with [DIR]
59 --noprefix Do not prefix initramfs files (default)
60 --mdadmconf Include local /etc/mdadm.conf
61 --nomdadmconf Do not include local /etc/mdadm.conf
62 --lvmconf Include local /etc/lvm/lvm.conf
63 --nolvmconf Do not include local /etc/lvm/lvm.conf
64 --fscks [LIST] Add a space-separated list of fsck helpers.
65 --nofscks Inhibit installation of any fsck helpers.
66 -h, --help This message
67 --debug Output debug information of the build process
68 --profile Output profile information of the build process
69 -L, --stdlog [0-6] Specify logging level (to standard error)
70 0 - suppress any messages
71 1 - only fatal errors
72 2 - all errors
73 3 - warnings
74 4 - info (default)
75 5 - debug info (here starts lots of output)
76 6 - trace info (and even more)
77 -v, --verbose Increase verbosity level (default is info(4))
78 -q, --quiet Decrease verbosity level (default is info(4))
79 -c, --conf [FILE] Specify configuration file to use.
80 Default: /etc/dracut.conf
81 --confdir [DIR] Specify configuration directory to use *.conf files
82 from. Default: /etc/dracut.conf.d
83 -l, --local Local mode. Use modules from the current working
84 directory instead of the system-wide installed in
85 /usr/lib/dracut/modules.d.
86 Useful when running dracut from a git checkout.
87 -H, --hostonly Host-Only mode: Install only what is needed for
88 booting the local host instead of a generic host.
89 --fstab Use /etc/fstab to determine the root device.
90 --add-fstab [FILE] Add file to the initramfs fstab
91 --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
92 Mount device [DEV] on mountpoint [MP] with filesystem
93 [FSTYPE] and options [FSOPTS] in the initramfs
94 -i, --include [SOURCE] [TARGET]
95 Include the files in the SOURCE directory into the
96 Target directory in the final initramfs.
97 If SOURCE is a file, it will be installed to TARGET
98 in the final initramfs.
99 -I, --install [LIST] Install the space separated list of files into the
100 initramfs.
101 --gzip Compress the generated initramfs using gzip.
102 This will be done by default, unless another
103 compression option or --no-compress is passed.
104 --bzip2 Compress the generated initramfs using bzip2.
105 Make sure your kernel has bzip2 decompression support
106 compiled in, otherwise you will not be able to boot.
107 --lzma Compress the generated initramfs using lzma.
108 Make sure your kernel has lzma support compiled in,
109 otherwise you will not be able to boot.
110 --xz Compress the generated initramfs using xz.
111 Make sure that your kernel has xz support compiled
112 in, otherwise you will not be able to boot.
113 --compress [COMPRESSION] Compress the generated initramfs with the
114 passed compression program. Make sure your kernel
115 knows how to decompress the generated initramfs,
116 otherwise you will not be able to boot.
117 --no-compress Do not compress the generated initramfs. This will
118 override any other compression options.
119 --list-modules List all available dracut modules.
120 -M, --show-modules Print included module's name to standard output during
121 build.
122 --keep Keep the temporary initramfs for debugging purposes
123 --sshkey [SSHKEY] Add ssh key to initramfs (use with ssh-client module)
124
125 If [LIST] has multiple arguments, then you have to put these in quotes.
126 For example:
127 # dracut --add-drivers "module1 module2" ...
128 EOF
129 }
130
131 # function push()
132 # push values to a stack
133 # $1 = stack variable
134 # $2.. values
135 # example:
136 # push stack 1 2 "3 4"
137 push() {
138 local __stack=$1; shift
139 for i in "$@"; do
140 eval ${__stack}'[${#'${__stack}'[@]}]="$i"'
141 done
142 }
143
144 # function pop()
145 # pops the last value from a stack
146 # assigns value to second argument variable
147 # or echo to stdout, if no second argument
148 # $1 = stack variable
149 # $2 = optional variable to store the value
150 # example:
151 # pop stack val
152 # val=$(pop stack)
153 pop() {
154 local __stack=$1; shift
155 local __resultvar=$1
156 local myresult;
157 # check for empty stack
158 eval '[[ ${#'${__stack}'[@]} -eq 0 ]] && return 1'
159
160 eval myresult='${'${__stack}'[${#'${__stack}'[@]}-1]}'
161
162 if [[ "$__resultvar" ]]; then
163 eval $__resultvar="'$myresult'"
164 else
165 echo "$myresult"
166 fi
167 eval unset ${__stack}'[${#'${__stack}'[@]}-1]'
168 return 0
169 }
170
171 # Little helper function for reading args from the commandline.
172 # it automatically handles -a b and -a=b variants, and returns 1 if
173 # we need to shift $3.
174 read_arg() {
175 # $1 = arg name
176 # $2 = arg value
177 # $3 = arg parameter
178 local rematch='^[^=]*=(.*)$'
179 if [[ $2 =~ $rematch ]]; then
180 read "$1" <<< "${BASH_REMATCH[1]}"
181 else
182 read "$1" <<< "$3"
183 # There is no way to shift our callers args, so
184 # return 1 to indicate they should do it instead.
185 return 1
186 fi
187 }
188
189 # Little helper function for reading args from the commandline to a stack.
190 # it automatically handles -a b and -a=b variants, and returns 1 if
191 # we need to shift $3.
192 push_arg() {
193 # $1 = arg name
194 # $2 = arg value
195 # $3 = arg parameter
196 local rematch='^[^=]*=(.*)$'
197 if [[ $2 =~ $rematch ]]; then
198 push "$1" "${BASH_REMATCH[1]}"
199 else
200 push "$1" "$3"
201 # There is no way to shift our callers args, so
202 # return 1 to indicate they should do it instead.
203 return 1
204 fi
205 }
206
207 verbosity_mod_l=0
208
209 while (($# > 0)); do
210 case ${1%%=*} in
211 -a|--add) push_arg add_dracutmodules_l "$@" || shift;;
212 --force-add) push_arg force_add_dracutmodules_l "$@" || shift;;
213 --add-drivers) push_arg add_drivers_l "$@" || shift;;
214 --omit-drivers) push_arg omit_drivers_l "$@" || shift;;
215 -m|--modules) push_arg dracutmodules_l "$@" || shift;;
216 -o|--omit) push_arg omit_dracutmodules_l "$@" || shift;;
217 -d|--drivers) push_arg drivers_l "$@" || shift;;
218 --filesystems) push_arg filesystems_l "$@" || shift;;
219 -I|--install) push_arg install_items_l "$@" || shift;;
220 --fwdir) push_arg fw_dir_l "$@" || shift;;
221 --fscks) push_arg fscks_l "$@" || shift;;
222 --add-fstab) push_arg add_fstab_l "$@" || shift;;
223 --mount) push_arg fstab_lines "$@" || shift;;
224 --nofscks) nofscks_l="yes";;
225 -k|--kmoddir) read_arg drivers_dir_l "$@" || shift;;
226 -c|--conf) read_arg conffile "$@" || shift;;
227 --confdir) read_arg confdir "$@" || shift;;
228 -L|--stdlog) read_arg stdloglvl_l "$@" || shift;;
229 --compress) read_arg compress_l "$@" || shift;;
230 --prefix) read_arg prefix_l "$@" || shift;;
231 -f|--force) force=yes;;
232 --kernel-only) kernel_only="yes"; no_kernel="no";;
233 --no-kernel) kernel_only="no"; no_kernel="yes";;
234 --strip) do_strip_l="yes";;
235 --nostrip) do_strip_l="no";;
236 --noprefix) prefix_l="/";;
237 --mdadmconf) mdadmconf_l="yes";;
238 --nomdadmconf) mdadmconf_l="no";;
239 --lvmconf) lvmconf_l="yes";;
240 --nolvmconf) lvmconf_l="no";;
241 --debug) debug="yes";;
242 --profile) profile="yes";;
243 --sshkey) read_arg sshkey "$@" || shift;;
244 -v|--verbose) ((verbosity_mod_l++));;
245 -q|--quiet) ((verbosity_mod_l--));;
246 -l|--local) allowlocal="yes" ;;
247 -H|--hostonly) hostonly_l="yes" ;;
248 --fstab) use_fstab_l="yes" ;;
249 -h|--help) usage; exit 1 ;;
250 -i|--include) push include_src "$2"
251 push include_target "$3"
252 shift 2;;
253 --bzip2) compress_l="bzip2";;
254 --lzma) compress_l="lzma";;
255 --xz) compress_l="xz";;
256 --no-compress) _no_compress_l="cat";;
257 --gzip) compress_l="gzip";;
258 --list-modules)
259 do_list="yes";
260 ;;
261 -M|--show-modules)
262 show_modules_l="yes"
263 ;;
264 --keep) keep="yes";;
265 -*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage; exit 1;;
266 *)
267 if ! [[ ${outfile+x} ]]; then
268 outfile=$1
269 elif ! [[ ${kernel+x} ]]; then
270 kernel=$1
271 else
272 usage; exit 1;
273 fi
274 ;;
275 esac
276 shift
277 done
278 if ! [[ $kernel ]]; then
279 kernel=$(uname -r)
280 fi
281 [[ $outfile ]] || outfile="/boot/initramfs-$kernel.img"
282
283 for i in /usr/sbin /sbin /usr/bin /bin; do
284 rl=$i
285 if [ -L "$i" ]; then
286 rl=$(readlink -f $i)
287 fi
288 NPATH+=":$rl"
289 done
290 export PATH="${NPATH#:}"
291 unset NPATH
292 unset LD_LIBRARY_PATH
293 unset GREP_OPTIONS
294
295 [[ $debug ]] && {
296 export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
297 set -x
298 }
299
300 [[ $profile ]] && {
301 export PS4='+ $(date "+%s.%N") ${BASH_SOURCE}@${LINENO}: ';
302 set -x
303 debug=yes
304 }
305
306 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
307
308 [[ $allowlocal && -f "$(readlink -f ${0%/*})/dracut-functions.sh" ]] && \
309 dracutbasedir="$(readlink -f ${0%/*})"
310
311 # if we were not passed a config file, try the default one
312 if [[ ! -f $conffile ]]; then
313 [[ $allowlocal ]] && conffile="$dracutbasedir/dracut.conf" || \
314 conffile="/etc/dracut.conf"
315 fi
316
317 if [[ ! -d $confdir ]]; then
318 [[ $allowlocal ]] && confdir="$dracutbasedir/dracut.conf.d" || \
319 confdir="/etc/dracut.conf.d"
320 fi
321
322 # source our config file
323 [[ -f $conffile ]] && . "$conffile"
324
325 # source our config dir
326 if [[ $confdir && -d $confdir ]]; then
327 for f in "$confdir"/*.conf; do
328 [[ -e $f ]] && . "$f"
329 done
330 fi
331
332 # these optins add to the stuff in the config file
333 if (( ${#add_dracutmodules_l[@]} )); then
334 while pop add_dracutmodules_l val; do
335 add_dracutmodules+=" $val "
336 done
337 fi
338
339 if (( ${#force_add_dracutmodules_l[@]} )); then
340 while pop force_add_dracutmodules_l val; do
341 force_add_dracutmodules+=" $val "
342 done
343 fi
344
345 if (( ${#fscks_l[@]} )); then
346 while pop fscks_l val; do
347 fscks+=" $val "
348 done
349 fi
350
351 if (( ${#add_fstab_l[@]} )); then
352 while pop add_fstab_l val; do
353 add_fstab+=" $val "
354 done
355 fi
356
357 if (( ${#fstab_lines_l[@]} )); then
358 while pop fstab_lines_l val; do
359 push fstab_lines $val
360 done
361 fi
362
363 if (( ${#install_items_l[@]} )); then
364 while pop install_items_l val; do
365 install_items+=" $val "
366 done
367 fi
368
369 # these options override the stuff in the config file
370 if (( ${#dracutmodules_l[@]} )); then
371 dracutmodules=''
372 while pop dracutmodules_l val; do
373 dracutmodules+="$val "
374 done
375 fi
376
377 if (( ${#omit_dracutmodules_l[@]} )); then
378 omit_dracutmodules=''
379 while pop omit_dracutmodules_l val; do
380 omit_dracutmodules+="$val "
381 done
382 fi
383
384 if (( ${#filesystems_l[@]} )); then
385 filesystems=''
386 while pop filesystems_l val; do
387 filesystems+="$val "
388 done
389 fi
390
391 if (( ${#fw_dir_l[@]} )); then
392 fw_dir=''
393 while pop fw_dir_l val; do
394 fw_dir+="$val "
395 done
396 fi
397
398 [[ $stdloglvl_l ]] && stdloglvl=$stdloglvl_l
399 [[ ! $stdloglvl ]] && stdloglvl=4
400 stdloglvl=$((stdloglvl + verbosity_mod_l))
401 ((stdloglvl > 6)) && stdloglvl=6
402 ((stdloglvl < 0)) && stdloglvl=0
403
404 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
405 [[ $do_strip_l ]] && do_strip=$do_strip_l
406 [[ $prefix_l ]] && prefix=$prefix_l
407 [[ $prefix = "/" ]] && unset prefix
408 [[ $hostonly_l ]] && hostonly=$hostonly_l
409 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
410 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
411 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
412 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
413 [[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
414 [[ $do_strip ]] || do_strip=no
415 [[ $compress_l ]] && compress=$compress_l
416 [[ $show_modules_l ]] && show_modules=$show_modules_l
417 [[ $nofscks_l ]] && nofscks="yes"
418 # eliminate IFS hackery when messing with fw_dir
419 fw_dir=${fw_dir//:/ }
420
421 # handle compression options.
422 [[ $compress ]] || compress="gzip"
423 case $compress in
424 bzip2) compress="bzip2 -9";;
425 lzma) compress="lzma -9";;
426 xz) compress="xz --check=crc32 --lzma2=dict=1MiB";;
427 gzip) command -v pigz > /dev/null 2>&1 && compress="pigz -9" || \
428 compress="gzip -9";;
429 esac
430 if [[ $_no_compress_l = "cat" ]]; then
431 compress="cat"
432 fi
433
434 [[ $hostonly = yes ]] && hostonly="-h"
435 [[ $hostonly != "-h" ]] && unset hostonly
436
437 if [[ -f $dracutbasedir/dracut-functions.sh ]]; then
438 . $dracutbasedir/dracut-functions.sh
439 else
440 echo "Cannot find $dracutbasedir/dracut-functions.sh." >&2
441 echo "Are you running from a git checkout?" >&2
442 echo "Try passing -l as an argument to $0" >&2
443 exit 1
444 fi
445
446 # Verify bash version, curret minimum is 3.1
447 if (( ${BASH_VERSINFO[0]} < 3 ||
448 ( ${BASH_VERSINFO[0]} == 3 && ${BASH_VERSINFO[1]} < 1 ) )); then
449 dfatal 'You need at least Bash 3.1 to use dracut, sorry.'
450 exit 1
451 fi
452
453 dracutfunctions=$dracutbasedir/dracut-functions.sh
454 export dracutfunctions
455
456 if (( ${#drivers_l[@]} )); then
457 drivers=''
458 while pop drivers_l val; do
459 drivers+="$val "
460 done
461 fi
462 drivers=${drivers/-/_}
463
464 if (( ${#add_drivers_l[@]} )); then
465 while pop add_drivers_l val; do
466 add_drivers+=" $val "
467 done
468 fi
469 add_drivers=${add_drivers/-/_}
470
471 if (( ${#omit_drivers_l[@]} )); then
472 while pop omit_drivers_l val; do
473 omit_drivers+=" $val "
474 done
475 fi
476 omit_drivers=${omit_drivers/-/_}
477
478 omit_drivers_corrected=""
479 for d in $omit_drivers; do
480 strstr " $drivers $add_drivers " " $d " && continue
481 omit_drivers_corrected+="$d|"
482 done
483 omit_drivers="${omit_drivers_corrected%|}"
484 unset omit_drivers_corrected
485
486
487 ddebug "Executing $0 $dracut_args"
488
489 [[ $do_list = yes ]] && {
490 for mod in $dracutbasedir/modules.d/*; do
491 [[ -d $mod ]] || continue;
492 [[ -e $mod/install || -e $mod/installkernel || \
493 -e $mod/module-setup.sh ]] || continue
494 echo ${mod##*/??}
495 done
496 exit 0
497 }
498
499 # Detect lib paths
500 [[ $libdir ]] || for libdir in /lib64 /lib; do
501 [[ -d $libdir ]] && break
502 done || {
503 dfatal 'No lib directory?!!!'
504 exit 1
505 }
506
507 [[ $usrlibdir ]] || for usrlibdir in /usr/lib64 /usr/lib; do
508 [[ -d $usrlibdir ]] && break
509 done || dwarn 'No usr/lib directory!'
510
511 # This is kinda legacy -- eventually it should go away.
512 case $dracutmodules in
513 ""|auto) dracutmodules="all" ;;
514 esac
515
516 abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
517
518 srcmods="/lib/modules/$kernel/"
519 [[ $drivers_dir ]] && {
520 if vercmp $(modprobe --version | cut -d' ' -f3) lt 3.7; then
521 dfatal 'To use --kmoddir option module-init-tools >= 3.7 is required.'
522 exit 1
523 fi
524 srcmods="$drivers_dir"
525 }
526 export srcmods
527
528 if [[ -f $outfile && ! $force ]]; then
529 dfatal "Will not override existing initramfs ($outfile) without --force"
530 exit 1
531 fi
532
533 outdir=${outfile%/*}
534 [[ $outdir ]] || outdir="/"
535
536 if [[ ! -d "$outdir" ]]; then
537 dfatal "Can't write $outfile: Directory $outdir does not exist."
538 exit 1
539 elif [[ ! -w "$outdir" ]]; then
540 dfatal "No permission to write $outdir."
541 exit 1
542 elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
543 dfatal "No permission to write $outfile."
544 exit 1
545 fi
546
547 readonly TMPDIR=/var/tmp
548 readonly initdir=$(mktemp --tmpdir=/var/tmp/ -d -t initramfs.XXXXXX)
549 [ -d "$initdir" ] || {
550 dfatal "mktemp failed."
551 exit 1
552 }
553
554 # clean up after ourselves no matter how we die.
555 trap 'ret=$?;[[ $keep ]] && echo "Not removing $initdir." >&2 || rm -rf "$initdir";exit $ret;' EXIT
556 # clean up after ourselves no matter how we die.
557 trap 'exit 1;' SIGINT
558
559 # Need to be able to have non-root users read stuff (rpcbind etc)
560 chmod 755 "$initdir"
561
562 for line in "${fstab_lines[@]}"; do
563 set -- $line
564 #dev mp fs fsopts
565 push host_devs "$1"
566 push host_fs_types "$1|$3"
567 done
568
569 for f in $add_fstab; do
570 [ -e $f ] || continue
571 while read dev rest; do
572 push host_devs $dev
573 done < $f
574 done
575
576 if [[ $hostonly ]]; then
577 # in hostonly mode, determine all devices, which have to be accessed
578 # and examine them for filesystem types
579
580 push host_mp \
581 "/" \
582 "/etc" \
583 "/usr" \
584 "/usr/bin" \
585 "/usr/sbin" \
586 "/usr/lib" \
587 "/usr/lib64" \
588 "/boot"
589
590 for mp in "${host_mp[@]}"; do
591 mountpoint "$mp" >/dev/null 2>&1 || continue
592 push host_devs $(readlink -f "/dev/block/$(find_block_device "$mp")")
593 done
594 fi
595
596 _get_fs_type() (
597 [[ $1 ]] || return
598 if [[ -b $1 ]] && get_fs_env $1; then
599 echo "$1|$ID_FS_TYPE"
600 return 1
601 fi
602 if [[ -b /dev/block/$1 ]] && get_fs_env /dev/block/$1; then
603 echo "/dev/block/$1|$ID_FS_TYPE"
604 return 1
605 fi
606 if fstype=$(find_dev_fstype $1); then
607 echo "$1|$fstype"
608 return 1
609 fi
610 return 1
611 )
612
613 for dev in "${host_devs[@]}"; do
614 unset fs_type
615 for fstype in $(_get_fs_type $dev) \
616 $(check_block_and_slaves _get_fs_type $(get_maj_min $dev)); do
617 if ! strstr " ${host_fs_types[*]} " " $fstype ";then
618 push host_fs_types "$fstype"
619 fi
620 done
621 done
622
623 export initdir dracutbasedir dracutmodules drivers \
624 fw_dir drivers_dir debug no_kernel kernel_only \
625 add_drivers omit_drivers mdadmconf lvmconf filesystems \
626 use_fstab fstab_lines libdir usrlibdir fscks nofscks \
627 stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
628 debug host_fs_types host_devs sshkey
629
630 # Create some directory structure first
631 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
632
633 [[ -h /lib ]] || mkdir -m 0755 -p "${initdir}${prefix}/lib"
634 [[ $prefix ]] && ln -sfn "${prefix#/}/lib" "$initdir/lib"
635
636 if [[ $prefix ]]; then
637 for d in bin etc lib "$libdir" sbin tmp usr var; do
638 ln -sfn "${prefix#/}/${d#/}" "$initdir/$d"
639 done
640 fi
641
642 if [[ $kernel_only != yes ]]; then
643 for d in usr/bin usr/sbin bin etc lib "$libdir" sbin tmp usr var var/log; do
644 [[ -e "${initdir}${prefix}/$d" ]] && continue
645 if [ -L "/$d" ]; then
646 inst_symlink "/$d" "${prefix}/$d"
647 else
648 mkdir -m 0755 -p "${initdir}${prefix}/$d"
649 fi
650 done
651
652 for d in dev proc sys sysroot root run run/lock run/initramfs; do
653 if [ -L "/$d" ]; then
654 inst_symlink "/$d"
655 else
656 mkdir -m 0755 -p "$initdir/$d"
657 fi
658 done
659
660 ln -sfn /run "$initdir/var/run"
661 ln -sfn /run/lock "$initdir/var/lock"
662 else
663 for d in lib "$libdir"; do
664 [[ -e "${initdir}${prefix}/$d" ]] && continue
665 if [ -h "/$d" ]; then
666 inst "/$d" "${prefix}/$d"
667 else
668 mkdir -m 0755 -p "${initdir}${prefix}/$d"
669 fi
670 done
671 fi
672
673 if [[ $kernel_only != yes ]]; then
674 mkdir -p "${initdir}/etc/cmdline.d"
675 for _d in $hookdirs; do
676 mkdir -m 0755 -p ${initdir}/lib/dracut/hooks/$_d
677 done
678 fi
679
680 mkdir -p "$initdir/.kernelmodseen"
681
682 mods_to_load=""
683 # check all our modules to see if they should be sourced.
684 # This builds a list of modules that we will install next.
685 for_each_module_dir check_module
686 for_each_module_dir check_mount
687
688 modules_loaded=" "
689 # source our modules.
690 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
691 _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
692 if strstr "$mods_to_load" " $_d_mod "; then
693 [[ $show_modules = yes ]] && echo "$_d_mod" || \
694 dinfo "*** Including module: $_d_mod ***"
695 if [[ $kernel_only = yes ]]; then
696 module_installkernel $_d_mod
697 else
698 module_install $_d_mod
699 if [[ $no_kernel != yes ]]; then
700 module_installkernel $_d_mod
701 fi
702 fi
703 mods_to_load=${mods_to_load// $_d_mod /}
704 modules_loaded+="$_d_mod "
705 fi
706 done
707 unset moddir
708 dinfo "*** Including modules done ***"
709
710 ## final stuff that has to happen
711
712 # generate module dependencies for the initrd
713 if [[ -d $initdir/lib/modules/$kernel ]] && \
714 ! depmod -a -b "$initdir" $kernel; then
715 dfatal "\"depmod -a $kernel\" failed."
716 exit 1
717 fi
718
719 while pop include_src src && pop include_target tgt; do
720 if [[ $src && $tgt ]]; then
721 if [[ -f $src ]]; then
722 inst $src $tgt
723 else
724 ddebug "Including directory: $src"
725 mkdir -p "${initdir}/${tgt}"
726 # check for preexisting symlinks, so we can cope with the
727 # symlinks to $prefix
728 for i in "$src"/*; do
729 [[ -e "$i" || -h "$i" ]] || continue
730 s=${initdir}/${tgt}/${i#$src/}
731 if [[ -d "$i" ]]; then
732 if ! [[ -e "$s" ]]; then
733 mkdir -m 0755 -p "$s"
734 chmod --reference="$i" "$s"
735 fi
736 cp -a -t "$s" "$i"/*
737 else
738 cp -a -t "$s" "$i"
739 fi
740 done
741 fi
742 fi
743 done
744
745 if [[ $kernel_only != yes ]]; then
746 for item in $install_items; do
747 dracut_install -o "$item"
748 done
749 unset item
750
751 while pop fstab_lines line; do
752 echo "$line 0 0" >> "${initdir}/etc/fstab"
753 done
754
755 for f in $add_fstab; do
756 cat $f >> "${initdir}/etc/fstab"
757 done
758
759 # make sure that library links are correct and up to date
760 for f in /etc/ld.so.conf /etc/ld.so.conf.d/*; do
761 [[ -f $f ]] && inst_simple "$f"
762 done
763 if ! ldconfig -r "$initdir"; then
764 if [[ $UID = 0 ]]; then
765 derror "ldconfig exited ungracefully"
766 else
767 derror "ldconfig might need uid=0 (root) for chroot()"
768 fi
769 fi
770 fi
771
772 rm -fr "$initdir/.kernelmodseen"
773
774
775 if (($maxloglvl >= 5)); then
776 ddebug "Listing sizes of included files:"
777 du -c "$initdir" | sort -n | ddebug
778 fi
779
780 # strip binaries
781 if [[ $do_strip = yes ]] ; then
782 for p in strip grep find; do
783 if ! type -P $p >/dev/null; then
784 derror "Could not find '$p'. You should run $0 with '--nostrip'."
785 do_strip=no
786 fi
787 done
788 fi
789
790 if [[ $do_strip = yes ]] ; then
791 for f in $(find "$initdir" -type f \
792 \( -perm -0100 -or -perm -0010 -or -perm -0001 \
793 -or -path '*/lib/modules/*.ko' \) ); do
794 dinfo "Stripping $f"
795 strip -g "$f" 2>/dev/null|| :
796 done
797 fi
798
799 type hardlink &>/dev/null && {
800 hardlink "$initdir" 2>&1
801 }
802
803 if strstr "$modules_loaded" " fips " && command -v prelink >/dev/null; then
804 for dir in "$initdir/bin" \
805 "$initdir/sbin" \
806 "$initdir/usr/bin" \
807 "$initdir/usr/sbin"; do
808 [[ -L "$dir" ]] && continue
809 for i in "$dir"/*; do
810 [[ -x $i ]] && prelink -u $i &>/dev/null
811 done
812 done
813 fi
814
815 if ! ( cd "$initdir"; find . |cpio -R 0:0 -H newc -o --quiet| \
816 $compress > "$outfile"; ); then
817 dfatal "dracut: creation of $outfile failed"
818 exit 1
819 fi
820
821 dinfo "Wrote $outfile:"
822 dinfo "$(ls -l "$outfile")"
823
824 exit 0