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