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