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