]>
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 | # |
c31050f3 | 9 | |
28eec2b1 | 10 | RCSID='$Id$' |
ca2c2012 ER |
11 | R=${RCSID#* * }; VERSION=${R%% *} |
12 | PROGRAM=${0##*/} | |
bb529f94 JK |
13 | |
14 | . /etc/rc.d/init.d/functions | |
ded87775 | 15 | . /lib/geninitrd/functions |
e2405b29 | 16 | . /etc/sysconfig/system |
bb529f94 | 17 | |
c124d0cf ER |
18 | # list of geninitrd modules which need setup routine after commandline args parsing |
19 | GENINITRD_MODS="" | |
c3667d07 | 20 | COMPRESS=yes |
10c3df06 MM |
21 | # it should be safe to remove scsi_mod from here, but I'm not sure... |
22 | PRESCSIMODS="-scsi_mod unknown -sd_mod" | |
bb529f94 JK |
23 | target="" |
24 | kernel="" | |
25 | force="" | |
26 | verbose="" | |
27 | MODULES="" | |
28 | img_vers="" | |
c3667d07 | 29 | fstab=/etc/fstab |
c3667d07 | 30 | modext=.o |
4e9eb79c | 31 | rootdev_nr=0 |
738c05d8 ER |
32 | # device node for rootfs from fstab |
33 | rootdev="" | |
bb529f94 | 34 | |
8bd582f1 ER |
35 | # internal variables |
36 | # is /dev on tmpfs | |
b64f015b ER |
37 | dev_mounted=no |
38 | # is /proc mounted | |
39 | proc_mounted=no | |
40 | # is /sys mounted | |
41 | sys_mounted=no | |
42 | # is /tmp mounted on tmpfs | |
43 | tmp_mounted=no | |
44 | ||
45 | # are /dev nodes already created from /proc/devices info? | |
8bd582f1 | 46 | proc_partitions=no |
6b013929 | 47 | |
b64f015b | 48 | usage() { |
553786c4 | 49 | uname_r=$(uname -r) |
00eaa938 | 50 | echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]" |
ac085800 | 51 | echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]" |
92ed99b6 | 52 | echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]" |
18ece493 | 53 | echo " [--with-raidstart] [--without-raidstart]" |
ba5d09f0 | 54 | echo " [--with-bootsplash] [--without-bootsplash]" |
6c69a2d4 ER |
55 | echo " [--with-fbsplash] [--without-fbsplash]" |
56 | echo " [--with-fbcondecor] [--without-fbcondecor]" | |
e4b07ddc | 57 | echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]" |
ba5d09f0 | 58 | echo " [--with-suspend] [--without-suspend]" |
1cd2aabd | 59 | echo " [--with-tuxonice] [--without-tuxonice]" |
2cc3ae8b | 60 | echo " [--without-dmraid] [--without-multipath]" |
3ef3d717 | 61 | echo " [--without-blkid] [--without-luks]" |
ac085800 | 62 | echo " <initrd-image> <kernel-version>" |
553786c4 ER |
63 | echo "" |
64 | echo "example:" | |
00eaa938 | 65 | echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r" |
36523626 | 66 | exit 0 |
bb529f94 JK |
67 | } |
68 | ||
779a218a | 69 | msg() { |
f4010f7f AM |
70 | echo "$PROGRAM: $*" |
71 | } | |
72 | ||
73 | warn() { | |
4a60c01f | 74 | msg "WARNING: $*" >&2 |
779a218a AM |
75 | } |
76 | ||
94769f11 | 77 | debug() { |
4a60c01f | 78 | [ -n "$verbose" ] && msg "$*" >&2 |
94769f11 | 79 | } |
aa69da6e | 80 | |
bf6c3fcb ER |
81 | # aborts program abnormally |
82 | die() { | |
b5f5c089 | 83 | local rc=${2:-1} |
046c68c9 | 84 | msg "ERROR: $1" >&2 |
bf6c3fcb ER |
85 | exit $rc |
86 | } | |
87 | ||
684d5d2a ER |
88 | # find program from specified paths |
89 | find_tool() { | |
90 | local x | |
91 | for x in "$@"; do | |
92 | if [ -x "$x" ]; then | |
93 | echo $x | |
94 | debug "find_tool: found $x" | |
95 | return 0 | |
96 | fi | |
97 | done | |
98 | debug "find_tool: did not found any of: $@" | |
99 | return 1 | |
100 | } | |
101 | ||
c124d0cf ER |
102 | # loads geninitrd modules |
103 | geninitrd_load_mods() { | |
104 | local mod | |
105 | for mod in "$@"; do | |
106 | if [ ! -f /lib/geninitrd/mod-$mod.sh ]; then | |
107 | die "$mod geninitrd module can't be loaded" | |
108 | fi | |
109 | . /lib/geninitrd/mod-$mod.sh | |
110 | ||
111 | if type setup_mod_$mod > /dev/null; then | |
112 | # add to list which need init | |
113 | GENINITRD_MODS="$GENINITRD_MODS $mod" | |
114 | fi | |
115 | done | |
116 | } | |
117 | ||
118 | # setup geninitrd modules | |
119 | geninitrd_setup_mods() { | |
120 | local mod | |
121 | ||
122 | for mod in $GENINITRD_MODS; do | |
123 | eval setup_mod_$mod | |
124 | done | |
125 | } | |
126 | ||
c6c6ce01 ER |
127 | # append text to /linuxrc |
128 | # takes STDIN as input | |
129 | add_linuxrc() { | |
b64f015b | 130 | cat >> "$RCFILE" |
c6c6ce01 ER |
131 | } |
132 | ||
b64f015b ER |
133 | # generate code to mount /dev on tmpfs and create initial nodes |
134 | # can be called multiple times. /dev is cleaned up (umounted) automatically at | |
135 | # the end of script. | |
136 | mount_dev() { | |
137 | if [ "$INITRDFS" = "initramfs" ]; then | |
138 | # initramfs is read-write filesystem, no need for tmpfs | |
139 | return | |
140 | fi | |
141 | ||
142 | # we already generated tmpfs code; return | |
143 | if is_yes "$dev_mounted"; then | |
144 | return | |
145 | fi | |
146 | ||
147 | dev_mounted=yes | |
148 | ||
149 | busybox_applet mount mknod mkdir | |
150 | add_linuxrc <<-EOF | |
151 | : 'Creating /dev' | |
152 | mount -o mode=0755 -t tmpfs none /dev | |
153 | mknod /dev/console c 5 1 | |
154 | mknod /dev/null c 1 3 | |
155 | mknod /dev/zero c 1 5 | |
156 | mkdir /dev/pts | |
157 | mkdir /dev/shm | |
158 | EOF | |
159 | } | |
160 | ||
161 | # generate code to mount /proc on initrd | |
162 | # can be called multiple times | |
163 | mount_proc() { | |
164 | if is_yes "$proc_mounted"; then | |
165 | return | |
166 | fi | |
167 | ||
168 | proc_mounted=yes | |
2bface63 ER |
169 | if [ "$INITRDFS" = "initramfs" ]; then |
170 | # /proc is mounted with initramfs 2.6.22.14 kernel | |
171 | # XXX: remove when it is clear why proc was already mounted | |
172 | echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc | |
173 | else | |
174 | echo "mount -t proc none /proc" | add_linuxrc | |
175 | fi | |
b64f015b ER |
176 | } |
177 | ||
178 | # generate code to mount /sys on initrd | |
179 | # can be called multiple times | |
180 | mount_sys() { | |
181 | if is_yes "$sys_mounted"; then | |
182 | return | |
183 | fi | |
184 | ||
185 | sys_mounted=yes | |
186 | echo "mount -t sysfs none /sys" | add_linuxrc | |
187 | } | |
188 | ||
189 | # generate code to mount /tmp on initrd | |
190 | # can be called multiple times | |
191 | mount_tmp() { | |
192 | if [ "$INITRDFS" = "initramfs" ]; then | |
193 | # initramfs is read-write filesystem, no need for tmpfs | |
194 | return | |
195 | fi | |
196 | ||
197 | if is_yes "$tmp_mounted"; then | |
198 | return | |
199 | fi | |
200 | ||
201 | tmp_mounted=yes | |
202 | echo "mount -t tmpfs none /tmp" | add_linuxrc | |
203 | } | |
204 | ||
205 | # unmount all mountpoints mounted by geninitrd | |
206 | umount_all() { | |
ec49b7e6 ER |
207 | |
208 | add_linuxrc <<-'EOF' | |
903f21ea | 209 | : Last shell before umounting all and giving control over to real init. |
ec49b7e6 ER |
210 | debugshell |
211 | EOF | |
5b70f84d | 212 | |
b64f015b ER |
213 | if is_yes "$dev_mounted"; then |
214 | echo 'umount /dev' | add_linuxrc | |
215 | dev_mounted=no | |
216 | fi | |
217 | if is_yes "$proc_mounted"; then | |
218 | echo 'umount /proc' | add_linuxrc | |
219 | proc_mounted=no | |
220 | fi | |
221 | if is_yes "$sys_mounted"; then | |
222 | echo 'umount /sys' | add_linuxrc | |
223 | sys_mounted=no | |
224 | fi | |
225 | if is_yes "$tmp_mounted"; then | |
226 | echo 'umount /tmp' | add_linuxrc | |
227 | tmp_mounted=no | |
228 | fi | |
229 | } | |
230 | ||
231 | ||
9299682f ER |
232 | # Checks if busybox has support for APPLET(s) |
233 | # Exits from geninitrd if the support is not present. | |
234 | # | |
235 | # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases! | |
236 | busybox_applet() { | |
237 | local err=0 | |
238 | ||
239 | if [ -z "$busybox_functions" ]; then | |
684d5d2a | 240 | local tmp=$($busybox 2>&1) |
9b1373fb ER |
241 | |
242 | # BusyBox v1.1.3 says applet not found if it's not called 'busybox'. | |
243 | if [[ "$tmp" = *applet\ not\ found* ]]; then | |
244 | local t=$(mktemp -d) | |
684d5d2a | 245 | ln -s $busybox $t/busybox |
9b1373fb ER |
246 | local tmp=$($t/busybox 2>&1) |
247 | rm -rf $t | |
248 | fi | |
249 | ||
250 | busybox_functions=$(echo "$tmp" | \ | |
9299682f ER |
251 | sed -ne '/Currently defined functions:/,$p' | \ |
252 | xargs | sed -e 's,.*Currently defined functions: ,,' | |
253 | ) | |
254 | fi | |
255 | for applet in $*; do | |
256 | local have | |
257 | # try cache | |
258 | eval have='$'busybox_have_$applet | |
259 | if [ -z "$have" ]; then | |
260 | have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)") | |
261 | if [ "$have" = 0 ]; then | |
f4010f7f | 262 | warn "This setup requires busybox-initrd compiled with applet '$applet' support" |
9299682f ER |
263 | err=1 |
264 | fi | |
265 | eval busybox_have_$applet=$have | |
266 | fi | |
267 | done | |
268 | if [ $err = 1 ]; then | |
00eaa938 | 269 | die "Aborted" |
9299682f ER |
270 | fi |
271 | } | |
272 | ||
7ffba534 ER |
273 | # Finds module dependencies |
274 | # | |
7ffba534 ER |
275 | # @param $module |
276 | # | |
046c68c9 | 277 | # Outputs full path to module and it's dependencies |
7ffba534 | 278 | find_depmod() { |
fe280785 | 279 | local module="$1" |
046c68c9 ER |
280 | local skiperrors=0 |
281 | ||
282 | # if module is prefixed with dash, we should ignore errors if the module | |
283 | # can't be found. | |
284 | if [ ${module#-} != $module ]; then | |
285 | skiperrors=1 | |
286 | module=${module#-} | |
287 | fi | |
288 | ||
046c68c9 ER |
289 | # This works when user has module-init-tools installed even on 2.4 kernels |
290 | local modprobe | |
291 | modprobe=$(modprobe --set-version $kernel --show-depends $module --ignore-install 2>&1) | |
292 | ||
293 | if [ $? != 0 ]; then | |
294 | if [ $skiperrors = 1 ]; then | |
7cac5014 ER |
295 | return |
296 | fi | |
046c68c9 | 297 | echo >&2 "$modprobe" |
7cac5014 | 298 | |
7ffba534 | 299 | if ! is_no "$EXIT_IF_MISSING"; then |
046c68c9 | 300 | die "$module: module not found for $kernel kernel" |
7ffba534 | 301 | fi |
046c68c9 ER |
302 | |
303 | warn "$module: module not found for $kernel kernel" | |
304 | warn "If $module isn't compiled in kernel then this initrd may not start your system." | |
7ffba534 ER |
305 | fi |
306 | ||
046c68c9 | 307 | echo "$modprobe" | \ |
c25765ed | 308 | while read insmod modpath options; do |
59a68735 | 309 | [ "$insmod" = "insmod" ] && echo $modpath |
7ffba534 ER |
310 | done |
311 | } | |
312 | ||
4a60c01f AM |
313 | find_firmware() { |
314 | local module="$1" | |
601127ea ER |
315 | |
316 | # no firmware support in 2.4 kernels | |
317 | if [ "$kernel_version_long" -lt "002005048" ]; then | |
318 | return | |
319 | fi | |
320 | echo -n $(NEW_MODINFO=1 modinfo -k $kernel -F firmware $module 2>/dev/null | xargs) | |
4a60c01f AM |
321 | } |
322 | ||
046c68c9 ER |
323 | # @param $module |
324 | find_module() { | |
325 | local mod depmod module=$1 | |
ac085800 | 326 | |
046c68c9 | 327 | depmod=$(find_depmod $module) || exit 1 |
fe280785 | 328 | for mod in $depmod; do |
7ffba534 | 329 | mod=${mod#/lib/modules/$kernel/} |
fe280785 ER |
330 | |
331 | # add each module only once | |
332 | local m have=0 | |
333 | for m in $MODULES; do | |
334 | [ $m = $mod ] && have=1 | |
335 | done | |
336 | if [ $have = 0 ]; then | |
c2eb7d4f | 337 | MODULES="$MODULES $mod" |
fe280785 | 338 | fi |
10c3df06 | 339 | done |
bb529f94 JK |
340 | } |
341 | ||
034fdd5d ER |
342 | # install a file to temporary mount image. |
343 | # it will operate recursively (copying directories) | |
344 | # and will symlink destinations if source is symlink. | |
bb529f94 | 345 | inst() { |
17e97aec | 346 | if [ $# -lt 2 ]; then |
a9ace64a | 347 | die 'Usage: inst <file> [<file>] <destination>' |
c31050f3 | 348 | fi |
17e97aec ER |
349 | |
350 | local src i=0 c=$(($# - 1)) | |
351 | while [ $i -lt $c ]; do | |
352 | src="$src $1" | |
353 | i=$((i + 1)) | |
354 | shift | |
355 | done | |
356 | local dest=$1 | |
357 | set -- $src | |
242f2358 PZ |
358 | parentDir=$(dirname $DESTDIR$dest) |
359 | [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir) | |
d8056591 | 360 | debug "+ cp $* $DESTDIR$dest" |
9b557a09 | 361 | cp -HR "$@" "$DESTDIR$dest" |
bb529f94 JK |
362 | } |
363 | ||
dab92b1d | 364 | inst_d() { |
17e97aec | 365 | if [ $# = 0 ]; then |
a9ace64a | 366 | die 'Usage: inst_d <destination> <destination>' |
034fdd5d ER |
367 | fi |
368 | for dir in "$@"; do | |
9b557a09 | 369 | install -d "$DESTDIR$dir" |
034fdd5d ER |
370 | done |
371 | } | |
372 | ||
209061e3 ER |
373 | # install executable and it's shared libraries |
374 | inst_exec() { | |
17e97aec | 375 | if [ $# -lt 2 ]; then |
3601c2fa | 376 | die "Invalid params ($@), Usage: inst_exec <file>[, <file>] <destination>" |
17e97aec | 377 | fi |
209061e3 ER |
378 | local src i=0 c=$(($# - 1)) |
379 | while [ $i -lt $c ]; do | |
380 | src="$src $1" | |
381 | i=$((i + 1)) | |
382 | shift | |
383 | done | |
9b532fe6 | 384 | local dest=$1 |
209061e3 ER |
385 | set -- $src |
386 | ||
9b532fe6 ER |
387 | inst "$@" $dest |
388 | ||
5265962d | 389 | local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u) |
9b532fe6 | 390 | for lib in $libs; do |
9b557a09 | 391 | if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then |
7efbe841 ER |
392 | inst_d /$_lib |
393 | inst_exec $lib /$_lib | |
17e97aec | 394 | fi |
209061e3 | 395 | done |
c7ade647 ER |
396 | |
397 | # hack for uclibc linked binaries requiring this fixed path | |
398 | # XXX: shouldn't rpath be used here instead so th | |
399 | if [ -f $DESTDIR/$_lib/libc.so.0 ]; then | |
400 | local lib=$DESTDIR/$_lib/libc.so.0 | |
401 | lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u) | |
402 | local libdir=$(cd $(dirname "$lib"); pwd) | |
403 | if [ ! -e $DESTDIR$libdir ]; then | |
404 | libdir=$(dirname "$libdir") | |
405 | inst_d $libdir | |
406 | debug "+ ln -s /$_lib $DESTDIR$libdir" | |
407 | ln -s /$_lib $DESTDIR$libdir | |
408 | fi | |
409 | fi | |
209061e3 ER |
410 | } |
411 | ||
82474db9 ER |
412 | # output modules.conf / modprobe.conf |
413 | modprobe_conf() { | |
414 | echo "$modprobe_conf_cache" | |
415 | } | |
416 | ||
417 | # | |
418 | # defaults to modprobe -c if not told otherwise, this means include statements | |
419 | # work from there. | |
420 | cache_modprobe_conf() { | |
707f5e60 | 421 | if [ "$kernel_version" -lt "002005" ]; then |
82474db9 ER |
422 | modulefile=/etc/modules.conf |
423 | if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then | |
424 | modulefile=/etc/conf.modules | |
425 | fi | |
426 | fi | |
427 | ||
428 | if [ -n "$modulefile" ]; then | |
d8056591 | 429 | debug "Using $modulefile for modules config" |
82474db9 ER |
430 | modprobe_conf_cache=$(cat $modulefile) |
431 | else | |
d8056591 | 432 | debug "Using modprobe -c to get modules config" |
520412e9 | 433 | modprobe_conf_cache=$(modprobe -c --set-version $kernel) |
82474db9 ER |
434 | fi |
435 | } | |
436 | ||
7c38b114 | 437 | find_modules_scsi() { |
c3667d07 | 438 | local n |
7c38b114 | 439 | for n in $PRESCSIMODS; do |
07b09cf9 | 440 | if [ "X$n" = "Xunknown" ]; then |
f5db170b | 441 | debug "Finding SCSI modules using scsi_hostadapter" |
60899da0 ER |
442 | local mod scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }') |
443 | for mod in $scsimodules; do | |
444 | # for now allow scsi modules to come from anywhere. There are some | |
445 | # RAID controllers with drivers in block | |
046c68c9 | 446 | find_module "$mod" |
60899da0 | 447 | done |
7c38b114 | 448 | else |
046c68c9 | 449 | find_module "$n" |
7c38b114 AF |
450 | fi |
451 | done | |
046c68c9 | 452 | find_module "-scsi_wait_scan" |
7c38b114 AF |
453 | } |
454 | ||
bc0d6f2d | 455 | # find modules for $devpath |
d8056591 | 456 | find_modules_for_devpath() { |
bc0d6f2d ER |
457 | local devpath="$1" |
458 | if [ -z "$devpath" ]; then | |
d8056591 | 459 | die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?" |
f6536797 | 460 | fi |
ac085800 | 461 | |
c2eb7d4f ER |
462 | if [[ "$devpath" = /dev/dm-* ]]; then |
463 | # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3 | |
bc0d6f2d | 464 | devpath=$(dm_longname "$devpath") |
c2eb7d4f ER |
465 | fi |
466 | ||
67aa84bd | 467 | if [ -L "$devpath" ] && ! is_lvm "$devpath"; then |
c2eb7d4f ER |
468 | # sanitize things like: |
469 | # /dev/block/104:2 -> /dev/cciss/c0d0p2 | |
470 | devpath=$(readlink -f "$devpath") | |
471 | fi | |
472 | ||
d8056591 | 473 | debug "Finding modules for device path $devpath" |
bc0d6f2d | 474 | |
3ef3d717 ER |
475 | if is_luks "$devpath"; then |
476 | find_modules_luks "$devpath" | |
477 | return | |
478 | fi | |
479 | ||
74d45ce1 ER |
480 | if is_nfs "$devpath"; then |
481 | find_modules_nfs "$devpath" | |
d9179777 ER |
482 | return |
483 | fi | |
484 | ||
e16414d9 | 485 | if is_md "$devpath"; then |
df738638 | 486 | find_modules_md "$devpath" |
d9179777 ER |
487 | return |
488 | fi | |
489 | ||
c3b54060 | 490 | if is_multipath "$devpath"; then |
07137fe3 | 491 | if find_modules_multipath "$devpath"; then |
9baf4f3f | 492 | return |
9baf4f3f | 493 | fi |
9baf4f3f ER |
494 | # fallback |
495 | fi | |
496 | ||
36523626 | 497 | if is_dmraid "$devpath"; then |
c083ae23 ER |
498 | if find_modules_dmraid "$devpath"; then |
499 | return | |
500 | fi | |
501 | # fallback | |
502 | fi | |
503 | ||
82474db9 | 504 | if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then |
7c38b114 | 505 | find_modules_scsi |
d9179777 ER |
506 | return |
507 | fi | |
508 | ||
30ca4815 | 509 | if is_ide "$devpath"; then |
bc0d6f2d | 510 | find_modules_ide "$devpath" |
d9179777 ER |
511 | return |
512 | fi | |
513 | ||
07b09cf9 | 514 | if [[ "$devpath" == /dev/rd/* ]]; then |
046c68c9 | 515 | find_module "DAC960" |
c3313cd6 | 516 | rootdev_add=/dev/rd/ |
d9179777 ER |
517 | return |
518 | fi | |
519 | ||
07b09cf9 | 520 | if [[ "$devpath" == /dev/ida/* ]]; then |
046c68c9 | 521 | find_module "cpqarray" |
c3313cd6 | 522 | rootdev_add=/dev/ida/ |
d9179777 ER |
523 | return |
524 | fi | |
525 | ||
08651ad1 | 526 | if [[ "$devpath" == /dev/cciss/* ]]; then |
046c68c9 | 527 | find_module "cciss" |
c3313cd6 | 528 | rootdev_add=/dev/cciss/ |
d9179777 ER |
529 | return |
530 | fi | |
531 | ||
07b09cf9 | 532 | if [[ "$devpath" == /dev/ataraid/* ]]; then |
ac085800 | 533 | find_modules_ide |
046c68c9 | 534 | find_module "ataraid" |
82474db9 | 535 | ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }') |
9ae446b9 | 536 | if [ -n "$ataraidmodules" ]; then |
7c38b114 | 537 | # FIXME: think about modules compiled in kernel |
82474db9 | 538 | die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again." |
7c38b114 AF |
539 | fi |
540 | for n in $ataraidmodules; do | |
046c68c9 | 541 | find_module "$n" |
7c38b114 | 542 | done |
c3313cd6 | 543 | rootdev_add=/dev/ataraid/ |
d9179777 ER |
544 | return |
545 | fi | |
546 | ||
7c38b114 | 547 | # check to see if we need to set up a loopback filesystem |
07b09cf9 | 548 | if [[ "$devpath" == /dev/loop* ]]; then |
00eaa938 | 549 | die "Sorry, root on loop device isn't supported." |
7c38b114 AF |
550 | # TODO: rewrite for bsp and make nfs ready |
551 | if [ ! -x /sbin/losetup ]; then | |
00eaa938 | 552 | die "losetup is missing" |
7c38b114 | 553 | fi |
bc0d6f2d | 554 | key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):" |
82474db9 | 555 | if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then |
42820142 | 556 | 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 |
557 | fi |
558 | ||
559 | line="`awk '/'$key'/ { print $0; }' $fstab`" | |
560 | loopDev="$(echo $line | awk '{print $3}')" | |
561 | loopFs="$(echo $line | awk '{print $4}')" | |
562 | loopFile="$(echo $line | awk '{print $5}')" | |
563 | ||
564 | BASICMODULES="$BASICMODULES -loop" | |
046c68c9 | 565 | find_module "-$loopFs" |
7c38b114 | 566 | BASICMODULES="$BASICMODULES -${loopFs}" |
d9179777 ER |
567 | return |
568 | fi | |
569 | ||
67aa84bd ER |
570 | if is_lvm "$devpath"; then |
571 | find_modules_lvm "$devpath" | |
d9179777 | 572 | return |
7c38b114 AF |
573 | fi |
574 | } | |
575 | ||
b64f015b | 576 | firmware_install_module() { |
c3667d07 | 577 | local module="$1" |
c6c6ce01 | 578 | local firmware_files="$2" |
9ed6e1db | 579 | |
94769f11 | 580 | debug "Adding Firmwares ($firmware_files) to initrd for module $module" |
9ed6e1db | 581 | # firmware not yet installed |
9b557a09 | 582 | if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then |
034fdd5d | 583 | inst_d /lib/firmware |
9b557a09 | 584 | cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh" |
9ed6e1db | 585 | #!/bin/sh -e |
8639f99a AM |
586 | echo 1 > /sys$DEVPATH/loading |
587 | cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data | |
588 | echo 0 > /sys$DEVPATH/loading | |
589 | exit 0 | |
9ed6e1db | 590 | EOF |
9b557a09 | 591 | chmod 755 "$DESTDIR/lib/firmware/firmware.sh" |
9ed6e1db AM |
592 | fi |
593 | ||
594 | for firmware in $firmware_files; do | |
4a60c01f | 595 | if [ ! -f "/lib/firmware/$firmware" ]; then |
4a60c01f | 596 | die "firmware file /lib/firmware/$firmware doesn't exist." |
4a60c01f | 597 | else |
486d26a5 | 598 | FIRMWAREDIR=${firmware%/*} |
4a9920e7 | 599 | [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR |
7fde1ea5 | 600 | inst /lib/firmware/$firmware /lib/firmware/$firmware |
4a60c01f | 601 | fi |
9ed6e1db AM |
602 | done |
603 | ||
b64f015b | 604 | mount_sys |
c6c6ce01 | 605 | echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc |
9ed6e1db AM |
606 | } |
607 | ||
2a5bcca9 | 608 | modules_install() { |
c3667d07 ER |
609 | local modules="$1" |
610 | local mod | |
2a5bcca9 AM |
611 | |
612 | for mod in $modules; do | |
fe280785 | 613 | MODULEDIR=${mod%/*} |
4a9920e7 | 614 | inst_d "/lib/modules/$kernel/$MODULEDIR" |
9b557a09 ER |
615 | cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod" |
616 | gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null | |
2a5bcca9 AM |
617 | done |
618 | } | |
619 | ||
620 | modules_add_linuxrc() { | |
fe280785 | 621 | local mod modpath |
ac085800 | 622 | |
fe280785 ER |
623 | for mod in "$@"; do |
624 | # module path without optional compression | |
625 | modpath=${mod%.gz} | |
626 | ||
627 | # name of the module | |
628 | module=${modpath##*/} | |
629 | module=${module%$modext} | |
630 | ||
631 | options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs) | |
ffa1b198 | 632 | |
fe280785 ER |
633 | generic_module=$(echo $module | tr - _) |
634 | sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP) | |
635 | firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE) | |
2a5bcca9 | 636 | |
ac085800 | 637 | if [ -n "$verbose" ]; then |
8a47b72c ER |
638 | s="" |
639 | if [ "$options" ]; then | |
640 | s="$s with options [$options]" | |
641 | fi | |
642 | if [ "$sleep_var" ]; then | |
643 | s="$s and $sleep_var usleep" | |
644 | fi | |
4a60c01f | 645 | debug "Loading module [$module]$s" |
ac085800 ER |
646 | fi |
647 | ||
9ed6e1db | 648 | if [ -n "$firmware_var" ]; then |
d814e616 | 649 | firmware_install_module "$module" "$firmware_var" |
4a60c01f AM |
650 | else |
651 | firmware_files=$(find_firmware "$module") | |
652 | if [ -n "$firmware_files" ]; then | |
653 | for file in $firmware_files; do | |
654 | firmware_install_module "$module" "$file" | |
655 | done | |
656 | fi | |
9ed6e1db | 657 | fi |
4a60c01f | 658 | |
18ece493 | 659 | echo "insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc |
fe280785 | 660 | if [ -n "$sleep_var" ]; then |
c6c6ce01 | 661 | echo "usleep $sleep_var" | add_linuxrc |
8e598759 | 662 | fi |
2a5bcca9 AM |
663 | done |
664 | } | |
665 | ||
82b2dba2 ER |
666 | # Generates /dev nodes based on /proc/partitions information. |
667 | # Needs /proc mounted. | |
668 | # Can be called multiple times. | |
669 | initrd_gen_devices() { | |
670 | if is_yes "$proc_partitions"; then | |
671 | return | |
672 | fi | |
673 | proc_partitions=yes | |
335cd101 | 674 | |
82b2dba2 ER |
675 | mount_dev |
676 | add_linuxrc <<-'EOF' | |
677 | : 'Making device nodes' | |
678 | cat /proc/partitions | ( | |
8d4aba01 | 679 | # ignore first two lines: header, empty line |
82b2dba2 | 680 | read b; read b |
2cc3ae8b | 681 | |
82b2dba2 ER |
682 | while read major minor blocks dev rest; do |
683 | node=/dev/$dev | |
684 | mkdir -p ${node%/*} | |
8d4aba01 | 685 | [ -e $node ] || mknod $node b $major $minor |
82b2dba2 ER |
686 | done |
687 | ) | |
688 | EOF | |
689 | } | |
bb529f94 | 690 | |
82b2dba2 | 691 | |
4828c787 | 692 | initrd_gen_setrootdev() { |
5a761721 | 693 | debug "Adding rootfs finding based on kernel cmdline root= option support." |
82b2dba2 | 694 | add_linuxrc <<-'EOF' |
dcdf6b49 ER |
695 | if [ "${ROOT##/dev/}" != "${ROOT}" ]; then |
696 | rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)" | |
82b2dba2 ER |
697 | if [ -n "$rootnr" ]; then |
698 | echo "$rootnr" > /proc/sys/kernel/real-root-dev | |
699 | fi | |
700 | fi | |
b64f015b | 701 | EOF |
1606e343 AM |
702 | } |
703 | ||
4671d086 ER |
704 | initrd_gen_initramfs_switchroot() { |
705 | inst_d /newroot | |
706 | if [ "$rootdev" = "/dev/nfs" ]; then | |
707 | echo "rootfs on NFS root=/dev/nfs" | |
708 | else | |
709 | [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev | |
710 | fi | |
5845b321 ER |
711 | |
712 | # parse 'root=xxx' kernel commandline | |
4671d086 ER |
713 | # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303 |
714 | add_linuxrc <<-'EOF' | |
715 | device=/dev/no_partition_found | |
716 | eval "$(busybox awk -v c="$ROOT" ' | |
717 | BEGIN { | |
718 | num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]"; | |
719 | num_pattern = "[0-9a-f]" num_pattern_short; | |
720 | dev_pattern = "[hms][a-z][a-z]([0-9])+"; | |
721 | partition = "no_partition_found"; | |
722 | min = -1; maj = -1; | |
723 | ||
724 | sub("^0x", "", c); | |
725 | if (c ~ "^" num_pattern_short "$") sub("^", "0", c); | |
726 | if (c ~ "^" num_pattern "$") { | |
727 | maj = sprintf("%s",substr(c,1,2)); | |
728 | min = sprintf("%s",substr(c,3)); | |
729 | } | |
730 | if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c); | |
731 | if (c ~ "^" dev_pattern "$") partition = c; | |
732 | } | |
733 | ||
734 | $4 ~ partition { maj = $1; min = $2; } | |
735 | $1 ~ maj && $2 ~ min { partition = $4; } | |
736 | ||
737 | END { | |
fa3a5452 ER |
738 | if (maj >= 0 && min >= 0) { |
739 | printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min); | |
740 | } | |
4671d086 ER |
741 | } |
742 | ' /proc/partitions)" | |
743 | if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then | |
744 | mknod $device b $maj $min | |
745 | fi | |
746 | EOF | |
747 | ||
748 | add_linuxrc <<-EOF | |
749 | rootdev=$rootdev | |
750 | rootfs=$rootFs | |
751 | EOF | |
752 | ||
753 | add_linuxrc <<-'EOF' | |
754 | if [ "$device" = '/dev/no_partition_found' ]; then | |
755 | device=$rootdev | |
756 | fi | |
757 | ||
758 | mount -t $rootfs -r $device /newroot | |
759 | init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')" | |
760 | if [ -z "$init" -o ! -x "/newroot$init" ]; then | |
761 | init=/sbin/init | |
762 | fi | |
763 | EOF | |
764 | ||
765 | umount_all | |
766 | busybox_applet switch_root | |
767 | add_linuxrc <<-'EOF' | |
768 | exec switch_root /newroot $init | |
769 | ||
770 | echo "Error! initramfs should not reach this place." | |
771 | echo "It probably means you've got old version of busybox, with broken" | |
772 | echo "initramfs support. Trying to boot anyway, but won't promise anything." | |
773 | ||
774 | exec chroot /newroot $init | |
775 | ||
776 | echo "Failed to chroot!" | |
777 | EOF | |
778 | # we need /init being real file, not symlink, otherwise the initramfs will | |
779 | # not be ran by pid 1 which is required for switch_root | |
780 | mv $DESTDIR/linuxrc $DESTDIR/init | |
781 | ln -s init $DESTDIR/linuxrc | |
782 | } | |
783 | ||
034056fd ER |
784 | # main() |
785 | if [ "$(id -u)" != 0 ]; then | |
786 | die "You need to be root to generate initrd" | |
787 | fi | |
788 | ||
82b2dba2 ER |
789 | if [ -r /etc/sysconfig/geninitrd ]; then |
790 | . /etc/sysconfig/geninitrd | |
791 | fi | |
2cc3ae8b | 792 | |
74d45ce1 | 793 | geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs |
c124d0cf | 794 | |
82b2dba2 ER |
795 | while [ $# -gt 0 ]; do |
796 | case $1 in | |
797 | --fstab=*) | |
798 | fstab=${1#--fstab=} | |
799 | ;; | |
800 | --fstab) | |
801 | fstab=$2 | |
802 | shift | |
803 | ;; | |
804 | --modules-conf=*) | |
805 | modulefile=${1#--modules-conf=} | |
806 | ;; | |
807 | --modules-conf) | |
808 | modulefile=$2 | |
809 | shift | |
810 | ;; | |
811 | --use-raidstart|--with-raidstart) | |
812 | USERAIDSTART=yes | |
813 | ;; | |
814 | --without-raidstart) | |
815 | USERAIDSTART=no | |
816 | ;; | |
82b2dba2 ER |
817 | --with-bootsplash) |
818 | BOOT_SPLASH=yes | |
819 | ;; | |
820 | --without-bootsplash) | |
821 | BOOT_SPLASH=no | |
822 | ;; | |
823 | --with-fbsplash) | |
824 | FB_SPLASH=yes | |
825 | ;; | |
826 | --without-fbsplash) | |
827 | FB_SPLASH=no | |
828 | ;; | |
6c69a2d4 ER |
829 | --with-fbcondecor) |
830 | FB_CON_DECOR=yes | |
831 | ;; | |
832 | --without-fbcondecor) | |
833 | FB_CON_DECOR=no | |
834 | ;; | |
82b2dba2 ER |
835 | --with-suspend) |
836 | USE_SUSPEND=yes | |
837 | ;; | |
838 | --without-suspend) | |
839 | USE_SUSPEND=no | |
840 | ;; | |
841 | --with-suspend2 | --with-tuxonice) | |
842 | USE_TUXONICE=yes | |
843 | ;; | |
844 | --without-suspend2 | --without-tuxonice) | |
845 | USE_TUXONICE=no | |
846 | ;; | |
80b1ed79 | 847 | --lvmversion=*) |
7308edee | 848 | LVMTOOLSVERSION=${1#--lvmversion=} |
82b2dba2 | 849 | ;; |
80b1ed79 | 850 | --lvmtoolsversion=*) |
851 | LVMTOOLSVERSION=${1#--lvmtoolsversion=} | |
852 | ;; | |
82b2dba2 ER |
853 | --lvmtoolsversion|--lvmversion) |
854 | LVMTOOLSVERSION=$2 | |
855 | shift | |
856 | ;; | |
857 | --without-udev) | |
858 | USE_UDEV=no | |
859 | ;; | |
860 | --with-udev) | |
861 | USE_UDEV=yes | |
862 | ;; | |
863 | --without-dmraid) | |
864 | USE_DMRAID=no | |
865 | ;; | |
866 | --without-multipath) | |
867 | USE_MULTPATH=no | |
868 | ;; | |
af075488 | 869 | --without-blkid) |
870 | USE_BLKID=no | |
289fbc9b | 871 | ;; |
3ef3d717 ER |
872 | --without-luks) |
873 | USE_LUKS=no | |
874 | ;; | |
82b2dba2 ER |
875 | --with=*) |
876 | BASICMODULES="$BASICMODULES ${1#--with=}" | |
877 | ;; | |
878 | --with) | |
879 | BASICMODULES="$BASICMODULES $2" | |
880 | shift | |
881 | ;; | |
882 | --version) | |
883 | echo "$PROGRAM: version $VERSION" | |
884 | exit 0 | |
885 | ;; | |
886 | -v) | |
887 | verbose=-v | |
888 | ;; | |
889 | --nocompress) | |
890 | COMPRESS=no | |
891 | ;; | |
892 | --ifneeded) | |
893 | ifneeded=1 | |
894 | ;; | |
895 | -f) | |
896 | force=1 | |
897 | ;; | |
898 | --preload=*) | |
899 | PREMODS="$PREMODS ${1#--preload=}" | |
900 | ;; | |
901 | --preload) | |
902 | PREMODS="$PREMODS $2" | |
903 | shift | |
904 | ;; | |
905 | --fs=*) | |
bbbc32d0 | 906 | die "--fs option is obsoleted. Use --initrdfs instead" |
82b2dba2 ER |
907 | INITRDFS=${1#--fs=} |
908 | ;; | |
909 | --fs) | |
bbbc32d0 | 910 | die "--fs option is obsoleted. Use --initrdfs instead" |
82b2dba2 ER |
911 | INITRDFS=$2 |
912 | shift | |
913 | ;; | |
914 | --initrdfs=*) | |
915 | INITRDFS=${1#--initrdfs=} | |
916 | ;; | |
917 | --initrdfs) | |
918 | INITRDFS=$2 | |
919 | shift | |
920 | ;; | |
921 | --image-version) | |
922 | img_vers=yes | |
923 | ;; | |
924 | --ide-only-root) | |
925 | ide_only_root="yes" | |
926 | ;; | |
927 | *) | |
928 | if [ -z "$target" ]; then | |
929 | target="$1" | |
930 | elif [ -z "$kernel" ]; then | |
931 | kernel="$1" | |
932 | else | |
36523626 ER |
933 | usage >&2 |
934 | exit 1 | |
82b2dba2 ER |
935 | fi |
936 | ;; | |
937 | esac | |
f5db170b | 938 | |
82b2dba2 ER |
939 | shift |
940 | done | |
941 | ||
942 | if [ -z "$target" -o -z "$kernel" ]; then | |
36523626 ER |
943 | usage >&2 |
944 | exit 1 | |
82b2dba2 ER |
945 | fi |
946 | ||
c124d0cf ER |
947 | if [ -d /usr/lib64 ]; then |
948 | _lib=lib64 | |
949 | else | |
950 | _lib=lib | |
130aadc1 ER |
951 | fi |
952 | ||
c124d0cf | 953 | initrd_dir=/usr/$_lib/initrd |
707f5e60 ER |
954 | kernel_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}') |
955 | kernel_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}') | |
82b2dba2 | 956 | |
c124d0cf ER |
957 | debug "# $RCSID" |
958 | debug "Using _lib: $_lib" | |
959 | debug "Using initrd_dir: $initrd_dir" | |
960 | ||
961 | busybox=$(find_tool $initrd_dir/initrd-busybox /bin/initrd-busybox) || die "Couldn't find busybox suitable for initrd" | |
962 | ||
963 | # we setup mods after parsing command line args | |
964 | geninitrd_setup_mods | |
965 | ||
966 | if [ ! -f /boot/vmlinuz-"$kernel" ]; then | |
967 | warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?" | |
968 | fi | |
969 | ||
82b2dba2 | 970 | if [ -z "$INITRDFS" ]; then |
bbbc32d0 ER |
971 | if [ -n "$FS" ]; then |
972 | # FS= can came only via /etc/sysconfig/geninitrd likely? | |
973 | die "FS configuration option is obsoleted. Use INITRDFS instead" | |
f5db170b | 974 | fi |
f5db170b | 975 | |
bbbc32d0 ER |
976 | # default value |
977 | if [ "$kernel_version" -ge "002005" ]; then | |
978 | INITRDFS="initramfs" | |
979 | else | |
980 | INITRDFS="rom" | |
981 | fi | |
82b2dba2 | 982 | fi |
966c32cc | 983 | |
82b2dba2 | 984 | case "$INITRDFS" in |
4877276e ER |
985 | ext2) |
986 | [ -x /sbin/mke2fs ] || die "/sbin/mke2fs is missing" | |
987 | ;; | |
988 | rom|romfs) | |
989 | [ -x /sbin/genromfs ] || die "/sbin/genromfs is missing" | |
990 | ;; | |
991 | cram|cramfs) | |
992 | [ -x /sbin/mkcramfs ] || die "/sbin/mkcramfs is missing" | |
993 | ;; | |
994 | initramfs) | |
995 | [ -x /bin/cpio ] || die "/bin/cpio is missing" | |
996 | [ -x /usr/bin/find ] || die "/usr/bin/find is missing" | |
997 | ;; | |
998 | *) | |
999 | die "Filesystem $INITRDFS on initrd is not supported" | |
1000 | ;; | |
82b2dba2 | 1001 | esac |
f5db170b | 1002 | |
9323ada3 | 1003 | if [ -L "$target" ]; then |
1004 | target=$(readlink -f "$target") | |
1005 | fi | |
1006 | ||
82b2dba2 ER |
1007 | if [ -n "$img_vers" ]; then |
1008 | target="$target-$kernel" | |
1009 | fi | |
8bd582f1 | 1010 | |
82b2dba2 ER |
1011 | if [ -z "$force" -a -f "$target" ]; then |
1012 | die "$target already exists." | |
1013 | fi | |
c6c6ce01 | 1014 | |
82b2dba2 ER |
1015 | if [ ! -d "/lib/modules/$kernel" ]; then |
1016 | die "/lib/modules/$kernel is not a directory." | |
1017 | fi | |
2ffb1734 | 1018 | |
bbbc32d0 ER |
1019 | if [ ! -f /proc/mounts ]; then |
1020 | warn "/proc filesystem not mounted, may cause wrong results or failure." | |
1021 | fi | |
1022 | ||
1023 | if [ "$kernel_version" -ge "002005" ]; then | |
1024 | modext=".ko" | |
1025 | fi | |
1026 | ||
82b2dba2 ER |
1027 | cache_modprobe_conf |
1028 | ||
1029 | for n in $PREMODS; do | |
046c68c9 | 1030 | find_module "$n" |
82b2dba2 ER |
1031 | done |
1032 | ||
ed30e3a8 | 1033 | if [ "$FBMODULE" ]; then |
046c68c9 | 1034 | find_module "$FBMODULE" |
ed30e3a8 ER |
1035 | fi |
1036 | ||
82b2dba2 ER |
1037 | # allow forcing loading SCSI and/or IDE modules |
1038 | if is_yes "$ADDSCSI"; then | |
1039 | find_modules_scsi | |
1040 | fi | |
1041 | ||
1042 | if is_yes "$ADDIDE"; then | |
1043 | find_modules_ide | |
1044 | fi | |
1045 | ||
4c16dac4 ER |
1046 | if is_yes "$USE_SUSPEND"; then |
1047 | find_modules_suspend | |
1048 | fi | |
1049 | ||
82b2dba2 ER |
1050 | find_root "$fstab" || exit |
1051 | debug "Using $rootdev as device for rootfs" | |
1052 | ||
d8056591 | 1053 | find_modules_for_devpath "$rootdev" |
ac085800 | 1054 | |
046c68c9 | 1055 | find_module "-$rootFs" |
ac085800 | 1056 | |
82b2dba2 | 1057 | for n in $BASICMODULES; do |
046c68c9 | 1058 | find_module "$n" |
82b2dba2 | 1059 | done |
4e9eb79c | 1060 | |
82b2dba2 | 1061 | if is_yes "$USE_TUXONICE"; then |
046c68c9 | 1062 | find_module "-lzf" |
82b2dba2 | 1063 | fi |
33d24e12 | 1064 | |
bf6d9c64 | 1065 | find_modules_fbsplash |
2968c9dd | 1066 | |
82b2dba2 ER |
1067 | if [ -n "$ifneeded" -a -z "$MODULES" ]; then |
1068 | debug "No modules are needed -- not building initrd image." | |
1069 | exit 0 | |
1070 | fi | |
c6c6ce01 | 1071 | |
d8056591 | 1072 | DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed" |
9b557a09 | 1073 | RCFILE="$DESTDIR/linuxrc" |
82b2dba2 ER |
1074 | > "$RCFILE" |
1075 | chmod a+rx "$RCFILE" | |
9b557a09 | 1076 | ln -s linuxrc $DESTDIR/init |
e8d178ff | 1077 | |
82b2dba2 ER |
1078 | # create dirs that we really need |
1079 | inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys} | |
e8d178ff | 1080 | |
82b2dba2 | 1081 | modules_install "$MODULES" |
b64f015b | 1082 | |
82b2dba2 ER |
1083 | # mknod'ing the devices instead of copying them works both with and |
1084 | # without devfs... | |
9b557a09 ER |
1085 | mknod "$DESTDIR/dev/console" c 5 1 |
1086 | mknod "$DESTDIR/dev/null" c 1 3 | |
1087 | mknod "$DESTDIR/dev/zero" c 1 5 | |
be2f3ecc | 1088 | |
684d5d2a | 1089 | inst_exec $busybox /bin/initrd-busybox |
9b557a09 | 1090 | ln -s initrd-busybox $DESTDIR/bin/sh |
684d5d2a ER |
1091 | # for older busyboxes who had /bin/busybox as EXEPATH |
1092 | ln -s initrd-busybox $DESTDIR/bin/busybox | |
2ffb1734 | 1093 | |
82b2dba2 ER |
1094 | add_linuxrc <<EOF |
1095 | #!/bin/sh | |
1096 | # initrd generated by: | |
1097 | # $RCSID | |
c6c6ce01 | 1098 | |
82b2dba2 ER |
1099 | EOF |
1100 | mount_proc | |
1101 | add_linuxrc <<-'EOF' | |
3a1d3d88 | 1102 | read CMDLINE < /proc/cmdline; export CMDLINE |
c6c6ce01 | 1103 | |
82b2dba2 ER |
1104 | for arg in $CMDLINE; do |
1105 | if [ "${arg}" = "debuginitrd" ]; then | |
1106 | DEBUGINITRD=yes | |
1107 | fi | |
1108 | if [ "${arg##debuginitrd=}" != "${arg}" ]; then | |
1109 | DEBUGINITRD=${arg##debuginitrd=} | |
1110 | fi | |
fc787d45 | 1111 | if [ "${arg##root=}" != "${arg}" ]; then |
1112 | ROOT=${arg##root=} | |
1113 | fi | |
82b2dba2 | 1114 | done |
c6c6ce01 | 1115 | |
82b2dba2 ER |
1116 | # make debugshell() invoke subshell if $DEBUGINITRD=sh |
1117 | if [ "$DEBUGINITRD" = "sh" ]; then | |
1118 | debugshell() { | |
e2405b29 AM |
1119 | EOF |
1120 | if is_yes "$RUN_SULOGIN_ON_ERR"; then | |
1121 | add_linuxrc <<-'EOF' | |
1122 | echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting" | |
1123 | EOF | |
1124 | else | |
1125 | add_linuxrc <<-'EOF' | |
1126 | sh | |
1127 | EOF | |
1128 | fi | |
1129 | add_linuxrc <<-'EOF' | |
82b2dba2 ER |
1130 | } |
1131 | else | |
1132 | debugshell() { | |
1133 | : | |
1134 | } | |
1135 | fi | |
e934d044 | 1136 | |
82b2dba2 ER |
1137 | if [ "$DEBUGINITRD" ]; then |
1138 | set -x | |
cff3058d | 1139 | fi |
82b2dba2 | 1140 | EOF |
2df2e995 | 1141 | |
fe280785 | 1142 | modules_add_linuxrc $MODULES |
82b2dba2 ER |
1143 | |
1144 | # TODO: rewrite for busybox | |
1145 | #if [ -n "$loopDev" ]; then | |
1146 | # if [ ! -d /initrd ]; then | |
1147 | # mkdir /initrd | |
1148 | # fi | |
1149 | # | |
9b557a09 ER |
1150 | # cp -a "$loopDev" "$DESTDIR/dev" |
1151 | # cp -a "$rootdev" "$DESTDIR/dev" | |
82b2dba2 ER |
1152 | # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE" |
1153 | # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE" | |
1154 | # echo "echo Setting up loopback device $rootdev" >> $RCFILE | |
1155 | # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE" | |
1156 | #fi | |
2b1a3707 | 1157 | |
1606e343 AM |
1158 | if is_yes "$USE_UDEV"; then |
1159 | initrd_gen_udev | |
1160 | fi | |
1161 | ||
1cd2aabd ER |
1162 | if is_yes "$USE_TUXONICE"; then |
1163 | initrd_gen_tuxonice | |
2df2e995 AM |
1164 | fi |
1165 | ||
3dd50160 ER |
1166 | find_modules_uvesafb |
1167 | initrd_gen_uvesafb | |
43258faf | 1168 | |
3ef3d717 ER |
1169 | if is_yes "$have_luks"; then |
1170 | initrd_gen_luks | |
1171 | fi | |
1172 | ||
cc8e8a99 | 1173 | if is_yes "$have_dmraid"; then |
882472ae ER |
1174 | initrd_gen_dmraid |
1175 | fi | |
1176 | ||
c083ae23 | 1177 | if is_yes "$have_multipath"; then |
2cc3ae8b ER |
1178 | initrd_gen_multipath |
1179 | fi | |
1180 | ||
cc8e8a99 | 1181 | if is_yes "$USE_BLKID"; then |
289fbc9b | 1182 | initrd_gen_blkid |
1183 | fi | |
1184 | ||
69b1e935 | 1185 | if is_yes "$have_nfs"; then |
2df2e995 | 1186 | initrd_gen_nfs |
df738638 ER |
1187 | elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then |
1188 | initrd_gen_md | |
69b1e935 | 1189 | if is_yes "$have_lvm"; then |
2df2e995 | 1190 | initrd_gen_lvm |
bfea009a | 1191 | else |
4828c787 | 1192 | initrd_gen_setrootdev |
2df2e995 | 1193 | fi |
69b1e935 | 1194 | elif is_yes "$have_lvm"; then |
2df2e995 | 1195 | initrd_gen_lvm |
2b1a3707 | 1196 | else |
4828c787 | 1197 | initrd_gen_setrootdev |
7c38b114 AF |
1198 | fi |
1199 | ||
4c16dac4 ER |
1200 | if is_yes "$USE_SUSPEND"; then |
1201 | initrd_gen_suspend | |
1202 | fi | |
1203 | ||
5101a385 | 1204 | # additional devs always needed |
9b557a09 | 1205 | [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev |
5101a385 | 1206 | |
82de999f ER |
1207 | if is_yes "$USE_UDEV"; then |
1208 | initrd_gen_stop_udevd | |
1209 | fi | |
1210 | ||
f8f9e56d | 1211 | if [ "$INITRDFS" = "initramfs" ]; then |
4671d086 | 1212 | initrd_gen_initramfs_switchroot |
b64f015b | 1213 | else |
b64f015b | 1214 | umount_all |
f8f9e56d AM |
1215 | fi |
1216 | ||
b7feffb3 ER |
1217 | if is_yes "$FB_SPLASH"; then |
1218 | initrd_gen_fbsplash | |
1219 | fi | |
1220 | ||
6c69a2d4 ER |
1221 | if is_yes "$FB_CON_DECOR"; then |
1222 | initrd_gen_fbcondecor | |
1223 | fi | |
1224 | ||
d8056591 | 1225 | IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed" |
51dc1fe6 AM |
1226 | |
1227 | debug "Creating $INITRDFS image $IMAGE" | |
2ad94d8a | 1228 | case "$INITRDFS" in |
4877276e ER |
1229 | ext2) |
1230 | IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}') | |
1231 | debug "ext2 image size: $IMAGESIZE ($DESTDIR)" | |
1232 | if [ "$IMAGESIZE" -gt 4096 ]; then | |
1233 | warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!" | |
1234 | fi | |
d8056591 | 1235 | |
4877276e ER |
1236 | dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null |
1237 | mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2 | |
1238 | tune2fs -i 0 "$IMAGE" >/dev/null 2>&1 | |
1239 | ||
1240 | local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX) | |
1241 | debug "Mounting ext2 image $IMAGE to $tmpmnt" | |
1242 | mount -o loop -t ext2 "$IMAGE" "$tmpmnt" | |
1243 | # We don't need this directory, so let's save space | |
1244 | rm -rf "$tmpmnt"/lost+found | |
1245 | ||
1246 | debug "Copy recursively $DESTDIR -> $tmpmnt" | |
1247 | cp -a $DESTDIR/* $tmpmnt | |
1248 | umount "$IMAGE" | |
1249 | rmdir "$tmpmnt" | |
1250 | ||
1251 | ;; | |
1252 | rom|romfs) | |
1253 | genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel" | |
1254 | IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}') | |
1255 | debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)" | |
1256 | if [ "$IMAGESIZE" -gt 4096 ]; then | |
1257 | warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!" | |
1258 | fi | |
1259 | ;; | |
1260 | cram|cramfs) | |
1261 | mkcramfs "$DESTDIR" "$IMAGE" | |
1262 | ;; | |
1263 | initramfs) | |
1264 | (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE") | |
1265 | ;; | |
1266 | *) | |
1267 | echo "Filesystem $INITRDFS not supported by $PROGRAM"; | |
c31050f3 | 1268 | esac |
bb529f94 | 1269 | |
82474db9 | 1270 | if is_yes "$COMPRESS"; then |
aecfd33d | 1271 | tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed" |
d8056591 ER |
1272 | debug "Compressing $target" |
1273 | gzip -9 < "$IMAGE" > "$tmp" | |
1274 | mv -f "$tmp" "$target" | |
bb529f94 | 1275 | else |
7d2fc5eb | 1276 | cp -a "$IMAGE" "$target" |
bb529f94 | 1277 | fi |
5b71959c | 1278 | |
edd9c362 ER |
1279 | size=$(stat -c %s $target | awk '{print int((($1/1024)+1023)/1024)*1024}') |
1280 | debug "Minimum RAM size that could be used for $target is: ramdisk_size=$size" | |
1281 | ||
7992356a | 1282 | # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image. |
5b71959c | 1283 | if is_yes "$BOOT_SPLASH"; then |
f5db170b | 1284 | initrd_gen_bootsplash "$target" |
5b71959c AM |
1285 | fi |
1286 | ||
d8056591 | 1287 | rm -rf "$DESTDIR" "$IMAGE" |
ac085800 ER |
1288 | |
1289 | # vim:ts=4:sw=4:noet:fdm=marker |