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