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