]>
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() { | |
ec49b7e6 ER |
200 | |
201 | add_linuxrc <<-'EOF' | |
903f21ea | 202 | : Last shell before umounting all and giving control over to real init. |
ec49b7e6 ER |
203 | debugshell |
204 | EOF | |
5b70f84d | 205 | |
b64f015b ER |
206 | if is_yes "$dev_mounted"; then |
207 | echo 'umount /dev' | add_linuxrc | |
208 | dev_mounted=no | |
209 | fi | |
210 | if is_yes "$proc_mounted"; then | |
211 | echo 'umount /proc' | add_linuxrc | |
212 | proc_mounted=no | |
213 | fi | |
214 | if is_yes "$sys_mounted"; then | |
215 | echo 'umount /sys' | add_linuxrc | |
216 | sys_mounted=no | |
217 | fi | |
218 | if is_yes "$tmp_mounted"; then | |
219 | echo 'umount /tmp' | add_linuxrc | |
220 | tmp_mounted=no | |
221 | fi | |
222 | } | |
223 | ||
224 | ||
9299682f ER |
225 | # Checks if busybox has support for APPLET(s) |
226 | # Exits from geninitrd if the support is not present. | |
227 | # | |
228 | # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases! | |
229 | busybox_applet() { | |
230 | local err=0 | |
231 | ||
232 | if [ -z "$busybox_functions" ]; then | |
9b1373fb ER |
233 | local tmp=$(/bin/initrd-busybox 2>&1) |
234 | ||
235 | # BusyBox v1.1.3 says applet not found if it's not called 'busybox'. | |
236 | if [[ "$tmp" = *applet\ not\ found* ]]; then | |
237 | local t=$(mktemp -d) | |
238 | ln -s /bin/initrd-busybox $t/busybox | |
239 | local tmp=$($t/busybox 2>&1) | |
240 | rm -rf $t | |
241 | fi | |
242 | ||
243 | busybox_functions=$(echo "$tmp" | \ | |
9299682f ER |
244 | sed -ne '/Currently defined functions:/,$p' | \ |
245 | xargs | sed -e 's,.*Currently defined functions: ,,' | |
246 | ) | |
247 | fi | |
248 | for applet in $*; do | |
249 | local have | |
250 | # try cache | |
251 | eval have='$'busybox_have_$applet | |
252 | if [ -z "$have" ]; then | |
253 | have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)") | |
254 | if [ "$have" = 0 ]; then | |
255 | echo >&2 "This setup requires busybox-initrd compiled with applet '$applet' support" | |
256 | err=1 | |
257 | fi | |
258 | eval busybox_have_$applet=$have | |
259 | fi | |
260 | done | |
261 | if [ $err = 1 ]; then | |
00eaa938 | 262 | die "Aborted" |
9299682f ER |
263 | fi |
264 | } | |
265 | ||
10c3df06 MM |
266 | find_depmod () { |
267 | typeset mods module f level depfile first | |
268 | ||
269 | depfile=/lib/modules/$kernel/modules.dep | |
ac085800 | 270 | |
00eaa938 | 271 | if [ ! -f $depfile ]; then |
9e1ceabe | 272 | die "No $depfile! Run depmod and rerun $PROGRAM." |
f6de9380 | 273 | fi |
ac085800 | 274 | |
0868f49f | 275 | # prepend / if no path given, append $modext.gz if not given, |
10c3df06 | 276 | # quote / |
3b00e899 | 277 | origmodule="$2" |
10c3df06 | 278 | module=$(echo "$2" | \ |
ac085800 ER |
279 | awk '/\// {print;next} {print "/" $0}' | \ |
280 | awk '/\./ {print;next} {print $0 "'$modext'.gz"}' | | |
281 | awk '{gsub("/","\\/");print}') | |
10c3df06 MM |
282 | mods=$(awk ' |
283 | BEGIN { here = 0 } | |
284 | /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next } | |
285 | /:/ { here = 0 } | |
286 | /(.*)/ { gsub(/\\/," "); if (here) print } | |
4fd11db9 AF |
287 | ' $depfile | xargs) |
288 | ||
0868f49f | 289 | # fallback to $modext |
07b09cf9 | 290 | if [ "$mods" = "" ]; then |
00eaa938 | 291 | module=$(echo "$module" | awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}') |
740d6215 | 292 | # ") - vim |
ac085800 | 293 | fi |
00eaa938 | 294 | |
4fd11db9 AF |
295 | mods=$(awk ' |
296 | BEGIN { here = 0 } | |
297 | /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next } | |
298 | /:/ { here = 0 } | |
299 | /(.*)/ { gsub(/\\/," "); if (here) print } | |
10c3df06 MM |
300 | ' $depfile | xargs) |
301 | ||
07b09cf9 ER |
302 | if [ "$mods" = "" ]; then |
303 | if [ "$1" != silent ]; then | |
94769f11 | 304 | echo >&2 "$origmodule: module not found in $depfile" |
10c3df06 | 305 | fi |
00eaa938 | 306 | if ! is_no "$EXIT_IF_MISSING"; then |
fd2dc249 AF |
307 | exit 1 |
308 | else | |
94769f11 | 309 | echo >&2 "If $origmodule isn't compiled in kernel then this initrd may not start your system." |
fd2dc249 | 310 | fi |
10c3df06 | 311 | fi |
ac085800 | 312 | |
10c3df06 | 313 | level=$3 |
07b09cf9 | 314 | if [ "$level" = "" ]; then |
10c3df06 MM |
315 | level=0 |
316 | fi | |
94769f11 | 317 | level=$((level + 1)) |
07b09cf9 | 318 | if [ $level -gt 20 ]; then |
00eaa938 | 319 | die "$origmodule: cycle in $depfile" |
10c3df06 | 320 | fi |
ac085800 | 321 | |
10c3df06 | 322 | first= |
82474db9 | 323 | for f in $mods; do |
07b09cf9 | 324 | if [ "$first" = "" ]; then |
10c3df06 | 325 | first=$f |
413878f8 | 326 | else |
10c3df06 | 327 | find_depmod $1 $f $level |
9c9f7cdb | 328 | fi |
aa69da6e | 329 | done |
ac085800 | 330 | |
10c3df06 | 331 | echo $first |
aa69da6e | 332 | } |
333 | ||
10c3df06 | 334 | addmodule() { |
c3667d07 ER |
335 | local fmPath=$1 |
336 | local skiperrors=$2 | |
10c3df06 MM |
337 | |
338 | if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then | |
339 | if [ -n "$skiperrors" ]; then | |
340 | return | |
341 | fi | |
342 | ||
00eaa938 | 343 | die "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" |
10c3df06 MM |
344 | fi |
345 | ||
346 | # only need to add each module once | |
347 | # quote / | |
c3667d07 | 348 | local tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}') |
82474db9 | 349 | if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}'; then |
10c3df06 MM |
350 | MODULES="$MODULES $fmPath" |
351 | fi | |
81de8443 AF |
352 | } |
353 | ||
bb529f94 | 354 | findmodule() { |
c3667d07 ER |
355 | local skiperrors="" |
356 | local modName=$1 | |
10c3df06 | 357 | |
94769f11 | 358 | if [ ${modName#-} != ${modName} ]; then |
413878f8 | 359 | skiperrors=1 |
94769f11 | 360 | modName=${modName#-} |
413878f8 | 361 | fi |
bb529f94 | 362 | |
10c3df06 | 363 | # what's that? |
413878f8 | 364 | if [ "$modName" = "pluto" ]; then |
365 | findmodule fc4 | |
366 | findmodule soc | |
367 | fi | |
368 | if [ "$modName" = "fcal" ]; then | |
369 | findmodule fc4 | |
370 | findmodule socal | |
371 | fi | |
bb529f94 | 372 | |
c3667d07 | 373 | local mod allModulesToFind |
10c3df06 | 374 | if [ -n "$skiperrors" ]; then |
94769f11 | 375 | allModulesToFind=$(find_depmod silent $modName) |
10c3df06 | 376 | else |
94769f11 ER |
377 | allModulesToFind=$(find_depmod normal $modName) |
378 | if [ $? != 0 ]; then | |
10c3df06 | 379 | exit 1 |
413878f8 | 380 | fi |
413878f8 | 381 | fi |
ac085800 | 382 | |
94769f11 ER |
383 | for mod in $allModulesToFind; do |
384 | mod=$(echo $mod | awk '{sub(/^\/lib\/modules\/[^\/]*\//, ""); print}') | |
10c3df06 MM |
385 | addmodule $mod "$skiperrors" |
386 | done | |
bb529f94 JK |
387 | } |
388 | ||
034fdd5d ER |
389 | # install a file to temporary mount image. |
390 | # it will operate recursively (copying directories) | |
391 | # and will symlink destinations if source is symlink. | |
bb529f94 | 392 | inst() { |
17e97aec ER |
393 | if [ $# -lt 2 ]; then |
394 | die 'Usage: inst <file> [<file>] $MNTIMAGE<destination>' | |
c31050f3 | 395 | fi |
17e97aec ER |
396 | |
397 | local src i=0 c=$(($# - 1)) | |
398 | while [ $i -lt $c ]; do | |
399 | src="$src $1" | |
400 | i=$((i + 1)) | |
401 | shift | |
402 | done | |
403 | local dest=$1 | |
404 | set -- $src | |
405 | ||
406 | debug "cp $* $MNTIMAGE$dest" | |
407 | cp -HR "$@" "$MNTIMAGE$dest" | |
bb529f94 JK |
408 | } |
409 | ||
dab92b1d | 410 | inst_d() { |
17e97aec | 411 | if [ $# = 0 ]; then |
dab92b1d | 412 | die 'Usage: inst_d $MNTIMAGE<destination> $MNTIMAGE<destination>' |
034fdd5d ER |
413 | fi |
414 | for dir in "$@"; do | |
034fdd5d ER |
415 | install -d "$MNTIMAGE$dir" |
416 | done | |
417 | } | |
418 | ||
209061e3 ER |
419 | # install executable and it's shared libraries |
420 | inst_exec() { | |
17e97aec ER |
421 | if [ $# -lt 2 ]; then |
422 | die 'Usage: inst_exec <file> [, <file>] $MNTIMAGE<destination>' | |
423 | fi | |
209061e3 ER |
424 | local src i=0 c=$(($# - 1)) |
425 | while [ $i -lt $c ]; do | |
426 | src="$src $1" | |
427 | i=$((i + 1)) | |
428 | shift | |
429 | done | |
9b532fe6 | 430 | local dest=$1 |
209061e3 ER |
431 | set -- $src |
432 | ||
9b532fe6 ER |
433 | inst "$@" $dest |
434 | ||
42820142 | 435 | local lib libs=$(ldd "$@" | awk '/statically|linux-gate\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u) |
9b532fe6 | 436 | for lib in $libs; do |
7efbe841 ER |
437 | if [ ! -f "$MNTIMAGE/$_lib/${lib##*/}" ]; then |
438 | inst_d /$_lib | |
439 | inst_exec $lib /$_lib | |
17e97aec | 440 | fi |
209061e3 ER |
441 | done |
442 | } | |
443 | ||
82474db9 ER |
444 | # output modules.conf / modprobe.conf |
445 | modprobe_conf() { | |
446 | echo "$modprobe_conf_cache" | |
447 | } | |
448 | ||
449 | # | |
450 | # defaults to modprobe -c if not told otherwise, this means include statements | |
451 | # work from there. | |
452 | cache_modprobe_conf() { | |
453 | if [ "$pack_version" -lt "002005" ]; then | |
454 | modulefile=/etc/modules.conf | |
455 | if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then | |
456 | modulefile=/etc/conf.modules | |
457 | fi | |
458 | fi | |
459 | ||
460 | if [ -n "$modulefile" ]; then | |
461 | debug "modprobe: using $modulefile" | |
462 | modprobe_conf_cache=$(cat $modulefile) | |
463 | else | |
464 | debug "modprobe: using modprobe -c" | |
465 | modprobe_conf_cache=$(modprobe -c) | |
466 | fi | |
467 | } | |
468 | ||
df738638 ER |
469 | find_modules_md() { |
470 | local found raidlevel | |
471 | ||
ac085800 | 472 | if [ -f /etc/mdadm.conf ]; then |
94769f11 | 473 | debug "Finding RAID details using mdadm for rootdev=$1" |
ac085800 ER |
474 | eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" ' |
475 | BEGIN { | |
476 | found = "no"; | |
477 | dev_list = ""; | |
478 | raidlevel = "" | |
479 | rootdev_devfs = rootdev; | |
480 | if (rootdev ~ /\/dev\/md\/[0-9]/) { | |
481 | gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs); | |
482 | } | |
514a668a | 483 | } |
ac085800 ER |
484 | |
485 | /^ARRAY/ { | |
486 | if (($2 == rootdev) || ($2 == rootdev_devfs)) { | |
487 | raidlevel=$3; | |
488 | gsub(/level=/,NUL,raidlevel); | |
489 | if (raidlevel ~ /^raid([0-6]|10)/) { | |
490 | gsub(/raid/,NUL,raidlevel); | |
491 | }; | |
492 | found="yes"; | |
493 | getline x; | |
494 | if (x ~ /devices=/) { | |
495 | dev_list = x; | |
496 | gsub(".*devices=", NUL, dev_list); | |
497 | gsub(",", " ", dev_list); | |
498 | } | |
499 | } | |
56946560 | 500 | } |
ac085800 ER |
501 | |
502 | END { | |
df738638 | 503 | print "have_md=" found; |
ac085800 ER |
504 | print "raidlevel=" raidlevel; |
505 | print "dev_list=\"" dev_list "\""; | |
506 | }'` | |
507 | fi | |
7c38b114 | 508 | |
df738638 | 509 | if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then |
00eaa938 | 510 | die "raidtools are not longer supported. Please migrate to mdadm setup!" |
809cc4cc | 511 | fi |
ac085800 | 512 | |
82474db9 | 513 | if is_yes "$have_md"; then |
7c38b114 | 514 | case "$raidlevel" in |
bf17c86c | 515 | [01]|10) |
7c38b114 AF |
516 | findmodule "raid$raidlevel" |
517 | ;; | |
bf17c86c AM |
518 | [456]) |
519 | findmodule "-raid$raidlevel" | |
520 | findmodule "-raid456" | |
521 | ;; | |
7c38b114 AF |
522 | linear) |
523 | findmodule "linear" | |
524 | ;; | |
525 | *) | |
94769f11 | 526 | echo >&2 "raid level $number (in mdadm config) not recognized" |
7c38b114 AF |
527 | ;; |
528 | esac | |
88614cd1 | 529 | else |
00eaa938 | 530 | die "RAID devices not found for \"$1\", check your configuration!" |
7c38b114 | 531 | fi |
4e9eb79c AM |
532 | |
533 | rootdev_nr=$(( $rootdev_nr + 1 )) | |
534 | eval "rootdev${rootdev_nr}=\"$1\"" | |
535 | eval "dev_list${rootdev_nr}=\"${dev_list}\"" | |
ac085800 | 536 | |
7c38b114 | 537 | for device in $dev_list; do |
a8007847 | 538 | find_modules_for_device $device |
7c38b114 AF |
539 | done |
540 | } | |
541 | ||
542 | find_modules_scsi() { | |
c3667d07 | 543 | local n |
7c38b114 | 544 | for n in $PRESCSIMODS; do |
07b09cf9 | 545 | if [ "X$n" = "Xunknown" ]; then |
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 | ||
9baf4f3f | 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" |
034fdd5d ER |
911 | inst_d /proc |
912 | inst_d /sys | |
9ed6e1db AM |
913 | # firmware not yet installed |
914 | if [ ! -f "$MNTIMAGE/lib/firmware/firmware.sh" ]; then | |
034fdd5d | 915 | inst_d /lib/firmware |
9ed6e1db AM |
916 | cat << 'EOF' >> "$MNTIMAGE/lib/firmware/firmware.sh" |
917 | #!/bin/sh -e | |
8639f99a AM |
918 | echo 1 > /sys$DEVPATH/loading |
919 | cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data | |
920 | echo 0 > /sys$DEVPATH/loading | |
921 | exit 0 | |
9ed6e1db | 922 | EOF |
94769f11 | 923 | chmod 755 "$MNTIMAGE/lib/firmware/firmware.sh" |
9ed6e1db AM |
924 | fi |
925 | ||
926 | for firmware in $firmware_files; do | |
dcc1b914 | 927 | inst /lib/firmware/$firmware /lib/firmware/$firmware |
9ed6e1db AM |
928 | done |
929 | ||
b64f015b ER |
930 | mount_proc |
931 | mount_sys | |
c6c6ce01 | 932 | echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc |
9ed6e1db AM |
933 | } |
934 | ||
2a5bcca9 | 935 | modules_install() { |
c3667d07 ER |
936 | local modules="$1" |
937 | local mod | |
2a5bcca9 AM |
938 | |
939 | for mod in $modules; do | |
034fdd5d ER |
940 | MODULEDIR=$(dirname "$mod") |
941 | inst_d "/lib/modules/$kernel/$MODULEDIR" | |
dd87738f | 942 | cp -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod" |
ac085800 | 943 | gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null |
2a5bcca9 AM |
944 | done |
945 | } | |
946 | ||
947 | modules_add_linuxrc() { | |
c3667d07 | 948 | local modules="$1" |
c3667d07 | 949 | local mod |
ac085800 | 950 | |
2a5bcca9 | 951 | for mod in $modules; do |
87d21026 | 952 | MODULE2="`dirname "$mod"`" |
ac085800 ER |
953 | NAME2=`basename "$mod" .gz` |
954 | MODULE2=$MODULE2/$NAME2 | |
955 | module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`" | |
82474db9 | 956 | options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}') |
ffa1b198 | 957 | |
9ed6e1db AM |
958 | generic_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ') |
959 | sleep_var="$(eval echo \$MODULE_${generic_module}_USLEEP)" | |
94769f11 | 960 | firmware_var="$(eval echo \$MODULE_${generic_module}_FIRMWARE)" |
2a5bcca9 | 961 | |
ac085800 ER |
962 | if [ -n "$verbose" ]; then |
963 | echo -n "Loading module [$module] " | |
07b09cf9 | 964 | if [ -n "$options" ]; then |
ac085800 ER |
965 | echo -n "with options [$options]" |
966 | else | |
967 | echo -n "without options" | |
968 | fi | |
8e598759 | 969 | if [ -n "$sleep_var" ]; then |
ba0552ce | 970 | echo " and $sleep_var usleep." |
8e598759 AM |
971 | else |
972 | echo "." | |
973 | fi | |
ac085800 ER |
974 | fi |
975 | ||
9ed6e1db | 976 | if [ -n "$firmware_var" ]; then |
b64f015b | 977 | firmware_install_module "$module" "$firmware_var" |
9ed6e1db | 978 | fi |
c6c6ce01 | 979 | echo "$insmod /lib/modules/$kernel/$MODULE2 $options" | add_linuxrc |
8e598759 | 980 | if [ -n "${sleep_var}" ]; then |
c6c6ce01 | 981 | echo "usleep $sleep_var" | add_linuxrc |
8e598759 | 982 | fi |
2a5bcca9 AM |
983 | done |
984 | } | |
985 | ||
07b09cf9 | 986 | if [ -r /etc/sysconfig/geninitrd ]; then |
5dc785c7 | 987 | . /etc/sysconfig/geninitrd |
988 | fi | |
989 | ||
07b09cf9 | 990 | if [ -r /etc/sysconfig/bootsplash ]; then |
5b71959c AM |
991 | . /etc/sysconfig/bootsplash |
992 | fi | |
993 | ||
07b09cf9 | 994 | if [ -r /etc/sysconfig/fbsplash ]; then |
e4b07ddc | 995 | . /etc/sysconfig/fbsplash |
996 | fi | |
997 | ||
07b09cf9 | 998 | if [ ! -x /bin/initrd-busybox ]; then |
00eaa938 | 999 | die "/bin/initrd-busybox is missing!" |
5dc785c7 | 1000 | fi |
901afd79 | 1001 | |
7591cd37 | 1002 | # backwards compatible |
07b09cf9 | 1003 | if [ "$USE_SUSPEND2" ]; then |
7591cd37 ER |
1004 | USE_TUXONICE=$USE_SUSPEND2 |
1005 | echo >&2 "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead." | |
1006 | fi | |
1007 | ||
bb529f94 | 1008 | while [ $# -gt 0 ]; do |
413878f8 | 1009 | case $1 in |
6bd433bc | 1010 | --fstab=*) |
c3667d07 | 1011 | fstab=${1#--fstab=} |
6bd433bc AF |
1012 | ;; |
1013 | --fstab) | |
c3667d07 | 1014 | fstab=$2 |
6bd433bc | 1015 | shift |
413878f8 | 1016 | ;; |
cd670d83 | 1017 | --modules-conf=*) |
c3667d07 | 1018 | modulefile=${1#--modules-conf=} |
cd670d83 | 1019 | ;; |
57188d60 | 1020 | --modules-conf) |
c3667d07 | 1021 | modulefile=$2 |
cd670d83 AF |
1022 | shift |
1023 | ;; | |
6bd433bc | 1024 | --use-raidstart|--with-raidstart) |
c3667d07 | 1025 | USERAIDSTART=yes |
6bd433bc AF |
1026 | ;; |
1027 | --without-raidstart) | |
c3667d07 | 1028 | USERAIDSTART=no |
6bd433bc | 1029 | ;; |
57227e0a | 1030 | --use-insmod-static|--with-insmod-static) |
c3667d07 | 1031 | USEINSMODSTATIC=yes |
57227e0a AF |
1032 | ;; |
1033 | --without-insmod-static) | |
c3667d07 | 1034 | USEINSMODSTATIC=no |
57227e0a | 1035 | ;; |
ba5d09f0 | 1036 | --with-bootsplash) |
c3667d07 | 1037 | BOOT_SPLASH=yes |
ba5d09f0 | 1038 | ;; |
5b71959c | 1039 | --without-bootsplash) |
c3667d07 | 1040 | BOOT_SPLASH=no |
5b71959c | 1041 | ;; |
ba5d09f0 | 1042 | --with-fbsplash) |
c3667d07 | 1043 | FB_SPLASH=yes |
ba5d09f0 | 1044 | ;; |
e4b07ddc | 1045 | --without-fbsplash) |
c3667d07 | 1046 | FB_SPLASH=no |
e4b07ddc | 1047 | ;; |
ba5d09f0 | 1048 | --with-suspend) |
c3667d07 | 1049 | USE_SUSPEND=yes |
ba5d09f0 | 1050 | ;; |
4ef98747 | 1051 | --without-suspend) |
c3667d07 | 1052 | USE_SUSPEND=no |
ba5d09f0 | 1053 | ;; |
1cd2aabd | 1054 | --with-suspend2 | --with-tuxonice) |
c3667d07 | 1055 | USE_TUXONICE=yes |
22b0c9f4 | 1056 | ;; |
1cd2aabd | 1057 | --without-suspend2 | --without-tuxonice) |
c3667d07 | 1058 | USE_TUXONICE=no |
2c52f208 | 1059 | ;; |
e0c502bb AM |
1060 | --lvmtoolsversion=|--lvmversion=) |
1061 | LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`" | |
77bcfc68 | 1062 | ;; |
e0c502bb | 1063 | --lvmtoolsversion|--lvmversion) |
c3667d07 | 1064 | LVMTOOLSVERSION=$2 |
77bcfc68 AF |
1065 | shift |
1066 | ;; | |
1606e343 | 1067 | --without-udev) |
c3667d07 | 1068 | USE_UDEV=no |
1606e343 | 1069 | ;; |
d7d5530e | 1070 | --with-udev) |
c3667d07 | 1071 | USE_UDEV=yes |
d7d5530e | 1072 | ;; |
882472ae | 1073 | --without-dmraid) |
c3667d07 | 1074 | USE_DMRAID=no |
882472ae | 1075 | ;; |
2cc3ae8b | 1076 | --without-multipath) |
c3667d07 | 1077 | USE_MULTPATH=no |
2cc3ae8b | 1078 | ;; |
6bd433bc | 1079 | --with=*) |
c3667d07 | 1080 | BASICMODULES="$BASICMODULES ${1#--with=}" |
6bd433bc AF |
1081 | ;; |
1082 | --with) | |
1083 | BASICMODULES="$BASICMODULES $2" | |
1084 | shift | |
413878f8 | 1085 | ;; |
bb529f94 | 1086 | --version) |
9e1ceabe | 1087 | echo "$PROGRAM: version $VERSION" |
413878f8 | 1088 | exit 0 |
1089 | ;; | |
bb529f94 | 1090 | -v) |
413878f8 | 1091 | verbose=-v |
1092 | ;; | |
bb529f94 | 1093 | --nocompress) |
c3667d07 | 1094 | COMPRESS=no |
413878f8 | 1095 | ;; |
bb529f94 | 1096 | --ifneeded) |
413878f8 | 1097 | ifneeded=1 |
1098 | ;; | |
bb529f94 | 1099 | -f) |
413878f8 | 1100 | force=1 |
1101 | ;; | |
6bd433bc | 1102 | --preload=*) |
c3667d07 | 1103 | PREMODS="$PREMODS ${1#--preload=}" |
6bd433bc AF |
1104 | ;; |
1105 | --preload) | |
72623c13 | 1106 | PREMODS="$PREMODS $2" |
6bd433bc | 1107 | shift |
413878f8 | 1108 | ;; |
2ad94d8a | 1109 | --fs=*) |
94769f11 | 1110 | echo >&2 "Warning: --fs option is obsoleted. Use --initrdfs instead" |
c3667d07 | 1111 | INITRDFS=${1#--fs=} |
2ad94d8a | 1112 | ;; |
2ad94d8a | 1113 | --fs) |
94769f11 | 1114 | echo >&2 "Warning: --fs option is obsoleted. Use --initrdfs instead" |
c3667d07 | 1115 | INITRDFS=$2 |
2ad94d8a | 1116 | shift |
cd670d83 | 1117 | ;; |
6bd433bc | 1118 | --initrdfs=*) |
c3667d07 | 1119 | INITRDFS=${1#--initrdfs=} |
6bd433bc | 1120 | ;; |
fd2dc249 | 1121 | --initrdfs) |
c3667d07 | 1122 | INITRDFS=$2 |
413878f8 | 1123 | shift |
1124 | ;; | |
bb529f94 | 1125 | --image-version) |
413878f8 | 1126 | img_vers=yes |
1127 | ;; | |
4f4e832d AM |
1128 | --ide-only-root) |
1129 | ide_only_root="yes" | |
1130 | ;; | |
bb529f94 | 1131 | *) |
413878f8 | 1132 | if [ -z "$target" ]; then |
1133 | target="$1" | |
1134 | elif [ -z "$kernel" ]; then | |
1135 | kernel="$1" | |
1136 | else | |
1137 | usage | |
1138 | fi | |
1139 | ;; | |
1140 | esac | |
1141 | ||
1142 | shift | |
bb529f94 JK |
1143 | done |
1144 | ||
06ac05d6 | 1145 | if [ -z "$target" -o -z "$kernel" ]; then |
413878f8 | 1146 | usage |
06ac05d6 AF |
1147 | fi |
1148 | ||
0868f49f | 1149 | pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`" |
64497ebb | 1150 | pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`" |
0868f49f | 1151 | |
c1548a54 ER |
1152 | if [ -z "$INITRDFS" ]; then |
1153 | if [ -z = "$FS" ]; then | |
48413b7f | 1154 | # default value |
07b09cf9 | 1155 | if [ "$pack_version" -ge "002005" ]; then |
8d6cdf87 | 1156 | INITRDFS="initramfs" |
1157 | else | |
ac085800 | 1158 | INITRDFS="rom" |
8d6cdf87 | 1159 | fi |
48413b7f | 1160 | else |
94769f11 | 1161 | echo >&2 "Warning: FS configuration options is obsoleted. Use INITRDFS instead" |
48413b7f AM |
1162 | INITRDFS="$FS" |
1163 | fi | |
1164 | fi | |
1165 | ||
07b09cf9 | 1166 | if [ "$pack_version" -lt "002006" ]; then |
c3667d07 ER |
1167 | USE_UDEV=no |
1168 | USE_DMRAID=no | |
1606e343 | 1169 | fi |
ac085800 | 1170 | |
07b09cf9 | 1171 | if [ "$pack_version" -ge "002005" ]; then |
0868f49f | 1172 | modext=".ko" |
0b6536f5 | 1173 | insmod="insmod" |
0868f49f AF |
1174 | fi |
1175 | ||
82474db9 | 1176 | if is_yes "$USEINSMODSTATIC"; then |
57227e0a | 1177 | insmod="insmod.static" |
b2e62ae1 | 1178 | INSMOD="/sbin/insmod.static" |
07b09cf9 | 1179 | if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then |
f7c18703 | 1180 | INSMOD="/sbin/insmod.static.modutils" |
b2e62ae1 | 1181 | fi |
07b09cf9 | 1182 | if [ ! -f "$INSMOD" ]; then |
00eaa938 | 1183 | die "insmod.static requested but /sbin/insmod.static not found!" |
b2e62ae1 | 1184 | fi |
57227e0a AF |
1185 | fi |
1186 | ||
2ad94d8a | 1187 | case "$INITRDFS" in |
8b1e4ac7 | 1188 | ext2) |
f5d71bb2 | 1189 | if [ ! -x /sbin/mke2fs ]; then |
00eaa938 | 1190 | die "/sbin/mke2fs is missing" |
8b1e4ac7 AF |
1191 | fi |
1192 | ;; | |
c1548a54 | 1193 | rom|romfs) |
8b1e4ac7 | 1194 | if [ ! -x /sbin/genromfs ]; then |
00eaa938 | 1195 | die "/sbin/genromfs is missing" |
8b1e4ac7 AF |
1196 | fi |
1197 | ;; | |
c1548a54 | 1198 | cram|cramfs) |
8b1e4ac7 | 1199 | if [ ! -x /sbin/mkcramfs ]; then |
00eaa938 | 1200 | die "/sbin/mkcramfs is missing" |
8b1e4ac7 | 1201 | fi |
c31050f3 | 1202 | ;; |
48413b7f AM |
1203 | initramfs) |
1204 | if [ ! -x /bin/cpio ]; then | |
00eaa938 | 1205 | die "/bin/cpio is missing" |
48413b7f AM |
1206 | fi |
1207 | if [ ! -x /usr/bin/find ]; then | |
00eaa938 | 1208 | die "/usr/bin/find is missing" |
48413b7f AM |
1209 | fi |
1210 | ;; | |
8b1e4ac7 | 1211 | *) |
00eaa938 | 1212 | die "Filesystem $INITRDFS on initrd is not supported" |
8b1e4ac7 AF |
1213 | ;; |
1214 | esac | |
bb529f94 | 1215 | |
bb529f94 | 1216 | if [ -n "$img_vers" ]; then |
413878f8 | 1217 | target="$target-$kernel" |
bb529f94 JK |
1218 | fi |
1219 | ||
35164381 | 1220 | if [ -z "$force" -a -f "$target" ]; then |
00eaa938 | 1221 | die "$target already exists." |
bb529f94 JK |
1222 | fi |
1223 | ||
35164381 | 1224 | if [ ! -d "/lib/modules/$kernel" ]; then |
00eaa938 | 1225 | die "/lib/modules/$kernel is not a directory." |
bb529f94 JK |
1226 | fi |
1227 | ||
1cd2aabd ER |
1228 | if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then |
1229 | die "Tuxonice shouldn't be used in parallel with mainline suspend!." | |
22b0c9f4 AM |
1230 | fi |
1231 | ||
e4b07ddc | 1232 | if is_yes "$FB_SPLASH"; then |
1233 | if is_yes "$BOOT_SPLASH"; then | |
00eaa938 | 1234 | die "You can't use both bootsplash and fbsplash! Please choose one." |
e4b07ddc | 1235 | elif [ "$INITRDFS" != "initramfs" ]; then |
00eaa938 | 1236 | die "FB_SPLASH works only if INITRDFS is initramfs!." |
e4b07ddc | 1237 | fi |
1238 | fi | |
1239 | ||
48762878 | 1240 | if [ ! -f /proc/mounts ]; then |
94769f11 | 1241 | echo >&2 "WARNING: /proc filesystem not mounted, may cause wrong results or failure." |
48762878 | 1242 | fi |
f121024f | 1243 | |
7efbe841 ER |
1244 | if [ -d /usr/lib64 ]; then |
1245 | _lib=lib64 | |
1246 | else | |
1247 | _lib=lib | |
551c3b3e | 1248 | fi |
7efbe841 | 1249 | debug "_lib: $_lib" |
551c3b3e | 1250 | |
82474db9 | 1251 | cache_modprobe_conf |
ac085800 | 1252 | |
bb529f94 | 1253 | for n in $PREMODS; do |
35164381 | 1254 | findmodule "$n" |
bb529f94 JK |
1255 | done |
1256 | ||
7c38b114 | 1257 | # allow forcing loading SCSI and/or IDE modules |
82474db9 | 1258 | if is_yes "$ADDSCSI"; then |
7c38b114 | 1259 | find_modules_scsi |
bb529f94 JK |
1260 | fi |
1261 | ||
82474db9 | 1262 | if is_yes "$ADDIDE"; then |
7c38b114 | 1263 | find_modules_ide |
cd670d83 AF |
1264 | fi |
1265 | ||
1cea325b ER |
1266 | find_root "$fstab" || exit |
1267 | debug "Using $rootdev as device for rootfs" | |
1268 | ||
a8007847 ER |
1269 | find_modules_for_device "$rootdev" |
1270 | [ -n "$rootdev_add" ] && find_modules_for_device "$rootdev_add" | |
cd670d83 | 1271 | |
7c38b114 | 1272 | findmodule "-$rootFs" |
bb529f94 | 1273 | |
c31050f3 | 1274 | for n in $BASICMODULES; do |
7d2fc5eb | 1275 | findmodule "$n" |
bb529f94 JK |
1276 | done |
1277 | ||
1cd2aabd | 1278 | if is_yes "$USE_TUXONICE"; then |
335cd101 JR |
1279 | findmodule "-lzf" |
1280 | fi | |
1281 | ||
e4b07ddc | 1282 | if is_yes "$FB_SPLASH"; then |
1283 | findmodule "-evdev" | |
1284 | fi | |
2cc3ae8b | 1285 | |
bb529f94 | 1286 | if [ -n "$ifneeded" -a -z "$MODULES" ]; then |
94769f11 | 1287 | debug "No modules are needed -- not building initrd image." |
7d2fc5eb | 1288 | exit 0 |
bb529f94 | 1289 | fi |
94769f11 | 1290 | debug "Using modules: $MODULES" |
bb529f94 | 1291 | |
35164381 SZ |
1292 | MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`" |
1293 | IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`" | |
1294 | MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`" | |
1295 | RCFILE="$MNTIMAGE/linuxrc" | |
bb529f94 | 1296 | |
35164381 | 1297 | if [ -f "$MNTIMAGE" ]; then |
00eaa938 | 1298 | die "$MNTIMAGE already exists. Remove it and try again" |
bb529f94 JK |
1299 | fi |
1300 | ||
35164381 | 1301 | if [ -f "$IMAGE" ]; then |
00eaa938 | 1302 | die "$IMAGE already exists. Remove it and try again" |
bb529f94 JK |
1303 | fi |
1304 | ||
73edc0c1 | 1305 | mkdir -p "$MNTPOINT" |
bb529f94 | 1306 | # We don't need this directory, so let's save space |
35164381 | 1307 | rm -rf "$MNTPOINT"/lost+found |
bb529f94 | 1308 | |
034fdd5d ER |
1309 | inst_d /{lib,bin,etc,dev,loopfs,var} |
1310 | ||
2a5bcca9 | 1311 | modules_install "$MODULES" |
bb529f94 JK |
1312 | |
1313 | # mknod'ing the devices instead of copying them works both with and | |
1314 | # without devfs... | |
35164381 | 1315 | mknod "$MNTIMAGE/dev/console" c 5 1 |
eb6e37ff MM |
1316 | mknod "$MNTIMAGE/dev/null" c 1 3 |
1317 | mknod "$MNTIMAGE/dev/zero" c 1 5 | |
034fdd5d | 1318 | inst_d /dev/pts /dev/shm |
bb529f94 | 1319 | |
566ad08b | 1320 | ln -s /linuxrc $MNTIMAGE/init |
ef66f232 | 1321 | |
dcc1b914 | 1322 | inst /bin/initrd-busybox /bin/initrd-busybox |
dab92b1d ER |
1323 | ln -s initrd-busybox $MNTIMAGE/bin/sh |
1324 | ln -s initrd-busybox $MNTIMAGE/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH | |
ef66f232 | 1325 | |
1775ba37 ER |
1326 | if is_yes "$USEINSMODSTATIC"; then |
1327 | inst "$INSMOD" /bin/insmod.static | |
57227e0a AF |
1328 | fi |
1329 | ||
b64f015b ER |
1330 | echo '#!/bin/sh' | add_linuxrc |
1331 | mount_proc | |
c6c6ce01 | 1332 | add_linuxrc <<-'EOF' |
c6c6ce01 | 1333 | export CMDLINE="$(cat /proc/cmdline)" |
e7751933 ER |
1334 | |
1335 | 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; } } }') | |
1336 | ||
1337 | # make debugshell() invoke subshell if $DEBUGINITRD=sh | |
1338 | if [ "$DEBUGINITRD" = "sh" ]; then | |
c6c6ce01 | 1339 | debugshell() { |
c6c6ce01 ER |
1340 | sh |
1341 | } | |
c6c6ce01 ER |
1342 | else |
1343 | debugshell() { | |
1344 | : | |
1345 | } | |
1346 | fi | |
e7751933 ER |
1347 | |
1348 | if [ "$DEBUGINITRD" ]; then | |
1349 | set -x | |
1350 | fi | |
84670990 | 1351 | EOF |
c31050f3 | 1352 | |
c6c6ce01 | 1353 | modules_add_linuxrc "$MODULES" |
fd2dc249 | 1354 | |
4e9eb79c | 1355 | # TODO: rewrite for busybox |
fd2dc249 AF |
1356 | #if [ -n "$loopDev" ]; then |
1357 | # if [ ! -d /initrd ]; then | |
1358 | # mkdir /initrd | |
1359 | # fi | |
1360 | # | |
1361 | # cp -a "$loopDev" "$MNTIMAGE/dev" | |
738c05d8 | 1362 | # cp -a "$rootdev" "$MNTIMAGE/dev" |
fd2dc249 AF |
1363 | # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE" |
1364 | # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE" | |
738c05d8 ER |
1365 | # echo "echo Setting up loopback device $rootdev" >> $RCFILE |
1366 | # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE" | |
fd2dc249 | 1367 | #fi |
bb529f94 | 1368 | |
22b0c9f4 | 1369 | initrd_gen_suspend() { |
551c3b3e AM |
1370 | if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then |
1371 | die "/usr/${_lib}/suspend/resume is missing!" | |
22b0c9f4 | 1372 | fi |
034fdd5d | 1373 | inst_d /etc /dev |
22b0c9f4 | 1374 | resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)" |
0a01e285 | 1375 | mknod $MNTIMAGE/dev/snapshot c 10 231 |
1775ba37 ER |
1376 | inst $resume_dev /dev |
1377 | inst /etc/suspend.conf /etc/suspend.conf | |
551c3b3e AM |
1378 | if [ -x /usr/${_lib}/suspend/resume ]; then |
1379 | inst /usr/${_lib}/suspend/resume /bin/resume | |
1380 | else | |
1381 | inst /usr/sbin/resume /bin/resume | |
1382 | fi | |
c6c6ce01 | 1383 | echo "resume" | add_linuxrc |
22b0c9f4 AM |
1384 | } |
1385 | ||
1cd2aabd | 1386 | initrd_gen_tuxonice() { |
034fdd5d | 1387 | inst_d /sys /proc |
b64f015b ER |
1388 | mount_proc |
1389 | mount_sys | |
c6c6ce01 | 1390 | add_linuxrc <<-'EOF' |
c6c6ce01 ER |
1391 | if [ "$(echo "$CMDLINE" | awk ' /resume2=/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then |
1392 | [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume | |
1393 | [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume | |
1394 | [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume | |
1395 | fi | |
c6c6ce01 | 1396 | EOF |
b4d9d384 ER |
1397 | } |
1398 | ||
1606e343 | 1399 | initrd_gen_udev() { |
94769f11 | 1400 | debug "Setting up udev..." |
034fdd5d | 1401 | inst_d /sbin /proc /etc/udev /sys |
ac085800 | 1402 | |
9299682f | 1403 | if [ ! -x /sbin/initrd-udevd ]; then |
00eaa938 | 1404 | die "/sbin/initrd-udevd not present" |
9299682f ER |
1405 | fi |
1406 | ||
1775ba37 ER |
1407 | inst /sbin/initrd-udevd /sbin/udevd |
1408 | inst /etc/udev/udev.conf /etc/udev/udev.conf | |
1606e343 | 1409 | |
b64f015b ER |
1410 | mount_dev |
1411 | mount_sys | |
1412 | add_linuxrc <<-'EOF' | |
1413 | : 'Starting udev' | |
1414 | /sbin/udevd --daemon | |
1415 | EOF | |
1416 | if is_yes "$PROBESTATICMODS"; then | |
1417 | inst /sbin/initrd-udevtrigger /sbin/udevtrigger | |
1418 | inst /sbin/initrd-udevsettle /sbin/udevsettle | |
c6c6ce01 | 1419 | add_linuxrc <<-'EOF' |
b64f015b ER |
1420 | /sbin/udevtrigger |
1421 | /sbin/udevsettle | |
7915c8b1 | 1422 | EOF |
1606e343 | 1423 | fi |
b64f015b ER |
1424 | |
1425 | busybox_applet killall | |
1426 | add_linuxrc <<-'EOF' | |
1427 | killall udevd | |
1428 | EOF | |
1606e343 AM |
1429 | } |
1430 | ||
2cc3ae8b | 1431 | initrd_gen_multipath() { |
9b532fe6 | 1432 | inst_d /proc /sys /sbin /lib/udev /etc |
209061e3 ER |
1433 | inst_exec /sbin/kpartx /sbin |
1434 | inst_exec /sbin/multipath /sbin | |
2cc3ae8b | 1435 | # for udev callouts |
209061e3 ER |
1436 | inst_exec /sbin/scsi_id /lib/udev |
1437 | inst_exec /sbin/mpath* /sbin | |
9b532fe6 | 1438 | inst /etc/multipath.conf /etc |
482091c4 ER |
1439 | if [ -f /var/lib/multipath/bindings ]; then |
1440 | inst_d /var/lib/multipath | |
1441 | inst /var/lib/multipath/bindings /var/lib/multipath | |
1442 | fi | |
2cc3ae8b | 1443 | |
b64f015b ER |
1444 | mount_proc |
1445 | mount_dev | |
2cc3ae8b ER |
1446 | initrd_gen_devices |
1447 | ||
b64f015b | 1448 | mount_sys |
c6c6ce01 ER |
1449 | echo "export multipath_id=$MULTIPATH_ID" | add_linuxrc |
1450 | add_linuxrc <<-'EOF' | |
7efbe841 | 1451 | debugshell |
c6c6ce01 | 1452 | /sbin/multipath -v 0 $multipath_id |
2cc3ae8b | 1453 | |
c6c6ce01 ER |
1454 | for a in /dev/mapper/*; do |
1455 | [ $a = /dev/mapper/control ] && continue | |
1456 | /sbin/kpartx -a $a | |
1457 | done | |
c6c6ce01 | 1458 | debugshell |
c6c6ce01 | 1459 | EOF |
2cc3ae8b ER |
1460 | } |
1461 | ||
882472ae | 1462 | initrd_gen_dmraid() { |
07b09cf9 | 1463 | if [ ! -x /sbin/dmraid-initrd ]; then |
6b013929 | 1464 | die "/sbin/dmraid-initrd is missing!" |
ac085800 ER |
1465 | fi |
1466 | ||
034fdd5d | 1467 | inst_d /sbin /sys |
1775ba37 | 1468 | inst /sbin/dmraid-initrd /sbin/dmraid |
2ffb1734 | 1469 | |
b64f015b ER |
1470 | mount_dev |
1471 | mount_proc | |
1472 | mount_sys | |
2ffb1734 | 1473 | initrd_gen_devices |
c6c6ce01 ER |
1474 | add_linuxrc <<-EOF |
1475 | # 2 secs was enough for my system to initialize. but really this is udev issue? | |
1476 | usleep 2000000 | |
1477 | : 'Activating Device-Mapper RAID(s)' | |
1478 | /sbin/dmraid -ay -i | |
1479 | ||
1480 | debugshell | |
c6c6ce01 | 1481 | EOF |
882472ae ER |
1482 | } |
1483 | ||
8bd582f1 ER |
1484 | # Generates /dev nodes based on /proc/partitions information. |
1485 | # Needs /proc mounted. | |
1486 | # Can be called multiple times. | |
2ffb1734 | 1487 | initrd_gen_devices() { |
8bd582f1 ER |
1488 | if is_yes "$proc_partitions"; then |
1489 | return | |
1490 | fi | |
1491 | proc_partitions=yes | |
1492 | ||
b64f015b ER |
1493 | mount_proc |
1494 | mount_dev | |
c6c6ce01 ER |
1495 | add_linuxrc <<-'EOF' |
1496 | : 'Making device nodes' | |
1497 | cat /proc/partitions | ( | |
1498 | # ignore first two lines, header, empty line and process rest | |
1499 | read b; read b | |
1500 | ||
1501 | while read major minor blocks dev rest; do | |
1502 | node=/dev/$dev | |
1503 | mkdir -p ${node%/*} | |
1504 | mknod $node b $major $minor | |
1505 | done | |
1506 | ) | |
1507 | EOF | |
2ffb1734 ER |
1508 | } |
1509 | ||
df738638 | 1510 | initrd_gen_md() { |
94769f11 | 1511 | debug "Setting up mdadm..." |
ac085800 | 1512 | |
00eaa938 ER |
1513 | if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then |
1514 | die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!" | |
d3fa6ec7 | 1515 | fi |
994eb509 | 1516 | |
dcc1b914 | 1517 | inst /sbin/initrd-mdassemble /bin/mdassemble |
6cca3165 | 1518 | |
4e9eb79c | 1519 | # LVM on RAID case |
6cca3165 AM |
1520 | dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf) |
1521 | for ex_dev in $dev_list_extra; do | |
1522 | echo "DEVICE $ex_dev" >> "$MNTIMAGE/etc/mdadm.conf" | |
1523 | done | |
ac085800 | 1524 | do_md0=1 |
4e9eb79c | 1525 | for nr in `seq 1 $rootdev_nr`; do |
ac085800 ER |
1526 | eval cr_rootdev="\$rootdev${nr}" |
1527 | eval cr_dev_list="\$dev_list${nr}" | |
94769f11 | 1528 | debug echo "Setting up array ($cr_rootdev = $cr_dev_list)" |
ac085800 ER |
1529 | |
1530 | [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0 | |
1531 | ||
1532 | echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf" | |
1533 | cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')" | |
a46f8bda | 1534 | cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }') |
ac085800 ER |
1535 | if [ -n "$cr_md_conf" ]; then |
1536 | echo "$cr_md_conf" >> "$MNTIMAGE/etc/mdadm.conf" | |
1537 | else | |
1538 | echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf" | |
1539 | fi | |
1540 | ||
1541 | for f in $cr_dev_list $cr_rootdev $dev_list_extra; do | |
1542 | # mkdir in case of devfs name | |
034fdd5d | 1543 | inst_d $(dirname $f) |
ac085800 | 1544 | [ -e "$MNTIMAGE/$f" ] && continue |
ac085800 | 1545 | # this works fine with and without devfs |
1775ba37 | 1546 | inst $f $f |
ac085800 | 1547 | done |
ef66f232 | 1548 | done |
4e9eb79c | 1549 | |
c6c6ce01 | 1550 | echo "mdassemble" | add_linuxrc |
33d24e12 | 1551 | |
4e9eb79c | 1552 | # needed to determine md-version |
07b09cf9 | 1553 | if [ "$do_md0" -eq 1 ]; then |
4e9eb79c AM |
1554 | mknod $MNTIMAGE/dev/md0 b 9 0 |
1555 | fi | |
2df2e995 | 1556 | } |
2968c9dd | 1557 | |
2df2e995 | 1558 | initrd_gen_nfs() { |
5a61a17c | 1559 | # use root=/dev/ram0 init=/linuxrc when starting kernel or you will |
51447ab3 | 1560 | # have problems like init(XX) being child process of swapper(1). |
94769f11 | 1561 | debug "Adding rootfs on NFS support to initrd (dhcp)" |
7fc1e5bd | 1562 | mknod "$MNTIMAGE/dev/urandom" c 1 9 |
5c4cec75 | 1563 | mkdir "$MNTIMAGE/newroot" |
7d400dbe | 1564 | mkdir "$MNTIMAGE/proc" |
c6c6ce01 ER |
1565 | echo "ifconfig lo 127.0.0.1 up" | add_linuxrc |
1566 | echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" | add_linuxrc | |
1567 | echo "ifconfig eth0 0.0.0.0 up" | add_linuxrc | |
1568 | echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" | add_linuxrc | |
1569 | ||
1570 | cat <<-'EOF' > "$MNTIMAGE/bin/setdhcp" | |
1571 | #!/bin/sh | |
1572 | [ "$1" != "bound" ] && exit | |
1573 | [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" | |
1574 | [ -n "$subnet" ] && NETMASK="netmask $subnet" | |
1575 | ifconfig $interface $ip $BROADCAST $NETMASK up | |
1576 | if [ -n "$router" ]; then | |
1577 | for r in $router; do | |
1578 | route add default gw $r dev $interface | |
1579 | done | |
1580 | fi | |
b64f015b ER |
1581 | EOF |
1582 | ||
1583 | mount_proc | |
7d400dbe | 1584 | |
b64f015b | 1585 | cat <<-'EOF' > "$MNTIMAGE/bin/setdhcp" |
c6c6ce01 ER |
1586 | for o in $(cat /proc/cmdline); do |
1587 | case $o in | |
1588 | nfsroot=*) | |
1589 | rootpath=${o#nfsroot=} | |
1590 | ;; | |
1591 | esac | |
1592 | done | |
c6c6ce01 ER |
1593 | |
1594 | if [ -n "$rootpath" ]; then | |
1595 | mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot | |
1596 | else | |
1597 | echo "Missing rootpath in what DHCP server sent to us. Failing..." | |
1598 | echo "All seen variables are listed below:" | |
1599 | set | |
1600 | fi | |
1601 | EOF | |
7d400dbe | 1602 | |
5c4cec75 | 1603 | chmod 755 "$MNTIMAGE/bin/setdhcp" |
c6c6ce01 ER |
1604 | add_linuxrc <<-'EOF' |
1605 | cd /newroot | |
1606 | pivot_root . initrd | |
1607 | [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1 | |
1608 | exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1 | |
1609 | EOF | |
2df2e995 | 1610 | } |
6fe19d5b | 1611 | |
2df2e995 | 1612 | initrd_gen_lvm() { |
94769f11 | 1613 | debug "Adding LVM support to initrd" |
034fdd5d | 1614 | inst_d /etc /tmp /proc /newroot |
903f21ea | 1615 | inst /sbin/initrd-lvm /bin/lvm.static |
e8d178ff ER |
1616 | |
1617 | # always make /dev on tmpfs for LVM2 | |
7915c8b1 | 1618 | if [ "$LVMTOOLSVERSION" = "2" ]; then |
b64f015b | 1619 | mount_dev |
e8d178ff ER |
1620 | fi |
1621 | ||
b64f015b | 1622 | if ! is_yes "$dev_mounted"; then |
034fdd5d | 1623 | inst_d /dev/mapper |
afaefcb5 | 1624 | mknod $MNTIMAGE/dev/mapper/control c 10 63 |
b007399c | 1625 | for device in $PVDEVICES; do |
df738638 | 1626 | # if LVM on RAID then device might be copied already in gen_md |
13b29c8f | 1627 | [ -e "$MNTIMAGE/dev/$(basename $device)" ] && continue |
1775ba37 | 1628 | inst $device /dev |
b007399c | 1629 | done |
afaefcb5 | 1630 | fi |
b64f015b ER |
1631 | |
1632 | mount_proc | |
1633 | mount_tmp | |
07b09cf9 | 1634 | if [ "$LVMTOOLSVERSION" = "1" ]; then |
c6c6ce01 ER |
1635 | add_linuxrc <<-EOF |
1636 | lvm vgscan -T | |
1637 | lvm vgchange -T -a y $VGVOLUME | |
c6c6ce01 | 1638 | EOF |
cff3058d | 1639 | else |
c6c6ce01 | 1640 | echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc |
ac085800 | 1641 | echo "global {" > "$MNTIMAGE/etc/lvm.conf" |
f34c76a3 AM |
1642 | echo " locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf" |
1643 | echo " locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf" | |
1644 | echo "}" >> "$MNTIMAGE/etc/lvm.conf" | |
ac085800 | 1645 | echo "devices {" >> "$MNTIMAGE/etc/lvm.conf" |
8fb0a4d2 | 1646 | echo " sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf" |
df738638 | 1647 | if is_yes "$have_md"; then |
ac085800 | 1648 | echo " md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf" |
f34c76a3 | 1649 | fi |
c083ae23 | 1650 | if is_yes "$have_dmraid" || is_yes "$have_multipath"; then |
3938fd10 | 1651 | echo ' types = [ "device-mapper", 254 ]' >> "$MNTIMAGE/etc/lvm.conf" |
2cc3ae8b | 1652 | fi |
6b013929 ER |
1653 | if [ "$lvm_ignore_devices" ]; then |
1654 | # TODO: think of merging with lvm dumpconfig output | |
2cc3ae8b | 1655 | echo ' filter = [' >> "$MNTIMAGE/etc/lvm.conf" |
6b013929 ER |
1656 | local dev |
1657 | for dev in $lvm_ignore_devices; do | |
1658 | debug "LVM2: ignore device $dev" | |
2cc3ae8b ER |
1659 | printf ' "r|^%s.*|",\n' $dev |
1660 | done >> "$MNTIMAGE/etc/lvm.conf" | |
1661 | echo ']' >> "$MNTIMAGE/etc/lvm.conf" | |
3938fd10 | 1662 | fi |
6b013929 | 1663 | # XXX filter= must be on one line! |
f34c76a3 AM |
1664 | lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf" |
1665 | echo "}" >> "$MNTIMAGE/etc/lvm.conf" | |
be2f3ecc | 1666 | |
2ffb1734 ER |
1667 | initrd_gen_devices |
1668 | ||
c6c6ce01 | 1669 | add_linuxrc <<-EOF |
ec49b7e6 ER |
1670 | export LVM_ROOTDEV=$rootdev |
1671 | export LVM_VGVOLUME=$VGVOLUME | |
1672 | EOF | |
1673 | add_linuxrc <<-'EOF' | |
c6c6ce01 | 1674 | # disable noise from lvm accessing devices that aren't ready. |
ec49b7e6 | 1675 | printk=$(cat /proc/sys/kernel/printk) |
c6c6ce01 ER |
1676 | echo 0 > /proc/sys/kernel/printk |
1677 | ||
1678 | export LVM_SYSTEM_DIR=/tmp | |
1679 | : 'Scanning for Volume Groups' | |
903f21ea | 1680 | lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null |
c6c6ce01 ER |
1681 | |
1682 | : 'Activating Volume Groups' | |
903f21ea | 1683 | lvm.static vgchange --ignorelockingfailure -a y $LVM_VGVOLUME 2>/dev/null |
c6c6ce01 | 1684 | |
ec49b7e6 | 1685 | echo "$printk" > /proc/sys/kernel/printk |
c6c6ce01 ER |
1686 | |
1687 | # Find out major/minor | |
e537bb5b | 1688 | attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $LVM_ROOTDEV 2>/dev/null)" |
ec49b7e6 ER |
1689 | if [ "$attrs" ]; then |
1690 | majmin="${attrs#*/}" | |
1691 | majmin="${majmin#*:*:*:*:*:*:*:*:*:*:*:*}" | |
1692 | major="${majmin%:*}" | |
1693 | minor="${majmin#*:}" | |
1694 | fi | |
1695 | if [ "$major" -a "$minor" ]; then | |
1696 | # Pass it to kernel | |
1697 | echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev | |
e537bb5b ER |
1698 | else |
1699 | echo 2>&1 "Error figuring out real root device for $LVM_ROOTDEV!" | |
428b57c8 | 1700 | echo 2>&1 "System will not most likely boot up! So dropping you to a shell!" |
e537bb5b ER |
1701 | echo 2>&1 "" |
1702 | sh | |
ec49b7e6 | 1703 | fi |
c6c6ce01 | 1704 | EOF |
cff3058d | 1705 | fi |
2df2e995 AM |
1706 | } |
1707 | ||
2b1a3707 | 1708 | initrd_gen_procdata() { |
94769f11 | 1709 | debug "Adding rootfs finding based on root= option support." |
034fdd5d | 1710 | inst_d /proc |
b64f015b | 1711 | mount_proc |
c6c6ce01 | 1712 | add_linuxrc <<-'EOF' |
c6c6ce01 ER |
1713 | root="$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ' /proc/cmdline)" |
1714 | if [ -n "$root" ]; then | |
1715 | rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)" | |
1716 | if [ -n "$rootnr" ]; then | |
1717 | echo "$rootnr" > /proc/sys/kernel/real-root-dev | |
1718 | fi | |
1719 | fi | |
c6c6ce01 | 1720 | EOF |
2b1a3707 AM |
1721 | } |
1722 | ||
2df2e995 | 1723 | # main generation |
1606e343 AM |
1724 | if is_yes "$USE_UDEV"; then |
1725 | initrd_gen_udev | |
1726 | fi | |
1727 | ||
2ce7656a | 1728 | if is_yes "$USE_SUSPEND"; then |
22b0c9f4 AM |
1729 | initrd_gen_suspend |
1730 | fi | |
1731 | ||
1cd2aabd ER |
1732 | if is_yes "$USE_TUXONICE"; then |
1733 | initrd_gen_tuxonice | |
2df2e995 AM |
1734 | fi |
1735 | ||
c083ae23 | 1736 | if is_yes "$have_dmraid" ]; then |
882472ae ER |
1737 | initrd_gen_dmraid |
1738 | fi | |
1739 | ||
c083ae23 | 1740 | if is_yes "$have_multipath"; then |
2cc3ae8b ER |
1741 | initrd_gen_multipath |
1742 | fi | |
1743 | ||
69b1e935 | 1744 | if is_yes "$have_nfs"; then |
2df2e995 | 1745 | initrd_gen_nfs |
df738638 ER |
1746 | elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then |
1747 | initrd_gen_md | |
69b1e935 | 1748 | if is_yes "$have_lvm"; then |
2df2e995 | 1749 | initrd_gen_lvm |
bfea009a AM |
1750 | else |
1751 | initrd_gen_procdata | |
2df2e995 | 1752 | fi |
69b1e935 | 1753 | elif is_yes "$have_lvm"; then |
2df2e995 | 1754 | initrd_gen_lvm |
2b1a3707 AM |
1755 | else |
1756 | initrd_gen_procdata | |
7c38b114 AF |
1757 | fi |
1758 | ||
5101a385 | 1759 | # additional devs always needed |
1775ba37 | 1760 | [ ! -e "$MNTIMAGE/$rootdev_add" ] && inst $rootdev_add /dev |
5101a385 | 1761 | |
f8f9e56d | 1762 | if [ "$INITRDFS" = "initramfs" ]; then |
034fdd5d | 1763 | inst_d /newroot |
1775ba37 | 1764 | [ ! -e "$MNTIMAGE/$rootdev" ] && inst $rootdev /dev |
e4b07ddc | 1765 | # Parsing root parameter |
81d53704 | 1766 | # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303 |
b64f015b | 1767 | mount_proc |
c6c6ce01 | 1768 | add_linuxrc <<-'EOF' |
c6c6ce01 ER |
1769 | eval "$(busybox awk -v c="$CMDLINE" ' |
1770 | BEGIN { | |
1771 | num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]"; | |
1772 | num_pattern = "[0-9a-f]" num_pattern_short; | |
1773 | dev_pattern = "[hms][a-z][a-z]([0-9])+"; | |
1774 | partition = "no_partition_found"; | |
1775 | min = -1; maj = -1; | |
1776 | ||
1777 | gsub(/.*root=/,NIL,c); | |
1778 | gsub(/ .*/,NIL,c); | |
1779 | ||
1780 | sub("^0x", "", c); | |
1781 | if (c ~ "^" num_pattern_short "$") sub("^", "0", c); | |
1782 | if (c ~ "^" num_pattern "$") { | |
1783 | maj = sprintf("%s",substr(c,1,2)); | |
1784 | min = sprintf("%s",substr(c,3)); | |
1785 | } | |
1786 | if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c); | |
1787 | if (c ~ "^" dev_pattern "$") partition = c; | |
1788 | } | |
df391e6f | 1789 | |
c6c6ce01 ER |
1790 | $4 ~ partition { maj = $1; min = $2; } |
1791 | $1 ~ maj && $2 ~ min { partition = $4; } | |
1792 | ||
1793 | END { | |
1794 | print sprintf("device=/dev/%s\nmaj=%s\nmin=%s", | |
1795 | partition, maj, min); | |
1796 | } | |
1797 | ' /proc/partitions)" | |
1798 | if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then | |
1799 | mknod $device b $maj $min | |
1800 | fi | |
1801 | EOF | |
92a4990b ER |
1802 | |
1803 | busybox_applet switch_root | |
c6c6ce01 ER |
1804 | add_linuxrc <<-EOF |
1805 | if [ "\$device" = '/dev/no_partition_found' ]; then | |
1806 | device="$rootdev" | |
1807 | fi | |
e620b426 | 1808 | |
c6c6ce01 ER |
1809 | mount -t $rootFs -r \$device /newroot |
1810 | init="\$(busybox awk ' /init=\// { gsub(/.*init=/,NIL,\$0); gsub(/ .*/,NIL,\$0); print \$0; } ' /proc/cmdline )" | |
1811 | if [ -z "\$init" -o ! -x "/newroot\$init" ]; then | |
1812 | init=/sbin/init | |
1813 | fi | |
b64f015b ER |
1814 | EOF |
1815 | umount_all | |
1816 | add_linuxrc <<-EOF | |
c6c6ce01 | 1817 | exec switch_root /newroot \$init |
f1a5a1b0 | 1818 | |
c6c6ce01 ER |
1819 | echo "Error ! initramfs should not reach this place." |
1820 | echo "It probably means you've got old version of busybox, with broken" | |
1821 | echo "initramfs support. Trying to boot anyway, but won't promise anything." | |
f1a5a1b0 | 1822 | |
c6c6ce01 | 1823 | exec chroot /newroot \$init |
f1a5a1b0 | 1824 | |
c6c6ce01 ER |
1825 | echo "Failed to chroot !" |
1826 | EOF | |
f8f9e56d AM |
1827 | # we need real file, not symlink |
1828 | rm -f $MNTIMAGE/init | |
1829 | cp -a $MNTIMAGE/linuxrc $MNTIMAGE/init | |
b64f015b ER |
1830 | else |
1831 | # other than initramfs | |
1832 | umount_all | |
f8f9e56d AM |
1833 | fi |
1834 | ||
35164381 | 1835 | chmod +x "$RCFILE" |
bb529f94 | 1836 | |
35164381 | 1837 | (cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -) |
bb529f94 | 1838 | |
2ad94d8a | 1839 | case "$INITRDFS" in |
8b1e4ac7 | 1840 | ext2) |
94d430a8 | 1841 | IMAGESIZE=$(du -ks $MNTPOINT | awk '{print int(($1+1023+512)/1024)*1024}') |
94769f11 | 1842 | debug "ext2 image size: $IMAGESIZE ($MNTPOINT)" |
73edc0c1 | 1843 | if [ "$IMAGESIZE" -gt 4096 ]; then |
7758e45c | 1844 | echo >&2 "$PROGRAM: Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!" |
73edc0c1 ER |
1845 | fi |
1846 | ||
1847 | dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null | |
1848 | mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2 | |
1849 | tune2fs -i 0 "$IMAGE" >/dev/null 2>&1 | |
1850 | ||
1851 | tmpmnt="`mktemp -d /tmp/initrd.mnte2-XXXXXX`" | |
1852 | mount -o loop -t ext2 "$IMAGE" "$tmpmnt" | |
1853 | ||
1854 | (cd "$MNTPOINT"; tar cf - .) | (cd "$tmpmnt"; tar xf -) | |
1855 | ||
35164381 | 1856 | umount "$IMAGE" |
8b1e4ac7 | 1857 | ;; |
c1548a54 | 1858 | rom|romfs) |
8b1e4ac7 | 1859 | genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel" |
cdf1e7c9 | 1860 | IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}') |
a8b63949 ER |
1861 | debug "romfs image size: $IMAGESIZE ($IMAGE)" |
1862 | if [ "$IMAGESIZE" -gt 4096 ]; then | |
7758e45c | 1863 | echo >&2 "$PROGRAM: Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!" |
a8b63949 | 1864 | fi |
8b1e4ac7 | 1865 | ;; |
c1548a54 | 1866 | cram|cramfs) |
8b1e4ac7 | 1867 | mkcramfs "$MNTPOINT" "$IMAGE" |
8b1e4ac7 | 1868 | ;; |
48413b7f | 1869 | initramfs) |
82474db9 | 1870 | (cd $MNTPOINT; find . | cpio --quiet -H newc -o > "$IMAGE") |
48413b7f | 1871 | ;; |
8b1e4ac7 | 1872 | *) |
7758e45c | 1873 | echo "Filesystem $INITRDFS not supported by $PROGRAM"; |
c31050f3 | 1874 | esac |
bb529f94 | 1875 | |
82474db9 | 1876 | if is_yes "$COMPRESS"; then |
7d2fc5eb | 1877 | gzip -9 < "$IMAGE" > "$target" |
bb529f94 | 1878 | else |
7d2fc5eb | 1879 | cp -a "$IMAGE" "$target" |
bb529f94 | 1880 | fi |
5b71959c AM |
1881 | |
1882 | if is_yes "$BOOT_SPLASH"; then | |
1883 | if [ ! -x /bin/splash.bin ]; then | |
94769f11 | 1884 | echo >&2 "Failed to execute /bin/splash.bin. Is bootsplash package installed?" |
5b71959c | 1885 | elif [ -z "$THEME" ]; then |
94769f11 ER |
1886 | echo >&2 "Please configure your /etc/sysconfig/bootsplash first." |
1887 | echo >&2 "Generating bootsplashes skipped." | |
5b71959c | 1888 | else |
ac085800 ER |
1889 | if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then |
1890 | for res in $BOOT_SPLASH_RESOLUTIONS; do | |
1891 | if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then | |
1892 | /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \ | |
94769f11 | 1893 | debug "Added $res $THEME theme to initrd." |
ac085800 | 1894 | else |
94769f11 | 1895 | echo >&2 "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" |
ac085800 ER |
1896 | fi |
1897 | done | |
1898 | else | |
94769f11 ER |
1899 | echo >&2 "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." |
1900 | echo >&2 "Not adding bootsplash to initrd." | |
ac085800 | 1901 | fi |
5b71959c AM |
1902 | fi |
1903 | fi | |
1904 | ||
e4b07ddc | 1905 | if is_yes "$FB_SPLASH"; then |
1906 | if [ ! -x /usr/bin/splash_geninitramfs ]; then | |
1907 | echo >&2 "Failed to execute /usr/bin/splash_geninitramfs. Is splashutils package installed?" | |
1908 | elif [ -z "$SPLASH_THEME" ]; then | |
1909 | echo >&2 "Please configure your /etc/sysconfig/fbsplash first." | |
1910 | echo >&2 "Generating fbsplashes skipped." | |
1911 | else | |
1912 | if [ -n "$FB_SPLASH_RESOLUTIONS" ]; then | |
1913 | for res in $FB_SPLASH_RESOLUTIONS; do | |
1914 | if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then | |
1915 | /usr/bin/splash_geninitramfs -a $target -r $res $SPLASH_THEME && \ | |
1916 | debug "Added $res $SPLASH_THEME theme to initramfs." | |
1917 | else | |
1918 | echo >&2 "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped" | |
1919 | fi | |
1920 | done | |
1921 | else | |
1922 | echo >&2 "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash." | |
1923 | echo >&2 "Not adding fbsplash to initramfs." | |
1924 | fi | |
1925 | fi | |
1926 | fi | |
1927 | ||
35164381 | 1928 | rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE" |
ac085800 ER |
1929 | |
1930 | # vim:ts=4:sw=4:noet:fdm=marker |