]>
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 |
ef08134f | 11 | # - make proper use of USE_UDEV - don't copy rules 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 |
e2405b29 | 20 | . /etc/sysconfig/system |
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="" | |
6c69a2d4 | 44 | # requires bootsplash package to operate |
5b71959c | 45 | BOOT_SPLASH=no |
6c69a2d4 | 46 | # requires splashutils package to operate |
e4b07ddc | 47 | FB_SPLASH=no |
6c69a2d4 ER |
48 | # requires splashutils package to operate |
49 | FB_CON_DECOR=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='' |
4c16dac4 | 66 | |
43258faf AG |
67 | # whether v86d should be installed |
68 | need_v86d=0 | |
69 | ||
4c16dac4 ER |
70 | # LVM volumes that are needed to activate |
71 | # VG for root dev | |
72 | ROOTVG="" | |
73 | # VG for suspend resume dev | |
74 | SUSPENDVG="" | |
75 | ||
3ef3d717 ER |
76 | # DM name for cryptsetup luks |
77 | LUKSNAME="" | |
78 | ||
4c16dac4 ER |
79 | # resume device |
80 | resume_dev="" | |
c083ae23 | 81 | |
69b1e935 ER |
82 | # if we should init NFS at boot |
83 | have_nfs=no | |
84 | # if we should init LVM at boot | |
df738638 ER |
85 | have_lvm=no |
86 | # if we should init md (softraid) at boot | |
87 | have_md=no | |
c083ae23 ER |
88 | # if we should init dmraid at boot |
89 | have_dmraid=no | |
3ef3d717 ER |
90 | # if we should init cryptsetup luks at boot |
91 | have_luks=no | |
9baf4f3f | 92 | # if we should init dm-multipath at boot |
69b1e935 | 93 | have_multipath=no |
e136dd8b | 94 | # dm-multipath wwid which is used for rootfs |
7548b210 | 95 | MPATH_WWID= |
b4d9d384 | 96 | |
b64f015b | 97 | usage() { |
553786c4 | 98 | uname_r=$(uname -r) |
00eaa938 | 99 | echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]" |
ac085800 | 100 | echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]" |
92ed99b6 | 101 | echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]" |
ac085800 | 102 | echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]" |
ba5d09f0 | 103 | echo " [--with-bootsplash] [--without-bootsplash]" |
6c69a2d4 ER |
104 | echo " [--with-fbsplash] [--without-fbsplash]" |
105 | echo " [--with-fbcondecor] [--without-fbcondecor]" | |
e4b07ddc | 106 | echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]" |
ba5d09f0 | 107 | echo " [--with-suspend] [--without-suspend]" |
1cd2aabd | 108 | echo " [--with-tuxonice] [--without-tuxonice]" |
2cc3ae8b | 109 | echo " [--without-dmraid] [--without-multipath]" |
3ef3d717 | 110 | echo " [--without-blkid] [--without-luks]" |
ac085800 | 111 | echo " <initrd-image> <kernel-version>" |
553786c4 ER |
112 | echo "" |
113 | echo "example:" | |
00eaa938 | 114 | echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r" |
7d2fc5eb | 115 | exit 1 |
bb529f94 JK |
116 | } |
117 | ||
779a218a | 118 | msg() { |
f4010f7f AM |
119 | echo "$PROGRAM: $*" |
120 | } | |
121 | ||
122 | warn() { | |
4a60c01f | 123 | msg "WARNING: $*" >&2 |
779a218a AM |
124 | } |
125 | ||
94769f11 | 126 | debug() { |
4a60c01f | 127 | [ -n "$verbose" ] && msg "$*" >&2 |
94769f11 | 128 | } |
aa69da6e | 129 | |
bf6c3fcb ER |
130 | # aborts program abnormally |
131 | die() { | |
b5f5c089 | 132 | local rc=${2:-1} |
524cafef | 133 | msg "ERROR: $1" 2>&2 |
bf6c3fcb ER |
134 | exit $rc |
135 | } | |
136 | ||
c6c6ce01 ER |
137 | # append text to /linuxrc |
138 | # takes STDIN as input | |
139 | add_linuxrc() { | |
b64f015b | 140 | cat >> "$RCFILE" |
c6c6ce01 ER |
141 | } |
142 | ||
b64f015b ER |
143 | # generate code to mount /dev on tmpfs and create initial nodes |
144 | # can be called multiple times. /dev is cleaned up (umounted) automatically at | |
145 | # the end of script. | |
146 | mount_dev() { | |
147 | if [ "$INITRDFS" = "initramfs" ]; then | |
148 | # initramfs is read-write filesystem, no need for tmpfs | |
149 | return | |
150 | fi | |
151 | ||
152 | # we already generated tmpfs code; return | |
153 | if is_yes "$dev_mounted"; then | |
154 | return | |
155 | fi | |
156 | ||
157 | dev_mounted=yes | |
158 | ||
159 | busybox_applet mount mknod mkdir | |
160 | add_linuxrc <<-EOF | |
161 | : 'Creating /dev' | |
162 | mount -o mode=0755 -t tmpfs none /dev | |
163 | mknod /dev/console c 5 1 | |
164 | mknod /dev/null c 1 3 | |
165 | mknod /dev/zero c 1 5 | |
166 | mkdir /dev/pts | |
167 | mkdir /dev/shm | |
168 | EOF | |
169 | } | |
170 | ||
171 | # generate code to mount /proc on initrd | |
172 | # can be called multiple times | |
173 | mount_proc() { | |
174 | if is_yes "$proc_mounted"; then | |
175 | return | |
176 | fi | |
177 | ||
178 | proc_mounted=yes | |
2bface63 ER |
179 | if [ "$INITRDFS" = "initramfs" ]; then |
180 | # /proc is mounted with initramfs 2.6.22.14 kernel | |
181 | # XXX: remove when it is clear why proc was already mounted | |
182 | echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc | |
183 | else | |
184 | echo "mount -t proc none /proc" | add_linuxrc | |
185 | fi | |
b64f015b ER |
186 | } |
187 | ||
188 | # generate code to mount /sys on initrd | |
189 | # can be called multiple times | |
190 | mount_sys() { | |
191 | if is_yes "$sys_mounted"; then | |
192 | return | |
193 | fi | |
194 | ||
195 | sys_mounted=yes | |
196 | echo "mount -t sysfs none /sys" | add_linuxrc | |
197 | } | |
198 | ||
199 | # generate code to mount /tmp on initrd | |
200 | # can be called multiple times | |
201 | mount_tmp() { | |
202 | if [ "$INITRDFS" = "initramfs" ]; then | |
203 | # initramfs is read-write filesystem, no need for tmpfs | |
204 | return | |
205 | fi | |
206 | ||
207 | if is_yes "$tmp_mounted"; then | |
208 | return | |
209 | fi | |
210 | ||
211 | tmp_mounted=yes | |
212 | echo "mount -t tmpfs none /tmp" | add_linuxrc | |
213 | } | |
214 | ||
215 | # unmount all mountpoints mounted by geninitrd | |
216 | umount_all() { | |
ec49b7e6 ER |
217 | |
218 | add_linuxrc <<-'EOF' | |
903f21ea | 219 | : Last shell before umounting all and giving control over to real init. |
ec49b7e6 ER |
220 | debugshell |
221 | EOF | |
5b70f84d | 222 | |
b64f015b ER |
223 | if is_yes "$dev_mounted"; then |
224 | echo 'umount /dev' | add_linuxrc | |
225 | dev_mounted=no | |
226 | fi | |
227 | if is_yes "$proc_mounted"; then | |
228 | echo 'umount /proc' | add_linuxrc | |
229 | proc_mounted=no | |
230 | fi | |
231 | if is_yes "$sys_mounted"; then | |
232 | echo 'umount /sys' | add_linuxrc | |
233 | sys_mounted=no | |
234 | fi | |
235 | if is_yes "$tmp_mounted"; then | |
236 | echo 'umount /tmp' | add_linuxrc | |
237 | tmp_mounted=no | |
238 | fi | |
239 | } | |
240 | ||
241 | ||
9299682f ER |
242 | # Checks if busybox has support for APPLET(s) |
243 | # Exits from geninitrd if the support is not present. | |
244 | # | |
245 | # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases! | |
246 | busybox_applet() { | |
247 | local err=0 | |
248 | ||
249 | if [ -z "$busybox_functions" ]; then | |
9b1373fb ER |
250 | local tmp=$(/bin/initrd-busybox 2>&1) |
251 | ||
252 | # BusyBox v1.1.3 says applet not found if it's not called 'busybox'. | |
253 | if [[ "$tmp" = *applet\ not\ found* ]]; then | |
254 | local t=$(mktemp -d) | |
255 | ln -s /bin/initrd-busybox $t/busybox | |
256 | local tmp=$($t/busybox 2>&1) | |
257 | rm -rf $t | |
258 | fi | |
259 | ||
260 | busybox_functions=$(echo "$tmp" | \ | |
9299682f ER |
261 | sed -ne '/Currently defined functions:/,$p' | \ |
262 | xargs | sed -e 's,.*Currently defined functions: ,,' | |
263 | ) | |
264 | fi | |
265 | for applet in $*; do | |
266 | local have | |
267 | # try cache | |
268 | eval have='$'busybox_have_$applet | |
269 | if [ -z "$have" ]; then | |
270 | have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)") | |
271 | if [ "$have" = 0 ]; then | |
f4010f7f | 272 | warn "This setup requires busybox-initrd compiled with applet '$applet' support" |
9299682f ER |
273 | err=1 |
274 | fi | |
275 | eval busybox_have_$applet=$have | |
276 | fi | |
277 | done | |
278 | if [ $err = 1 ]; then | |
00eaa938 | 279 | die "Aborted" |
9299682f ER |
280 | fi |
281 | } | |
282 | ||
7ffba534 ER |
283 | # Finds module dependencies |
284 | # | |
7ffba534 | 285 | # @param $module |
fe280785 | 286 | # @param $mode [silent] |
7ffba534 ER |
287 | # |
288 | # Outputs each dependant module full path including the module itself. | |
289 | find_depmod() { | |
fe280785 ER |
290 | local module="$1" |
291 | local mode="$2" | |
7ffba534 ER |
292 | |
293 | # backwards compatible, process $mode | |
294 | local modfile | |
fe280785 | 295 | if [ "$mode" = "silent" ]; then |
52836fc5 | 296 | modfile=$(modinfo -k $kernel -n $module 2>/dev/null) |
7ffba534 | 297 | else |
52836fc5 | 298 | modfile=$(modinfo -k $kernel -n $module) |
7ffba534 ER |
299 | fi |
300 | if [ ! -f "$modfile" ]; then | |
fe280785 | 301 | if [ "$mode" != "silent" ]; then |
7ffba534 ER |
302 | warn "$module: module not found for $kernel kernel" |
303 | fi | |
304 | if ! is_no "$EXIT_IF_MISSING"; then | |
305 | exit 1 | |
306 | else | |
307 | warn "If $module isn't compiled in kernel then this initrd may not start your system." | |
308 | fi | |
309 | fi | |
310 | ||
311 | # This works when user has module-init-tools installed even on 2.4 kernels | |
312 | modprobe --set-version $kernel --show-depends $module | \ | |
c25765ed | 313 | while read insmod modpath options; do |
7ffba534 ER |
314 | echo $modpath |
315 | done | |
316 | } | |
317 | ||
4a60c01f AM |
318 | find_firmware() { |
319 | local module="$1" | |
320 | echo -n $(modinfo -k $kernel -F firmware $module 2>/dev/null | xargs) | |
321 | } | |
322 | ||
bb529f94 | 323 | findmodule() { |
c3667d07 ER |
324 | local skiperrors="" |
325 | local modName=$1 | |
10c3df06 | 326 | |
fe280785 | 327 | if [ ${modName#-} != $modName ]; then |
413878f8 | 328 | skiperrors=1 |
94769f11 | 329 | modName=${modName#-} |
413878f8 | 330 | fi |
bb529f94 | 331 | |
10c3df06 | 332 | # what's that? |
413878f8 | 333 | if [ "$modName" = "pluto" ]; then |
334 | findmodule fc4 | |
335 | findmodule soc | |
336 | fi | |
337 | if [ "$modName" = "fcal" ]; then | |
338 | findmodule fc4 | |
339 | findmodule socal | |
340 | fi | |
bb529f94 | 341 | |
12617f8e | 342 | local mod depmod |
7ffba534 | 343 | if [ "$skiperrors" = 1 ]; then |
fe280785 | 344 | depmod=$(find_depmod $modName silent) |
10c3df06 | 345 | else |
fe280785 | 346 | depmod=$(find_depmod $modName) |
94769f11 | 347 | if [ $? != 0 ]; then |
10c3df06 | 348 | exit 1 |
413878f8 | 349 | fi |
413878f8 | 350 | fi |
ac085800 | 351 | |
fe280785 | 352 | for mod in $depmod; do |
7ffba534 | 353 | mod=${mod#/lib/modules/$kernel/} |
fe280785 ER |
354 | |
355 | # add each module only once | |
356 | local m have=0 | |
357 | for m in $MODULES; do | |
358 | [ $m = $mod ] && have=1 | |
359 | done | |
360 | if [ $have = 0 ]; then | |
43258faf AG |
361 | MODULES="$MODULES $mod" |
362 | ||
363 | # if we are adding uvesafb, we need v86d as well | |
364 | if [ "$modName" = "uvesafb" ]; then | |
365 | need_v86d=yes | |
366 | fi | |
fe280785 | 367 | fi |
10c3df06 | 368 | done |
bb529f94 JK |
369 | } |
370 | ||
034fdd5d ER |
371 | # install a file to temporary mount image. |
372 | # it will operate recursively (copying directories) | |
373 | # and will symlink destinations if source is symlink. | |
bb529f94 | 374 | inst() { |
17e97aec | 375 | if [ $# -lt 2 ]; then |
a9ace64a | 376 | die 'Usage: inst <file> [<file>] <destination>' |
c31050f3 | 377 | fi |
17e97aec ER |
378 | |
379 | local src i=0 c=$(($# - 1)) | |
380 | while [ $i -lt $c ]; do | |
381 | src="$src $1" | |
382 | i=$((i + 1)) | |
383 | shift | |
384 | done | |
385 | local dest=$1 | |
386 | set -- $src | |
242f2358 PZ |
387 | parentDir=$(dirname $DESTDIR$dest) |
388 | [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir) | |
d8056591 | 389 | debug "+ cp $* $DESTDIR$dest" |
9b557a09 | 390 | cp -HR "$@" "$DESTDIR$dest" |
bb529f94 JK |
391 | } |
392 | ||
dab92b1d | 393 | inst_d() { |
17e97aec | 394 | if [ $# = 0 ]; then |
a9ace64a | 395 | die 'Usage: inst_d <destination> <destination>' |
034fdd5d ER |
396 | fi |
397 | for dir in "$@"; do | |
9b557a09 | 398 | install -d "$DESTDIR$dir" |
034fdd5d ER |
399 | done |
400 | } | |
401 | ||
209061e3 ER |
402 | # install executable and it's shared libraries |
403 | inst_exec() { | |
17e97aec | 404 | if [ $# -lt 2 ]; then |
524cafef | 405 | die 'Usage: inst_exec <file>[, <file>] <destination>' |
17e97aec | 406 | fi |
209061e3 ER |
407 | local src i=0 c=$(($# - 1)) |
408 | while [ $i -lt $c ]; do | |
409 | src="$src $1" | |
410 | i=$((i + 1)) | |
411 | shift | |
412 | done | |
9b532fe6 | 413 | local dest=$1 |
209061e3 ER |
414 | set -- $src |
415 | ||
9b532fe6 ER |
416 | inst "$@" $dest |
417 | ||
42820142 | 418 | local lib libs=$(ldd "$@" | awk '/statically|linux-gate\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u) |
9b532fe6 | 419 | for lib in $libs; do |
9b557a09 | 420 | if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then |
7efbe841 ER |
421 | inst_d /$_lib |
422 | inst_exec $lib /$_lib | |
17e97aec | 423 | fi |
209061e3 ER |
424 | done |
425 | } | |
426 | ||
82474db9 ER |
427 | # output modules.conf / modprobe.conf |
428 | modprobe_conf() { | |
429 | echo "$modprobe_conf_cache" | |
430 | } | |
431 | ||
432 | # | |
433 | # defaults to modprobe -c if not told otherwise, this means include statements | |
434 | # work from there. | |
435 | cache_modprobe_conf() { | |
436 | if [ "$pack_version" -lt "002005" ]; then | |
437 | modulefile=/etc/modules.conf | |
438 | if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then | |
439 | modulefile=/etc/conf.modules | |
440 | fi | |
441 | fi | |
442 | ||
443 | if [ -n "$modulefile" ]; then | |
d8056591 | 444 | debug "Using $modulefile for modules config" |
82474db9 ER |
445 | modprobe_conf_cache=$(cat $modulefile) |
446 | else | |
d8056591 | 447 | debug "Using modprobe -c to get modules config" |
520412e9 | 448 | modprobe_conf_cache=$(modprobe -c --set-version $kernel) |
82474db9 ER |
449 | fi |
450 | } | |
451 | ||
df738638 ER |
452 | find_modules_md() { |
453 | local found raidlevel | |
454 | ||
ac085800 | 455 | if [ -f /etc/mdadm.conf ]; then |
94769f11 | 456 | debug "Finding RAID details using mdadm for rootdev=$1" |
ac085800 ER |
457 | eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" ' |
458 | BEGIN { | |
459 | found = "no"; | |
460 | dev_list = ""; | |
461 | raidlevel = "" | |
462 | rootdev_devfs = rootdev; | |
463 | if (rootdev ~ /\/dev\/md\/[0-9]/) { | |
464 | gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs); | |
465 | } | |
514a668a | 466 | } |
ac085800 ER |
467 | |
468 | /^ARRAY/ { | |
469 | if (($2 == rootdev) || ($2 == rootdev_devfs)) { | |
470 | raidlevel=$3; | |
471 | gsub(/level=/,NUL,raidlevel); | |
472 | if (raidlevel ~ /^raid([0-6]|10)/) { | |
473 | gsub(/raid/,NUL,raidlevel); | |
474 | }; | |
475 | found="yes"; | |
476 | getline x; | |
477 | if (x ~ /devices=/) { | |
478 | dev_list = x; | |
479 | gsub(".*devices=", NUL, dev_list); | |
480 | gsub(",", " ", dev_list); | |
481 | } | |
482 | } | |
56946560 | 483 | } |
ac085800 ER |
484 | |
485 | END { | |
df738638 | 486 | print "have_md=" found; |
ac085800 ER |
487 | print "raidlevel=" raidlevel; |
488 | print "dev_list=\"" dev_list "\""; | |
489 | }'` | |
490 | fi | |
7c38b114 | 491 | |
df738638 | 492 | if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then |
00eaa938 | 493 | die "raidtools are not longer supported. Please migrate to mdadm setup!" |
809cc4cc | 494 | fi |
ac085800 | 495 | |
82474db9 | 496 | if is_yes "$have_md"; then |
7c38b114 | 497 | case "$raidlevel" in |
bf17c86c | 498 | [01]|10) |
7c38b114 AF |
499 | findmodule "raid$raidlevel" |
500 | ;; | |
bf17c86c AM |
501 | [456]) |
502 | findmodule "-raid$raidlevel" | |
503 | findmodule "-raid456" | |
504 | ;; | |
7c38b114 AF |
505 | linear) |
506 | findmodule "linear" | |
507 | ;; | |
508 | *) | |
f4010f7f | 509 | warn "raid level $number (in mdadm config) not recognized" |
7c38b114 AF |
510 | ;; |
511 | esac | |
88614cd1 | 512 | else |
00eaa938 | 513 | die "RAID devices not found for \"$1\", check your configuration!" |
7c38b114 | 514 | fi |
4e9eb79c AM |
515 | |
516 | rootdev_nr=$(( $rootdev_nr + 1 )) | |
517 | eval "rootdev${rootdev_nr}=\"$1\"" | |
518 | eval "dev_list${rootdev_nr}=\"${dev_list}\"" | |
ac085800 | 519 | |
7c38b114 | 520 | for device in $dev_list; do |
d8056591 | 521 | find_modules_for_devpath $device |
7c38b114 AF |
522 | done |
523 | } | |
524 | ||
525 | find_modules_scsi() { | |
c3667d07 | 526 | local n |
7c38b114 | 527 | for n in $PRESCSIMODS; do |
07b09cf9 | 528 | if [ "X$n" = "Xunknown" ]; then |
f5db170b | 529 | debug "Finding SCSI modules using scsi_hostadapter" |
60899da0 ER |
530 | local mod scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }') |
531 | for mod in $scsimodules; do | |
532 | # for now allow scsi modules to come from anywhere. There are some | |
533 | # RAID controllers with drivers in block | |
534 | findmodule "$mod" | |
535 | done | |
7c38b114 AF |
536 | else |
537 | findmodule "$n" | |
538 | fi | |
539 | done | |
84df18b8 | 540 | findmodule "-scsi_wait_scan" |
7c38b114 AF |
541 | } |
542 | ||
543 | find_modules_ide() { | |
c3667d07 ER |
544 | local devpath=$1 |
545 | # remove partition, if any | |
546 | local disk=${devpath%[0-9]*} | |
f0615744 | 547 | # set blockdev for rootfs (hda, sdc, ...) |
c3667d07 | 548 | local rootblkdev=${disk#/dev/} |
ac085800 | 549 | |
c3667d07 | 550 | local n |
ac085800 | 551 | if [ "$pack_version_long" -lt "002004021" ]; then |
94769f11 | 552 | debug "Finding IDE modules for kernels <= 2.4.20" |
ac085800 ER |
553 | for n in $PREIDEMODSOLD; do |
554 | findmodule "$n" | |
555 | done | |
64497ebb | 556 | else |
c3667d07 | 557 | local tryauto=1 |
ac085800 | 558 | for n in $PREIDEMODS; do |
07b09cf9 | 559 | if [ "X$n" = "Xunknown" ]; then |
82474db9 ER |
560 | debug "Finding IDE modules using ide_hostadapter" |
561 | local mod idemodules=$(modprobe_conf | awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }') | |
562 | for mod in $idemodules; do | |
563 | tryauto=0; | |
564 | findmodule "$mod" | |
565 | done | |
64497ebb | 566 | |
ac085800 ER |
567 | if [ "$tryauto" -eq 1 ]; then |
568 | # If tryauto {{{ | |
569 | if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then | |
94769f11 | 570 | debug "Finding IDE modules using PCI ID database" |
ac085800 ER |
571 | # Finding IDE modules using PCI ID database {{{ |
572 | if is_yes "${ide_only_root}"; then | |
f0615744 ER |
573 | if [ -f /sys/block/${rootblkdev}/device/../../vendor -a -f /sys/block/${rootblkdev}/device/../../device ]; then |
574 | vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../vendor)" | |
575 | deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../device)" | |
ac085800 | 576 | searchpciid="${vendorid}${deviceid}" |
f0615744 ER |
577 | elif [ -f /proc/ide/${rootblkdev}/../config ]; then |
578 | searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootblkdev}/../config)" | |
ac085800 ER |
579 | fi |
580 | fi | |
581 | ||
582 | if [ -z "${searchpciid}" ]; then | |
583 | searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)" | |
584 | fi | |
585 | ||
586 | idemodules="" | |
587 | ||
588 | for nb in $searchpciid; do | |
589 | eval `awk -v pciid="$nb" '{ | |
590 | gsub("\t"," "); | |
591 | gsub(" +", " "); | |
592 | gsub("^ ",""); | |
593 | if (/^[\t ]*#/) | |
594 | next; | |
595 | compmod = $1 ""; # make sure comparison type will be string | |
596 | # cause pci IDs are hexadecimal numeric | |
597 | if (compmod == pciid) { | |
598 | module=$2; | |
599 | # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name | |
600 | # max_kernel=$4; # | |
601 | exit 0; | |
602 | } | |
603 | } | |
604 | ||
605 | END { | |
606 | print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n"; | |
607 | }' /usr/share/pci-database/ide.pci` | |
608 | [ -n "$module" ] && idemodules="$idemodules $module" | |
609 | done | |
610 | if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then | |
611 | new_idemodules="" | |
612 | for nc in idemodules; do | |
613 | new_idemodules="$nc $new_idemodules" | |
614 | done | |
615 | idemodules="${new_idemodules}" | |
616 | fi | |
617 | ||
618 | if [ -z "$idemodules" ]; then | |
4aa3bff8 | 619 | warn "rootfs on IDE device but no related modules found, loading ide-generic." |
ac085800 ER |
620 | idemodules="ide-generic" |
621 | fi | |
622 | ||
623 | # }}} | |
624 | for nd in $idemodules; do | |
625 | findmodule "-$nd" | |
626 | done | |
627 | # }}} | |
628 | # else tryauto {{{ | |
629 | else | |
4aa3bff8 PG |
630 | [ -r /usr/share/pci-database/ide.pci ] || warn "/usr/share/pci-database/ide.pci missing." |
631 | [ -r /proc/bus/pci/devices ] || warn "/proc/bus/pci/devices missing." | |
632 | warn "Automatic IDE modules finding not available." | |
ac085800 ER |
633 | fi |
634 | # }}} | |
635 | fi | |
636 | else | |
637 | findmodule "$n" | |
5de40f1f | 638 | fi |
ac085800 | 639 | done |
64497ebb | 640 | fi |
7c38b114 AF |
641 | } |
642 | ||
a7fce633 | 643 | # return true if node is lvm node |
4c16dac4 | 644 | is_lvm_node() { |
a7fce633 ER |
645 | local node="$1" |
646 | if [ ! -e "$node" ]; then | |
4aa3bff8 | 647 | warn "check_lvm(): node $node doesn't exist!" |
a7fce633 ER |
648 | return 1 |
649 | fi | |
650 | ||
651 | # block-major-58 is lvm1 | |
652 | ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}' | |
653 | rc=$? | |
654 | ||
655 | if [ $rc = 0 ]; then | |
d8056591 | 656 | debug "LVM check: $node is LVM v1 node" |
a7fce633 ER |
657 | # is lvm1 |
658 | return 0 | |
659 | fi | |
660 | ||
b49449ac ER |
661 | if [ ! -x /sbin/lvm ]; then |
662 | debug "LVM check: no lvm2 tools present to check" | |
663 | return 0 | |
664 | fi | |
665 | ||
a7fce633 ER |
666 | /sbin/lvm lvdisplay "$node" > /dev/null 2>&1 |
667 | rc=$? | |
668 | if [ $rc -gt 127 ]; then | |
669 | # lvdisplay terminated by signal! most likely it segfaulted. | |
00eaa938 | 670 | die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?" |
a7fce633 ER |
671 | fi |
672 | ||
673 | if [ $rc = 0 ]; then | |
d8056591 | 674 | debug "LVM check: $node is LVM v2 node" |
a7fce633 | 675 | else |
d8056591 | 676 | debug "LVM check: $node is not any LVM node" |
a7fce633 ER |
677 | fi |
678 | return $rc | |
679 | } | |
680 | ||
3ef3d717 ER |
681 | # return true if node is cryptsetup luks encrypted |
682 | is_luks() { | |
683 | local node="$1" | |
684 | if [ ! -e "$node" ]; then | |
685 | warn "is_luks(): node $node doesn't exist!" | |
686 | return 1 | |
687 | fi | |
688 | ||
689 | local dev dm_name=${node#/dev/mapper/} | |
690 | if [ "$node" = "$dm_name" ]; then | |
691 | debug "is_luks: $node is not device mapper name" | |
692 | return 1 | |
693 | fi | |
694 | ||
695 | dev=$(cryptsetup status $dm_name 2>/dev/null | awk '/device:/{print $2}') | |
696 | cryptsetup isLuks $dev | |
697 | rc=$? | |
698 | ||
699 | if [ $rc = 0 ]; then | |
700 | debug "is_luks: $node is cryptsetup luks" | |
701 | else | |
702 | debug "is_luks: $node is not cryptsetup luks" | |
703 | fi | |
704 | return $rc | |
705 | } | |
706 | ||
7548b210 ER |
707 | # return dependencies MAJOR:MINOR [MAJOR:MINOR] for DM_NAME |
708 | # TODO: patch `dmsetup export` | |
709 | dm_deps() { | |
710 | local dm_name="$1" | |
711 | dmsetup deps $dm_name | sed -e 's/, /:/g;s/^.\+ dependencies[^:]: //;s/[()]//g;' | |
712 | } | |
713 | ||
714 | # export info from dmsetup | |
715 | # param can be: | |
716 | # - MAJOR:MINOR | |
717 | # - /dev/dm-MINOR | |
718 | # - /dev/mapper/DM_NAME | |
719 | dm_export() { | |
720 | local arg="$1" | |
721 | ||
722 | case "$arg" in | |
723 | *:*) | |
724 | local maj=${arg%:*} min=${arg#*:} | |
725 | dmsetup -j $maj -m $min export | |
726 | ;; | |
727 | /dev/dm-*) | |
728 | local min=${arg#*dm-} | |
729 | local maj=$(awk '$2 == "device-mapper" {print $1}' /proc/devices) | |
730 | dm_export $maj:$min | |
731 | ;; | |
732 | /dev/mapper/*) | |
733 | local dm_name=${arg#/dev/mapper/} | |
734 | dmsetup export $dm_name | |
735 | ;; | |
736 | *) | |
737 | die "dm_export: unexpected $arg" | |
738 | ;; | |
739 | esac | |
740 | } | |
741 | ||
07137fe3 ER |
742 | # find dm-multipath modules for $devpath |
743 | # returns false if $devpath is not dm-multipath | |
744 | find_modules_multipath() { | |
745 | local devpath="$1" | |
746 | ||
7548b210 ER |
747 | DM_NAME= |
748 | eval $(dm_export "$devpath") | |
749 | if [ -z "$DM_NAME" ]; then | |
750 | die "dm_export failed unexpectedly" | |
751 | fi | |
07137fe3 | 752 | |
b0d329a2 ER |
753 | # Partition: |
754 | # DM_NAME=LUN-28p1 | |
755 | # DM_UUID=part1-mpath-36006016002c11800a0aa05fbfae0db11 | |
756 | # Disk: | |
757 | # DM_NAME=LUN-28 | |
758 | # DM_UUID=mpath-36006016002c11800a0aa05fbfae0db11 | |
7548b210 | 759 | MPATH_WWID=${DM_UUID##*-} |
b0d329a2 | 760 | |
7548b210 | 761 | local info=$(multipath -l $MPATH_WWID) |
07137fe3 ER |
762 | if [ -z "$info" ]; then |
763 | return 1 | |
764 | fi | |
765 | ||
7548b210 | 766 | debug "Finding modules for dm-multipath (WWID=$MPATH_WWID)" |
07137fe3 ER |
767 | have_multipath=yes |
768 | local dev phydevs=$(echo "$info" | awk '$2 ~ /^[0-9]+:[0-9]+:[0-9]+:[0-9]+$/{printf("/dev/%s\n", $3)}') | |
769 | for dev in $phydevs; do | |
d8056591 | 770 | find_modules_for_devpath $dev |
6b013929 | 771 | lvm_ignore_devices="$lvm_ignore_devices $dev" |
07137fe3 ER |
772 | done |
773 | ||
774 | local hw hwhandlers=$(echo "$info" | awk '/hwhandler=1/{sub(/.*hwhandler=1 /, ""); sub(/\]$/, ""); print}') | |
775 | for hw in $hwhandlers; do | |
776 | findmodule "dm-$hw" | |
777 | done | |
778 | ||
779 | local target targets=$(echo "$info" | awk '/prio=/{print $2}' | sort -u) | |
780 | for target in $targets; do | |
781 | findmodule "dm-$target" | |
782 | done | |
783 | ||
784 | findmodule "dm-mod" | |
785 | return 0 | |
786 | } | |
787 | ||
c083ae23 ER |
788 | # find dmraid modules for $devpath |
789 | # returns false if $devpath is not on dmraid | |
790 | find_modules_dmraid() { | |
791 | local devpath="$1" | |
792 | ||
793 | # get blockdev itself (without partition) | |
794 | # /dev/mapper/sil_ahbgadcbchfc3 -> /dev/mapper/sil_ahbgadcbchfc | |
795 | local blockdev=${devpath%%[0-9]*} | |
796 | local raidname=${blockdev#/dev/mapper/} | |
797 | local found=0 | |
798 | ||
799 | local dev phydevs=$(dmraid -r -cdevpath,raidname | awk -F, -vv="$raidname" '{if ($2 == v) print $1}') | |
800 | for dev in $phydevs; do | |
d8056591 | 801 | find_modules_for_devpath $dev |
6b013929 | 802 | lvm_ignore_devices="$lvm_ignore_devices $dev" |
c083ae23 ER |
803 | found=1 |
804 | done | |
805 | ||
806 | if [ $found = 0 ]; then | |
807 | return 1 | |
808 | fi | |
809 | ||
c083ae23 ER |
810 | findmodule "dm-mirror" |
811 | have_dmraid=yes | |
812 | return 0 | |
813 | } | |
814 | ||
3ef3d717 ER |
815 | # find modules for $devpath |
816 | find_modules_luks() { | |
817 | local devpath="$1" | |
818 | local dev | |
819 | ||
820 | LUKSNAME=${devpath#/dev/mapper/} | |
821 | LUKSDEV=$(cryptsetup status $LUKSNAME 2>/dev/null | awk '/device:/{print $2}') | |
822 | if [ -z "$LUKSDEV" ]; then | |
823 | die "Lost cryptsetup device meanwhile?" | |
824 | fi | |
825 | ||
826 | findmodule "dm-crypt" | |
827 | ||
828 | have_luks=yes | |
829 | ||
830 | # recurse | |
831 | find_modules_for_devpath $LUKSDEV | |
832 | return 0 | |
833 | } | |
834 | ||
bc0d6f2d | 835 | # find modules for $devpath |
d8056591 | 836 | find_modules_for_devpath() { |
bc0d6f2d ER |
837 | local devpath="$1" |
838 | if [ -z "$devpath" ]; then | |
d8056591 | 839 | die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?" |
f6536797 | 840 | fi |
ac085800 | 841 | |
bc0d6f2d ER |
842 | # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3 |
843 | case "$devpath" in | |
844 | /dev/dm-*) | |
845 | devpath=$(dm_longname "$devpath") | |
846 | ;; | |
847 | esac | |
d8056591 | 848 | debug "Finding modules for device path $devpath" |
bc0d6f2d | 849 | |
3ef3d717 ER |
850 | if is_luks "$devpath"; then |
851 | find_modules_luks "$devpath" | |
852 | return | |
853 | fi | |
854 | ||
bc0d6f2d | 855 | if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then |
07b09cf9 | 856 | if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then |
00eaa938 | 857 | die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM." |
6fe19d5b | 858 | fi |
7eccec8e ER |
859 | if [ ! -f /proc/bus/pci/devices ]; then |
860 | warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:" | |
861 | warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\"" | |
862 | else | |
863 | local m | |
864 | [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs) | |
865 | warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine" | |
866 | for m in $NFS_ETH_MODULES; do | |
867 | findmodule "$m" | |
868 | done | |
869 | fi | |
6fe19d5b | 870 | findmodule "-ipv4" |
ac085800 | 871 | findmodule "nfs" |
69b1e935 | 872 | have_nfs=yes |
f4010f7f AM |
873 | warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel" |
874 | warn "or you will have problems like init(xx) being child process of swapper(1)." | |
d9179777 ER |
875 | return |
876 | fi | |
877 | ||
26698ab2 | 878 | if [[ "$devpath" == /dev/md* ]]; then |
df738638 | 879 | find_modules_md "$devpath" |
d9179777 ER |
880 | return |
881 | fi | |
882 | ||
1a63b128 | 883 | if is_yes "$USE_MULTIPATH" && [[ "$devpath" == /dev/mapper/* ]]; then |
07137fe3 | 884 | if find_modules_multipath "$devpath"; then |
9baf4f3f | 885 | return |
9baf4f3f | 886 | fi |
9baf4f3f ER |
887 | # fallback |
888 | fi | |
889 | ||
c083ae23 ER |
890 | 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 |
891 | if find_modules_dmraid "$devpath"; then | |
892 | return | |
893 | fi | |
894 | # fallback | |
895 | fi | |
896 | ||
82474db9 | 897 | if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then |
7c38b114 | 898 | find_modules_scsi |
d9179777 ER |
899 | return |
900 | fi | |
901 | ||
82474db9 | 902 | if is_yes "$(echo "$devpath" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }')"; then |
bc0d6f2d | 903 | find_modules_ide "$devpath" |
d9179777 ER |
904 | return |
905 | fi | |
906 | ||
07b09cf9 | 907 | if [[ "$devpath" == /dev/rd/* ]]; then |
7c38b114 | 908 | findmodule "DAC960" |
12fcd1fd | 909 | rootdev_add="/dev/rd/" |
d9179777 ER |
910 | return |
911 | fi | |
912 | ||
07b09cf9 | 913 | if [[ "$devpath" == /dev/ida/* ]]; then |
7c38b114 | 914 | findmodule "cpqarray" |
12fcd1fd | 915 | rootdev_add="/dev/ida/" |
d9179777 ER |
916 | return |
917 | fi | |
918 | ||
08651ad1 | 919 | if [[ "$devpath" == /dev/cciss/* ]]; then |
7c38b114 | 920 | findmodule "cciss" |
b864a83e | 921 | rootdev_add="/dev/cciss/" |
d9179777 ER |
922 | return |
923 | fi | |
924 | ||
07b09cf9 | 925 | if [[ "$devpath" == /dev/ataraid/* ]]; then |
ac085800 | 926 | find_modules_ide |
7c38b114 | 927 | findmodule "ataraid" |
82474db9 | 928 | ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }') |
9ae446b9 | 929 | if [ -n "$ataraidmodules" ]; then |
7c38b114 | 930 | # FIXME: think about modules compiled in kernel |
82474db9 | 931 | die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again." |
7c38b114 AF |
932 | fi |
933 | for n in $ataraidmodules; do | |
934 | findmodule "$n" | |
935 | done | |
b864a83e | 936 | rootdev_add="/dev/ataraid/" |
d9179777 ER |
937 | return |
938 | fi | |
939 | ||
7c38b114 | 940 | # check to see if we need to set up a loopback filesystem |
07b09cf9 | 941 | if [[ "$devpath" == /dev/loop* ]]; then |
00eaa938 | 942 | die "Sorry, root on loop device isn't supported." |
7c38b114 AF |
943 | # TODO: rewrite for bsp and make nfs ready |
944 | if [ ! -x /sbin/losetup ]; then | |
00eaa938 | 945 | die "losetup is missing" |
7c38b114 | 946 | fi |
bc0d6f2d | 947 | key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):" |
82474db9 | 948 | if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then |
42820142 | 949 | 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 |
950 | fi |
951 | ||
952 | line="`awk '/'$key'/ { print $0; }' $fstab`" | |
953 | loopDev="$(echo $line | awk '{print $3}')" | |
954 | loopFs="$(echo $line | awk '{print $4}')" | |
955 | loopFile="$(echo $line | awk '{print $5}')" | |
956 | ||
957 | BASICMODULES="$BASICMODULES -loop" | |
958 | findmodule "-$loopFs" | |
959 | BASICMODULES="$BASICMODULES -${loopFs}" | |
d9179777 ER |
960 | return |
961 | fi | |
962 | ||
4c16dac4 | 963 | if is_lvm_node "$devpath"; then |
bc0d6f2d | 964 | node="$devpath" |
f6536797 | 965 | |
07b09cf9 | 966 | if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then |
00eaa938 | 967 | 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 | 968 | fi |
07b09cf9 | 969 | if [ -z "$LVMTOOLSVERSION" ]; then |
ac085800 | 970 | 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 | 971 | if [ -z "$LVMTOOLSVERSION" ]; then |
00eaa938 | 972 | die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM." |
ac085800 | 973 | fi |
77bcfc68 | 974 | fi |
4c16dac4 ER |
975 | |
976 | local vg=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ') | |
977 | VGVOLUMES=$(echo $VGVOLUMES $vg | tr ' ' '\n' | sort -u) | |
978 | local pv=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$vg" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ') | |
979 | PVDEVICES=$(echo $PVDEVICES $pv | tr ' ' '\n' | sort -u) | |
980 | ||
07b09cf9 | 981 | if [ -n "$PVDEVICES" ]; then |
7c38b114 | 982 | for device in $PVDEVICES; do |
d8056591 | 983 | find_modules_for_devpath $device |
7c38b114 AF |
984 | done |
985 | else | |
00eaa938 | 986 | die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd." |
7c38b114 | 987 | fi |
e0c502bb | 988 | if [ "$LVMTOOLSVERSION" = "2" ]; then |
ac085800 | 989 | findmodule "-dm-mod" |
e0c502bb | 990 | elif [ "$LVMTOOLSVERSION" = "1" ]; then |
ac085800 ER |
991 | findmodule "-lvm" |
992 | findmodule "-lvm-mod" | |
93d781d1 | 993 | else |
00eaa938 | 994 | die "LVM version $LVMTOOLSVERSION is not supported yet." |
93d781d1 | 995 | fi |
d8056591 | 996 | debug "LVM v$LVMTOOLSVERSION enabled" |
69b1e935 | 997 | have_lvm=yes |
d9179777 | 998 | return |
7c38b114 AF |
999 | fi |
1000 | } | |
1001 | ||
b64f015b | 1002 | firmware_install_module() { |
c3667d07 | 1003 | local module="$1" |
c6c6ce01 | 1004 | local firmware_files="$2" |
9ed6e1db | 1005 | |
94769f11 | 1006 | debug "Adding Firmwares ($firmware_files) to initrd for module $module" |
9ed6e1db | 1007 | # firmware not yet installed |
9b557a09 | 1008 | if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then |
034fdd5d | 1009 | inst_d /lib/firmware |
9b557a09 | 1010 | cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh" |
9ed6e1db | 1011 | #!/bin/sh -e |
8639f99a AM |
1012 | echo 1 > /sys$DEVPATH/loading |
1013 | cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data | |
1014 | echo 0 > /sys$DEVPATH/loading | |
1015 | exit 0 | |
9ed6e1db | 1016 | EOF |
9b557a09 | 1017 | chmod 755 "$DESTDIR/lib/firmware/firmware.sh" |
9ed6e1db AM |
1018 | fi |
1019 | ||
1020 | for firmware in $firmware_files; do | |
4a60c01f | 1021 | if [ ! -f "/lib/firmware/$firmware" ]; then |
4a60c01f | 1022 | die "firmware file /lib/firmware/$firmware doesn't exist." |
4a60c01f | 1023 | else |
486d26a5 | 1024 | FIRMWAREDIR=${firmware%/*} |
4a9920e7 | 1025 | [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR |
7fde1ea5 | 1026 | inst /lib/firmware/$firmware /lib/firmware/$firmware |
4a60c01f | 1027 | fi |
9ed6e1db AM |
1028 | done |
1029 | ||
b64f015b | 1030 | mount_sys |
c6c6ce01 | 1031 | echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc |
9ed6e1db AM |
1032 | } |
1033 | ||
2a5bcca9 | 1034 | modules_install() { |
c3667d07 ER |
1035 | local modules="$1" |
1036 | local mod | |
2a5bcca9 AM |
1037 | |
1038 | for mod in $modules; do | |
fe280785 | 1039 | MODULEDIR=${mod%/*} |
4a9920e7 | 1040 | inst_d "/lib/modules/$kernel/$MODULEDIR" |
9b557a09 ER |
1041 | cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod" |
1042 | gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null | |
2a5bcca9 AM |
1043 | done |
1044 | } | |
1045 | ||
1046 | modules_add_linuxrc() { | |
fe280785 | 1047 | local mod modpath |
ac085800 | 1048 | |
fe280785 ER |
1049 | for mod in "$@"; do |
1050 | # module path without optional compression | |
1051 | modpath=${mod%.gz} | |
1052 | ||
1053 | # name of the module | |
1054 | module=${modpath##*/} | |
1055 | module=${module%$modext} | |
1056 | ||
1057 | options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs) | |
ffa1b198 | 1058 | |
fe280785 ER |
1059 | generic_module=$(echo $module | tr - _) |
1060 | sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP) | |
1061 | firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE) | |
2a5bcca9 | 1062 | |
ac085800 | 1063 | if [ -n "$verbose" ]; then |
8a47b72c ER |
1064 | s="" |
1065 | if [ "$options" ]; then | |
1066 | s="$s with options [$options]" | |
1067 | fi | |
1068 | if [ "$sleep_var" ]; then | |
1069 | s="$s and $sleep_var usleep" | |
1070 | fi | |
4a60c01f | 1071 | debug "Loading module [$module]$s" |
ac085800 ER |
1072 | fi |
1073 | ||
9ed6e1db | 1074 | if [ -n "$firmware_var" ]; then |
d814e616 | 1075 | firmware_install_module "$module" "$firmware_var" |
4a60c01f AM |
1076 | else |
1077 | firmware_files=$(find_firmware "$module") | |
1078 | if [ -n "$firmware_files" ]; then | |
1079 | for file in $firmware_files; do | |
1080 | firmware_install_module "$module" "$file" | |
1081 | done | |
1082 | fi | |
9ed6e1db | 1083 | fi |
4a60c01f | 1084 | |
fe280785 ER |
1085 | echo "$insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc |
1086 | if [ -n "$sleep_var" ]; then | |
c6c6ce01 | 1087 | echo "usleep $sleep_var" | add_linuxrc |
8e598759 | 1088 | fi |
2a5bcca9 AM |
1089 | done |
1090 | } | |
1091 | ||
4c16dac4 | 1092 | find_modules_suspend() { |
82b2dba2 ER |
1093 | if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then |
1094 | die "/usr/${_lib}/suspend/resume is missing!" | |
1095 | fi | |
1096 | resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)" | |
441ba29b ER |
1097 | |
1098 | local vgvolumes=$VGVOLUMES | |
4c16dac4 ER |
1099 | find_modules_for_devpath $resume_dev |
1100 | ||
441ba29b ER |
1101 | if [ "$VGVOLUMES" != "$vgvolumes" ]; then |
1102 | # save our VG to be able to differenciate between rootfs VG | |
4c16dac4 | 1103 | SUSPENDVG=$VGVOLUMES |
441ba29b | 1104 | VGVOLUMES=$vgvolumes |
4c16dac4 ER |
1105 | debug "suspend device is on LVM" |
1106 | fi | |
1107 | } | |
1108 | ||
1109 | initrd_gen_suspend() { | |
9b557a09 | 1110 | mknod $DESTDIR/dev/snapshot c 10 231 |
b49449ac ER |
1111 | mkdir -p $DESTDIR${resume_dev%/*} |
1112 | inst $resume_dev $resume_dev | |
4c16dac4 | 1113 | |
82b2dba2 ER |
1114 | inst /etc/suspend.conf /etc/suspend.conf |
1115 | if [ -x /usr/${_lib}/suspend/resume ]; then | |
fb1e695a | 1116 | inst_exec /usr/${_lib}/suspend/resume /bin/resume |
82b2dba2 | 1117 | else |
fb1e695a | 1118 | inst_exec /usr/sbin/resume /bin/resume |
82b2dba2 | 1119 | fi |
55884ae2 ER |
1120 | |
1121 | add_linuxrc <<-'EOF' | |
30005e21 ER |
1122 | resume=no |
1123 | for arg in $CMDLINE; do | |
1124 | if [ "${arg##resume=}" != "${arg}" ]; then | |
1125 | resume=yes | |
1126 | fi | |
1127 | done | |
1128 | if [ "$resume" = "yes" ]; then | |
1129 | resume | |
1130 | fi | |
55884ae2 | 1131 | EOF |
82b2dba2 | 1132 | } |
7591cd37 | 1133 | |
82b2dba2 ER |
1134 | initrd_gen_tuxonice() { |
1135 | mount_sys | |
1136 | add_linuxrc <<-'EOF' | |
f7e0b46b | 1137 | resume=no |
55884ae2 | 1138 | for arg in $CMDLINE; do |
8fdec664 | 1139 | if [ "${arg##resume=}" != "${arg}" -o "${arg##resume2=}" != "${arg}" ]; then |
f7e0b46b | 1140 | resume=yes |
55884ae2 ER |
1141 | fi |
1142 | done | |
f7e0b46b | 1143 | if [ "$resume" = "yes" ]; then |
82b2dba2 ER |
1144 | [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume |
1145 | [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume | |
55884ae2 | 1146 | [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume |
413878f8 | 1147 | fi |
82b2dba2 ER |
1148 | EOF |
1149 | } | |
413878f8 | 1150 | |
43258faf AG |
1151 | initrd_gen_v86d() { |
1152 | debug "initrd_gen_v86d" | |
1153 | mknod $DESTDIR/dev/mem c 1 1 | |
1154 | mknod $DESTDIR/dev/tty1 c 4 1 | |
1155 | inst_d /sbin | |
1156 | inst_exec /sbin/v86d /sbin | |
1157 | } | |
1158 | ||
82b2dba2 ER |
1159 | initrd_gen_udev() { |
1160 | debug "Setting up udev..." | |
1161 | inst_d /sbin /etc/udev | |
bb529f94 | 1162 | |
82b2dba2 ER |
1163 | if [ ! -x /sbin/initrd-udevd ]; then |
1164 | die "/sbin/initrd-udevd not present" | |
1165 | fi | |
06ac05d6 | 1166 | |
fb1e695a | 1167 | inst_exec /sbin/initrd-udevd /sbin/udevd |
82b2dba2 | 1168 | inst /etc/udev/udev.conf /etc/udev/udev.conf |
0868f49f | 1169 | |
82b2dba2 ER |
1170 | mount_dev |
1171 | mount_sys | |
1172 | add_linuxrc <<-'EOF' | |
1173 | : 'Starting udev' | |
1174 | /sbin/udevd --daemon | |
1175 | EOF | |
0e37e33e | 1176 | |
fb1e695a | 1177 | inst_exec /sbin/initrd-udevadm /sbin/udevadm |
15538850 | 1178 | ln -s udevadm $DESTDIR/sbin/udevsettle |
1179 | ln -s udevadm $DESTDIR/sbin/udevtrigger | |
0e37e33e | 1180 | add_linuxrc <<-'EOF' |
1181 | /sbin/udevtrigger | |
1182 | /sbin/udevsettle | |
1183 | EOF | |
48413b7f | 1184 | |
82b2dba2 ER |
1185 | busybox_applet killall |
1186 | add_linuxrc <<-'EOF' | |
1187 | killall udevd | |
1188 | EOF | |
1189 | } | |
ac085800 | 1190 | |
82b2dba2 | 1191 | initrd_gen_multipath() { |
6d02dd34 | 1192 | inst_d /sbin /lib/udev /etc/multipath |
82b2dba2 ER |
1193 | inst_exec /sbin/kpartx /sbin |
1194 | inst_exec /sbin/multipath /sbin | |
1195 | # for udev callouts | |
1196 | inst_exec /sbin/scsi_id /lib/udev | |
1197 | inst_exec /sbin/mpath* /sbin | |
7548b210 | 1198 | egrep -v '^([ ]*$|#)' /etc/multipath.conf > $DESTDIR/etc/multipath.conf |
6d02dd34 ER |
1199 | |
1200 | if [ -f /etc/multipath/bindings ]; then | |
1201 | egrep -v '^([ ]*$|#)' /etc/multipath/bindings > $DESTDIR/etc/multipath/bindings | |
9b557a09 | 1202 | else |
6d02dd34 | 1203 | touch $DESTDIR/etc/multipath/bindings |
82b2dba2 | 1204 | fi |
0868f49f | 1205 | |
82b2dba2 ER |
1206 | mount_dev |
1207 | initrd_gen_devices | |
bb529f94 | 1208 | |
82b2dba2 | 1209 | mount_sys |
7548b210 | 1210 | echo "export MPATH_WWID=$MPATH_WWID" | add_linuxrc |
82b2dba2 | 1211 | add_linuxrc <<-'EOF' |
7548b210 | 1212 | # parse mpath_wwid= from kernel commandline |
d23ec84f | 1213 | for arg in $CMDLINE; do |
7548b210 ER |
1214 | if [ "${arg##mpath_wwid=}" != "${arg}" ]; then |
1215 | MPATH_WWID=${arg##mpath_wwid=} | |
1216 | if [ "$MPATH_WWID" = "*" ]; then | |
d23ec84f | 1217 | # '*' would mean activate all WWID-s |
7548b210 | 1218 | MPATH_WWID= |
d23ec84f ER |
1219 | echo "multipath: Activating all WWID-s" |
1220 | else | |
1221 | echo "multipath: Activating WWID=$WWID" | |
1222 | fi | |
1223 | fi | |
1224 | done | |
1225 | ||
82b2dba2 | 1226 | debugshell |
7548b210 | 1227 | /sbin/multipath -v 0 $MPATH_WWID |
bb529f94 | 1228 | |
82b2dba2 ER |
1229 | for a in /dev/mapper/*; do |
1230 | [ $a = /dev/mapper/control ] && continue | |
d23ec84f | 1231 | /sbin/kpartx -a -p p $a |
82b2dba2 ER |
1232 | done |
1233 | debugshell | |
1234 | EOF | |
1235 | } | |
22b0c9f4 | 1236 | |
82b2dba2 ER |
1237 | initrd_gen_dmraid() { |
1238 | if [ ! -x /sbin/dmraid-initrd ]; then | |
1239 | die "/sbin/dmraid-initrd is missing!" | |
e4b07ddc | 1240 | fi |
e4b07ddc | 1241 | |
82b2dba2 | 1242 | inst_d /sbin |
fb1e695a | 1243 | inst_exec /sbin/dmraid-initrd /sbin/dmraid |
f121024f | 1244 | |
82b2dba2 ER |
1245 | mount_dev |
1246 | mount_sys | |
1247 | initrd_gen_devices | |
1248 | add_linuxrc <<-EOF | |
1249 | # 2 secs was enough for my system to initialize. but really this is udev issue? | |
1250 | usleep 2000000 | |
1251 | : 'Activating Device-Mapper RAID(s)' | |
1252 | /sbin/dmraid -ay -i | |
551c3b3e | 1253 | |
82b2dba2 ER |
1254 | debugshell |
1255 | EOF | |
1256 | } | |
ac085800 | 1257 | |
3ef3d717 ER |
1258 | key_is_random() { |
1259 | [ "$1" = "/dev/urandom" -o "$1" = "/dev/hw_random" -o "$1" = "/dev/random" ] | |
1260 | } | |
1261 | ||
1262 | # produce cryptsetup from $name from /etc/crypttab | |
1263 | luks_crypttab() { | |
1264 | local LUKSNAME="$1" | |
1265 | local LUKSDEV="$2" | |
1266 | ||
1267 | # copy from /etc/rc.d/init.d/cryptsetup | |
1268 | local dst src key opt mode owner | |
1269 | ||
1270 | while read dst src key opt; do | |
1271 | [ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue | |
1272 | [ "$dst" != "$LUKSNAME" ] && continue | |
1273 | ||
1274 | if [ -n "$key" -a "x$key" != "xnone" ]; then | |
1275 | if test -e "$key" ; then | |
1276 | mode=$(LC_ALL=C ls -l "$key" | cut -c 5-10) | |
1277 | owner=$(LC_ALL=C ls -l $key | awk '{ print $3 }') | |
1278 | if [ "$mode" != "------" ] && ! key_is_random "$key"; then | |
1279 | die "INSECURE MODE FOR $key" | |
1280 | fi | |
1281 | if [ "$owner" != root ]; then | |
1282 | die "INSECURE OWNER FOR $key" | |
1283 | fi | |
1284 | else | |
1285 | die "Key file for $dst not found" | |
1286 | fi | |
1287 | else | |
1288 | key="" | |
1289 | fi | |
1290 | ||
1291 | if /sbin/cryptsetup isLuks "$src" 2>/dev/null; then | |
1292 | if key_is_random "$key"; then | |
1293 | die "$dst: LUKS requires non-random key, skipping" | |
1294 | fi | |
1295 | if [ -n "$opt" ]; then | |
1296 | warn "$dst: options are invalid for LUKS partitions, ignoring them" | |
1297 | fi | |
1298 | echo "/sbin/cryptsetup ${key:+-d $key} luksOpen '$src' '$dst' <&1" | add_linuxrc | |
1299 | else | |
1300 | die "$dst: only LUKS encryption supported" | |
1301 | fi | |
1302 | done < /etc/crypttab | |
1303 | } | |
1304 | ||
1305 | initrd_gen_luks() { | |
1306 | if [ ! -x /sbin/cryptsetup-initrd ]; then | |
1307 | die "/sbin/cryptsetup-initrd is missing!" | |
1308 | fi | |
1309 | ||
1310 | inst_d /sbin | |
1311 | inst_exec /sbin/cryptsetup-initrd /sbin/cryptsetup | |
1312 | ||
1313 | mount_dev | |
1314 | mount_sys | |
1315 | initrd_gen_devices | |
1316 | ||
1317 | luks_crypttab $LUKSNAME $LUKSDEV | |
1318 | } | |
1319 | ||
82b2dba2 ER |
1320 | initrd_gen_bootsplash() { |
1321 | local target="$1" | |
bb529f94 | 1322 | |
d8056591 | 1323 | debug "Generating bootsplash" |
7992356a | 1324 | |
82b2dba2 | 1325 | if [ ! -x /bin/splash.bin ]; then |
f4010f7f | 1326 | warn "Failed to execute /bin/splash.bin. Is bootsplash package installed?" |
7992356a ER |
1327 | return |
1328 | fi | |
1329 | ||
1330 | if [ -r /etc/sysconfig/bootsplash ]; then | |
1331 | . /etc/sysconfig/bootsplash | |
1332 | fi | |
1333 | ||
1334 | if [ -z "$THEME" ]; then | |
f4010f7f AM |
1335 | warn "Please configure your /etc/sysconfig/bootsplash first." |
1336 | warn "Generating bootsplashes skipped." | |
7992356a ER |
1337 | return |
1338 | fi | |
1339 | ||
1340 | if [ -z "$BOOT_SPLASH_RESOLUTIONS" ]; then | |
1341 | warn "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." | |
1342 | warn "Not adding bootsplash to initrd." | |
1343 | fi | |
1344 | ||
1345 | for res in $BOOT_SPLASH_RESOLUTIONS; do | |
1346 | if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then | |
1347 | /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \ | |
1348 | debug "Added $res $THEME theme to initrd." | |
82b2dba2 | 1349 | else |
7992356a | 1350 | warn "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" |
82b2dba2 | 1351 | fi |
7992356a | 1352 | done |
82b2dba2 | 1353 | } |
bb529f94 | 1354 | |
82b2dba2 | 1355 | initrd_gen_fbsplash() { |
d8056591 | 1356 | debug "Generating fbsplash" |
cd670d83 | 1357 | |
6c69a2d4 | 1358 | if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then |
889e2bf2 | 1359 | warn "Failed to find splash_geninitramfs. Is splashutils package installed?" |
82b2dba2 ER |
1360 | return |
1361 | fi | |
fc629084 AG |
1362 | splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs |
1363 | [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs | |
1cea325b | 1364 | |
7992356a ER |
1365 | if [ -r /etc/sysconfig/fbsplash ]; then |
1366 | . /etc/sysconfig/fbsplash | |
1367 | fi | |
1368 | ||
82b2dba2 | 1369 | if [ -z "$SPLASH_THEME" ]; then |
f4010f7f AM |
1370 | warn "Please configure your /etc/sysconfig/fbsplash first." |
1371 | warn "Generating fbsplashes skipped." | |
82b2dba2 ER |
1372 | return |
1373 | fi | |
cd670d83 | 1374 | |
82b2dba2 | 1375 | if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then |
f4010f7f AM |
1376 | warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash." |
1377 | warn "Not adding fbsplash to initramfs." | |
82b2dba2 ER |
1378 | return |
1379 | fi | |
bb529f94 | 1380 | |
82b2dba2 ER |
1381 | for res in $FB_SPLASH_RESOLUTIONS; do |
1382 | if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then | |
fc629084 | 1383 | $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \ |
6c69a2d4 ER |
1384 | debug "Added $res $SPLASH_THEME theme to initramfs." |
1385 | else | |
1386 | warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped" | |
1387 | fi | |
1388 | done | |
1389 | } | |
1390 | ||
1391 | initrd_gen_fbcondecor() { | |
1392 | debug "Generating fbcondecor" | |
1393 | ||
6c69a2d4 ER |
1394 | if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then |
1395 | warn "Failed to find splash_geninitramfs. Is splashutils package installed?" | |
1396 | return | |
1397 | fi | |
fc629084 AG |
1398 | splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs |
1399 | [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs | |
6c69a2d4 ER |
1400 | |
1401 | if [ -r /etc/sysconfig/splash ]; then | |
1402 | . /etc/sysconfig/splash | |
1403 | fi | |
1404 | ||
1405 | if [ -z "$SPLASH_THEME" ]; then | |
1406 | warn "Please configure your /etc/sysconfig/splash first." | |
1407 | warn "Generating of splashes skipped." | |
1408 | return | |
1409 | fi | |
1410 | ||
1411 | if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then | |
1412 | warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/splash." | |
1413 | warn "Not adding fbcondecor to initramfs." | |
1414 | return | |
1415 | fi | |
1416 | ||
1417 | for res in $FB_SPLASH_RESOLUTIONS; do | |
1418 | if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then | |
fc629084 | 1419 | $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \ |
82b2dba2 ER |
1420 | debug "Added $res $SPLASH_THEME theme to initramfs." |
1421 | else | |
f4010f7f | 1422 | warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped" |
82b2dba2 ER |
1423 | fi |
1424 | done | |
1425 | } | |
bb529f94 | 1426 | |
82b2dba2 ER |
1427 | # Generates /dev nodes based on /proc/partitions information. |
1428 | # Needs /proc mounted. | |
1429 | # Can be called multiple times. | |
1430 | initrd_gen_devices() { | |
1431 | if is_yes "$proc_partitions"; then | |
1432 | return | |
1433 | fi | |
1434 | proc_partitions=yes | |
335cd101 | 1435 | |
82b2dba2 ER |
1436 | mount_dev |
1437 | add_linuxrc <<-'EOF' | |
1438 | : 'Making device nodes' | |
1439 | cat /proc/partitions | ( | |
8d4aba01 | 1440 | # ignore first two lines: header, empty line |
82b2dba2 | 1441 | read b; read b |
2cc3ae8b | 1442 | |
82b2dba2 ER |
1443 | while read major minor blocks dev rest; do |
1444 | node=/dev/$dev | |
1445 | mkdir -p ${node%/*} | |
8d4aba01 | 1446 | [ -e $node ] || mknod $node b $major $minor |
82b2dba2 ER |
1447 | done |
1448 | ) | |
1449 | EOF | |
1450 | } | |
bb529f94 | 1451 | |
82b2dba2 ER |
1452 | initrd_gen_md() { |
1453 | debug "Setting up mdadm..." | |
bb529f94 | 1454 | |
82b2dba2 ER |
1455 | if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then |
1456 | die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!" | |
1457 | fi | |
bb529f94 | 1458 | |
fb1e695a | 1459 | inst_exec /sbin/initrd-mdassemble /bin/mdassemble |
bb529f94 | 1460 | |
82b2dba2 | 1461 | # LVM on RAID case |
e0f3739d | 1462 | dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs) |
666778eb AM |
1463 | if [ "$dev_list_extra" = "partitions" ]; then |
1464 | # FIXME: handle this case (see man mdadm.conf) | |
1465 | echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf" | |
1466 | dev_list_extra="" | |
1467 | else | |
1468 | for ex_dev in $dev_list_extra; do | |
1469 | echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf" | |
1470 | done | |
1471 | fi | |
82b2dba2 ER |
1472 | do_md0=1 |
1473 | for nr in `seq 1 $rootdev_nr`; do | |
1474 | eval cr_rootdev="\$rootdev${nr}" | |
1475 | eval cr_dev_list="\$dev_list${nr}" | |
1476 | debug echo "Setting up array ($cr_rootdev = $cr_dev_list)" | |
bb529f94 | 1477 | |
82b2dba2 | 1478 | [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0 |
f5db170b | 1479 | |
9b557a09 | 1480 | echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf" |
82b2dba2 ER |
1481 | cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')" |
1482 | cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }') | |
1483 | if [ -n "$cr_md_conf" ]; then | |
9b557a09 | 1484 | echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf" |
82b2dba2 | 1485 | else |
9b557a09 | 1486 | echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf" |
82b2dba2 | 1487 | fi |
034fdd5d | 1488 | |
82b2dba2 ER |
1489 | for f in $cr_dev_list $cr_rootdev $dev_list_extra; do |
1490 | # mkdir in case of devfs name | |
1491 | inst_d $(dirname $f) | |
9b557a09 | 1492 | [ -e "$DESTDIR/$f" ] && continue |
82b2dba2 ER |
1493 | # this works fine with and without devfs |
1494 | inst $f $f | |
1495 | done | |
1496 | done | |
bb529f94 | 1497 | |
82b2dba2 | 1498 | echo "mdassemble" | add_linuxrc |
bb529f94 | 1499 | |
82b2dba2 ER |
1500 | # needed to determine md-version |
1501 | if [ "$do_md0" -eq 1 ]; then | |
9b557a09 | 1502 | mknod $DESTDIR/dev/md0 b 9 0 |
82b2dba2 ER |
1503 | fi |
1504 | } | |
ef66f232 | 1505 | |
82b2dba2 ER |
1506 | initrd_gen_nfs() { |
1507 | # use root=/dev/ram0 init=/linuxrc when starting kernel or you will | |
1508 | # have problems like init(XX) being child process of swapper(1). | |
1509 | debug "Adding rootfs on NFS support to initrd (dhcp)" | |
9b557a09 ER |
1510 | mknod "$DESTDIR/dev/urandom" c 1 9 |
1511 | mkdir "$DESTDIR/newroot" | |
a7592d42 AG |
1512 | add_linuxrc <<-'EOF' |
1513 | ifconfig lo 127.0.0.1 up | |
1514 | route add -net 127.0.0.0 mask 255.0.0.0 lo | |
1515 | ifconfig eth0 up | |
1516 | udhcpc -i eth0 -f -q -s /bin/setdhcp | |
1517 | ||
1518 | cd /newroot | |
1519 | pivot_root . initrd | |
1520 | [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1 | |
1521 | exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1 | |
1522 | EOF | |
57227e0a | 1523 | |
9b557a09 | 1524 | cat <<-'EOF' > "$DESTDIR/bin/setdhcp" |
82b2dba2 ER |
1525 | #!/bin/sh |
1526 | [ "$1" != "bound" ] && exit | |
1527 | [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" | |
1528 | [ -n "$subnet" ] && NETMASK="netmask $subnet" | |
1529 | ifconfig $interface $ip $BROADCAST $NETMASK up | |
1530 | if [ -n "$router" ]; then | |
1531 | for r in $router; do | |
1532 | route add default gw $r dev $interface | |
1533 | done | |
1534 | fi | |
aeb75537 | 1535 | |
3a1d3d88 | 1536 | for o in $CMDLINE; do |
82b2dba2 ER |
1537 | case $o in |
1538 | nfsroot=*) | |
1539 | rootpath=${o#nfsroot=} | |
1540 | ;; | |
1541 | esac | |
1542 | done | |
e7751933 | 1543 | |
82b2dba2 ER |
1544 | if [ -n "$rootpath" ]; then |
1545 | mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot | |
1546 | else | |
1547 | echo "Missing rootpath in what DHCP server sent to us. Failing..." | |
1548 | echo "All seen variables are listed below:" | |
1549 | set | |
e934d044 | 1550 | fi |
82b2dba2 | 1551 | EOF |
e7751933 | 1552 | |
9b557a09 | 1553 | chmod 755 "$DESTDIR/bin/setdhcp" |
82b2dba2 ER |
1554 | } |
1555 | ||
1556 | initrd_gen_lvm() { | |
1557 | debug "Adding LVM support to initrd" | |
1558 | inst_d /tmp /newroot | |
fb1e695a | 1559 | inst_exec /sbin/initrd-lvm /bin/lvm.static |
82b2dba2 ER |
1560 | |
1561 | # always make /dev on tmpfs for LVM2 | |
1562 | if [ "$LVMTOOLSVERSION" = "2" ]; then | |
1563 | mount_dev | |
c6c6ce01 | 1564 | fi |
e7751933 | 1565 | |
82b2dba2 ER |
1566 | if ! is_yes "$dev_mounted"; then |
1567 | inst_d /dev/mapper | |
9b557a09 | 1568 | mknod $DESTDIR/dev/mapper/control c 10 63 |
82b2dba2 ER |
1569 | for device in $PVDEVICES; do |
1570 | # if LVM on RAID then device might be copied already in gen_md | |
9b557a09 | 1571 | [ -e "$DESTDIR/dev/$(basename $device)" ] && continue |
82b2dba2 ER |
1572 | inst $device /dev |
1573 | done | |
e7751933 | 1574 | fi |
c31050f3 | 1575 | |
82b2dba2 ER |
1576 | mount_tmp |
1577 | if [ "$LVMTOOLSVERSION" = "1" ]; then | |
1578 | add_linuxrc <<-EOF | |
1579 | lvm vgscan -T | |
4c16dac4 ER |
1580 | for vg in $VGVOLUMES; do |
1581 | lvm vgchange -T -a y $vg | |
1582 | done | |
82b2dba2 ER |
1583 | EOF |
1584 | else | |
1585 | echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc | |
9b557a09 ER |
1586 | echo "global {" > "$DESTDIR/etc/lvm.conf" |
1587 | echo " locking_type = 0" >> "$DESTDIR/etc/lvm.conf" | |
1588 | echo " locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf" | |
1589 | echo "}" >> "$DESTDIR/etc/lvm.conf" | |
1590 | echo "devices {" >> "$DESTDIR/etc/lvm.conf" | |
1591 | echo " sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf" | |
82b2dba2 | 1592 | if is_yes "$have_md"; then |
9b557a09 | 1593 | echo " md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf" |
82b2dba2 ER |
1594 | fi |
1595 | if is_yes "$have_dmraid" || is_yes "$have_multipath"; then | |
9b557a09 | 1596 | echo ' types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf" |
82b2dba2 ER |
1597 | fi |
1598 | if [ "$lvm_ignore_devices" ]; then | |
1599 | # TODO: think of merging with lvm dumpconfig output | |
9b557a09 | 1600 | echo ' filter = [' >> "$DESTDIR/etc/lvm.conf" |
82b2dba2 ER |
1601 | local dev |
1602 | for dev in $lvm_ignore_devices; do | |
d8056591 | 1603 | debug "LVM v2: ignore device $dev" |
82b2dba2 | 1604 | printf ' "r|^%s.*|",\n' $dev |
9b557a09 ER |
1605 | done >> "$DESTDIR/etc/lvm.conf" |
1606 | echo ']' >> "$DESTDIR/etc/lvm.conf" | |
82b2dba2 ER |
1607 | fi |
1608 | # XXX filter= must be on one line! | |
9b557a09 ER |
1609 | lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf" |
1610 | echo "}" >> "$DESTDIR/etc/lvm.conf" | |
fd2dc249 | 1611 | |
82b2dba2 | 1612 | initrd_gen_devices |
bb529f94 | 1613 | |
82b2dba2 | 1614 | add_linuxrc <<-EOF |
6bdc2eeb | 1615 | export ROOTDEV=$rootdev |
4c16dac4 ER |
1616 | export ROOTVG="$VGVOLUMES" |
1617 | export SUSPENDVG=$SUSPENDVG | |
82b2dba2 ER |
1618 | EOF |
1619 | add_linuxrc <<-'EOF' | |
a22ce693 AM |
1620 | # parse rootdev from kernel commandline if it begins with / |
1621 | case "$ROOT" in | |
1622 | /*) | |
1623 | if [ "$ROOT" != "$ROOTDEV" ]; then | |
1624 | ROOTDEV=$ROOT | |
1625 | echo "LVM: Using 'root=$ROOTDEV' from kernel commandline" | |
1626 | local tmp=${ROOTDEV#/dev/} | |
1627 | if [ "$tmp" != "$ROOTDEV" ]; then | |
1628 | ROOTVG=${tmp%/*} | |
1629 | echo "LVM: Using Volume Group '$ROOTVG' for rootfs" | |
1630 | fi | |
6bdc2eeb | 1631 | fi |
a22ce693 AM |
1632 | ;; |
1633 | esac | |
6bdc2eeb | 1634 | |
b80ac01c ER |
1635 | # skip duplicate VG |
1636 | if [ "$SUSPENDVG" = "$ROOTVG" ]; then | |
1637 | export VGVOLUMES="$ROOTVG" | |
1638 | else | |
1639 | export VGVOLUMES="$SUSPENDVG $ROOTVG" | |
1640 | fi | |
4c16dac4 | 1641 | |
3a1d3d88 | 1642 | # disable noise from LVM accessing devices that aren't ready. |
f258d870 | 1643 | read printk < /proc/sys/kernel/printk |
ef5812f8 AM |
1644 | if [ ! "$DEBUGINITRD" ]; then |
1645 | echo 0 > /proc/sys/kernel/printk | |
1646 | fi | |
22b0c9f4 | 1647 | |
82b2dba2 ER |
1648 | export LVM_SYSTEM_DIR=/tmp |
1649 | : 'Scanning for Volume Groups' | |
1650 | lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null | |
b4d9d384 | 1651 | |
82b2dba2 | 1652 | : 'Activating Volume Groups' |
4c16dac4 ER |
1653 | for vol in $VGVOLUMES; do |
1654 | lvm.static vgchange --ignorelockingfailure -a y $vol 2>/dev/null | |
1655 | done | |
ac085800 | 1656 | |
82b2dba2 | 1657 | echo "$printk" > /proc/sys/kernel/printk |
9299682f | 1658 | |
82b2dba2 | 1659 | # Find out major/minor |
6bdc2eeb | 1660 | attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $ROOTDEV 2>/dev/null)" |
82b2dba2 | 1661 | if [ "$attrs" ]; then |
6bdc2eeb | 1662 | majmin="${attrs#*$ROOTDEV*:*:*:*:*:*:*:*:*:*:*:*}" |
82b2dba2 ER |
1663 | if [ "$majmin" != "$attrs" ]; then |
1664 | major="${majmin%:*}" | |
1665 | minor="${majmin#*:}" | |
1666 | fi | |
1667 | fi | |
1606e343 | 1668 | |
82b2dba2 ER |
1669 | if [ "$major" -a "$minor" ]; then |
1670 | # Pass it to kernel | |
1671 | echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev | |
1672 | else | |
6bdc2eeb | 1673 | echo 2>&1 "Error figuring out real root device for $ROOTDEV!" |
82b2dba2 ER |
1674 | echo 2>&1 "System will not most likely boot up! So dropping you to a shell!" |
1675 | echo 2>&1 "" | |
1676 | sh | |
1677 | fi | |
7915c8b1 | 1678 | EOF |
1606e343 | 1679 | fi |
82b2dba2 | 1680 | } |
b64f015b | 1681 | |
289fbc9b | 1682 | initrd_gen_blkid() |
1683 | { | |
1684 | debug "Adding BLKID support to initrd" | |
fb1e695a | 1685 | inst_exec /sbin/initrd-blkid /bin/blkid |
289fbc9b | 1686 | initrd_gen_devices |
1687 | add_linuxrc <<-'EOF' | |
12617f8e | 1688 | # if built with blkid change ROOT=LABEL=something into ROOT=/dev/somethingelse - |
fc787d45 | 1689 | # parsed by blkid |
1690 | if [ "${ROOT##LABEL=}" != "${ROOT}" -o "${ROOT##UUID=}" != "${ROOT}" ]; then | |
1691 | ROOT="$(/bin/blkid -t $ROOT -o device -l)" | |
1692 | fi | |
289fbc9b | 1693 | EOF |
1694 | } | |
1695 | ||
4828c787 | 1696 | initrd_gen_setrootdev() { |
5a761721 | 1697 | debug "Adding rootfs finding based on kernel cmdline root= option support." |
82b2dba2 | 1698 | add_linuxrc <<-'EOF' |
dcdf6b49 ER |
1699 | if [ "${ROOT##/dev/}" != "${ROOT}" ]; then |
1700 | rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)" | |
82b2dba2 ER |
1701 | if [ -n "$rootnr" ]; then |
1702 | echo "$rootnr" > /proc/sys/kernel/real-root-dev | |
1703 | fi | |
1704 | fi | |
b64f015b | 1705 | EOF |
1606e343 AM |
1706 | } |
1707 | ||
034056fd ER |
1708 | # main() |
1709 | if [ "$(id -u)" != 0 ]; then | |
1710 | die "You need to be root to generate initrd" | |
1711 | fi | |
1712 | ||
82b2dba2 ER |
1713 | if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then |
1714 | USE_UDEV=yes | |
1715 | . /etc/udev/udev.conf | |
1716 | fi | |
2cc3ae8b | 1717 | |
82b2dba2 ER |
1718 | if [ -x /sbin/dmraid-initrd ]; then |
1719 | USE_DMRAID=yes | |
1720 | fi | |
2cc3ae8b | 1721 | |
3ef3d717 ER |
1722 | if [ -x /sbin/cryptsetup ]; then |
1723 | USE_LUKS=yes | |
1724 | fi | |
1725 | ||
82b2dba2 ER |
1726 | if [ -x /sbin/multipath ]; then |
1727 | USE_MULTIPATH=yes | |
1728 | fi | |
2cc3ae8b | 1729 | |
af075488 | 1730 | if [ -x /sbin/initrd-blkid ]; then |
1731 | USE_BLKID=yes | |
1732 | fi | |
1733 | ||
82b2dba2 ER |
1734 | if [ -r /etc/sysconfig/geninitrd ]; then |
1735 | . /etc/sysconfig/geninitrd | |
1736 | fi | |
2cc3ae8b | 1737 | |
82b2dba2 ER |
1738 | if [ ! -x /bin/initrd-busybox ]; then |
1739 | die "/bin/initrd-busybox is missing!" | |
1740 | fi | |
c6c6ce01 | 1741 | |
82b2dba2 ER |
1742 | # backwards compatible |
1743 | if [ "$USE_SUSPEND2" ]; then | |
1744 | USE_TUXONICE=$USE_SUSPEND2 | |
f4010f7f | 1745 | warn "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead." |
82b2dba2 | 1746 | fi |
882472ae | 1747 | |
82b2dba2 ER |
1748 | while [ $# -gt 0 ]; do |
1749 | case $1 in | |
1750 | --fstab=*) | |
1751 | fstab=${1#--fstab=} | |
1752 | ;; | |
1753 | --fstab) | |
1754 | fstab=$2 | |
1755 | shift | |
1756 | ;; | |
1757 | --modules-conf=*) | |
1758 | modulefile=${1#--modules-conf=} | |
1759 | ;; | |
1760 | --modules-conf) | |
1761 | modulefile=$2 | |
1762 | shift | |
1763 | ;; | |
1764 | --use-raidstart|--with-raidstart) | |
1765 | USERAIDSTART=yes | |
1766 | ;; | |
1767 | --without-raidstart) | |
1768 | USERAIDSTART=no | |
1769 | ;; | |
1770 | --use-insmod-static|--with-insmod-static) | |
1771 | USEINSMODSTATIC=yes | |
1772 | ;; | |
1773 | --without-insmod-static) | |
1774 | USEINSMODSTATIC=no | |
1775 | ;; | |
1776 | --with-bootsplash) | |
1777 | BOOT_SPLASH=yes | |
1778 | ;; | |
1779 | --without-bootsplash) | |
1780 | BOOT_SPLASH=no | |
1781 | ;; | |
1782 | --with-fbsplash) | |
1783 | FB_SPLASH=yes | |
1784 | ;; | |
1785 | --without-fbsplash) | |
1786 | FB_SPLASH=no | |
1787 | ;; | |
6c69a2d4 ER |
1788 | --with-fbcondecor) |
1789 | FB_CON_DECOR=yes | |
1790 | ;; | |
1791 | --without-fbcondecor) | |
1792 | FB_CON_DECOR=no | |
1793 | ;; | |
82b2dba2 ER |
1794 | --with-suspend) |
1795 | USE_SUSPEND=yes | |
1796 | ;; | |
1797 | --without-suspend) | |
1798 | USE_SUSPEND=no | |
1799 | ;; | |
1800 | --with-suspend2 | --with-tuxonice) | |
1801 | USE_TUXONICE=yes | |
1802 | ;; | |
1803 | --without-suspend2 | --without-tuxonice) | |
1804 | USE_TUXONICE=no | |
1805 | ;; | |
1806 | --lvmtoolsversion=|--lvmversion=) | |
7308edee ER |
1807 | LVMTOOLSVERSION=${1#--lvmtoolsversion=} |
1808 | LVMTOOLSVERSION=${1#--lvmversion=} | |
82b2dba2 ER |
1809 | ;; |
1810 | --lvmtoolsversion|--lvmversion) | |
1811 | LVMTOOLSVERSION=$2 | |
1812 | shift | |
1813 | ;; | |
1814 | --without-udev) | |
1815 | USE_UDEV=no | |
1816 | ;; | |
1817 | --with-udev) | |
1818 | USE_UDEV=yes | |
1819 | ;; | |
1820 | --without-dmraid) | |
1821 | USE_DMRAID=no | |
1822 | ;; | |
1823 | --without-multipath) | |
1824 | USE_MULTPATH=no | |
1825 | ;; | |
af075488 | 1826 | --without-blkid) |
1827 | USE_BLKID=no | |
289fbc9b | 1828 | ;; |
3ef3d717 ER |
1829 | --without-luks) |
1830 | USE_LUKS=no | |
1831 | ;; | |
82b2dba2 ER |
1832 | --with=*) |
1833 | BASICMODULES="$BASICMODULES ${1#--with=}" | |
1834 | ;; | |
1835 | --with) | |
1836 | BASICMODULES="$BASICMODULES $2" | |
1837 | shift | |
1838 | ;; | |
1839 | --version) | |
1840 | echo "$PROGRAM: version $VERSION" | |
1841 | exit 0 | |
1842 | ;; | |
1843 | -v) | |
1844 | verbose=-v | |
1845 | ;; | |
1846 | --nocompress) | |
1847 | COMPRESS=no | |
1848 | ;; | |
1849 | --ifneeded) | |
1850 | ifneeded=1 | |
1851 | ;; | |
1852 | -f) | |
1853 | force=1 | |
1854 | ;; | |
1855 | --preload=*) | |
1856 | PREMODS="$PREMODS ${1#--preload=}" | |
1857 | ;; | |
1858 | --preload) | |
1859 | PREMODS="$PREMODS $2" | |
1860 | shift | |
1861 | ;; | |
1862 | --fs=*) | |
f4010f7f | 1863 | warn "Warning: --fs option is obsoleted. Use --initrdfs instead" |
82b2dba2 ER |
1864 | INITRDFS=${1#--fs=} |
1865 | ;; | |
1866 | --fs) | |
f4010f7f | 1867 | warn "Warning: --fs option is obsoleted. Use --initrdfs instead" |
82b2dba2 ER |
1868 | INITRDFS=$2 |
1869 | shift | |
1870 | ;; | |
1871 | --initrdfs=*) | |
1872 | INITRDFS=${1#--initrdfs=} | |
1873 | ;; | |
1874 | --initrdfs) | |
1875 | INITRDFS=$2 | |
1876 | shift | |
1877 | ;; | |
1878 | --image-version) | |
1879 | img_vers=yes | |
1880 | ;; | |
1881 | --ide-only-root) | |
1882 | ide_only_root="yes" | |
1883 | ;; | |
1884 | *) | |
1885 | if [ -z "$target" ]; then | |
1886 | target="$1" | |
1887 | elif [ -z "$kernel" ]; then | |
1888 | kernel="$1" | |
1889 | else | |
1890 | usage | |
1891 | fi | |
1892 | ;; | |
1893 | esac | |
f5db170b | 1894 | |
82b2dba2 ER |
1895 | shift |
1896 | done | |
1897 | ||
1898 | if [ -z "$target" -o -z "$kernel" ]; then | |
1899 | usage | |
1900 | fi | |
1901 | ||
130aadc1 | 1902 | if [ ! -f /boot/vmlinuz-"$kernel" ]; then |
f4010f7f | 1903 | warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?" |
130aadc1 ER |
1904 | fi |
1905 | ||
7308edee ER |
1906 | pack_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}') |
1907 | pack_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}') | |
82b2dba2 ER |
1908 | |
1909 | if [ -z "$INITRDFS" ]; then | |
326dd4ad | 1910 | if [ -z "$FS" ]; then |
6d60e1b7 ER |
1911 | # default value |
1912 | if [ "$pack_version" -ge "002005" ]; then | |
1913 | INITRDFS="initramfs" | |
1914 | else | |
1915 | INITRDFS="rom" | |
1916 | fi | |
82b2dba2 | 1917 | else |
f4010f7f | 1918 | warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead" |
82b2dba2 | 1919 | INITRDFS="$FS" |
f5db170b | 1920 | fi |
82b2dba2 | 1921 | fi |
f5db170b | 1922 | |
82b2dba2 ER |
1923 | if [ "$pack_version" -lt "002006" ]; then |
1924 | USE_UDEV=no | |
1925 | USE_DMRAID=no | |
1926 | fi | |
f5db170b | 1927 | |
82b2dba2 ER |
1928 | if [ "$pack_version" -ge "002005" ]; then |
1929 | modext=".ko" | |
1930 | insmod="insmod" | |
1931 | fi | |
966c32cc | 1932 | |
82b2dba2 ER |
1933 | if is_yes "$USEINSMODSTATIC"; then |
1934 | insmod="insmod.static" | |
1935 | INSMOD="/sbin/insmod.static" | |
1936 | if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then | |
1937 | INSMOD="/sbin/insmod.static.modutils" | |
966c32cc | 1938 | fi |
82b2dba2 ER |
1939 | if [ ! -f "$INSMOD" ]; then |
1940 | die "insmod.static requested but /sbin/insmod.static not found!" | |
966c32cc | 1941 | fi |
82b2dba2 | 1942 | fi |
966c32cc | 1943 | |
82b2dba2 ER |
1944 | case "$INITRDFS" in |
1945 | ext2) | |
1946 | if [ ! -x /sbin/mke2fs ]; then | |
1947 | die "/sbin/mke2fs is missing" | |
f5db170b | 1948 | fi |
82b2dba2 ER |
1949 | ;; |
1950 | rom|romfs) | |
1951 | if [ ! -x /sbin/genromfs ]; then | |
1952 | die "/sbin/genromfs is missing" | |
1953 | fi | |
1954 | ;; | |
1955 | cram|cramfs) | |
1956 | if [ ! -x /sbin/mkcramfs ]; then | |
1957 | die "/sbin/mkcramfs is missing" | |
1958 | fi | |
1959 | ;; | |
1960 | initramfs) | |
1961 | if [ ! -x /bin/cpio ]; then | |
1962 | die "/bin/cpio is missing" | |
1963 | fi | |
1964 | if [ ! -x /usr/bin/find ]; then | |
1965 | die "/usr/bin/find is missing" | |
1966 | fi | |
1967 | ;; | |
1968 | *) | |
1969 | die "Filesystem $INITRDFS on initrd is not supported" | |
1970 | ;; | |
1971 | esac | |
f5db170b | 1972 | |
9323ada3 | 1973 | if [ -L "$target" ]; then |
1974 | target=$(readlink -f "$target") | |
1975 | fi | |
1976 | ||
82b2dba2 ER |
1977 | if [ -n "$img_vers" ]; then |
1978 | target="$target-$kernel" | |
1979 | fi | |
8bd582f1 | 1980 | |
82b2dba2 ER |
1981 | if [ -z "$force" -a -f "$target" ]; then |
1982 | die "$target already exists." | |
1983 | fi | |
c6c6ce01 | 1984 | |
82b2dba2 ER |
1985 | if [ ! -d "/lib/modules/$kernel" ]; then |
1986 | die "/lib/modules/$kernel is not a directory." | |
1987 | fi | |
2ffb1734 | 1988 | |
12617f8e | 1989 | if [ "$INITRDFS" != "initramfs" ]; then |
12617f8e ER |
1990 | if is_yes "$FB_SPLASH"; then |
1991 | warn "Using fbsplash requires INITRDFS=initramfs; skipping fbsplash generation" | |
1992 | FB_SPLASH=no | |
1993 | fi | |
1994 | if is_yes "$FB_CON_DECOR"; then | |
1995 | warn "Using fbcondecor requires INITRDFS=initramfs; skipping fbcondecor generation" | |
1996 | FB_CON_DECOR=no | |
1997 | fi | |
1998 | fi | |
1999 | ||
82b2dba2 | 2000 | if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then |
6c69a2d4 | 2001 | warn "Tuxonice and mainline suspend are exclusive!" |
82b2dba2 | 2002 | fi |
ac085800 | 2003 | |
7992356a | 2004 | if is_yes "$FB_SPLASH" && is_yes "$BOOT_SPLASH"; then |
6c69a2d4 | 2005 | warn "bootsplash and fbsplash are exclusive!" |
82b2dba2 | 2006 | fi |
994eb509 | 2007 | |
82b2dba2 | 2008 | if [ ! -f /proc/mounts ]; then |
4aa3bff8 | 2009 | warn "/proc filesystem not mounted, may cause wrong results or failure." |
82b2dba2 | 2010 | fi |
6cca3165 | 2011 | |
82b2dba2 ER |
2012 | if [ -d /usr/lib64 ]; then |
2013 | _lib=lib64 | |
2014 | else | |
2015 | _lib=lib | |
2016 | fi | |
d8056591 | 2017 | debug "Using libdir: $_lib" |
ac085800 | 2018 | |
82b2dba2 ER |
2019 | cache_modprobe_conf |
2020 | ||
2021 | for n in $PREMODS; do | |
2022 | findmodule "$n" | |
2023 | done | |
2024 | ||
ed30e3a8 ER |
2025 | if [ "$FBMODULE" ]; then |
2026 | findmodule "$FBMODULE" | |
2027 | fi | |
2028 | ||
82b2dba2 ER |
2029 | # allow forcing loading SCSI and/or IDE modules |
2030 | if is_yes "$ADDSCSI"; then | |
2031 | find_modules_scsi | |
2032 | fi | |
2033 | ||
2034 | if is_yes "$ADDIDE"; then | |
2035 | find_modules_ide | |
2036 | fi | |
2037 | ||
4c16dac4 ER |
2038 | if is_yes "$USE_SUSPEND"; then |
2039 | find_modules_suspend | |
2040 | fi | |
2041 | ||
82b2dba2 ER |
2042 | find_root "$fstab" || exit |
2043 | debug "Using $rootdev as device for rootfs" | |
2044 | ||
d8056591 ER |
2045 | find_modules_for_devpath "$rootdev" |
2046 | [ -n "$rootdev_add" ] && find_modules_for_devpath "$rootdev_add" | |
ac085800 | 2047 | |
82b2dba2 | 2048 | findmodule "-$rootFs" |
ac085800 | 2049 | |
82b2dba2 ER |
2050 | for n in $BASICMODULES; do |
2051 | findmodule "$n" | |
2052 | done | |
4e9eb79c | 2053 | |
82b2dba2 ER |
2054 | if is_yes "$USE_TUXONICE"; then |
2055 | findmodule "-lzf" | |
2056 | fi | |
33d24e12 | 2057 | |
82b2dba2 ER |
2058 | if is_yes "$FB_SPLASH"; then |
2059 | findmodule "-evdev" | |
2060 | fi | |
2968c9dd | 2061 | |
82b2dba2 ER |
2062 | if [ -n "$ifneeded" -a -z "$MODULES" ]; then |
2063 | debug "No modules are needed -- not building initrd image." | |
2064 | exit 0 | |
2065 | fi | |
c6c6ce01 | 2066 | |
d8056591 | 2067 | DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed" |
9b557a09 | 2068 | RCFILE="$DESTDIR/linuxrc" |
82b2dba2 ER |
2069 | > "$RCFILE" |
2070 | chmod a+rx "$RCFILE" | |
9b557a09 | 2071 | ln -s linuxrc $DESTDIR/init |
e8d178ff | 2072 | |
82b2dba2 ER |
2073 | # create dirs that we really need |
2074 | inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys} | |
e8d178ff | 2075 | |
82b2dba2 | 2076 | modules_install "$MODULES" |
b64f015b | 2077 | |
82b2dba2 ER |
2078 | # mknod'ing the devices instead of copying them works both with and |
2079 | # without devfs... | |
9b557a09 ER |
2080 | mknod "$DESTDIR/dev/console" c 5 1 |
2081 | mknod "$DESTDIR/dev/null" c 1 3 | |
2082 | mknod "$DESTDIR/dev/zero" c 1 5 | |
be2f3ecc | 2083 | |
fb1e695a | 2084 | inst_exec /bin/initrd-busybox /bin/initrd-busybox |
9b557a09 ER |
2085 | ln -s initrd-busybox $DESTDIR/bin/sh |
2086 | ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH | |
2ffb1734 | 2087 | |
82b2dba2 | 2088 | if is_yes "$USEINSMODSTATIC"; then |
fb1e695a | 2089 | inst_exec "$INSMOD" /bin/insmod.static |
82b2dba2 | 2090 | fi |
c6c6ce01 | 2091 | |
82b2dba2 ER |
2092 | add_linuxrc <<EOF |
2093 | #!/bin/sh | |
2094 | # initrd generated by: | |
2095 | # $RCSID | |
c6c6ce01 | 2096 | |
82b2dba2 ER |
2097 | EOF |
2098 | mount_proc | |
2099 | add_linuxrc <<-'EOF' | |
3a1d3d88 | 2100 | read CMDLINE < /proc/cmdline; export CMDLINE |
c6c6ce01 | 2101 | |
82b2dba2 ER |
2102 | for arg in $CMDLINE; do |
2103 | if [ "${arg}" = "debuginitrd" ]; then | |
2104 | DEBUGINITRD=yes | |
2105 | fi | |
2106 | if [ "${arg##debuginitrd=}" != "${arg}" ]; then | |
2107 | DEBUGINITRD=${arg##debuginitrd=} | |
2108 | fi | |
fc787d45 | 2109 | if [ "${arg##root=}" != "${arg}" ]; then |
2110 | ROOT=${arg##root=} | |
2111 | fi | |
82b2dba2 | 2112 | done |
c6c6ce01 | 2113 | |
82b2dba2 ER |
2114 | # make debugshell() invoke subshell if $DEBUGINITRD=sh |
2115 | if [ "$DEBUGINITRD" = "sh" ]; then | |
2116 | debugshell() { | |
e2405b29 AM |
2117 | EOF |
2118 | if is_yes "$RUN_SULOGIN_ON_ERR"; then | |
2119 | add_linuxrc <<-'EOF' | |
2120 | echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting" | |
2121 | EOF | |
2122 | else | |
2123 | add_linuxrc <<-'EOF' | |
2124 | sh | |
2125 | EOF | |
2126 | fi | |
2127 | add_linuxrc <<-'EOF' | |
82b2dba2 ER |
2128 | } |
2129 | else | |
2130 | debugshell() { | |
2131 | : | |
2132 | } | |
2133 | fi | |
e934d044 | 2134 | |
82b2dba2 ER |
2135 | if [ "$DEBUGINITRD" ]; then |
2136 | set -x | |
cff3058d | 2137 | fi |
82b2dba2 | 2138 | EOF |
2df2e995 | 2139 | |
fe280785 | 2140 | modules_add_linuxrc $MODULES |
82b2dba2 ER |
2141 | |
2142 | # TODO: rewrite for busybox | |
2143 | #if [ -n "$loopDev" ]; then | |
2144 | # if [ ! -d /initrd ]; then | |
2145 | # mkdir /initrd | |
2146 | # fi | |
2147 | # | |
9b557a09 ER |
2148 | # cp -a "$loopDev" "$DESTDIR/dev" |
2149 | # cp -a "$rootdev" "$DESTDIR/dev" | |
82b2dba2 ER |
2150 | # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE" |
2151 | # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE" | |
2152 | # echo "echo Setting up loopback device $rootdev" >> $RCFILE | |
2153 | # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE" | |
2154 | #fi | |
2b1a3707 | 2155 | |
1606e343 AM |
2156 | if is_yes "$USE_UDEV"; then |
2157 | initrd_gen_udev | |
2158 | fi | |
2159 | ||
1cd2aabd ER |
2160 | if is_yes "$USE_TUXONICE"; then |
2161 | initrd_gen_tuxonice | |
2df2e995 AM |
2162 | fi |
2163 | ||
43258faf AG |
2164 | if is_yes "$need_v86d"; then |
2165 | initrd_gen_v86d | |
2166 | fi | |
2167 | ||
3ef3d717 ER |
2168 | if is_yes "$have_luks"; then |
2169 | initrd_gen_luks | |
2170 | fi | |
2171 | ||
cc8e8a99 | 2172 | if is_yes "$have_dmraid"; then |
882472ae ER |
2173 | initrd_gen_dmraid |
2174 | fi | |
2175 | ||
c083ae23 | 2176 | if is_yes "$have_multipath"; then |
2cc3ae8b ER |
2177 | initrd_gen_multipath |
2178 | fi | |
2179 | ||
cc8e8a99 | 2180 | if is_yes "$USE_BLKID"; then |
289fbc9b | 2181 | initrd_gen_blkid |
2182 | fi | |
2183 | ||
69b1e935 | 2184 | if is_yes "$have_nfs"; then |
2df2e995 | 2185 | initrd_gen_nfs |
df738638 ER |
2186 | elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then |
2187 | initrd_gen_md | |
69b1e935 | 2188 | if is_yes "$have_lvm"; then |
2df2e995 | 2189 | initrd_gen_lvm |
bfea009a | 2190 | else |
4828c787 | 2191 | initrd_gen_setrootdev |
2df2e995 | 2192 | fi |
69b1e935 | 2193 | elif is_yes "$have_lvm"; then |
2df2e995 | 2194 | initrd_gen_lvm |
2b1a3707 | 2195 | else |
4828c787 | 2196 | initrd_gen_setrootdev |
7c38b114 AF |
2197 | fi |
2198 | ||
4c16dac4 ER |
2199 | if is_yes "$USE_SUSPEND"; then |
2200 | initrd_gen_suspend | |
2201 | fi | |
2202 | ||
5101a385 | 2203 | # additional devs always needed |
9b557a09 | 2204 | [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev |
5101a385 | 2205 | |
f8f9e56d | 2206 | if [ "$INITRDFS" = "initramfs" ]; then |
034fdd5d | 2207 | inst_d /newroot |
6d2c63ed ER |
2208 | if [ "$rootdev" = "/dev/nfs" ]; then |
2209 | echo "rootfs on NFS root=/dev/nfs" | |
2210 | else | |
b864a83e | 2211 | [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev |
6d2c63ed | 2212 | fi |
e4b07ddc | 2213 | # Parsing root parameter |
81d53704 | 2214 | # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303 |
c6c6ce01 | 2215 | add_linuxrc <<-'EOF' |
12617f8e | 2216 | device=/dev/no_partition_found |
fc787d45 | 2217 | eval "$(busybox awk -v c="$ROOT" ' |
675e6f41 | 2218 | BEGIN { |
2219 | num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]"; | |
2220 | num_pattern = "[0-9a-f]" num_pattern_short; | |
2221 | dev_pattern = "[hms][a-z][a-z]([0-9])+"; | |
2222 | partition = "no_partition_found"; | |
2223 | min = -1; maj = -1; | |
2224 | ||
675e6f41 | 2225 | sub("^0x", "", c); |
2226 | if (c ~ "^" num_pattern_short "$") sub("^", "0", c); | |
2227 | if (c ~ "^" num_pattern "$") { | |
2228 | maj = sprintf("%s",substr(c,1,2)); | |
2229 | min = sprintf("%s",substr(c,3)); | |
2230 | } | |
2231 | if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c); | |
2232 | if (c ~ "^" dev_pattern "$") partition = c; | |
c6c6ce01 | 2233 | } |
df391e6f | 2234 | |
675e6f41 | 2235 | $4 ~ partition { maj = $1; min = $2; } |
2236 | $1 ~ maj && $2 ~ min { partition = $4; } | |
c6c6ce01 | 2237 | |
675e6f41 | 2238 | END { |
2239 | print sprintf("device=/dev/%s\nmaj=%s\nmin=%s", | |
2240 | partition, maj, min); | |
2241 | } | |
2242 | ' /proc/partitions)" | |
c6c6ce01 ER |
2243 | if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then |
2244 | mknod $device b $maj $min | |
2245 | fi | |
2246 | EOF | |
92a4990b | 2247 | |
c6c6ce01 | 2248 | add_linuxrc <<-EOF |
f5db170b ER |
2249 | rootdev=$rootdev |
2250 | rootfs=$rootFs | |
2251 | EOF | |
2252 | ||
2253 | add_linuxrc <<-'EOF' | |
2254 | if [ "$device" = '/dev/no_partition_found' ]; then | |
2255 | device=$rootdev | |
c6c6ce01 | 2256 | fi |
e620b426 | 2257 | |
f5db170b ER |
2258 | mount -t $rootfs -r $device /newroot |
2259 | init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')" | |
2260 | if [ -z "$init" -o ! -x "/newroot$init" ]; then | |
c6c6ce01 ER |
2261 | init=/sbin/init |
2262 | fi | |
b64f015b | 2263 | EOF |
f1a5a1b0 | 2264 | |
f5db170b ER |
2265 | umount_all |
2266 | busybox_applet switch_root | |
2267 | add_linuxrc <<-'EOF' | |
2268 | exec switch_root /newroot $init | |
2269 | ||
2270 | echo "Error! initramfs should not reach this place." | |
c6c6ce01 ER |
2271 | echo "It probably means you've got old version of busybox, with broken" |
2272 | echo "initramfs support. Trying to boot anyway, but won't promise anything." | |
f1a5a1b0 | 2273 | |
f5db170b | 2274 | exec chroot /newroot $init |
f1a5a1b0 | 2275 | |
f5db170b | 2276 | echo "Failed to chroot!" |
c6c6ce01 | 2277 | EOF |
f5db170b ER |
2278 | # we need /init being real file, not symlink, otherwise the initramfs will |
2279 | # not be ran by pid 1 which is required for switch_root | |
9b557a09 | 2280 | mv $DESTDIR/linuxrc $DESTDIR/init |
d8056591 | 2281 | ln -s init $DESTDIR/linuxrc |
b64f015b ER |
2282 | else |
2283 | # other than initramfs | |
2284 | umount_all | |
f8f9e56d AM |
2285 | fi |
2286 | ||
b7feffb3 ER |
2287 | if is_yes "$FB_SPLASH"; then |
2288 | initrd_gen_fbsplash | |
2289 | fi | |
2290 | ||
6c69a2d4 ER |
2291 | if is_yes "$FB_CON_DECOR"; then |
2292 | initrd_gen_fbcondecor | |
2293 | fi | |
2294 | ||
d8056591 | 2295 | IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed" |
51dc1fe6 AM |
2296 | |
2297 | debug "Creating $INITRDFS image $IMAGE" | |
2ad94d8a | 2298 | case "$INITRDFS" in |
8b1e4ac7 | 2299 | ext2) |
d8056591 ER |
2300 | IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}') |
2301 | debug "ext2 image size: $IMAGESIZE ($DESTDIR)" | |
73edc0c1 | 2302 | if [ "$IMAGESIZE" -gt 4096 ]; then |
19afb117 | 2303 | warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!" |
73edc0c1 ER |
2304 | fi |
2305 | ||
2306 | dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null | |
2307 | mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2 | |
2308 | tune2fs -i 0 "$IMAGE" >/dev/null 2>&1 | |
2309 | ||
d8056591 ER |
2310 | local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX) |
2311 | debug "Mounting ext2 image $IMAGE to $tmpmnt" | |
73edc0c1 | 2312 | mount -o loop -t ext2 "$IMAGE" "$tmpmnt" |
d8056591 ER |
2313 | # We don't need this directory, so let's save space |
2314 | rm -rf "$tmpmnt"/lost+found | |
73edc0c1 | 2315 | |
d8056591 ER |
2316 | debug "Copy recursively $DESTDIR -> $tmpmnt" |
2317 | cp -a $DESTDIR/* $tmpmnt | |
35164381 | 2318 | umount "$IMAGE" |
d8056591 ER |
2319 | rmdir "$tmpmnt" |
2320 | ||
8b1e4ac7 | 2321 | ;; |
c1548a54 | 2322 | rom|romfs) |
d8056591 | 2323 | genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel" |
cdf1e7c9 | 2324 | IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}') |
d8056591 | 2325 | debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)" |
a8b63949 | 2326 | if [ "$IMAGESIZE" -gt 4096 ]; then |
19afb117 | 2327 | warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!" |
a8b63949 | 2328 | fi |
8b1e4ac7 | 2329 | ;; |
c1548a54 | 2330 | cram|cramfs) |
d8056591 | 2331 | mkcramfs "$DESTDIR" "$IMAGE" |
8b1e4ac7 | 2332 | ;; |
48413b7f | 2333 | initramfs) |
d8056591 | 2334 | (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE") |
48413b7f | 2335 | ;; |
8b1e4ac7 | 2336 | *) |
7758e45c | 2337 | echo "Filesystem $INITRDFS not supported by $PROGRAM"; |
c31050f3 | 2338 | esac |
bb529f94 | 2339 | |
82474db9 | 2340 | if is_yes "$COMPRESS"; then |
aecfd33d | 2341 | tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed" |
d8056591 ER |
2342 | debug "Compressing $target" |
2343 | gzip -9 < "$IMAGE" > "$tmp" | |
2344 | mv -f "$tmp" "$target" | |
bb529f94 | 2345 | else |
7d2fc5eb | 2346 | cp -a "$IMAGE" "$target" |
bb529f94 | 2347 | fi |
5b71959c | 2348 | |
7992356a | 2349 | # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image. |
5b71959c | 2350 | if is_yes "$BOOT_SPLASH"; then |
f5db170b | 2351 | initrd_gen_bootsplash "$target" |
5b71959c AM |
2352 | fi |
2353 | ||
d8056591 | 2354 | rm -rf "$DESTDIR" "$IMAGE" |
ac085800 ER |
2355 | |
2356 | # vim:ts=4:sw=4:noet:fdm=marker |