]> git.pld-linux.org Git - projects/geninitrd.git/blame - geninitrd
- pack_version -> kernel_version to avoid confusion what the variable is
[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#
9# TODO:
c3667d07 10# - make udev start before insmods
ef08134f 11# - make proper use of USE_UDEV - don't copy rules if USE_UDEV is off no!
aebe301c 12#
c31050f3 13
28eec2b1 14RCSID='$Id$'
ca2c2012
ER
15R=${RCSID#* * }; VERSION=${R%% *}
16PROGRAM=${0##*/}
bb529f94
JK
17
18. /etc/rc.d/init.d/functions
ded87775 19. /lib/geninitrd/functions
e2405b29 20. /etc/sysconfig/system
bb529f94 21
c3667d07
ER
22COMPRESS=yes
23USERAIDSTART=yes
24USEMDADMSTATIC=no
25USEINSMODSTATIC=no
26USE_SUSPEND=yes
24067b6f 27USE_TUXONICE=no
10c3df06
MM
28# it should be safe to remove scsi_mod from here, but I'm not sure...
29PRESCSIMODS="-scsi_mod unknown -sd_mod"
bb529f94
JK
30target=""
31kernel=""
32force=""
33verbose=""
34MODULES=""
35img_vers=""
c3667d07
ER
36fstab=/etc/fstab
37insmod=insmod
38modext=.o
4e9eb79c 39rootdev_nr=0
738c05d8
ER
40# device node for rootfs from fstab
41rootdev=""
6c69a2d4 42# requires bootsplash package to operate
5b71959c 43BOOT_SPLASH=no
6c69a2d4 44# requires splashutils package to operate
e4b07ddc 45FB_SPLASH=no
6c69a2d4
ER
46# requires splashutils package to operate
47FB_CON_DECOR=no
bb529f94 48
8bd582f1
ER
49# internal variables
50# is /dev on tmpfs
b64f015b
ER
51dev_mounted=no
52# is /proc mounted
53proc_mounted=no
54# is /sys mounted
55sys_mounted=no
56# is /tmp mounted on tmpfs
57tmp_mounted=no
58
59# are /dev nodes already created from /proc/devices info?
8bd582f1 60proc_partitions=no
6b013929 61
43258faf
AG
62# whether v86d should be installed
63need_v86d=0
64
4c16dac4
ER
65# resume device
66resume_dev=""
c083ae23 67
69b1e935
ER
68# if we should init NFS at boot
69have_nfs=no
df738638
ER
70# if we should init md (softraid) at boot
71have_md=no
b4d9d384 72
b64f015b 73usage() {
553786c4 74 uname_r=$(uname -r)
00eaa938 75 echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
ac085800 76 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
92ed99b6 77 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
ac085800 78 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
ba5d09f0 79 echo " [--with-bootsplash] [--without-bootsplash]"
6c69a2d4
ER
80 echo " [--with-fbsplash] [--without-fbsplash]"
81 echo " [--with-fbcondecor] [--without-fbcondecor]"
e4b07ddc 82 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
ba5d09f0 83 echo " [--with-suspend] [--without-suspend]"
1cd2aabd 84 echo " [--with-tuxonice] [--without-tuxonice]"
2cc3ae8b 85 echo " [--without-dmraid] [--without-multipath]"
3ef3d717 86 echo " [--without-blkid] [--without-luks]"
ac085800 87 echo " <initrd-image> <kernel-version>"
553786c4
ER
88 echo ""
89 echo "example:"
00eaa938 90 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
36523626 91 exit 0
bb529f94
JK
92}
93
779a218a 94msg() {
f4010f7f
AM
95 echo "$PROGRAM: $*"
96}
97
98warn() {
4a60c01f 99 msg "WARNING: $*" >&2
779a218a
AM
100}
101
94769f11 102debug() {
4a60c01f 103 [ -n "$verbose" ] && msg "$*" >&2
94769f11 104}
aa69da6e 105
bf6c3fcb
ER
106# aborts program abnormally
107die() {
b5f5c089 108 local rc=${2:-1}
524cafef 109 msg "ERROR: $1" 2>&2
bf6c3fcb
ER
110 exit $rc
111}
112
c6c6ce01
ER
113# append text to /linuxrc
114# takes STDIN as input
115add_linuxrc() {
b64f015b 116 cat >> "$RCFILE"
c6c6ce01
ER
117}
118
b64f015b
ER
119# generate code to mount /dev on tmpfs and create initial nodes
120# can be called multiple times. /dev is cleaned up (umounted) automatically at
121# the end of script.
122mount_dev() {
123 if [ "$INITRDFS" = "initramfs" ]; then
124 # initramfs is read-write filesystem, no need for tmpfs
125 return
126 fi
127
128 # we already generated tmpfs code; return
129 if is_yes "$dev_mounted"; then
130 return
131 fi
132
133 dev_mounted=yes
134
135 busybox_applet mount mknod mkdir
136 add_linuxrc <<-EOF
137 : 'Creating /dev'
138 mount -o mode=0755 -t tmpfs none /dev
139 mknod /dev/console c 5 1
140 mknod /dev/null c 1 3
141 mknod /dev/zero c 1 5
142 mkdir /dev/pts
143 mkdir /dev/shm
144 EOF
145}
146
147# generate code to mount /proc on initrd
148# can be called multiple times
149mount_proc() {
150 if is_yes "$proc_mounted"; then
151 return
152 fi
153
154 proc_mounted=yes
2bface63
ER
155 if [ "$INITRDFS" = "initramfs" ]; then
156 # /proc is mounted with initramfs 2.6.22.14 kernel
157 # XXX: remove when it is clear why proc was already mounted
158 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
159 else
160 echo "mount -t proc none /proc" | add_linuxrc
161 fi
b64f015b
ER
162}
163
164# generate code to mount /sys on initrd
165# can be called multiple times
166mount_sys() {
167 if is_yes "$sys_mounted"; then
168 return
169 fi
170
171 sys_mounted=yes
172 echo "mount -t sysfs none /sys" | add_linuxrc
173}
174
175# generate code to mount /tmp on initrd
176# can be called multiple times
177mount_tmp() {
178 if [ "$INITRDFS" = "initramfs" ]; then
179 # initramfs is read-write filesystem, no need for tmpfs
180 return
181 fi
182
183 if is_yes "$tmp_mounted"; then
184 return
185 fi
186
187 tmp_mounted=yes
188 echo "mount -t tmpfs none /tmp" | add_linuxrc
189}
190
191# unmount all mountpoints mounted by geninitrd
192umount_all() {
ec49b7e6
ER
193
194 add_linuxrc <<-'EOF'
903f21ea 195 : Last shell before umounting all and giving control over to real init.
ec49b7e6
ER
196 debugshell
197 EOF
5b70f84d 198
b64f015b
ER
199 if is_yes "$dev_mounted"; then
200 echo 'umount /dev' | add_linuxrc
201 dev_mounted=no
202 fi
203 if is_yes "$proc_mounted"; then
204 echo 'umount /proc' | add_linuxrc
205 proc_mounted=no
206 fi
207 if is_yes "$sys_mounted"; then
208 echo 'umount /sys' | add_linuxrc
209 sys_mounted=no
210 fi
211 if is_yes "$tmp_mounted"; then
212 echo 'umount /tmp' | add_linuxrc
213 tmp_mounted=no
214 fi
215}
216
217
9299682f
ER
218# Checks if busybox has support for APPLET(s)
219# Exits from geninitrd if the support is not present.
220#
221# NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
222busybox_applet() {
223 local err=0
224
225 if [ -z "$busybox_functions" ]; then
9b1373fb
ER
226 local tmp=$(/bin/initrd-busybox 2>&1)
227
228 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
229 if [[ "$tmp" = *applet\ not\ found* ]]; then
230 local t=$(mktemp -d)
231 ln -s /bin/initrd-busybox $t/busybox
232 local tmp=$($t/busybox 2>&1)
233 rm -rf $t
234 fi
235
236 busybox_functions=$(echo "$tmp" | \
9299682f
ER
237 sed -ne '/Currently defined functions:/,$p' | \
238 xargs | sed -e 's,.*Currently defined functions: ,,'
239 )
240 fi
241 for applet in $*; do
242 local have
243 # try cache
244 eval have='$'busybox_have_$applet
245 if [ -z "$have" ]; then
246 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
247 if [ "$have" = 0 ]; then
f4010f7f 248 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
9299682f
ER
249 err=1
250 fi
251 eval busybox_have_$applet=$have
252 fi
253 done
254 if [ $err = 1 ]; then
00eaa938 255 die "Aborted"
9299682f
ER
256 fi
257}
258
7ffba534
ER
259# Finds module dependencies
260#
7ffba534 261# @param $module
fe280785 262# @param $mode [silent]
7ffba534 263#
6ae2e4d0 264# Outputs each dependant module full path.
7ffba534 265find_depmod() {
fe280785
ER
266 local module="$1"
267 local mode="$2"
7ffba534
ER
268
269 # backwards compatible, process $mode
97a482df 270 local modfile=$(modinfo -k $kernel -n $module 2>/dev/null)
7ffba534 271 if [ ! -f "$modfile" ]; then
7cac5014
ER
272 # module not found. try aliases!
273 local alias aliases=$(modprobe_conf | awk -vm="$module" '$1 == "alias" && $2 == m { print $3 }')
274 if [ "$aliases" ]; then
275 for alias in $aliases; do
276 debug "Try $alias alias for $module"
277 find_depmod "$alias"
278 done
279 return
280 fi
281
fe280785 282 if [ "$mode" != "silent" ]; then
7ffba534
ER
283 warn "$module: module not found for $kernel kernel"
284 fi
285 if ! is_no "$EXIT_IF_MISSING"; then
286 exit 1
287 else
288 warn "If $module isn't compiled in kernel then this initrd may not start your system."
289 fi
290 fi
291
292 # This works when user has module-init-tools installed even on 2.4 kernels
59a68735 293 modprobe --set-version $kernel --show-depends $module --ignore-install | \
c25765ed 294 while read insmod modpath options; do
59a68735 295 [ "$insmod" = "insmod" ] && echo $modpath
7ffba534
ER
296 done
297}
298
4a60c01f
AM
299find_firmware() {
300 local module="$1"
301 echo -n $(modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
302}
303
bb529f94 304findmodule() {
c3667d07
ER
305 local skiperrors=""
306 local modName=$1
10c3df06 307
fe280785 308 if [ ${modName#-} != $modName ]; then
413878f8 309 skiperrors=1
94769f11 310 modName=${modName#-}
413878f8 311 fi
bb529f94 312
10c3df06 313 # what's that?
413878f8 314 if [ "$modName" = "pluto" ]; then
315 findmodule fc4
316 findmodule soc
317 fi
318 if [ "$modName" = "fcal" ]; then
319 findmodule fc4
320 findmodule socal
321 fi
bb529f94 322
12617f8e 323 local mod depmod
7ffba534 324 if [ "$skiperrors" = 1 ]; then
fe280785 325 depmod=$(find_depmod $modName silent)
10c3df06 326 else
fe280785 327 depmod=$(find_depmod $modName)
94769f11 328 if [ $? != 0 ]; then
10c3df06 329 exit 1
413878f8 330 fi
413878f8 331 fi
ac085800 332
fe280785 333 for mod in $depmod; do
7ffba534 334 mod=${mod#/lib/modules/$kernel/}
fe280785
ER
335
336 # add each module only once
337 local m have=0
338 for m in $MODULES; do
339 [ $m = $mod ] && have=1
340 done
341 if [ $have = 0 ]; then
c2eb7d4f 342 MODULES="$MODULES $mod"
43258faf
AG
343
344 # if we are adding uvesafb, we need v86d as well
345 if [ "$modName" = "uvesafb" ]; then
346 need_v86d=yes
347 fi
fe280785 348 fi
10c3df06 349 done
bb529f94
JK
350}
351
034fdd5d
ER
352# install a file to temporary mount image.
353# it will operate recursively (copying directories)
354# and will symlink destinations if source is symlink.
bb529f94 355inst() {
17e97aec 356 if [ $# -lt 2 ]; then
a9ace64a 357 die 'Usage: inst <file> [<file>] <destination>'
c31050f3 358 fi
17e97aec
ER
359
360 local src i=0 c=$(($# - 1))
361 while [ $i -lt $c ]; do
362 src="$src $1"
363 i=$((i + 1))
364 shift
365 done
366 local dest=$1
367 set -- $src
242f2358
PZ
368 parentDir=$(dirname $DESTDIR$dest)
369 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
d8056591 370 debug "+ cp $* $DESTDIR$dest"
9b557a09 371 cp -HR "$@" "$DESTDIR$dest"
bb529f94
JK
372}
373
dab92b1d 374inst_d() {
17e97aec 375 if [ $# = 0 ]; then
a9ace64a 376 die 'Usage: inst_d <destination> <destination>'
034fdd5d
ER
377 fi
378 for dir in "$@"; do
9b557a09 379 install -d "$DESTDIR$dir"
034fdd5d
ER
380 done
381}
382
209061e3
ER
383# install executable and it's shared libraries
384inst_exec() {
17e97aec 385 if [ $# -lt 2 ]; then
524cafef 386 die 'Usage: inst_exec <file>[, <file>] <destination>'
17e97aec 387 fi
209061e3
ER
388 local src i=0 c=$(($# - 1))
389 while [ $i -lt $c ]; do
390 src="$src $1"
391 i=$((i + 1))
392 shift
393 done
9b532fe6 394 local dest=$1
209061e3
ER
395 set -- $src
396
9b532fe6
ER
397 inst "$@" $dest
398
5265962d 399 local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
9b532fe6 400 for lib in $libs; do
9b557a09 401 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
7efbe841
ER
402 inst_d /$_lib
403 inst_exec $lib /$_lib
17e97aec 404 fi
209061e3 405 done
c7ade647
ER
406
407 # hack for uclibc linked binaries requiring this fixed path
408 # XXX: shouldn't rpath be used here instead so th
409 if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
410 local lib=$DESTDIR/$_lib/libc.so.0
411 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
412 local libdir=$(cd $(dirname "$lib"); pwd)
413 if [ ! -e $DESTDIR$libdir ]; then
414 libdir=$(dirname "$libdir")
415 inst_d $libdir
416 debug "+ ln -s /$_lib $DESTDIR$libdir"
417 ln -s /$_lib $DESTDIR$libdir
418 fi
419 fi
209061e3
ER
420}
421
82474db9
ER
422# output modules.conf / modprobe.conf
423modprobe_conf() {
424 echo "$modprobe_conf_cache"
425}
426
427#
428# defaults to modprobe -c if not told otherwise, this means include statements
429# work from there.
430cache_modprobe_conf() {
707f5e60 431 if [ "$kernel_version" -lt "002005" ]; then
82474db9
ER
432 modulefile=/etc/modules.conf
433 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
434 modulefile=/etc/conf.modules
435 fi
436 fi
437
438 if [ -n "$modulefile" ]; then
d8056591 439 debug "Using $modulefile for modules config"
82474db9
ER
440 modprobe_conf_cache=$(cat $modulefile)
441 else
d8056591 442 debug "Using modprobe -c to get modules config"
520412e9 443 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
82474db9
ER
444 fi
445}
446
df738638
ER
447find_modules_md() {
448 local found raidlevel
449
ac085800 450 if [ -f /etc/mdadm.conf ]; then
94769f11 451 debug "Finding RAID details using mdadm for rootdev=$1"
ac085800
ER
452 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
453 BEGIN {
454 found = "no";
455 dev_list = "";
456 raidlevel = ""
457 rootdev_devfs = rootdev;
458 if (rootdev ~ /\/dev\/md\/[0-9]/) {
459 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
460 }
514a668a 461 }
ac085800
ER
462
463 /^ARRAY/ {
464 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
465 raidlevel=$3;
466 gsub(/level=/,NUL,raidlevel);
467 if (raidlevel ~ /^raid([0-6]|10)/) {
468 gsub(/raid/,NUL,raidlevel);
469 };
470 found="yes";
471 getline x;
472 if (x ~ /devices=/) {
473 dev_list = x;
474 gsub(".*devices=", NUL, dev_list);
475 gsub(",", " ", dev_list);
476 }
477 }
56946560 478 }
ac085800
ER
479
480 END {
df738638 481 print "have_md=" found;
ac085800
ER
482 print "raidlevel=" raidlevel;
483 print "dev_list=\"" dev_list "\"";
484 }'`
485 fi
7c38b114 486
df738638 487 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
00eaa938 488 die "raidtools are not longer supported. Please migrate to mdadm setup!"
809cc4cc 489 fi
ac085800 490
82474db9 491 if is_yes "$have_md"; then
7c38b114 492 case "$raidlevel" in
bf17c86c 493 [01]|10)
7c38b114
AF
494 findmodule "raid$raidlevel"
495 ;;
bf17c86c
AM
496 [456])
497 findmodule "-raid$raidlevel"
498 findmodule "-raid456"
499 ;;
7c38b114
AF
500 linear)
501 findmodule "linear"
502 ;;
503 *)
f4010f7f 504 warn "raid level $number (in mdadm config) not recognized"
7c38b114
AF
505 ;;
506 esac
88614cd1 507 else
00eaa938 508 die "RAID devices not found for \"$1\", check your configuration!"
7c38b114 509 fi
4e9eb79c
AM
510
511 rootdev_nr=$(( $rootdev_nr + 1 ))
512 eval "rootdev${rootdev_nr}=\"$1\""
513 eval "dev_list${rootdev_nr}=\"${dev_list}\""
ac085800 514
7c38b114 515 for device in $dev_list; do
d8056591 516 find_modules_for_devpath $device
7c38b114
AF
517 done
518}
519
520find_modules_scsi() {
c3667d07 521 local n
7c38b114 522 for n in $PRESCSIMODS; do
07b09cf9 523 if [ "X$n" = "Xunknown" ]; then
f5db170b 524 debug "Finding SCSI modules using scsi_hostadapter"
60899da0
ER
525 local mod scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
526 for mod in $scsimodules; do
527 # for now allow scsi modules to come from anywhere. There are some
528 # RAID controllers with drivers in block
529 findmodule "$mod"
530 done
7c38b114
AF
531 else
532 findmodule "$n"
533 fi
534 done
84df18b8 535 findmodule "-scsi_wait_scan"
7c38b114
AF
536}
537
bc0d6f2d 538# find modules for $devpath
d8056591 539find_modules_for_devpath() {
bc0d6f2d
ER
540 local devpath="$1"
541 if [ -z "$devpath" ]; then
d8056591 542 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
f6536797 543 fi
ac085800 544
c2eb7d4f
ER
545 if [[ "$devpath" = /dev/dm-* ]]; then
546 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
bc0d6f2d 547 devpath=$(dm_longname "$devpath")
c2eb7d4f
ER
548 fi
549
67aa84bd 550 if [ -L "$devpath" ] && ! is_lvm "$devpath"; then
c2eb7d4f
ER
551 # sanitize things like:
552 # /dev/block/104:2 -> /dev/cciss/c0d0p2
553 devpath=$(readlink -f "$devpath")
554 fi
555
d8056591 556 debug "Finding modules for device path $devpath"
bc0d6f2d 557
3ef3d717
ER
558 if is_luks "$devpath"; then
559 find_modules_luks "$devpath"
560 return
561 fi
562
bc0d6f2d 563 if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
07b09cf9 564 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
00eaa938 565 die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
6fe19d5b 566 fi
7eccec8e
ER
567 if [ ! -f /proc/bus/pci/devices ]; then
568 warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:"
569 warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\""
570 else
571 local m
572 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
573 warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
574 for m in $NFS_ETH_MODULES; do
575 findmodule "$m"
576 done
577 fi
6fe19d5b 578 findmodule "-ipv4"
ac085800 579 findmodule "nfs"
69b1e935 580 have_nfs=yes
f4010f7f
AM
581 warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
582 warn "or you will have problems like init(xx) being child process of swapper(1)."
d9179777
ER
583 return
584 fi
585
26698ab2 586 if [[ "$devpath" == /dev/md* ]]; then
df738638 587 find_modules_md "$devpath"
d9179777
ER
588 return
589 fi
590
c3b54060 591 if is_multipath "$devpath"; then
07137fe3 592 if find_modules_multipath "$devpath"; then
9baf4f3f 593 return
9baf4f3f 594 fi
9baf4f3f
ER
595 # fallback
596 fi
597
36523626 598 if is_dmraid "$devpath"; then
c083ae23
ER
599 if find_modules_dmraid "$devpath"; then
600 return
601 fi
602 # fallback
603 fi
604
82474db9 605 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
7c38b114 606 find_modules_scsi
d9179777
ER
607 return
608 fi
609
30ca4815 610 if is_ide "$devpath"; then
bc0d6f2d 611 find_modules_ide "$devpath"
d9179777
ER
612 return
613 fi
614
07b09cf9 615 if [[ "$devpath" == /dev/rd/* ]]; then
7c38b114 616 findmodule "DAC960"
c3313cd6 617 rootdev_add=/dev/rd/
d9179777
ER
618 return
619 fi
620
07b09cf9 621 if [[ "$devpath" == /dev/ida/* ]]; then
7c38b114 622 findmodule "cpqarray"
c3313cd6 623 rootdev_add=/dev/ida/
d9179777
ER
624 return
625 fi
626
08651ad1 627 if [[ "$devpath" == /dev/cciss/* ]]; then
7c38b114 628 findmodule "cciss"
c3313cd6 629 rootdev_add=/dev/cciss/
d9179777
ER
630 return
631 fi
632
07b09cf9 633 if [[ "$devpath" == /dev/ataraid/* ]]; then
ac085800 634 find_modules_ide
7c38b114 635 findmodule "ataraid"
82474db9 636 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
9ae446b9 637 if [ -n "$ataraidmodules" ]; then
7c38b114 638 # FIXME: think about modules compiled in kernel
82474db9 639 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
7c38b114
AF
640 fi
641 for n in $ataraidmodules; do
642 findmodule "$n"
643 done
c3313cd6 644 rootdev_add=/dev/ataraid/
d9179777
ER
645 return
646 fi
647
7c38b114 648 # check to see if we need to set up a loopback filesystem
07b09cf9 649 if [[ "$devpath" == /dev/loop* ]]; then
00eaa938 650 die "Sorry, root on loop device isn't supported."
7c38b114
AF
651 # TODO: rewrite for bsp and make nfs ready
652 if [ ! -x /sbin/losetup ]; then
00eaa938 653 die "losetup is missing"
7c38b114 654 fi
bc0d6f2d 655 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
82474db9 656 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
42820142 657 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
658 fi
659
660 line="`awk '/'$key'/ { print $0; }' $fstab`"
661 loopDev="$(echo $line | awk '{print $3}')"
662 loopFs="$(echo $line | awk '{print $4}')"
663 loopFile="$(echo $line | awk '{print $5}')"
664
665 BASICMODULES="$BASICMODULES -loop"
666 findmodule "-$loopFs"
667 BASICMODULES="$BASICMODULES -${loopFs}"
d9179777
ER
668 return
669 fi
670
67aa84bd
ER
671 if is_lvm "$devpath"; then
672 find_modules_lvm "$devpath"
d9179777 673 return
7c38b114
AF
674 fi
675}
676
b64f015b 677firmware_install_module() {
c3667d07 678 local module="$1"
c6c6ce01 679 local firmware_files="$2"
9ed6e1db 680
94769f11 681 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
9ed6e1db 682 # firmware not yet installed
9b557a09 683 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
034fdd5d 684 inst_d /lib/firmware
9b557a09 685cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
9ed6e1db 686#!/bin/sh -e
8639f99a
AM
687echo 1 > /sys$DEVPATH/loading
688cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
689echo 0 > /sys$DEVPATH/loading
690exit 0
9ed6e1db 691EOF
9b557a09 692 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
9ed6e1db
AM
693 fi
694
695 for firmware in $firmware_files; do
4a60c01f 696 if [ ! -f "/lib/firmware/$firmware" ]; then
4a60c01f 697 die "firmware file /lib/firmware/$firmware doesn't exist."
4a60c01f 698 else
486d26a5 699 FIRMWAREDIR=${firmware%/*}
4a9920e7 700 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
7fde1ea5 701 inst /lib/firmware/$firmware /lib/firmware/$firmware
4a60c01f 702 fi
9ed6e1db
AM
703 done
704
b64f015b 705 mount_sys
c6c6ce01 706 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
9ed6e1db
AM
707}
708
2a5bcca9 709modules_install() {
c3667d07
ER
710 local modules="$1"
711 local mod
2a5bcca9
AM
712
713 for mod in $modules; do
fe280785 714 MODULEDIR=${mod%/*}
4a9920e7 715 inst_d "/lib/modules/$kernel/$MODULEDIR"
9b557a09
ER
716 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
717 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
2a5bcca9
AM
718 done
719}
720
721modules_add_linuxrc() {
fe280785 722 local mod modpath
ac085800 723
fe280785
ER
724 for mod in "$@"; do
725 # module path without optional compression
726 modpath=${mod%.gz}
727
728 # name of the module
729 module=${modpath##*/}
730 module=${module%$modext}
731
732 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
ffa1b198 733
fe280785
ER
734 generic_module=$(echo $module | tr - _)
735 sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
736 firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
2a5bcca9 737
ac085800 738 if [ -n "$verbose" ]; then
8a47b72c
ER
739 s=""
740 if [ "$options" ]; then
741 s="$s with options [$options]"
742 fi
743 if [ "$sleep_var" ]; then
744 s="$s and $sleep_var usleep"
745 fi
4a60c01f 746 debug "Loading module [$module]$s"
ac085800
ER
747 fi
748
9ed6e1db 749 if [ -n "$firmware_var" ]; then
d814e616 750 firmware_install_module "$module" "$firmware_var"
4a60c01f
AM
751 else
752 firmware_files=$(find_firmware "$module")
753 if [ -n "$firmware_files" ]; then
754 for file in $firmware_files; do
755 firmware_install_module "$module" "$file"
756 done
757 fi
9ed6e1db 758 fi
4a60c01f 759
fe280785
ER
760 echo "$insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
761 if [ -n "$sleep_var" ]; then
c6c6ce01 762 echo "usleep $sleep_var" | add_linuxrc
8e598759 763 fi
2a5bcca9
AM
764 done
765}
766
4c16dac4 767find_modules_suspend() {
82b2dba2
ER
768 if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then
769 die "/usr/${_lib}/suspend/resume is missing!"
770 fi
771 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
441ba29b
ER
772
773 local vgvolumes=$VGVOLUMES
4c16dac4
ER
774 find_modules_for_devpath $resume_dev
775
441ba29b
ER
776 if [ "$VGVOLUMES" != "$vgvolumes" ]; then
777 # save our VG to be able to differenciate between rootfs VG
4c16dac4 778 SUSPENDVG=$VGVOLUMES
441ba29b 779 VGVOLUMES=$vgvolumes
4c16dac4
ER
780 debug "suspend device is on LVM"
781 fi
782}
783
784initrd_gen_suspend() {
9b557a09 785 mknod $DESTDIR/dev/snapshot c 10 231
b49449ac
ER
786 mkdir -p $DESTDIR${resume_dev%/*}
787 inst $resume_dev $resume_dev
4c16dac4 788
82b2dba2
ER
789 inst /etc/suspend.conf /etc/suspend.conf
790 if [ -x /usr/${_lib}/suspend/resume ]; then
fb1e695a 791 inst_exec /usr/${_lib}/suspend/resume /bin/resume
82b2dba2 792 else
fb1e695a 793 inst_exec /usr/sbin/resume /bin/resume
82b2dba2 794 fi
55884ae2
ER
795
796 add_linuxrc <<-'EOF'
30005e21
ER
797 resume=no
798 for arg in $CMDLINE; do
799 if [ "${arg##resume=}" != "${arg}" ]; then
800 resume=yes
801 fi
802 done
803 if [ "$resume" = "yes" ]; then
804 resume
805 fi
55884ae2 806 EOF
82b2dba2 807}
7591cd37 808
82b2dba2
ER
809initrd_gen_tuxonice() {
810 mount_sys
811 add_linuxrc <<-'EOF'
f7e0b46b 812 resume=no
55884ae2 813 for arg in $CMDLINE; do
8fdec664 814 if [ "${arg##resume=}" != "${arg}" -o "${arg##resume2=}" != "${arg}" ]; then
f7e0b46b 815 resume=yes
55884ae2
ER
816 fi
817 done
f7e0b46b 818 if [ "$resume" = "yes" ]; then
82b2dba2
ER
819 [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
820 [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
55884ae2 821 [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
413878f8 822 fi
82b2dba2
ER
823 EOF
824}
413878f8 825
43258faf
AG
826initrd_gen_v86d() {
827 debug "initrd_gen_v86d"
828 mknod $DESTDIR/dev/mem c 1 1
829 mknod $DESTDIR/dev/tty1 c 4 1
830 inst_d /sbin
831 inst_exec /sbin/v86d /sbin
832}
833
82b2dba2
ER
834initrd_gen_udev() {
835 debug "Setting up udev..."
836 inst_d /sbin /etc/udev
bb529f94 837
0db4e302
JR
838 if [ ! -x /sbin/initrd-udevd ]; then
839 die "/sbin/initrd-udevd not present"
82b2dba2 840 fi
06ac05d6 841
0db4e302 842 inst_exec /sbin/initrd-udevd /sbin/udevd
82b2dba2 843 inst /etc/udev/udev.conf /etc/udev/udev.conf
0868f49f 844
82b2dba2
ER
845 mount_dev
846 mount_sys
847 add_linuxrc <<-'EOF'
848 : 'Starting udev'
849 /sbin/udevd --daemon
850 EOF
0e37e33e 851
0db4e302 852 inst_exec /sbin/initrd-udevadm /sbin/udevadm
0e37e33e 853 add_linuxrc <<-'EOF'
79d7bc29
AM
854 /sbin/udevadm trigger
855 /sbin/udevadm settle
0e37e33e 856 EOF
48413b7f 857
82de999f
ER
858}
859
860initrd_gen_stop_udevd() {
82b2dba2
ER
861 busybox_applet killall
862 add_linuxrc <<-'EOF'
863 killall udevd
864 EOF
865}
ac085800 866
22b0c9f4 867
ac085800 868
82b2dba2
ER
869initrd_gen_bootsplash() {
870 local target="$1"
bb529f94 871
d8056591 872 debug "Generating bootsplash"
7992356a 873
82b2dba2 874 if [ ! -x /bin/splash.bin ]; then
f4010f7f 875 warn "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
7992356a
ER
876 return
877 fi
878
879 if [ -r /etc/sysconfig/bootsplash ]; then
880 . /etc/sysconfig/bootsplash
881 fi
882
883 if [ -z "$THEME" ]; then
f4010f7f
AM
884 warn "Please configure your /etc/sysconfig/bootsplash first."
885 warn "Generating bootsplashes skipped."
7992356a
ER
886 return
887 fi
888
889 if [ -z "$BOOT_SPLASH_RESOLUTIONS" ]; then
890 warn "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
891 warn "Not adding bootsplash to initrd."
892 fi
893
894 for res in $BOOT_SPLASH_RESOLUTIONS; do
895 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
896 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
897 debug "Added $res $THEME theme to initrd."
82b2dba2 898 else
7992356a 899 warn "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
82b2dba2 900 fi
7992356a 901 done
82b2dba2 902}
bb529f94 903
82b2dba2 904initrd_gen_fbsplash() {
d8056591 905 debug "Generating fbsplash"
cd670d83 906
6c69a2d4 907 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
889e2bf2 908 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
82b2dba2
ER
909 return
910 fi
fc629084
AG
911 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
912 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1cea325b 913
7992356a
ER
914 if [ -r /etc/sysconfig/fbsplash ]; then
915 . /etc/sysconfig/fbsplash
916 fi
917
82b2dba2 918 if [ -z "$SPLASH_THEME" ]; then
f4010f7f
AM
919 warn "Please configure your /etc/sysconfig/fbsplash first."
920 warn "Generating fbsplashes skipped."
82b2dba2
ER
921 return
922 fi
cd670d83 923
82b2dba2 924 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
f4010f7f
AM
925 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
926 warn "Not adding fbsplash to initramfs."
82b2dba2
ER
927 return
928 fi
bb529f94 929
82b2dba2
ER
930 for res in $FB_SPLASH_RESOLUTIONS; do
931 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
fc629084 932 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
6c69a2d4
ER
933 debug "Added $res $SPLASH_THEME theme to initramfs."
934 else
935 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
936 fi
937 done
938}
939
940initrd_gen_fbcondecor() {
941 debug "Generating fbcondecor"
942
6c69a2d4
ER
943 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
944 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
945 return
946 fi
fc629084
AG
947 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
948 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
6c69a2d4
ER
949
950 if [ -r /etc/sysconfig/splash ]; then
951 . /etc/sysconfig/splash
952 fi
953
954 if [ -z "$SPLASH_THEME" ]; then
955 warn "Please configure your /etc/sysconfig/splash first."
956 warn "Generating of splashes skipped."
957 return
958 fi
959
960 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
961 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/splash."
962 warn "Not adding fbcondecor to initramfs."
963 return
964 fi
965
966 for res in $FB_SPLASH_RESOLUTIONS; do
967 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
fc629084 968 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
82b2dba2
ER
969 debug "Added $res $SPLASH_THEME theme to initramfs."
970 else
f4010f7f 971 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
82b2dba2
ER
972 fi
973 done
974}
bb529f94 975
82b2dba2
ER
976# Generates /dev nodes based on /proc/partitions information.
977# Needs /proc mounted.
978# Can be called multiple times.
979initrd_gen_devices() {
980 if is_yes "$proc_partitions"; then
981 return
982 fi
983 proc_partitions=yes
335cd101 984
82b2dba2
ER
985 mount_dev
986 add_linuxrc <<-'EOF'
987 : 'Making device nodes'
988 cat /proc/partitions | (
8d4aba01 989 # ignore first two lines: header, empty line
82b2dba2 990 read b; read b
2cc3ae8b 991
82b2dba2
ER
992 while read major minor blocks dev rest; do
993 node=/dev/$dev
994 mkdir -p ${node%/*}
8d4aba01 995 [ -e $node ] || mknod $node b $major $minor
82b2dba2
ER
996 done
997 )
998 EOF
999}
bb529f94 1000
82b2dba2
ER
1001initrd_gen_md() {
1002 debug "Setting up mdadm..."
bb529f94 1003
82b2dba2
ER
1004 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1005 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
1006 fi
bb529f94 1007
fb1e695a 1008 inst_exec /sbin/initrd-mdassemble /bin/mdassemble
bb529f94 1009
82b2dba2 1010 # LVM on RAID case
e0f3739d 1011 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
666778eb
AM
1012 if [ "$dev_list_extra" = "partitions" ]; then
1013 # FIXME: handle this case (see man mdadm.conf)
1014 echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
1015 dev_list_extra=""
1016 else
1017 for ex_dev in $dev_list_extra; do
1018 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
1019 done
1020 fi
82b2dba2
ER
1021 do_md0=1
1022 for nr in `seq 1 $rootdev_nr`; do
1023 eval cr_rootdev="\$rootdev${nr}"
1024 eval cr_dev_list="\$dev_list${nr}"
1025 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
bb529f94 1026
82b2dba2 1027 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
f5db170b 1028
9b557a09 1029 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
82b2dba2
ER
1030 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1031 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
1032 if [ -n "$cr_md_conf" ]; then
9b557a09 1033 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
82b2dba2 1034 else
9b557a09 1035 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
82b2dba2 1036 fi
034fdd5d 1037
82b2dba2
ER
1038 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1039 # mkdir in case of devfs name
1040 inst_d $(dirname $f)
9b557a09 1041 [ -e "$DESTDIR/$f" ] && continue
82b2dba2
ER
1042 # this works fine with and without devfs
1043 inst $f $f
1044 done
1045 done
bb529f94 1046
82b2dba2 1047 echo "mdassemble" | add_linuxrc
bb529f94 1048
82b2dba2
ER
1049 # needed to determine md-version
1050 if [ "$do_md0" -eq 1 ]; then
9b557a09 1051 mknod $DESTDIR/dev/md0 b 9 0
82b2dba2
ER
1052 fi
1053}
ef66f232 1054
82b2dba2
ER
1055initrd_gen_nfs() {
1056 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1057 # have problems like init(XX) being child process of swapper(1).
1058 debug "Adding rootfs on NFS support to initrd (dhcp)"
9b557a09
ER
1059 mknod "$DESTDIR/dev/urandom" c 1 9
1060 mkdir "$DESTDIR/newroot"
a7592d42
AG
1061 add_linuxrc <<-'EOF'
1062 ifconfig lo 127.0.0.1 up
1063 route add -net 127.0.0.0 mask 255.0.0.0 lo
1064 ifconfig eth0 up
1065 udhcpc -i eth0 -f -q -s /bin/setdhcp
1066
1067 cd /newroot
1068 pivot_root . initrd
1069 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1070 exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1071 EOF
57227e0a 1072
9b557a09 1073 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
82b2dba2
ER
1074 #!/bin/sh
1075 [ "$1" != "bound" ] && exit
1076 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1077 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1078 ifconfig $interface $ip $BROADCAST $NETMASK up
1079 if [ -n "$router" ]; then
1080 for r in $router; do
1081 route add default gw $r dev $interface
1082 done
1083 fi
aeb75537 1084
3a1d3d88 1085 for o in $CMDLINE; do
82b2dba2
ER
1086 case $o in
1087 nfsroot=*)
1088 rootpath=${o#nfsroot=}
1089 ;;
1090 esac
1091 done
e7751933 1092
82b2dba2
ER
1093 if [ -n "$rootpath" ]; then
1094 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1095 else
1096 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1097 echo "All seen variables are listed below:"
1098 set
e934d044 1099 fi
82b2dba2 1100 EOF
e7751933 1101
9b557a09 1102 chmod 755 "$DESTDIR/bin/setdhcp"
82b2dba2
ER
1103}
1104
289fbc9b 1105initrd_gen_blkid()
1106{
1107 debug "Adding BLKID support to initrd"
fb1e695a 1108 inst_exec /sbin/initrd-blkid /bin/blkid
289fbc9b 1109 initrd_gen_devices
1110 add_linuxrc <<-'EOF'
12617f8e 1111 # if built with blkid change ROOT=LABEL=something into ROOT=/dev/somethingelse -
fc787d45 1112 # parsed by blkid
1113 if [ "${ROOT##LABEL=}" != "${ROOT}" -o "${ROOT##UUID=}" != "${ROOT}" ]; then
1114 ROOT="$(/bin/blkid -t $ROOT -o device -l)"
1115 fi
289fbc9b 1116 EOF
1117}
1118
4828c787 1119initrd_gen_setrootdev() {
5a761721 1120 debug "Adding rootfs finding based on kernel cmdline root= option support."
82b2dba2 1121 add_linuxrc <<-'EOF'
dcdf6b49
ER
1122 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
1123 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
82b2dba2
ER
1124 if [ -n "$rootnr" ]; then
1125 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1126 fi
1127 fi
b64f015b 1128 EOF
1606e343
AM
1129}
1130
4671d086
ER
1131initrd_gen_initramfs_switchroot() {
1132 inst_d /newroot
1133 if [ "$rootdev" = "/dev/nfs" ]; then
1134 echo "rootfs on NFS root=/dev/nfs"
1135 else
1136 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
1137 fi
5845b321
ER
1138
1139 # parse 'root=xxx' kernel commandline
4671d086
ER
1140 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
1141 add_linuxrc <<-'EOF'
1142 device=/dev/no_partition_found
1143 eval "$(busybox awk -v c="$ROOT" '
1144 BEGIN {
1145 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
1146 num_pattern = "[0-9a-f]" num_pattern_short;
1147 dev_pattern = "[hms][a-z][a-z]([0-9])+";
1148 partition = "no_partition_found";
1149 min = -1; maj = -1;
1150
1151 sub("^0x", "", c);
1152 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
1153 if (c ~ "^" num_pattern "$") {
1154 maj = sprintf("%s",substr(c,1,2));
1155 min = sprintf("%s",substr(c,3));
1156 }
1157 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
1158 if (c ~ "^" dev_pattern "$") partition = c;
1159 }
1160
1161 $4 ~ partition { maj = $1; min = $2; }
1162 $1 ~ maj && $2 ~ min { partition = $4; }
1163
1164 END {
fa3a5452
ER
1165 if (maj >= 0 && min >= 0) {
1166 printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
1167 }
4671d086
ER
1168 }
1169 ' /proc/partitions)"
1170 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
1171 mknod $device b $maj $min
1172 fi
1173 EOF
1174
1175 add_linuxrc <<-EOF
1176 rootdev=$rootdev
1177 rootfs=$rootFs
1178 EOF
1179
1180 add_linuxrc <<-'EOF'
1181 if [ "$device" = '/dev/no_partition_found' ]; then
1182 device=$rootdev
1183 fi
1184
1185 mount -t $rootfs -r $device /newroot
1186 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
1187 if [ -z "$init" -o ! -x "/newroot$init" ]; then
1188 init=/sbin/init
1189 fi
1190 EOF
1191
1192 umount_all
1193 busybox_applet switch_root
1194 add_linuxrc <<-'EOF'
1195 exec switch_root /newroot $init
1196
1197 echo "Error! initramfs should not reach this place."
1198 echo "It probably means you've got old version of busybox, with broken"
1199 echo "initramfs support. Trying to boot anyway, but won't promise anything."
1200
1201 exec chroot /newroot $init
1202
1203 echo "Failed to chroot!"
1204 EOF
1205 # we need /init being real file, not symlink, otherwise the initramfs will
1206 # not be ran by pid 1 which is required for switch_root
1207 mv $DESTDIR/linuxrc $DESTDIR/init
1208 ln -s init $DESTDIR/linuxrc
1209}
1210
034056fd
ER
1211# main()
1212if [ "$(id -u)" != 0 ]; then
1213 die "You need to be root to generate initrd"
1214fi
1215
0db4e302 1216if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
82b2dba2
ER
1217 USE_UDEV=yes
1218 . /etc/udev/udev.conf
1219fi
2cc3ae8b 1220
30ca4815 1221# ide addon
ded87775 1222. /lib/geninitrd/mod-ide.sh
8d07ddab 1223# cryptsetup luks addon
ded87775 1224. /lib/geninitrd/mod-luks.sh
c3b54060 1225# dm-multipath addon
ded87775 1226. /lib/geninitrd/mod-multipath.sh
36523626 1227# dmraid addon
ded87775 1228. /lib/geninitrd/mod-dmraid.sh
67aa84bd 1229# LVM addon
ded87775 1230. /lib/geninitrd/mod-lvm.sh
2cc3ae8b 1231
af075488 1232if [ -x /sbin/initrd-blkid ]; then
1233 USE_BLKID=yes
1234fi
1235
82b2dba2
ER
1236if [ -r /etc/sysconfig/geninitrd ]; then
1237 . /etc/sysconfig/geninitrd
1238fi
2cc3ae8b 1239
82b2dba2
ER
1240if [ ! -x /bin/initrd-busybox ]; then
1241 die "/bin/initrd-busybox is missing!"
1242fi
c6c6ce01 1243
82b2dba2
ER
1244# backwards compatible
1245if [ "$USE_SUSPEND2" ]; then
1246 USE_TUXONICE=$USE_SUSPEND2
f4010f7f 1247 warn "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
82b2dba2 1248fi
882472ae 1249
82b2dba2
ER
1250while [ $# -gt 0 ]; do
1251 case $1 in
1252 --fstab=*)
1253 fstab=${1#--fstab=}
1254 ;;
1255 --fstab)
1256 fstab=$2
1257 shift
1258 ;;
1259 --modules-conf=*)
1260 modulefile=${1#--modules-conf=}
1261 ;;
1262 --modules-conf)
1263 modulefile=$2
1264 shift
1265 ;;
1266 --use-raidstart|--with-raidstart)
1267 USERAIDSTART=yes
1268 ;;
1269 --without-raidstart)
1270 USERAIDSTART=no
1271 ;;
1272 --use-insmod-static|--with-insmod-static)
1273 USEINSMODSTATIC=yes
1274 ;;
1275 --without-insmod-static)
1276 USEINSMODSTATIC=no
1277 ;;
1278 --with-bootsplash)
1279 BOOT_SPLASH=yes
1280 ;;
1281 --without-bootsplash)
1282 BOOT_SPLASH=no
1283 ;;
1284 --with-fbsplash)
1285 FB_SPLASH=yes
1286 ;;
1287 --without-fbsplash)
1288 FB_SPLASH=no
1289 ;;
6c69a2d4
ER
1290 --with-fbcondecor)
1291 FB_CON_DECOR=yes
1292 ;;
1293 --without-fbcondecor)
1294 FB_CON_DECOR=no
1295 ;;
82b2dba2
ER
1296 --with-suspend)
1297 USE_SUSPEND=yes
1298 ;;
1299 --without-suspend)
1300 USE_SUSPEND=no
1301 ;;
1302 --with-suspend2 | --with-tuxonice)
1303 USE_TUXONICE=yes
1304 ;;
1305 --without-suspend2 | --without-tuxonice)
1306 USE_TUXONICE=no
1307 ;;
80b1ed79 1308 --lvmversion=*)
7308edee 1309 LVMTOOLSVERSION=${1#--lvmversion=}
82b2dba2 1310 ;;
80b1ed79 1311 --lvmtoolsversion=*)
1312 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
1313 ;;
82b2dba2
ER
1314 --lvmtoolsversion|--lvmversion)
1315 LVMTOOLSVERSION=$2
1316 shift
1317 ;;
1318 --without-udev)
1319 USE_UDEV=no
1320 ;;
1321 --with-udev)
1322 USE_UDEV=yes
1323 ;;
1324 --without-dmraid)
1325 USE_DMRAID=no
1326 ;;
1327 --without-multipath)
1328 USE_MULTPATH=no
1329 ;;
af075488 1330 --without-blkid)
1331 USE_BLKID=no
289fbc9b 1332 ;;
3ef3d717
ER
1333 --without-luks)
1334 USE_LUKS=no
1335 ;;
82b2dba2
ER
1336 --with=*)
1337 BASICMODULES="$BASICMODULES ${1#--with=}"
1338 ;;
1339 --with)
1340 BASICMODULES="$BASICMODULES $2"
1341 shift
1342 ;;
1343 --version)
1344 echo "$PROGRAM: version $VERSION"
1345 exit 0
1346 ;;
1347 -v)
1348 verbose=-v
1349 ;;
1350 --nocompress)
1351 COMPRESS=no
1352 ;;
1353 --ifneeded)
1354 ifneeded=1
1355 ;;
1356 -f)
1357 force=1
1358 ;;
1359 --preload=*)
1360 PREMODS="$PREMODS ${1#--preload=}"
1361 ;;
1362 --preload)
1363 PREMODS="$PREMODS $2"
1364 shift
1365 ;;
1366 --fs=*)
f4010f7f 1367 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
82b2dba2
ER
1368 INITRDFS=${1#--fs=}
1369 ;;
1370 --fs)
f4010f7f 1371 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
82b2dba2
ER
1372 INITRDFS=$2
1373 shift
1374 ;;
1375 --initrdfs=*)
1376 INITRDFS=${1#--initrdfs=}
1377 ;;
1378 --initrdfs)
1379 INITRDFS=$2
1380 shift
1381 ;;
1382 --image-version)
1383 img_vers=yes
1384 ;;
1385 --ide-only-root)
1386 ide_only_root="yes"
1387 ;;
1388 *)
1389 if [ -z "$target" ]; then
1390 target="$1"
1391 elif [ -z "$kernel" ]; then
1392 kernel="$1"
1393 else
36523626
ER
1394 usage >&2
1395 exit 1
82b2dba2
ER
1396 fi
1397 ;;
1398 esac
f5db170b 1399
82b2dba2
ER
1400 shift
1401done
1402
1403if [ -z "$target" -o -z "$kernel" ]; then
36523626
ER
1404 usage >&2
1405 exit 1
82b2dba2
ER
1406fi
1407
130aadc1 1408if [ ! -f /boot/vmlinuz-"$kernel" ]; then
f4010f7f 1409 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
130aadc1
ER
1410fi
1411
707f5e60
ER
1412kernel_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1413kernel_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
82b2dba2
ER
1414
1415if [ -z "$INITRDFS" ]; then
326dd4ad 1416 if [ -z "$FS" ]; then
6d60e1b7 1417 # default value
707f5e60 1418 if [ "$kernel_version" -ge "002005" ]; then
6d60e1b7
ER
1419 INITRDFS="initramfs"
1420 else
1421 INITRDFS="rom"
1422 fi
82b2dba2 1423 else
f4010f7f 1424 warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
82b2dba2 1425 INITRDFS="$FS"
f5db170b 1426 fi
82b2dba2 1427fi
f5db170b 1428
707f5e60 1429if [ "$kernel_version" -lt "002006" ]; then
82b2dba2
ER
1430 USE_UDEV=no
1431 USE_DMRAID=no
1432fi
f5db170b 1433
707f5e60 1434if [ "$kernel_version" -ge "002005" ]; then
82b2dba2
ER
1435 modext=".ko"
1436 insmod="insmod"
1437fi
966c32cc 1438
82b2dba2
ER
1439if is_yes "$USEINSMODSTATIC"; then
1440 insmod="insmod.static"
1441 INSMOD="/sbin/insmod.static"
707f5e60 1442 if [ "$kernel_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
82b2dba2 1443 INSMOD="/sbin/insmod.static.modutils"
966c32cc 1444 fi
82b2dba2
ER
1445 if [ ! -f "$INSMOD" ]; then
1446 die "insmod.static requested but /sbin/insmod.static not found!"
966c32cc 1447 fi
82b2dba2 1448fi
966c32cc 1449
82b2dba2
ER
1450case "$INITRDFS" in
1451 ext2)
1452 if [ ! -x /sbin/mke2fs ]; then
1453 die "/sbin/mke2fs is missing"
f5db170b 1454 fi
82b2dba2
ER
1455 ;;
1456 rom|romfs)
1457 if [ ! -x /sbin/genromfs ]; then
1458 die "/sbin/genromfs is missing"
1459 fi
1460 ;;
1461 cram|cramfs)
1462 if [ ! -x /sbin/mkcramfs ]; then
1463 die "/sbin/mkcramfs is missing"
1464 fi
1465 ;;
1466 initramfs)
1467 if [ ! -x /bin/cpio ]; then
1468 die "/bin/cpio is missing"
1469 fi
1470 if [ ! -x /usr/bin/find ]; then
1471 die "/usr/bin/find is missing"
1472 fi
1473 ;;
1474 *)
1475 die "Filesystem $INITRDFS on initrd is not supported"
1476 ;;
1477esac
f5db170b 1478
9323ada3 1479if [ -L "$target" ]; then
1480 target=$(readlink -f "$target")
1481fi
1482
82b2dba2
ER
1483if [ -n "$img_vers" ]; then
1484 target="$target-$kernel"
1485fi
8bd582f1 1486
82b2dba2
ER
1487if [ -z "$force" -a -f "$target" ]; then
1488 die "$target already exists."
1489fi
c6c6ce01 1490
82b2dba2
ER
1491if [ ! -d "/lib/modules/$kernel" ]; then
1492 die "/lib/modules/$kernel is not a directory."
1493fi
2ffb1734 1494
12617f8e 1495if [ "$INITRDFS" != "initramfs" ]; then
12617f8e
ER
1496 if is_yes "$FB_SPLASH"; then
1497 warn "Using fbsplash requires INITRDFS=initramfs; skipping fbsplash generation"
1498 FB_SPLASH=no
1499 fi
1500 if is_yes "$FB_CON_DECOR"; then
1501 warn "Using fbcondecor requires INITRDFS=initramfs; skipping fbcondecor generation"
1502 FB_CON_DECOR=no
1503 fi
1504fi
1505
82b2dba2 1506if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
6c69a2d4 1507 warn "Tuxonice and mainline suspend are exclusive!"
82b2dba2 1508fi
ac085800 1509
7992356a 1510if is_yes "$FB_SPLASH" && is_yes "$BOOT_SPLASH"; then
6c69a2d4 1511 warn "bootsplash and fbsplash are exclusive!"
82b2dba2 1512fi
994eb509 1513
82b2dba2 1514if [ ! -f /proc/mounts ]; then
4aa3bff8 1515 warn "/proc filesystem not mounted, may cause wrong results or failure."
82b2dba2 1516fi
6cca3165 1517
82b2dba2
ER
1518if [ -d /usr/lib64 ]; then
1519 _lib=lib64
1520else
1521 _lib=lib
1522fi
67aa84bd 1523debug "# $RCSID"
d8056591 1524debug "Using libdir: $_lib"
ac085800 1525
82b2dba2
ER
1526cache_modprobe_conf
1527
1528for n in $PREMODS; do
1529 findmodule "$n"
1530done
1531
ed30e3a8
ER
1532if [ "$FBMODULE" ]; then
1533 findmodule "$FBMODULE"
1534fi
1535
82b2dba2
ER
1536# allow forcing loading SCSI and/or IDE modules
1537if is_yes "$ADDSCSI"; then
1538 find_modules_scsi
1539fi
1540
1541if is_yes "$ADDIDE"; then
1542 find_modules_ide
1543fi
1544
4c16dac4
ER
1545if is_yes "$USE_SUSPEND"; then
1546 find_modules_suspend
1547fi
1548
82b2dba2
ER
1549find_root "$fstab" || exit
1550debug "Using $rootdev as device for rootfs"
1551
d8056591 1552find_modules_for_devpath "$rootdev"
ac085800 1553
82b2dba2 1554findmodule "-$rootFs"
ac085800 1555
82b2dba2
ER
1556for n in $BASICMODULES; do
1557 findmodule "$n"
1558done
4e9eb79c 1559
82b2dba2
ER
1560if is_yes "$USE_TUXONICE"; then
1561 findmodule "-lzf"
1562fi
33d24e12 1563
82b2dba2
ER
1564if is_yes "$FB_SPLASH"; then
1565 findmodule "-evdev"
1566fi
2968c9dd 1567
82b2dba2
ER
1568if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1569 debug "No modules are needed -- not building initrd image."
1570 exit 0
1571fi
c6c6ce01 1572
d8056591 1573DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
9b557a09 1574RCFILE="$DESTDIR/linuxrc"
82b2dba2
ER
1575> "$RCFILE"
1576chmod a+rx "$RCFILE"
9b557a09 1577ln -s linuxrc $DESTDIR/init
e8d178ff 1578
82b2dba2
ER
1579# create dirs that we really need
1580inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
e8d178ff 1581
82b2dba2 1582modules_install "$MODULES"
b64f015b 1583
82b2dba2
ER
1584# mknod'ing the devices instead of copying them works both with and
1585# without devfs...
9b557a09
ER
1586mknod "$DESTDIR/dev/console" c 5 1
1587mknod "$DESTDIR/dev/null" c 1 3
1588mknod "$DESTDIR/dev/zero" c 1 5
be2f3ecc 1589
fb1e695a 1590inst_exec /bin/initrd-busybox /bin/initrd-busybox
9b557a09
ER
1591ln -s initrd-busybox $DESTDIR/bin/sh
1592ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
2ffb1734 1593
82b2dba2 1594if is_yes "$USEINSMODSTATIC"; then
fb1e695a 1595 inst_exec "$INSMOD" /bin/insmod.static
82b2dba2 1596fi
c6c6ce01 1597
82b2dba2
ER
1598add_linuxrc <<EOF
1599#!/bin/sh
1600# initrd generated by:
1601# $RCSID
c6c6ce01 1602
82b2dba2
ER
1603EOF
1604mount_proc
1605add_linuxrc <<-'EOF'
3a1d3d88 1606 read CMDLINE < /proc/cmdline; export CMDLINE
c6c6ce01 1607
82b2dba2
ER
1608 for arg in $CMDLINE; do
1609 if [ "${arg}" = "debuginitrd" ]; then
1610 DEBUGINITRD=yes
1611 fi
1612 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1613 DEBUGINITRD=${arg##debuginitrd=}
1614 fi
fc787d45 1615 if [ "${arg##root=}" != "${arg}" ]; then
1616 ROOT=${arg##root=}
1617 fi
82b2dba2 1618 done
c6c6ce01 1619
82b2dba2
ER
1620 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1621 if [ "$DEBUGINITRD" = "sh" ]; then
1622 debugshell() {
e2405b29
AM
1623EOF
1624if is_yes "$RUN_SULOGIN_ON_ERR"; then
1625add_linuxrc <<-'EOF'
1626 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1627EOF
1628else
1629add_linuxrc <<-'EOF'
1630 sh
1631EOF
1632fi
1633add_linuxrc <<-'EOF'
82b2dba2
ER
1634 }
1635 else
1636 debugshell() {
1637 :
1638 }
1639 fi
e934d044 1640
82b2dba2
ER
1641 if [ "$DEBUGINITRD" ]; then
1642 set -x
cff3058d 1643 fi
82b2dba2 1644EOF
2df2e995 1645
fe280785 1646modules_add_linuxrc $MODULES
82b2dba2
ER
1647
1648# TODO: rewrite for busybox
1649#if [ -n "$loopDev" ]; then
1650# if [ ! -d /initrd ]; then
1651# mkdir /initrd
1652# fi
1653#
9b557a09
ER
1654# cp -a "$loopDev" "$DESTDIR/dev"
1655# cp -a "$rootdev" "$DESTDIR/dev"
82b2dba2
ER
1656# echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1657# echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1658# echo "echo Setting up loopback device $rootdev" >> $RCFILE
1659# echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1660#fi
2b1a3707 1661
1606e343
AM
1662if is_yes "$USE_UDEV"; then
1663 initrd_gen_udev
1664fi
1665
1cd2aabd
ER
1666if is_yes "$USE_TUXONICE"; then
1667 initrd_gen_tuxonice
2df2e995
AM
1668fi
1669
43258faf
AG
1670if is_yes "$need_v86d"; then
1671 initrd_gen_v86d
1672fi
1673
3ef3d717
ER
1674if is_yes "$have_luks"; then
1675 initrd_gen_luks
1676fi
1677
cc8e8a99 1678if is_yes "$have_dmraid"; then
882472ae
ER
1679 initrd_gen_dmraid
1680fi
1681
c083ae23 1682if is_yes "$have_multipath"; then
2cc3ae8b
ER
1683 initrd_gen_multipath
1684fi
1685
cc8e8a99 1686if is_yes "$USE_BLKID"; then
289fbc9b 1687 initrd_gen_blkid
1688fi
1689
69b1e935 1690if is_yes "$have_nfs"; then
2df2e995 1691 initrd_gen_nfs
df738638
ER
1692elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
1693 initrd_gen_md
69b1e935 1694 if is_yes "$have_lvm"; then
2df2e995 1695 initrd_gen_lvm
bfea009a 1696 else
4828c787 1697 initrd_gen_setrootdev
2df2e995 1698 fi
69b1e935 1699elif is_yes "$have_lvm"; then
2df2e995 1700 initrd_gen_lvm
2b1a3707 1701else
4828c787 1702 initrd_gen_setrootdev
7c38b114
AF
1703fi
1704
4c16dac4
ER
1705if is_yes "$USE_SUSPEND"; then
1706 initrd_gen_suspend
1707fi
1708
5101a385 1709# additional devs always needed
9b557a09 1710[ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
5101a385 1711
82de999f
ER
1712if is_yes "$USE_UDEV"; then
1713 initrd_gen_stop_udevd
1714fi
1715
f8f9e56d 1716if [ "$INITRDFS" = "initramfs" ]; then
4671d086 1717 initrd_gen_initramfs_switchroot
b64f015b 1718else
b64f015b 1719 umount_all
f8f9e56d
AM
1720fi
1721
b7feffb3
ER
1722if is_yes "$FB_SPLASH"; then
1723 initrd_gen_fbsplash
1724fi
1725
6c69a2d4
ER
1726if is_yes "$FB_CON_DECOR"; then
1727 initrd_gen_fbcondecor
1728fi
1729
d8056591 1730IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
51dc1fe6
AM
1731
1732debug "Creating $INITRDFS image $IMAGE"
2ad94d8a 1733case "$INITRDFS" in
8b1e4ac7 1734 ext2)
d8056591
ER
1735 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
1736 debug "ext2 image size: $IMAGESIZE ($DESTDIR)"
73edc0c1 1737 if [ "$IMAGESIZE" -gt 4096 ]; then
19afb117 1738 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
73edc0c1
ER
1739 fi
1740
1741 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1742 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1743 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1744
d8056591
ER
1745 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
1746 debug "Mounting ext2 image $IMAGE to $tmpmnt"
73edc0c1 1747 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
d8056591
ER
1748 # We don't need this directory, so let's save space
1749 rm -rf "$tmpmnt"/lost+found
73edc0c1 1750
d8056591
ER
1751 debug "Copy recursively $DESTDIR -> $tmpmnt"
1752 cp -a $DESTDIR/* $tmpmnt
35164381 1753 umount "$IMAGE"
d8056591
ER
1754 rmdir "$tmpmnt"
1755
8b1e4ac7 1756 ;;
c1548a54 1757 rom|romfs)
d8056591 1758 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
cdf1e7c9 1759 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
d8056591 1760 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
a8b63949 1761 if [ "$IMAGESIZE" -gt 4096 ]; then
19afb117 1762 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
a8b63949 1763 fi
8b1e4ac7 1764 ;;
c1548a54 1765 cram|cramfs)
d8056591 1766 mkcramfs "$DESTDIR" "$IMAGE"
8b1e4ac7 1767 ;;
48413b7f 1768 initramfs)
d8056591 1769 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
48413b7f 1770 ;;
8b1e4ac7 1771 *)
7758e45c 1772 echo "Filesystem $INITRDFS not supported by $PROGRAM";
c31050f3 1773esac
bb529f94 1774
82474db9 1775if is_yes "$COMPRESS"; then
aecfd33d 1776 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
d8056591
ER
1777 debug "Compressing $target"
1778 gzip -9 < "$IMAGE" > "$tmp"
1779 mv -f "$tmp" "$target"
bb529f94 1780else
7d2fc5eb 1781 cp -a "$IMAGE" "$target"
bb529f94 1782fi
5b71959c 1783
edd9c362
ER
1784size=$(stat -c %s $target | awk '{print int((($1/1024)+1023)/1024)*1024}')
1785debug "Minimum RAM size that could be used for $target is: ramdisk_size=$size"
1786
7992356a 1787# XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
5b71959c 1788if is_yes "$BOOT_SPLASH"; then
f5db170b 1789 initrd_gen_bootsplash "$target"
5b71959c
AM
1790fi
1791
d8056591 1792rm -rf "$DESTDIR" "$IMAGE"
ac085800
ER
1793
1794# vim:ts=4:sw=4:noet:fdm=marker
This page took 0.454032 seconds and 4 git commands to generate.