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