]> git.pld-linux.org Git - projects/geninitrd.git/blame - geninitrd
Timeout here is not a good idea. rootfs cannot be mounted and kernel oopses due to...
[projects/geninitrd.git] / geninitrd
CommitLineData
bb529f94
JK
1#!/bin/sh
2
3# geninitrd
4#
45d4d8cb 5# by PLD Linux Team
bb529f94 6#
9e1ceabe 7# based on mkinitrd from RedHat Linux
e4b07ddc 8#
c31050f3 9
b7114dde 10VERSION='devel'
ca2c2012 11PROGRAM=${0##*/}
bb529f94
JK
12
13. /etc/rc.d/init.d/functions
ded87775 14. /lib/geninitrd/functions
e2405b29 15. /etc/sysconfig/system
bb529f94 16
c124d0cf
ER
17# list of geninitrd modules which need setup routine after commandline args parsing
18GENINITRD_MODS=""
c3667d07 19COMPRESS=yes
897d14b7 20STRIP=/usr/bin/strip
bb529f94
JK
21target=""
22kernel=""
23force=""
24verbose=""
25MODULES=""
26img_vers=""
c3667d07 27fstab=/etc/fstab
c3667d07 28modext=.o
4e9eb79c 29rootdev_nr=0
738c05d8
ER
30# device node for rootfs from fstab
31rootdev=""
bb529f94 32
8bd582f1
ER
33# internal variables
34# is /dev on tmpfs
b64f015b
ER
35dev_mounted=no
36# is /proc mounted
37proc_mounted=no
38# is /sys mounted
39sys_mounted=no
40# is /tmp mounted on tmpfs
41tmp_mounted=no
42
43# are /dev nodes already created from /proc/devices info?
8bd582f1 44proc_partitions=no
6b013929 45
b64f015b 46usage() {
46768f45 47 echo "Usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
ac085800 48 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
60086bea 49 echo " [--compress=yes|zstd|xz|lzma|bzip2|gzip|lzo]"
76a48507 50 echo " [--nostrip ] [--strip PATH/strip] [--strip=PATH/strip]"
92ed99b6 51 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
ba5d09f0 52 echo " [--with-bootsplash] [--without-bootsplash]"
6c69a2d4
ER
53 echo " [--with-fbsplash] [--without-fbsplash]"
54 echo " [--with-fbcondecor] [--without-fbcondecor]"
e4b07ddc 55 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
ba5d09f0 56 echo " [--with-suspend] [--without-suspend]"
1cd2aabd 57 echo " [--with-tuxonice] [--without-tuxonice]"
ecd7bf46
ER
58 echo " [--without-dmraid]"
59 echo " [--with-multipath=DEVPATH] [--without-multipath]"
3ef3d717 60 echo " [--without-blkid] [--without-luks]"
ac085800 61 echo " <initrd-image> <kernel-version>"
553786c4 62 echo ""
46768f45
ER
63 echo "Example:"
64
0ad676eb 65 local kdir kver dir=${target:-/boot}
46768f45
ER
66 for kdir in /lib/modules/*; do
67 [ -d $kdir ] || continue
68 kver=${kdir##*/}
dfe1a27c 69 echo " $0 -f --initrdfs=initramfs $dir/initrd-$kver.gz $kver $verbose"
63514069 70 done | sort -V
bb529f94
JK
71}
72
779a218a 73msg() {
f4010f7f
AM
74 echo "$PROGRAM: $*"
75}
76
77warn() {
4a60c01f 78 msg "WARNING: $*" >&2
779a218a
AM
79}
80
02ba8ab7 81verbose() {
34f3f0e9 82 [ -n "$verbose" ] && msg "$*" >&3
02ba8ab7
ER
83}
84
94769f11 85debug() {
02ba8ab7 86 [ x"$verbose" = x"-v -v" ] && msg "$*" >&3
94769f11 87}
aa69da6e 88
2b945b6b
ER
89# add initrd code to print to kmsg
90# @param string message
91# @param int loglevel. defaults to "6" (info)
92# Log levels can be:
93# Name String Meaning
94# KERN_EMERG "0" Emergency messages, system is about to crash or is unstable
95# KERN_ALERT "1" Something bad happened and action must be taken immediately
96# KERN_CRIT "2" A critical condition occurred like a serious hardware/software failure
97# KERN_ERR "3" An error condition, often used by drivers to indicate difficulties with the hardware
98# KERN_WARNING "4" A warning, meaning nothing serious by itself but might indicate problems
99# KERN_NOTICE "5" Nothing serious, but notably nevertheless. Often used to report security events.
100# KERN_INFO "6" Informational message e.g. startup information at driver initialization
101# KERN_DEBUG "7" Debug messages
102# KERN_CONT "c" "continued" line of log printout (only done after a line that had no enclosing \n)
103kmsg() {
104 local msg="$1" level=${2:-6}
105 echo "echo '<$level>$msg' > /dev/kmsg" | add_linuxrc
106}
107
bf6c3fcb
ER
108# aborts program abnormally
109die() {
b5f5c089 110 local rc=${2:-1}
046c68c9 111 msg "ERROR: $1" >&2
bf6c3fcb
ER
112 exit $rc
113}
114
684d5d2a
ER
115# find program from specified paths
116find_tool() {
27442691 117 local x p b n
c45a111c 118 local paths="$initrd_dirs /bin /sbin /usr/bin /usr/sbin"
684d5d2a 119 for x in "$@"; do
5493388d 120 debug "find_tool: checking $x"
684d5d2a
ER
121 if [ -x "$x" ]; then
122 echo $x
02ba8ab7 123 verbose "find_tool: found $x"
684d5d2a
ER
124 return 0
125 fi
27442691
JR
126 n="$x"
127 for p in $paths; do
128 b=$(basename $x)
5493388d 129 debug "find_tool: checking $p/$b"
27442691
JR
130 if [ -x "$p/$b" ]; then
131 echo $p/$b
132 verbose "find_tool: found $p/$b"
133 return 0
134 fi
135 n="$n $p/$b"
136 done
684d5d2a 137 done
27442691 138 debug "find_tool: did not find any of: $n"
684d5d2a
ER
139 return 1
140}
141
c124d0cf
ER
142# loads geninitrd modules
143geninitrd_load_mods() {
144 local mod
145 for mod in "$@"; do
146 if [ ! -f /lib/geninitrd/mod-$mod.sh ]; then
147 die "$mod geninitrd module can't be loaded"
148 fi
149 . /lib/geninitrd/mod-$mod.sh
150
c34c6a69 151 GENINITRD_MODS="$GENINITRD_MODS $mod"
c124d0cf
ER
152 done
153}
154
155# setup geninitrd modules
156geninitrd_setup_mods() {
b7114dde 157 local mod
c124d0cf
ER
158
159 for mod in $GENINITRD_MODS; do
b7114dde 160 debug "# $mod"
c34c6a69
ER
161
162 # some mods want init
163 if type setup_mod_$mod > /dev/null; then
164 eval setup_mod_$mod
165 fi
c124d0cf
ER
166 done
167}
168
c6c6ce01
ER
169# append text to /linuxrc
170# takes STDIN as input
171add_linuxrc() {
b64f015b 172 cat >> "$RCFILE"
c6c6ce01
ER
173}
174
b64f015b
ER
175# generate code to mount /dev on tmpfs and create initial nodes
176# can be called multiple times. /dev is cleaned up (umounted) automatically at
177# the end of script.
178mount_dev() {
b64f015b
ER
179 # we already generated tmpfs code; return
180 if is_yes "$dev_mounted"; then
181 return
182 fi
183
184 dev_mounted=yes
185
186 busybox_applet mount mknod mkdir
187 add_linuxrc <<-EOF
188 : 'Creating /dev'
621695f6
AF
189 if ! mount -t devtmpfs -o mode=0755,nosuid devtmpfs /dev > /dev/null 2>&1; then
190 mount -o mode=0755,nosuid -t tmpfs tmpfs /dev
13659675
AM
191 mknod -m 600 /dev/console c 5 1
192 mknod -m 666 /dev/null c 1 3
193 mknod -m 666 /dev/zero c 1 5
194 mknod -m 666 /dev/random c 1 8
195 mknod -m 600 /dev/snapshot c 10 231
196 mknod -m 666 /dev/urandom c 1 9
197 mknod -m 666 /dev/ptmx c 5 2
198 mknod -m 644 /dev/kmsg c 1 11
621695f6 199 fi
b64f015b
ER
200 mkdir /dev/pts
201 mkdir /dev/shm
202 EOF
203}
204
ff9aded5
AM
205# load font
206load_font() {
207 local font
208 [ ! -r /etc/sysconfig/console ] && return
209 . /etc/sysconfig/console
210 if [ -n "$CONSOLEFONT" ]; then
211 font=$(ls -1 /lib/kbd/consolefonts/${CONSOLEFONT}*.gz 2> /dev/null)
212 if [ -n "$font" ]; then
213 verbose "Loading font $font"
214 busybox_applet loadfont
215 inst_d "/lib/kbd/consolefonts"
216 cp -a "$font" "$DESTDIR/lib/kbd/consolefonts/"
217 gunzip ${DESTDIR}/lib/kbd/consolefonts/${CONSOLEFONT}*.gz
218 font=${font%.gz}
219 echo "loadfont < $font" | add_linuxrc
220 fi
221 fi
222}
223
b64f015b
ER
224# generate code to mount /proc on initrd
225# can be called multiple times
226mount_proc() {
227 if is_yes "$proc_mounted"; then
228 return
229 fi
230
231 proc_mounted=yes
2bface63
ER
232 if [ "$INITRDFS" = "initramfs" ]; then
233 # /proc is mounted with initramfs 2.6.22.14 kernel
234 # XXX: remove when it is clear why proc was already mounted
235 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
236 else
237 echo "mount -t proc none /proc" | add_linuxrc
238 fi
b64f015b
ER
239}
240
241# generate code to mount /sys on initrd
242# can be called multiple times
243mount_sys() {
244 if is_yes "$sys_mounted"; then
245 return
246 fi
247
248 sys_mounted=yes
249 echo "mount -t sysfs none /sys" | add_linuxrc
250}
251
252# generate code to mount /tmp on initrd
253# can be called multiple times
254mount_tmp() {
255 if [ "$INITRDFS" = "initramfs" ]; then
256 # initramfs is read-write filesystem, no need for tmpfs
257 return
258 fi
259
260 if is_yes "$tmp_mounted"; then
261 return
262 fi
263
264 tmp_mounted=yes
265 echo "mount -t tmpfs none /tmp" | add_linuxrc
266}
267
d63131e0
AF
268# generate code to mount /run on initrd
269# can be called multiple times
270mount_run() {
271 if is_yes "$run_mounted"; then
272 return
273 fi
274
275 run_mounted=yes
7e3c63ed 276 echo "mount -t tmpfs run /run -o mode=0755,noexec,nosuid,nodev" | add_linuxrc
d63131e0
AF
277}
278
b64f015b 279# unmount all mountpoints mounted by geninitrd
c6d164fb 280# try to move pseudo filesystems to newroot if possible
b64f015b 281umount_all() {
ec49b7e6
ER
282
283 add_linuxrc <<-'EOF'
903f21ea 284 : Last shell before umounting all and giving control over to real init.
ec49b7e6
ER
285 debugshell
286 EOF
5b70f84d 287
d63131e0 288 if is_yes "$run_mounted"; then
c6d164fb
ER
289 add_linuxrc <<-EOF
290 mount --bind /run /newroot/run
291 umount /run
292 EOF
d63131e0
AF
293 run_mounted=no
294 fi
b64f015b 295 if is_yes "$dev_mounted"; then
c6d164fb
ER
296 add_linuxrc <<-EOF
297 mount --bind /dev /newroot/dev
298 umount /dev
299 EOF
b64f015b
ER
300 dev_mounted=no
301 fi
b64f015b 302 if is_yes "$sys_mounted"; then
c6d164fb
ER
303 add_linuxrc <<-EOF
304 mount --bind /sys /newroot/sys
305 umount /sys
306 EOF
b64f015b
ER
307 sys_mounted=no
308 fi
c6d164fb
ER
309 if is_yes "$proc_mounted"; then
310 add_linuxrc <<-EOF
311 mount --bind /proc /newroot/proc
312 umount /proc
313 EOF
314 proc_mounted=no
315 fi
b64f015b
ER
316 if is_yes "$tmp_mounted"; then
317 echo 'umount /tmp' | add_linuxrc
318 tmp_mounted=no
319 fi
320}
321
9299682f
ER
322# Checks if busybox has support for APPLET(s)
323# Exits from geninitrd if the support is not present.
324#
325# NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
326busybox_applet() {
30495bbf 327 local err=0 applet
9299682f
ER
328
329 if [ -z "$busybox_functions" ]; then
684d5d2a 330 local tmp=$($busybox 2>&1)
9b1373fb
ER
331
332 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
333 if [[ "$tmp" = *applet\ not\ found* ]]; then
334 local t=$(mktemp -d)
684d5d2a 335 ln -s $busybox $t/busybox
9b1373fb
ER
336 local tmp=$($t/busybox 2>&1)
337 rm -rf $t
338 fi
339
340 busybox_functions=$(echo "$tmp" | \
9299682f
ER
341 sed -ne '/Currently defined functions:/,$p' | \
342 xargs | sed -e 's,.*Currently defined functions: ,,'
343 )
344 fi
345 for applet in $*; do
346 local have
347 # try cache
348 eval have='$'busybox_have_$applet
349 if [ -z "$have" ]; then
e871f497 350 have=$(echo "$busybox_functions" | grep -Ec "( |^)$applet(,|$)")
9299682f 351 if [ "$have" = 0 ]; then
f4010f7f 352 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
9299682f
ER
353 err=1
354 fi
355 eval busybox_have_$applet=$have
356 fi
357 done
358 if [ $err = 1 ]; then
00eaa938 359 die "Aborted"
9299682f
ER
360 fi
361}
362
755e5cdc
ER
363# Extract the .config file from a kernel image
364# uses extract-ikconfig from kernel sources (scripts/extract-ikconfig)
365ikconfig() {
61d20b49 366 local kofile=$(modinfo -k $kernel -n configs 2> /dev/null)
755e5cdc
ER
367 if [ -n "$kofile" ]; then
368 /lib/geninitrd/extract-ikconfig $kofile
7283bf35 369 return
25cb53df 370 fi
7283bf35
ER
371
372 # see if config available as separate file
373 if [ -f /boot/config-$kernel ]; then
374 cat /boot/config-$kernel
375 return
376 fi
377
378 # finally try vmlinuz itself
379 /lib/geninitrd/extract-ikconfig /boot/vmlinuz-$kernel
25cb53df
ER
380}
381
faee129c
AM
382# @param $module
383basename_module() {
384 local module=$1
385
386 module=${module##*/}
387 module=${module%$modext*}
388 echo $module
389}
390
7ffba534
ER
391# Finds module dependencies
392#
7ffba534
ER
393# @param $module
394#
046c68c9 395# Outputs full path to module and it's dependencies
7ffba534 396find_depmod() {
fe280785 397 local module="$1"
046c68c9
ER
398 local skiperrors=0
399
400 # if module is prefixed with dash, we should ignore errors if the module
401 # can't be found.
402 if [ ${module#-} != $module ]; then
403 skiperrors=1
404 module=${module#-}
405 fi
406
046c68c9
ER
407 # This works when user has module-init-tools installed even on 2.4 kernels
408 local modprobe
409 modprobe=$(modprobe --set-version $kernel --show-depends $module --ignore-install 2>&1)
410
411 if [ $? != 0 ]; then
412 if [ $skiperrors = 1 ]; then
0c7e9123 413 return 0
7cac5014 414 fi
046c68c9 415 echo >&2 "$modprobe"
7cac5014 416
7ffba534 417 if ! is_no "$EXIT_IF_MISSING"; then
046c68c9 418 die "$module: module not found for $kernel kernel"
7ffba534 419 fi
046c68c9
ER
420
421 warn "$module: module not found for $kernel kernel"
422 warn "If $module isn't compiled in kernel then this initrd may not start your system."
7ffba534
ER
423 fi
424
faee129c
AM
425 local smodule
426
046c68c9 427 echo "$modprobe" | \
c25765ed 428 while read insmod modpath options; do
faee129c
AM
429 if [ "$insmod" = "insmod" ]; then
430
431 # XXX: find a away to autodetect
432 smodule=$(basename_module $modpath)
433 case "$smodule" in
b771ab7f 434 btrfs)
dfc0f1be 435 warn "mounting multidevice btrfs volume requires rootfsflags=device=/dev/...,device=/dev/... kernel option"
b771ab7f
AM
436 find_depmod "-libcrc32c"
437 ;;
b5a01dda
AM
438 ext4)
439 find_depmod "-libcrc32c"
440 ;;
bb0ca032 441 crc-t10dif)
e7d76a06 442 find_depmod "-crct10dif-pclmul"
bb0ca032
AM
443 find_depmod "-crct10dif"
444 ;;
faee129c
AM
445 libcrc32c)
446 find_depmod "-crc32c-intel"
447 find_depmod "-crc32c"
448 ;;
dd1e5379
AM
449 virtio_blk|virtio_scsi)
450 find_depmod "-virtio_pci"
451 find_depmod "-virtio_mmio"
452 ;;
faee129c
AM
453 esac
454
455 echo $modpath
456 fi
7ffba534 457 done
0c7e9123 458 return 0
7ffba534
ER
459}
460
4a60c01f
AM
461find_firmware() {
462 local module="$1"
601127ea
ER
463
464 # no firmware support in 2.4 kernels
465 if [ "$kernel_version_long" -lt "002005048" ]; then
466 return
467 fi
468 echo -n $(NEW_MODINFO=1 modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
4a60c01f
AM
469}
470
046c68c9
ER
471# @param $module
472find_module() {
473 local mod depmod module=$1
ac085800 474
046c68c9 475 depmod=$(find_depmod $module) || exit 1
fe280785 476 for mod in $depmod; do
7ffba534 477 mod=${mod#/lib/modules/$kernel/}
fe280785
ER
478
479 # add each module only once
480 local m have=0
481 for m in $MODULES; do
482 [ $m = $mod ] && have=1
483 done
484 if [ $have = 0 ]; then
c2eb7d4f 485 MODULES="$MODULES $mod"
fe280785 486 fi
10c3df06 487 done
bb529f94
JK
488}
489
034fdd5d
ER
490# install a file to temporary mount image.
491# it will operate recursively (copying directories)
492# and will symlink destinations if source is symlink.
bb529f94 493inst() {
17e97aec 494 if [ $# -lt 2 ]; then
a9ace64a 495 die 'Usage: inst <file> [<file>] <destination>'
c31050f3 496 fi
17e97aec
ER
497
498 local src i=0 c=$(($# - 1))
499 while [ $i -lt $c ]; do
500 src="$src $1"
501 i=$((i + 1))
502 shift
503 done
504 local dest=$1
505 set -- $src
ce40ba21 506 local parentDir=$(dirname $DESTDIR$dest)
02ba8ab7 507 if [ ! -d "$parentDir" ]; then
7f5eccc0 508 verbose "+ mkdir -p DESTDIR${parentDir#$DESTDIR}"
02ba8ab7
ER
509 mkdir -p $parentDir
510 fi
7f5eccc0 511 verbose "+ cp $* DESTDIR$dest"
b9c1a1c5 512 cp -HRp "$@" "$DESTDIR$dest"
bb529f94
JK
513}
514
dab92b1d 515inst_d() {
17e97aec 516 if [ $# = 0 ]; then
a9ace64a 517 die 'Usage: inst_d <destination> <destination>'
034fdd5d 518 fi
7c239866 519 local dir
034fdd5d 520 for dir in "$@"; do
9b557a09 521 install -d "$DESTDIR$dir"
034fdd5d
ER
522 done
523}
524
209061e3
ER
525# install executable and it's shared libraries
526inst_exec() {
17e97aec 527 if [ $# -lt 2 ]; then
3601c2fa 528 die "Invalid params ($@), Usage: inst_exec <file>[, <file>] <destination>"
17e97aec 529 fi
209061e3
ER
530 local src i=0 c=$(($# - 1))
531 while [ $i -lt $c ]; do
532 src="$src $1"
533 i=$((i + 1))
534 shift
535 done
9b532fe6 536 local dest=$1
209061e3
ER
537 set -- $src
538
9b532fe6
ER
539 inst "$@" $dest
540
042e65b6 541 local obj lib libs libs_additional libdir
10e8125f 542 for obj in "$@"; do
66aec48b 543 case "$obj" in
68c2e3b2 544 /lib/ld-linux.so.2 | /lib64/ld-linux-x86-64.so.2 | /libx32/ld-linux-x32.so.2)
66aec48b 545 continue
042e65b6
AM
546 ;;
547 /lib/libpthread.so* | /lib64/libpthread.so* | /libx32/libpthread.so*)
548 libs_additional="${obj%/libpthread*}/libgcc_s.so.1"
549 ;;
66aec48b
ER
550 esac
551
042e65b6 552
66aec48b 553 libs=$(ldd "$obj" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
042e65b6 554 for lib in $libs $libs_additional; do
1be24d6e
ER
555 libdir=$(cd $(dirname "$lib"); pwd)
556 if [ ! -f "$DESTDIR/$lib" ]; then
557 inst_d $libdir
558 inst_exec $lib $libdir
66aec48b
ER
559 fi
560 done
209061e3 561 done
c7ade647
ER
562
563 # hack for uclibc linked binaries requiring this fixed path
564 # XXX: shouldn't rpath be used here instead so th
54c9f5ee
AM
565 for _lib in $(get_libdir LIBDIR); do
566 if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
567 lib=$DESTDIR/$_lib/libc.so.0
568 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
569 libdir=$(cd $(dirname "$lib"); pwd)
570 if [ ! -e $DESTDIR$libdir ]; then
571 libdir=$(dirname "$libdir")
572 inst_d $libdir
573 verbose "+ ln -s /$_lib $DESTDIR$libdir"
574 ln -s /$_lib $DESTDIR$libdir
575 break
576 fi
c7ade647 577 fi
54c9f5ee 578 done
209061e3
ER
579}
580
82474db9
ER
581# output modules.conf / modprobe.conf
582modprobe_conf() {
583 echo "$modprobe_conf_cache"
584}
585
38ac83a5
ER
586# return options for MODULE
587# @param $1 module name
588modprobe_options() {
589 local module=$1
915ff812 590 local options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}')
38ac83a5
ER
591 echo ${options# }
592}
593
82474db9
ER
594#
595# defaults to modprobe -c if not told otherwise, this means include statements
596# work from there.
597cache_modprobe_conf() {
707f5e60 598 if [ "$kernel_version" -lt "002005" ]; then
82474db9
ER
599 modulefile=/etc/modules.conf
600 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
601 modulefile=/etc/conf.modules
602 fi
603 fi
604
605 if [ -n "$modulefile" ]; then
d8056591 606 debug "Using $modulefile for modules config"
99e7251e
ER
607 modprobe_conf_cache=$(cat $modulefile | awk '!/^[\t ]*#/ { print }')
608
82474db9 609 else
d8056591 610 debug "Using modprobe -c to get modules config"
99e7251e 611 modprobe_conf_cache=$(modprobe -c --set-version $kernel | awk '!/^[\t ]*#/ { print }')
82474db9
ER
612 fi
613}
614
bc0d6f2d 615# find modules for $devpath
d8056591 616find_modules_for_devpath() {
bc0d6f2d
ER
617 local devpath="$1"
618 if [ -z "$devpath" ]; then
d8056591 619 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
f6536797 620 fi
ac085800 621
c2eb7d4f
ER
622 if [[ "$devpath" = /dev/dm-* ]]; then
623 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
d2cb46cf 624 devpath=$(dm_node "$devpath")
c2eb7d4f
ER
625 fi
626
336018a5 627 if [ -L "$devpath" ] && ! is_lvm "$devpath" && ! is_luks "$devpath"; then
c2eb7d4f
ER
628 # sanitize things like:
629 # /dev/block/104:2 -> /dev/cciss/c0d0p2
630 devpath=$(readlink -f "$devpath")
631 fi
632
02ba8ab7 633 verbose "Finding modules for device path $devpath"
bc0d6f2d 634
3ef3d717
ER
635 if is_luks "$devpath"; then
636 find_modules_luks "$devpath"
637 return
638 fi
639
74d45ce1
ER
640 if is_nfs "$devpath"; then
641 find_modules_nfs "$devpath"
d9179777
ER
642 return
643 fi
644
e16414d9 645 if is_md "$devpath"; then
df738638 646 find_modules_md "$devpath"
d9179777
ER
647 return
648 fi
649
c3b54060 650 if is_multipath "$devpath"; then
07137fe3 651 if find_modules_multipath "$devpath"; then
9baf4f3f 652 return
9baf4f3f 653 fi
ecd7bf46 654
9baf4f3f
ER
655 # fallback
656 fi
657
36523626 658 if is_dmraid "$devpath"; then
c083ae23
ER
659 if find_modules_dmraid "$devpath"; then
660 return
661 fi
662 # fallback
663 fi
664
35043b20
ER
665 if is_scsi "$devpath"; then
666 find_modules_scsi "$devpath"
d9179777
ER
667 return
668 fi
669
30ca4815 670 if is_ide "$devpath"; then
bc0d6f2d 671 find_modules_ide "$devpath"
d9179777
ER
672 return
673 fi
674
0bdde1a1
ER
675 if [[ "$devpath" == /dev/bcache* ]]; then
676 find_modules_bcache "$devpath"
677 return
678 fi
679
07b09cf9 680 if [[ "$devpath" == /dev/rd/* ]]; then
046c68c9 681 find_module "DAC960"
c3313cd6 682 rootdev_add=/dev/rd/
d9179777
ER
683 return
684 fi
685
07b09cf9 686 if [[ "$devpath" == /dev/ida/* ]]; then
046c68c9 687 find_module "cpqarray"
c3313cd6 688 rootdev_add=/dev/ida/
d9179777
ER
689 return
690 fi
691
08651ad1 692 if [[ "$devpath" == /dev/cciss/* ]]; then
c3313cd6 693 rootdev_add=/dev/cciss/
df11fbe8
ER
694
695 # load hpsa for future kernels, cciss for backwards compat
696 if [ "$kernel_version_long" -ge "003000000" ]; then
697 find_module "hpsa" "-cciss"
649df3de 698 find_modules_scsi "$devpath"
df11fbe8
ER
699 else
700 find_module "cciss"
701 fi
702
d9179777
ER
703 return
704 fi
705
07b09cf9 706 if [[ "$devpath" == /dev/ataraid/* ]]; then
ac085800 707 find_modules_ide
046c68c9 708 find_module "ataraid"
99e7251e 709 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ { print $3 }')
9ae446b9 710 if [ -n "$ataraidmodules" ]; then
7c38b114 711 # FIXME: think about modules compiled in kernel
82474db9 712 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
7c38b114
AF
713 fi
714 for n in $ataraidmodules; do
046c68c9 715 find_module "$n"
7c38b114 716 done
c3313cd6 717 rootdev_add=/dev/ataraid/
d9179777
ER
718 return
719 fi
720
7c38b114 721 # check to see if we need to set up a loopback filesystem
07b09cf9 722 if [[ "$devpath" == /dev/loop* ]]; then
00eaa938 723 die "Sorry, root on loop device isn't supported."
7c38b114
AF
724 # TODO: rewrite for bsp and make nfs ready
725 if [ ! -x /sbin/losetup ]; then
00eaa938 726 die "losetup is missing"
7c38b114 727 fi
bc0d6f2d 728 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
82474db9 729 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
42820142 730 die "The root filesystem is on a $devpath, but there is no magic entry in $fstab for this device. Consult the $PROGRAM man page for more information"
7c38b114
AF
731 fi
732
733 line="`awk '/'$key'/ { print $0; }' $fstab`"
734 loopDev="$(echo $line | awk '{print $3}')"
735 loopFs="$(echo $line | awk '{print $4}')"
736 loopFile="$(echo $line | awk '{print $5}')"
737
738 BASICMODULES="$BASICMODULES -loop"
046c68c9 739 find_module "-$loopFs"
7c38b114 740 BASICMODULES="$BASICMODULES -${loopFs}"
d9179777
ER
741 return
742 fi
743
67aa84bd
ER
744 if is_lvm "$devpath"; then
745 find_modules_lvm "$devpath"
d9179777 746 return
7c38b114
AF
747 fi
748}
749
b64f015b 750firmware_install_module() {
c3667d07 751 local module="$1"
c6c6ce01 752 local firmware_files="$2"
9ed6e1db 753
02ba8ab7 754 verbose "Adding Firmwares ($firmware_files) to initrd for module $module"
9ed6e1db 755 # firmware not yet installed
9b557a09 756 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
034fdd5d 757 inst_d /lib/firmware
9b557a09 758cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
9ed6e1db 759#!/bin/sh -e
45294dc1
ER
760# handle only firmware add requests
761if [ "$SUBSYSTEM" != "firmware" ]; then
762 exit 0
763fi
764if [ "$ACTION" != "add" ]; then
765 exit 0
766fi
8639f99a
AM
767echo 1 > /sys$DEVPATH/loading
768cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
769echo 0 > /sys$DEVPATH/loading
770exit 0
9ed6e1db 771EOF
9b557a09 772 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
63cb815e
ER
773
774 # setup firmware loader agent
775 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
9ed6e1db
AM
776 fi
777
778 for firmware in $firmware_files; do
80b23733 779 if [ -f "/lib/firmware/$kernel/$firmware" ]; then
486d26a5 780 FIRMWAREDIR=${firmware%/*}
4a9920e7 781 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
80b23733
ER
782 inst /lib/firmware/$kernel/$firmware /lib/firmware/$firmware
783 elif [ -f "/lib/firmware/$firmware" ]; then
c661b23c 784 FIRMWAREDIR=${firmware%/*}
785 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
80b23733 786 inst /lib/firmware/$firmware /lib/firmware/$firmware
c661b23c 787 else
6652b089 788 warn "Possible missing firmware file /lib/firmware/$firmware or /lib/firmware/$kernel/$firmware for module $module."
4a60c01f 789 fi
9ed6e1db
AM
790 done
791
b64f015b 792 mount_sys
9ed6e1db
AM
793}
794
2a5bcca9 795modules_install() {
c3667d07
ER
796 local modules="$1"
797 local mod
2a5bcca9
AM
798
799 for mod in $modules; do
fe280785 800 MODULEDIR=${mod%/*}
4a9920e7 801 inst_d "/lib/modules/$kernel/$MODULEDIR"
9b557a09 802 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
5d62840e
AM
803 case $mod in
804 *.gz)
b657b865 805 gunzip "$DESTDIR/lib/modules/$kernel/$mod" || die "Can't uncompress gz"
5d62840e
AM
806 mod=${mod%.gz}
807 ;;
808 *.xz)
b657b865 809 xz -d "$DESTDIR/lib/modules/$kernel/$mod" || die "Can't uncompress xz"
5d62840e
AM
810 mod=${mod%.xz}
811 ;;
812 *.bz2)
b657b865 813 bzip2 -d "$DESTDIR/lib/modules/$kernel/$mod" || die "Can't uncompress bz2"
5d62840e
AM
814 mod=${mod%.bz2}
815 ;;
816 esac
897d14b7 817 if [ "$STRIP" ] && [ -x "$STRIP" ]; then
5d62840e 818 $STRIP -g --remove-section=.comment "$DESTDIR/lib/modules/$kernel/${mod}"
ccd1f65f 819 fi
2a5bcca9
AM
820 done
821}
822
823modules_add_linuxrc() {
fe280785 824 local mod modpath
ac085800 825
fe280785
ER
826 for mod in "$@"; do
827 # module path without optional compression
828 modpath=${mod%.gz}
5d62840e
AM
829 modpath=${modpath%.xz}
830 modpath=${modpath%.bz2}
fe280785
ER
831
832 # name of the module
8011a76c 833 local module=${modpath##*/}; module=${module%$modext}
38ac83a5 834 local options=$(modprobe_options "$module")
8011a76c
ER
835 local genericname=$(echo $module | tr - _)
836 local usleep=$(eval echo \$MODULE_${genericname}_USLEEP)
837 local firmware=$(eval echo \$MODULE_${genericname}_FIRMWARE)
2a5bcca9 838
3e1d0df9
AM
839 if [ "$module" = "scsi_mod" -a "$kernel_version_long" -ge "002006030" ]; then
840 options="scan=sync $options"
841 fi
842
02ba8ab7 843 if [ x"$verbose" = x"-v" ]; then
8a47b72c
ER
844 s=""
845 if [ "$options" ]; then
846 s="$s with options [$options]"
847 fi
8011a76c
ER
848 if [ "$usleep" ]; then
849 s="$s and $usleep usleep"
8a47b72c 850 fi
02ba8ab7 851 verbose "Loading module [$module]$s"
ac085800
ER
852 fi
853
8011a76c
ER
854 if [ -n "$firmware" ]; then
855 firmware_install_module "$module" "$firmware"
4a60c01f 856 else
06e481d7
ER
857 for file in $(find_firmware "$module"); do
858 firmware_install_module "$module" "$file"
859 done
9ed6e1db 860 fi
4a60c01f 861
18ece493 862 echo "insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
8011a76c
ER
863 if [ -n "$usleep" ]; then
864 echo "usleep $usleep" | add_linuxrc
8e598759 865 fi
e00dcfcb 866 if [ "$module" = "scsi_wait_scan" ]; then
d29583e0
ER
867 if [ "$(busybox_applet rmmod 2>/dev/null; echo $?)" = 0 ]; then
868 echo "rmmod scsi_wait_scan" | add_linuxrc
869 fi
e00dcfcb
AM
870 fi
871
2a5bcca9
AM
872 done
873}
874
82b2dba2
ER
875# Generates /dev nodes based on /proc/partitions information.
876# Needs /proc mounted.
877# Can be called multiple times.
878initrd_gen_devices() {
879 if is_yes "$proc_partitions"; then
880 return
881 fi
882 proc_partitions=yes
335cd101 883
82b2dba2
ER
884 mount_dev
885 add_linuxrc <<-'EOF'
886 : 'Making device nodes'
887 cat /proc/partitions | (
8d4aba01 888 # ignore first two lines: header, empty line
82b2dba2 889 read b; read b
2cc3ae8b 890
82b2dba2
ER
891 while read major minor blocks dev rest; do
892 node=/dev/$dev
893 mkdir -p ${node%/*}
6b45dd6c 894 [ -e $node ] || mknod -m 660 $node b $major $minor
82b2dba2
ER
895 done
896 )
897 EOF
898}
bb529f94 899
82b2dba2 900
4828c787 901initrd_gen_setrootdev() {
02ba8ab7 902 verbose "Adding rootfs finding based on kernel cmdline root= option support."
71b2d771 903 busybox_applet ls
b7114dde 904 debug "Current /proc/partitions:\n$(sed -e 's,^,| ,' /proc/partitions)"
82b2dba2 905 add_linuxrc <<-'EOF'
dcdf6b49
ER
906 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
907 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
94da85db
ER
908 # fallback to ls, try two different formats
909 # http://lists.pld-linux.org/mailman/pipermail/pld-devel-en/2014-May/023915.html
910 if [ "${rootnr:-0}" = 0 -a -e "$ROOT" ]; then
911 # busybox up to 1.22
5efa9a2e 912 rootnr="$(busybox ls -lL ${ROOT} | busybox awk '{if (/^b/) { print 256 * $3 + $4; }}')"
71b2d771 913 fi
94da85db
ER
914 if [ "${rootnr:-0}" = 0 -a -e "$ROOT" ]; then
915 # busybox 1.22 and upwards
916 rootnr="$(busybox ls -lL ${ROOT} | busybox awk '{if (/^b/) { print 256 * $5 + $6; }}')"
917 fi
918 if [ "${rootnr:-0}" -gt 0 ]; then
82b2dba2
ER
919 echo "$rootnr" > /proc/sys/kernel/real-root-dev
920 fi
921 fi
b64f015b 922 EOF
1606e343
AM
923}
924
4671d086
ER
925initrd_gen_initramfs_switchroot() {
926 inst_d /newroot
927 if [ "$rootdev" = "/dev/nfs" ]; then
928 echo "rootfs on NFS root=/dev/nfs"
929 else
930 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
931 fi
5845b321
ER
932
933 # parse 'root=xxx' kernel commandline
4671d086 934 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
ec21900e
ER
935
936 # from lilo-23.2/readme/README:
937 # root=<device> changes the root device. This overrides settings that may
938 # have been made in the boot image and on the LILO command line. <device> is
939 # either the hexadecimal device number or the full path name of the device,
940 # e.g. /dev/hda3 [*]
941 #
942 # * The device names are hard-coded in the kernel. Therefore, only the
943 # "standard" names are supported and some less common devices may not be
944 # recognized. In those cases, only numbers can be used.
5436b31f 945 busybox_applet cat
4671d086 946 add_linuxrc <<-'EOF'
7f187a08 947 device=
3564e6b6 948 eval "$(busybox awk -v root="$ROOT" '
512f3599
TP
949 function h2d(str, hstr, res, num, n, digit, i) { # http://9fans.net/archive/2006/09/261
950 hstr = "0123456789abdcef"; res = 0;
f9194b15
ER
951 n = split(tolower(str), digit, "");
952
953 for (i = 1; i <= n; i++) {
954 num = index(hstr, digit[i]) - 1;
955 res = res + (num * 16 ^ (n - i));
956 }
f9194b15
ER
957 return res;
958 }
4671d086 959 BEGIN {
f9194b15
ER
960 num_pattern_short = "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]";
961 num_pattern = "[0-9a-fA-F]" num_pattern_short;
4671d086 962 dev_pattern = "[hms][a-z][a-z]([0-9])+";
512f3599
TP
963 partition = ""; min = -1; maj = -1;
964
965 if (root ~ "^\/dev\/" dev_pattern "$" || root ~ "^" dev_pattern "$") { # see if we have /dev/hdX or hdX, we can just take partition name
966 partition = root; sub("^/dev/", "", partition);
967 } else { # unify values first
968 if (root ~ "^" num_pattern_short "$") { # change "303" => "0x0303"
3564e6b6 969 root = "0x0" root
512f3599 970 } else if (root ~ "^" num_pattern "$") { # change "0303" => "0x0303"
3564e6b6
ER
971 root = "0x" root
972 }
f9194b15
ER
973 maj = h2d(substr(root, 3, 2));
974 min = h2d(substr(root, 5, 2));
4671d086 975 }
4671d086 976 }
7f187a08 977 partition && $4 == partition { maj = $1; min = $2; }
afa32d0e 978 $1 == maj && $2 == min { partition = $4; }
4671d086 979 END {
512f3599
TP
980 if (maj >= 0 && min >= 0) { printf("maj=%s; min=%s;\n", maj, min); }
981 if (partition) { printf("device=/dev/%s;\n", partition); }
982 }' /proc/partitions)"
4671d086 983
7f187a08 984 if [ -z "$device" ]; then
0d9c261f 985 if [ "$DEBUGINITRD" -a "$DEBUGINITRD" != 'sh' ]; then
5436b31f
AM
986 cat /proc/partitions
987 fi
0fb9dda3 988 device=$ROOT
4671d086
ER
989 fi
990
481bdb77 991 if [ "$device" -a ! -b $device -a "$maj$min" ]; then
6b45dd6c 992 mknod -m 660 $device b $maj $min
7f187a08
ER
993 fi
994
dad8bc39
AM
995 # XXX hack, fallback to rootdev from geninitrd time
996 if [ ! -e "$device" ]; then
11202855
AM
997 EOF
998 add_linuxrc <<-EOF
dad8bc39 999 device="$rootdev"
11202855
AM
1000 EOF
1001 add_linuxrc <<-'EOF'
dad8bc39
AM
1002 echo "DEVICE set to $device based on fstab entry from initrd gen time"
1003 fi
1004
86aa389f
ER
1005 # XXX hack, if no device, try to parse it from /proc/partitions using /proc/sys/kernel/real-root-dev
1006 if [ ! -e "$device" ]; then
1007 rrd=$(cat /proc/sys/kernel/real-root-dev)
1008 major=$(($rrd / 256))
1009 minor=$(($rrd % 256))
1010
1011 while read pmajor pminor blocks dev rest; do
1012 # skip header and empty line
1013 [ -z "$pmajor" -o "$pmajor" = "major" ] && continue
1014
1015 if [ $pmajor = $major -a $pminor = $minor ]; then
1016 device=/dev/$dev
1017 echo "DEVICE set to $device based on real-root-dev"
1018 fi
1019 done < /proc/partitions
1020 fi
1021
144396dd 1022 [ -n "$ROOTFLAGS" ] && ROOTFLAGS="-o $ROOTFLAGS"
41d3645c 1023
144396dd 1024 mount -t $ROOTFS -r $device $ROOTFLAGS /newroot || echo "Mount of rootfs failed."
0fb9dda3 1025 init=$INIT
4671d086
ER
1026 if [ -z "$init" -o ! -x "/newroot$init" ]; then
1027 init=/sbin/init
1028 fi
1029 EOF
1030
b1ae7c80
AM
1031 busybox_applet dmesg
1032 busybox_applet tail
1033 add_linuxrc <<-'EOF'
0d9c261f 1034 if [ "$DEBUGINITRD" -a "$DEBUGINITRD" != 'sh' ]; then
b1ae7c80
AM
1035 echo "Last 20 lines of dmesg:"
1036 dmesg | tail -n 20
1037 fi
2b945b6b 1038
b1ae7c80
AM
1039 EOF
1040
2b945b6b
ER
1041 kmsg "geninitrd/$VERSION switching root"
1042
4671d086 1043 umount_all
0273c2c4 1044 busybox_applet switch_root usleep
4671d086 1045 add_linuxrc <<-'EOF'
278e5013 1046 [ ! -e /newroot/dev/console ] && mknod -m 660 /newroot/dev/console c 5 1
0273c2c4
ER
1047
1048 # switch root to empty dir will make kernel panic, so sleep 10s before it
1049 # switch_root needs to be pid 1, so there's no other way to recover from here
1050 # if /dev is missing, switch root will likely fail, give debug shell before that
1051 if [ ! -d /newroot/dev ]; then
1052 echo "/dev is missing, switch_root will likely fail"
1053 echo "if you booted with debugrd=sh, then you be given shell and you might able to recover this situation"
1054 debugshell
1055 [ "$DEBUGINITRD" ] || usleep 10000000
1056 fi
1057
72a1b0ef
ER
1058 # systemd[1]: /usr appears to be on its own filesytem and is not
1059 # already mounted. This is not a supported setup. Some things will
1060 # probably break (sometimes even silently) in mysterious ways. Consult
1061 # http://freedesktop.org/wiki/Software/systemd/separate-usr-is-broken
1062 # for more information.
1063 echo trying to mount /usr
1064 chroot /newroot mount -n /usr
1065
f8ea6a63 1066 exec switch_root /newroot $init ${1:+"$@"}
4671d086 1067
0273c2c4
ER
1068 # FIXME: this code is never executed, as "exec" does not return!
1069
4671d086
ER
1070 echo "Error! initramfs should not reach this place."
1071 echo "It probably means you've got old version of busybox, with broken"
1072 echo "initramfs support. Trying to boot anyway, but won't promise anything."
1073
f8ea6a63 1074 exec chroot /newroot $init ${1:+"$@"}
4671d086
ER
1075
1076 echo "Failed to chroot!"
b61aa273 1077 debugshell
4671d086
ER
1078 EOF
1079 # we need /init being real file, not symlink, otherwise the initramfs will
1080 # not be ran by pid 1 which is required for switch_root
1081 mv $DESTDIR/linuxrc $DESTDIR/init
1082 ln -s init $DESTDIR/linuxrc
1083}
1084
c552503c
ER
1085# find if $symbol exists in System.map $mapfile
1086sym_exists() {
1087 local mapfile="$1"
1088 local symbol="$2"
1089 if [ ! -f $mapfile ]; then
1090 # missing mapfile (not a pld kernel?)
1091 return 1
1092 fi
1093
fee61d3f 1094 awk -vc=1 -vsymbol="$symbol" '($2 == "T" || $2 == "t") && $3 == symbol {c = 0} END {exit c}' $mapfile
c552503c
ER
1095}
1096
1097# find best compressor (or forced one) for initrd
1098find_compressor() {
1099 local mode="$1"
60086bea 1100 local compressors='zstd xz lzma bzip2 gzip lzo'
c552503c
ER
1101
1102 # a specified one, take it
55aaf2fe
AM
1103 if ! is_yes "$mode"; then
1104 compressors="$mode"
c552503c
ER
1105 fi
1106
02ba8ab7 1107 verbose "finding compressor: $compressors (via $mode)"
c552503c
ER
1108 # check for compressor validity
1109 local c prog map=/boot/System.map-$kernel
1110 for c in $compressors; do
1111 case $c in
66d146a5 1112 xz)
29f7d622
AM
1113 sym=unxz
1114 prog=/usr/bin/xz
1115 ;;
1116 lzma)
c552503c 1117 sym=unlzma
66d146a5 1118 prog=/usr/bin/xz
c552503c
ER
1119 ;;
1120 bzip2)
1121 sym=bzip2
c42692d4 1122 prog=/usr/bin/bzip2
c552503c
ER
1123 ;;
1124 gzip)
1125 sym=gunzip
c42692d4 1126 prog=/bin/gzip
c552503c 1127 ;;
8a6f083b
AM
1128 lzo)
1129 sym=unlzo
1130 prog=/usr/bin/lzop
1131 ;;
60086bea
AM
1132 zstd)
1133 sym=zstd
1134 prog=/usr/bin/zstd
1135 ;;
5fcc3d04
AM
1136 none|no)
1137 # any existing sym will work
1138 sym=initrd_load
1139 prog=/bin/cat
1140 ;;
c552503c
ER
1141 *)
1142 die "Unknown compressor $c"
1143 ;;
1144 esac
c454c66e 1145 if sym_exists $map $sym && [ -x $prog ]; then
c552503c
ER
1146 echo $c
1147 return
1148 fi
1149 done
1150
02ba8ab7 1151 verbose "using gzip for compressor (fallback)"
c552503c
ER
1152 echo gzip
1153}
1154
97f51b6e
ER
1155# compresses kernel image image
1156# in function so we could retry with other compressor on failure
1157compress_image() {
1158 local compressor="$1" IMAGE="$2" target="$3" tmp
1159 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
1160
1161 case "$compressor" in
1162 xz)
1163 # don't use -9 here since kernel won't understand it
1164 xz --format=xz --check=crc32 --lzma2=preset=6e,dict=1MiB < "$IMAGE" > "$tmp" || return $?
1165 ;;
1166 lzma)
1167 xz --format=lzma -9 < "$IMAGE" > "$tmp" || return $?
1168 ;;
1169 bzip2)
1170 bzip2 -9 < "$IMAGE" > "$tmp" || return $?
1171 ;;
1172 gzip)
1173 gzip -9 < "$IMAGE" > "$tmp" || return $?
1174 ;;
8a6f083b
AM
1175 lzo)
1176 lzop -9 < "$IMAGE" > "$tmp" || return $?
1177 ;;
60086bea
AM
1178 zstd)
1179 zstd -9 < "$IMAGE" > "$tmp" || return $?
1180 ;;
5fcc3d04
AM
1181 none|no)
1182 cat < "$IMAGE" > "$tmp" || return $?
1183 ;;
97f51b6e
ER
1184 esac
1185
1186 mv -f "$tmp" "$target"
1187}
1188
82b2dba2
ER
1189if [ -r /etc/sysconfig/geninitrd ]; then
1190 . /etc/sysconfig/geninitrd
1191fi
2cc3ae8b 1192
c215292c
AG
1193if [ ! -f /proc/mounts ]; then
1194 warn "/proc filesystem not mounted, may cause wrong results or failure."
1195fi
1196
2d769917 1197geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs sata scsi usbkbd bcache
c124d0cf 1198
82b2dba2
ER
1199while [ $# -gt 0 ]; do
1200 case $1 in
1201 --fstab=*)
1202 fstab=${1#--fstab=}
1203 ;;
1204 --fstab)
1205 fstab=$2
1206 shift
1207 ;;
1208 --modules-conf=*)
1209 modulefile=${1#--modules-conf=}
1210 ;;
1211 --modules-conf)
1212 modulefile=$2
1213 shift
1214 ;;
82b2dba2
ER
1215 --with-bootsplash)
1216 BOOT_SPLASH=yes
1217 ;;
1218 --without-bootsplash)
1219 BOOT_SPLASH=no
1220 ;;
1221 --with-fbsplash)
1222 FB_SPLASH=yes
1223 ;;
1224 --without-fbsplash)
1225 FB_SPLASH=no
1226 ;;
6c69a2d4
ER
1227 --with-fbcondecor)
1228 FB_CON_DECOR=yes
1229 ;;
1230 --without-fbcondecor)
1231 FB_CON_DECOR=no
1232 ;;
82b2dba2
ER
1233 --with-suspend)
1234 USE_SUSPEND=yes
1235 ;;
1236 --without-suspend)
1237 USE_SUSPEND=no
1238 ;;
1239 --with-suspend2 | --with-tuxonice)
1240 USE_TUXONICE=yes
1241 ;;
1242 --without-suspend2 | --without-tuxonice)
1243 USE_TUXONICE=no
1244 ;;
80b1ed79 1245 --lvmversion=*)
7308edee 1246 LVMTOOLSVERSION=${1#--lvmversion=}
82b2dba2 1247 ;;
80b1ed79 1248 --lvmtoolsversion=*)
1249 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
1250 ;;
82b2dba2
ER
1251 --lvmtoolsversion|--lvmversion)
1252 LVMTOOLSVERSION=$2
1253 shift
1254 ;;
1255 --without-udev)
1256 USE_UDEV=no
1257 ;;
1258 --with-udev)
1259 USE_UDEV=yes
1260 ;;
1261 --without-dmraid)
1262 USE_DMRAID=no
1263 ;;
1264 --without-multipath)
ecd7bf46
ER
1265 USE_MULTIPATH=no
1266 ;;
1267 --with-multipath=*)
1268 USE_MULTIPATH=${1#--with-multipath=}
82b2dba2 1269 ;;
af075488 1270 --without-blkid)
1271 USE_BLKID=no
289fbc9b 1272 ;;
3ef3d717
ER
1273 --without-luks)
1274 USE_LUKS=no
1275 ;;
82b2dba2
ER
1276 --with=*)
1277 BASICMODULES="$BASICMODULES ${1#--with=}"
1278 ;;
1279 --with)
1280 BASICMODULES="$BASICMODULES $2"
1281 shift
1282 ;;
1283 --version)
1284 echo "$PROGRAM: version $VERSION"
1285 exit 0
1286 ;;
1287 -v)
02ba8ab7
ER
1288 if [ x"$verbose" = x"-v" ]; then
1289 verbose="-v -v"
1290 else
1291 verbose="-v"
1292 fi
11ab0dea 1293 exec 3>&1
82b2dba2 1294 ;;
c552503c
ER
1295 --compress)
1296 COMPRESS=$2
1297 ;;
1298 --compress=*)
1299 COMPRESS="${1#--compress=}"
1300 ;;
82b2dba2
ER
1301 --nocompress)
1302 COMPRESS=no
1303 ;;
ccd1f65f 1304 --nostrip)
76a48507
ER
1305 STRIP=
1306 ;;
1307 --strip=*)
1308 STRIP="${1#--strip=}"
1309 ;;
1310 --strip)
1311 STRIP=$2
1312 shift
ccd1f65f 1313 ;;
82b2dba2
ER
1314 --ifneeded)
1315 ifneeded=1
1316 ;;
1317 -f)
1318 force=1
1319 ;;
1320 --preload=*)
1321 PREMODS="$PREMODS ${1#--preload=}"
1322 ;;
1323 --preload)
1324 PREMODS="$PREMODS $2"
1325 shift
1326 ;;
2965cab9 1327 --fs=* | --fs)
bbbc32d0 1328 die "--fs option is obsoleted. Use --initrdfs instead"
82b2dba2
ER
1329 ;;
1330 --initrdfs=*)
1331 INITRDFS=${1#--initrdfs=}
1332 ;;
1333 --initrdfs)
1334 INITRDFS=$2
1335 shift
1336 ;;
1337 --image-version)
1338 img_vers=yes
1339 ;;
1340 --ide-only-root)
1341 ide_only_root="yes"
1342 ;;
1343 *)
1344 if [ -z "$target" ]; then
1345 target="$1"
1346 elif [ -z "$kernel" ]; then
1347 kernel="$1"
1348 else
7f6e5359 1349 usage
36523626 1350 exit 1
82b2dba2
ER
1351 fi
1352 ;;
1353 esac
f5db170b 1354
82b2dba2
ER
1355 shift
1356done
1357
1358if [ -z "$target" -o -z "$kernel" ]; then
7f6e5359 1359 usage
36523626 1360 exit 1
82b2dba2
ER
1361fi
1362
93a38d1a
ER
1363# main()
1364if [ "$(id -u)" != 0 ]; then
1365 die "You need to be root to generate initrd"
1366fi
1367
c45a111c
ER
1368for dir in libx32 lib64 lib; do
1369 initrd_dir=/usr/$dir/initrd
1370 if [ -d "$initrd_dir" ]; then
1371 initrd_dirs="$initrd_dirs $initrd_dir"
1372 fi
1373done
1374
e4487862
AM
1375kernel_version=$(echo "$kernel" | awk -F. '{gsub(/[_-].*/, "", $0); print sprintf("%03d%03d",$1,$2)}')
1376kernel_version_long=$(echo "$kernel" | awk -F. '{gsub(/[_-].*/, "", $0); print sprintf("%03d%03d%03d",$1,$2,$3)}')
82b2dba2 1377
b7114dde 1378verbose "# geninitrd $VERSION"
c124d0cf
ER
1379debug "Using initrd_dir: $initrd_dir"
1380
6ec4aea6 1381busybox=$(find_tool $initrd_dir/busybox $initrd_dir/initrd-busybox /bin/initrd-busybox) || die "Couldn't find busybox suitable for initrd"
c124d0cf
ER
1382
1383# we setup mods after parsing command line args
1384geninitrd_setup_mods
1385
1386if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1387 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1388fi
1389
82b2dba2 1390if [ -z "$INITRDFS" ]; then
bbbc32d0
ER
1391 if [ -n "$FS" ]; then
1392 # FS= can came only via /etc/sysconfig/geninitrd likely?
1393 die "FS configuration option is obsoleted. Use INITRDFS instead"
f5db170b 1394 fi
f5db170b 1395
bbbc32d0
ER
1396 # default value
1397 if [ "$kernel_version" -ge "002005" ]; then
1398 INITRDFS="initramfs"
1399 else
1400 INITRDFS="rom"
1401 fi
82b2dba2 1402fi
966c32cc 1403
fee61d3f
AM
1404check_initrd_fs() {
1405 local s sfound sym p prog map=/boot/System.map-$kernel
1406 case "$INITRDFS" in
1407 ext2)
1408 # TODO: symbols to check in case of ext2 used via ext3/4 subsystem
1409 sym=init_ext2_fs
1410 prog=/sbin/mke2fs
1411 ;;
1412 rom|romfs)
1413 sym=init_romfs_fs
1414 prog=/sbin/genromfs
1415 ;;
1416 cram|cramfs)
1417 sym=init_cramfs_fs
1418 prog=/sbin/mkcramfs
1419 ;;
1420 initramfs)
1421 sym=__initramfs_start
1422 prog="/bin/cpio /usr/bin/find"
1423 ;;
1424 *)
1425 die "Filesystem $INITRDFS on initrd is not supported by geninitrd"
1426 ;;
1427 esac
1428
1429 # only one is needed (for cases like ext2 via ext2 or via ext3 or via ext4 subsysytem)
1430 sfound=0
1431 for s in $sym; do
1432 sym_exists $map $s && sfound=1
1433 break
1434 done
1435 if [ "$sfound" -eq "0" ]; then
1436 die "Filesystem $INITRDFS on initrd is not supported by kernel"
1437 fi
1438
1439 for p in $prog; do
1440 [ ! -x "$p" ] && die "$prog is missing"
1441 done
1442}
1443check_initrd_fs
f5db170b 1444
9323ada3 1445if [ -L "$target" ]; then
1446 target=$(readlink -f "$target")
1447fi
1448
82b2dba2
ER
1449if [ -n "$img_vers" ]; then
1450 target="$target-$kernel"
1451fi
8bd582f1 1452
82b2dba2
ER
1453if [ -z "$force" -a -f "$target" ]; then
1454 die "$target already exists."
1455fi
c6c6ce01 1456
82b2dba2
ER
1457if [ ! -d "/lib/modules/$kernel" ]; then
1458 die "/lib/modules/$kernel is not a directory."
1459fi
2ffb1734 1460
bbbc32d0
ER
1461if [ "$kernel_version" -ge "002005" ]; then
1462 modext=".ko"
1463fi
1464
82b2dba2
ER
1465cache_modprobe_conf
1466
1467for n in $PREMODS; do
046c68c9 1468 find_module "$n"
82b2dba2
ER
1469done
1470
ed30e3a8 1471if [ "$FBMODULE" ]; then
046c68c9 1472 find_module "$FBMODULE"
ed30e3a8
ER
1473fi
1474
cefcd7bb
AM
1475# autodetect USB keyboards
1476find_modules_usbkbd
1477
82b2dba2 1478# allow forcing loading SCSI and/or IDE modules
35043b20 1479# XXX: where ADDSCSI cames from? drop?
82b2dba2
ER
1480if is_yes "$ADDSCSI"; then
1481 find_modules_scsi
1482fi
1483
3f53322c 1484# autodetect SATA modules
1485find_modules_sata
e2d6ca6c 1486
35043b20 1487# XXX: where ADDIDE cames from? drop?
82b2dba2
ER
1488if is_yes "$ADDIDE"; then
1489 find_modules_ide
1490fi
1491
4c16dac4
ER
1492if is_yes "$USE_SUSPEND"; then
1493 find_modules_suspend
1494fi
1495
82b2dba2 1496find_root "$fstab" || exit
02ba8ab7 1497verbose "Using $rootdev as device for rootfs"
82b2dba2 1498
d8056591 1499find_modules_for_devpath "$rootdev"
ac085800 1500
ecd7bf46
ER
1501# if USE_MULTIPATH is path to device, scan that too
1502# this is to bootstrap multipath setup into initrd.
1503if ! is_no "$USE_MULTIPATH" && ! is_yes "$USE_MULTIPATH"; then
1504 find_modules_multipath $USE_MULTIPATH
1505fi
1506
046c68c9 1507find_module "-$rootFs"
ac085800 1508
82b2dba2 1509for n in $BASICMODULES; do
046c68c9 1510 find_module "$n"
82b2dba2 1511done
4e9eb79c 1512
82b2dba2 1513if is_yes "$USE_TUXONICE"; then
046c68c9 1514 find_module "-lzf"
82b2dba2 1515fi
33d24e12 1516
2d769917 1517find_modules_uvesafb
bf6d9c64 1518find_modules_fbsplash
2968c9dd 1519
82b2dba2 1520if [ -n "$ifneeded" -a -z "$MODULES" ]; then
02ba8ab7 1521 verbose "No modules are needed -- not building initrd image."
82b2dba2
ER
1522 exit 0
1523fi
c6c6ce01 1524
02ba8ab7 1525verbose "Building initrd..."
d8056591 1526DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
9b557a09 1527RCFILE="$DESTDIR/linuxrc"
82b2dba2
ER
1528> "$RCFILE"
1529chmod a+rx "$RCFILE"
9b557a09 1530ln -s linuxrc $DESTDIR/init
e8d178ff 1531
82b2dba2 1532# create dirs that we really need
33cc4751 1533inst_d /{lib,bin,sbin,etc,dev{,/pts,/shm},loopfs,var,proc,run,sys,tmp}
e8d178ff 1534
82b2dba2 1535modules_install "$MODULES"
b64f015b 1536
82b2dba2
ER
1537# mknod'ing the devices instead of copying them works both with and
1538# without devfs...
6b45dd6c
AM
1539mknod -m 600 "$DESTDIR/dev/console" c 5 1
1540mknod -m 666 "$DESTDIR/dev/null" c 1 3
1541mknod -m 666 "$DESTDIR/dev/zero" c 1 5
1542mknod -m 666 "$DESTDIR/dev/random" c 1 8
1543mknod -m 666 "$DESTDIR/dev/urandom" c 1 9
2b945b6b 1544mknod -m 644 "$DESTDIR/dev/kmsg" c 1 11
be2f3ecc 1545
6ec4aea6
JR
1546inst_exec $busybox /bin/busybox
1547ln -s busybox $DESTDIR/bin/sh
1548# for older busyboxes who had /bin/initrd-busybox as EXEPATH
1549ln -s busybox $DESTDIR/bin/initrd-busybox
2ffb1734 1550
82b2dba2
ER
1551add_linuxrc <<EOF
1552#!/bin/sh
b7114dde 1553# initrd generated by geninitrd/$VERSION
8938f33d 1554# on $(LC_ALL=C date)
c6c6ce01 1555
82b2dba2 1556EOF
ff9aded5 1557load_font
82b2dba2 1558mount_proc
2b945b6b
ER
1559
1560kmsg "geninitrd/$VERSION starting"
1561
efb675bf
AM
1562inst_d /lib/geninitrd/
1563inst /lib/geninitrd/functions.initrd /lib/geninitrd/functions.initrd
1564
0fb9dda3 1565add_linuxrc <<-EOF
efb675bf 1566 . /lib/geninitrd/functions.initrd
0fb9dda3
ER
1567 # builtin defaults from geninitrd
1568 ROOT=$rootdev
1569 ROOTFS=$rootFs
1570EOF
82b2dba2 1571add_linuxrc <<-'EOF'
48d98595 1572 read CMDLINE < /proc/cmdline
c6c6ce01 1573
82b2dba2 1574 for arg in $CMDLINE; do
04bffd7a 1575 if [ "${arg}" = "debuginitrd" ] || [ "${arg}" = "debugrd" ]; then
82b2dba2
ER
1576 DEBUGINITRD=yes
1577 fi
04bffd7a
ER
1578 if [ "${arg##debuginitrd=}" != "${arg}" ] || [ "${arg##debugrd=}" != "${arg}" ]; then
1579 DEBUGINITRD=${arg##debug*rd=}
82b2dba2 1580 fi
fc787d45 1581 if [ "${arg##root=}" != "${arg}" ]; then
1582 ROOT=${arg##root=}
1583 fi
b13c409d
ER
1584 if [ "${arg##rootfs=}" != "${arg}" ]; then
1585 ROOTFS=${arg##rootfs=}
1586 fi
144396dd
AM
1587 if [ "${arg##rootflags=}" != "${arg}" ]; then
1588 ROOTFLAGS=${arg##rootflags=}
db795d06 1589 fi
41d3645c
AM
1590 if [ "${arg##rootfsflags=}" != "${arg}" ]; then
1591 ROOTFSFLAGS=${arg##rootfsflags=}
1592 fi
0fb9dda3
ER
1593 if [ "${arg##init=}" != "${arg}" ]; then
1594 INIT=${arg##init=}
1595 fi
82b2dba2 1596 done
c6c6ce01 1597
144396dd
AM
1598 # handling of invalid, rootfsflags, option
1599 if [ -n "$ROOTFSFLAGS" ]; then
1600 if [ -n "$ROOTFLAGS" ]; then
1601 ROOTFLAGS="$ROOTFLAGS,$ROOTFSFLAGS"
1602 else
1603 ROOTFLAGS="$ROOTFSFLAGS"
1604 fi
1605 fi
1606
82b2dba2 1607 if [ "$DEBUGINITRD" = "sh" ]; then
8938f33d 1608 # export some vars to subshell for debug to work
144396dd 1609 export CMDLINE ROOT ROOTFS ROOTDEV ROOTFLAGS DEBUGINITRD INIT
4569a02c
ER
1610 export LVM_ROOTVG LVM_SUSPENDVG LVM_VGVOLUMES
1611 export rootnr attrs majmin major minor device
1612
1613 # make debugshell() invoke subshell if $DEBUGINITRD=sh
82b2dba2 1614 debugshell() {
e2405b29
AM
1615EOF
1616if is_yes "$RUN_SULOGIN_ON_ERR"; then
1617add_linuxrc <<-'EOF'
0273c2c4 1618 echo "debug shell disabled by RUN_SULOGIN_ON_ERR=yes from /etc/sysconfig/system during initrd generation time"
e2405b29
AM
1619EOF
1620else
1621add_linuxrc <<-'EOF'
1622 sh
1623EOF
1624fi
1625add_linuxrc <<-'EOF'
82b2dba2
ER
1626 }
1627 else
1628 debugshell() {
1629 :
1630 }
1631 fi
e934d044 1632
82b2dba2
ER
1633 if [ "$DEBUGINITRD" ]; then
1634 set -x
cff3058d 1635 fi
82b2dba2 1636EOF
2df2e995 1637
efb675bf
AM
1638# mount early
1639mount_tmp
1640
fe280785 1641modules_add_linuxrc $MODULES
82b2dba2
ER
1642
1643# TODO: rewrite for busybox
1644#if [ -n "$loopDev" ]; then
1645# if [ ! -d /initrd ]; then
1646# mkdir /initrd
1647# fi
1648#
9b557a09
ER
1649# cp -a "$loopDev" "$DESTDIR/dev"
1650# cp -a "$rootdev" "$DESTDIR/dev"
82b2dba2
ER
1651# echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1652# echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1653# echo "echo Setting up loopback device $rootdev" >> $RCFILE
1654# echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1655#fi
2b1a3707 1656
1606e343
AM
1657if is_yes "$USE_UDEV"; then
1658 initrd_gen_udev
382ce856
AM
1659else
1660 initrd_gen_mdev
1606e343
AM
1661fi
1662
3dd50160 1663initrd_gen_uvesafb
1b481849
ER
1664initrd_gen_luks
1665initrd_gen_dmraid
1666initrd_gen_multipath
1667initrd_gen_blkid
289fbc9b 1668
69b1e935 1669if is_yes "$have_nfs"; then
2df2e995 1670 initrd_gen_nfs
1b481849
ER
1671else
1672 initrd_gen_md
1673 initrd_gen_lvm
2d769917 1674 initrd_gen_bcache
d222b474 1675 initrd_gen_blkid
1b481849 1676 initrd_gen_luks
4828c787 1677 initrd_gen_setrootdev
7c38b114
AF
1678fi
1679
5101a385 1680# additional devs always needed
9b557a09 1681[ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
5101a385 1682
1b481849 1683initrd_gen_stop_udevd
382ce856 1684initrd_gen_stop_mdev
6fadace4 1685initrd_gen_stop_uvesafb
82de999f 1686
4a362aea
ER
1687# resume after killing local processes
1688initrd_gen_tuxonice
1689initrd_gen_suspend
1690
52a92a2a
ER
1691# clean up env
1692add_linuxrc <<-'EOF'
4569a02c 1693if [ ! "$DEBUGINITRD" ]; then
52a92a2a
ER
1694 ifs=$IFS
1695 IFS="
1696 "
1697 for i in $(export -p); do
1698 i=${i#declare -x } # ksh/bash
1699 i=${i#export } # busybox
1700
1701 case "$i" in
1702 *=*)
1703 : ;;
1704 *)
1705 continue ;;
1706 esac
1707
1708 i=${i%%=*}
1709
1710 [ -z "$i" ] && continue
1711
1712 case "$i" in
62028605 1713 ROOT|PATH|HOME|TERM)
52a92a2a
ER
1714 :
1715 ;;
1716 *)
62028605 1717 unset $i
52a92a2a
ER
1718 ;;
1719 esac
1720 done
1721 IFS=$ifs
4569a02c 1722fi
52a92a2a
ER
1723EOF
1724
f8f9e56d 1725if [ "$INITRDFS" = "initramfs" ]; then
4671d086 1726 initrd_gen_initramfs_switchroot
b64f015b 1727else
b64f015b 1728 umount_all
f8f9e56d
AM
1729fi
1730
1b481849
ER
1731initrd_gen_fbsplash
1732initrd_gen_fbcondecor
6c69a2d4 1733
b7114dde 1734debug "Current /linuxrc:\n$(sed -e 's,^,| ,' $DESTDIR/linuxrc)"
2990ac33 1735
d8056591 1736IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
51dc1fe6 1737
5c7359e3 1738IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
02ba8ab7 1739verbose "image size: $IMAGESIZE KiB ($DESTDIR)"
5c7359e3 1740
02ba8ab7 1741verbose "Creating $INITRDFS image $IMAGE"
2ad94d8a 1742case "$INITRDFS" in
4877276e 1743 ext2)
4877276e 1744 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
c091a192
ER
1745 # NOTE: ext2 label is max 16 chars
1746 mke2fs -q -F -b 1024 -m 0 -L "PLD/$kernel" "$IMAGE" 2>/dev/null 1>&2
4877276e
ER
1747 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1748
1749 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
1750 debug "Mounting ext2 image $IMAGE to $tmpmnt"
5c7359e3 1751 mount -o loop -t ext2 "$IMAGE" "$tmpmnt" || die "mount failed, check dmesg(1)"
4877276e
ER
1752 # We don't need this directory, so let's save space
1753 rm -rf "$tmpmnt"/lost+found
1754
1755 debug "Copy recursively $DESTDIR -> $tmpmnt"
1756 cp -a $DESTDIR/* $tmpmnt
1757 umount "$IMAGE"
1758 rmdir "$tmpmnt"
1759
1760 ;;
1761 rom|romfs)
c091a192 1762 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD Linux/$kernel (geninitrd/$VERSION)"
4877276e
ER
1763 ;;
1764 cram|cramfs)
1765 mkcramfs "$DESTDIR" "$IMAGE"
1766 ;;
1767 initramfs)
1768 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
1769 ;;
1770 *)
93a38d1a 1771 die "Filesystem $INITRDFS not supported by $PROGRAM"
c31050f3 1772esac
bb529f94 1773
256e0bed
AM
1774if [ "$INITRDFS" != "initramfs" ]; then
1775 CONFIG_BLK_DEV_RAM_SIZE=$(ikconfig | awk -F= '/^CONFIG_BLK_DEV_RAM_SIZE/{print $2}')
1776 if [ -z "$CONFIG_BLK_DEV_RAM_SIZE" ]; then
1777 CONFIG_BLK_DEV_RAM_SIZE=4096
1778 warn "No CONFIG_BLK_DEV_RAM_SIZE detected, fallback to $CONFIG_BLK_DEV_RAM_SIZE"
1779 fi
e3bc44e2 1780
256e0bed
AM
1781 if [ "$IMAGESIZE" -gt $CONFIG_BLK_DEV_RAM_SIZE ]; then
1782 warn "Your image size is larger than $CONFIG_BLK_DEV_RAM_SIZE, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1783 fi
e3bc44e2
ER
1784fi
1785
c552503c 1786if ! is_no "$COMPRESS"; then
c552503c 1787 compressor=$(find_compressor "$COMPRESS")
02ba8ab7 1788 verbose "Compressing $target with $compressor"
c552503c
ER
1789
1790 # TODO: the image name (specified from kernel.spec) already contains
1791 # extension, which is .gz most of the time.
97f51b6e
ER
1792 compress_image "$compressor" "$IMAGE" "$target" || {
1793 if [ $compressor != gzip ]; then
1794 warn "Could not compress with $compressor, retrying with gzip"
1795 compress_image gzip "$IMAGE" "$target" || die "compress failed with gzip" $?
1796 else
1797 die "Could not compress image with $compressor"
1798 fi
1799 }
bb529f94 1800else
7d2fc5eb 1801 cp -a "$IMAGE" "$target"
bb529f94 1802fi
5b71959c 1803
7992356a 1804# XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
1b481849 1805initrd_gen_bootsplash "$target"
5b71959c 1806
d8056591 1807rm -rf "$DESTDIR" "$IMAGE"
ac085800
ER
1808
1809# vim:ts=4:sw=4:noet:fdm=marker
This page took 1.928663 seconds and 4 git commands to generate.