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