]> git.pld-linux.org Git - projects/geninitrd.git/blob - geninitrd
filter out comments in modprobe_conf_cache rather in some places of code to get 100...
[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
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                 if [ "$obj" != "/lib/ld-linux.so.2" ] && [ "$obj" != "/lib64/ld-linux-x86-64.so.2" ]; then
438                         libs=$(ldd "$obj" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
439                 fi
440         done
441         for lib in $libs; do
442                 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
443                         inst_d /$_lib
444                         inst_exec $lib /$_lib
445                 fi
446         done
447
448         # hack for uclibc linked binaries requiring this fixed path
449         # XXX: shouldn't rpath be used here instead so th
450         if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
451                 local lib=$DESTDIR/$_lib/libc.so.0
452                 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
453                 local libdir=$(cd $(dirname "$lib"); pwd)
454                 if [ ! -e $DESTDIR$libdir ]; then
455                         libdir=$(dirname "$libdir")
456                         inst_d $libdir
457                         debug "+ ln -s /$_lib $DESTDIR$libdir"
458                         ln -s /$_lib $DESTDIR$libdir
459                 fi
460         fi
461 }
462
463 # output modules.conf / modprobe.conf
464 modprobe_conf() {
465         echo "$modprobe_conf_cache"
466 }
467
468 #
469 # defaults to modprobe -c if not told otherwise, this means include statements
470 # work from there.
471 cache_modprobe_conf() {
472         if [ "$kernel_version" -lt "002005" ]; then
473                 modulefile=/etc/modules.conf
474                 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
475                         modulefile=/etc/conf.modules
476                 fi
477         fi
478
479         if [ -n "$modulefile" ]; then
480                 debug "Using $modulefile for modules config"
481                 modprobe_conf_cache=$(cat $modulefile | awk '!/^[\t ]*#/ { print }')
482
483         else
484                 debug "Using modprobe -c to get modules config"
485                 modprobe_conf_cache=$(modprobe -c --set-version $kernel | awk '!/^[\t ]*#/ { print }')
486         fi
487 }
488
489 # find modules for $devpath
490 find_modules_for_devpath() {
491         local devpath="$1"
492         if [ -z "$devpath" ]; then
493                 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
494         fi
495
496         if [[ "$devpath" = /dev/dm-* ]]; then
497                 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
498                 devpath=$(dm_node "$devpath")
499         fi
500
501         if [ -L "$devpath" ] && ! is_lvm "$devpath" && ! is_luks "$devpath"; then
502                 # sanitize things like:
503                 # /dev/block/104:2 -> /dev/cciss/c0d0p2
504                 devpath=$(readlink -f "$devpath")
505         fi
506
507         debug "Finding modules for device path $devpath"
508
509         if is_luks "$devpath"; then
510                 find_modules_luks "$devpath"
511                 return
512         fi
513
514         if is_nfs "$devpath"; then
515                 find_modules_nfs "$devpath"
516                 return
517         fi
518
519         if is_md "$devpath"; then
520                 find_modules_md "$devpath"
521                 return
522         fi
523
524         if is_multipath "$devpath"; then
525                 if find_modules_multipath "$devpath"; then
526                         return
527                 fi
528
529                 # fallback
530         fi
531
532         if is_dmraid "$devpath"; then
533                 if find_modules_dmraid "$devpath"; then
534                         return
535                 fi
536                 # fallback
537         fi
538
539         if is_scsi "$devpath"; then
540                 find_modules_scsi "$devpath"
541                 return
542         fi
543
544         if is_ide "$devpath"; then
545                 find_modules_ide "$devpath"
546                 return
547         fi
548
549         if [[ "$devpath" == /dev/rd/* ]]; then
550                 find_module "DAC960"
551                 rootdev_add=/dev/rd/
552                 return
553         fi
554
555         if [[ "$devpath" == /dev/ida/* ]]; then
556                 find_module "cpqarray"
557                 rootdev_add=/dev/ida/
558                 return
559         fi
560
561         if [[ "$devpath" == /dev/cciss/* ]]; then
562                 find_module "cciss"
563                 rootdev_add=/dev/cciss/
564                 return
565         fi
566
567         if [[ "$devpath" == /dev/ataraid/* ]]; then
568                 find_modules_ide
569                 find_module "ataraid"
570                 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ { print $3 }')
571                 if [ -n "$ataraidmodules" ]; then
572                         # FIXME: think about modules compiled in kernel
573                         die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
574                 fi
575                 for n in $ataraidmodules; do
576                         find_module "$n"
577                 done
578                 rootdev_add=/dev/ataraid/
579                 return
580         fi
581
582         # check to see if we need to set up a loopback filesystem
583         if [[ "$devpath" == /dev/loop*  ]]; then
584                 die "Sorry, root on loop device isn't supported."
585                 # TODO: rewrite for bsp and make nfs ready
586                 if [ ! -x /sbin/losetup ]; then
587                         die "losetup is missing"
588                 fi
589                 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
590                 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
591                         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"
592                 fi
593
594                 line="`awk '/'$key'/ { print $0; }' $fstab`"
595                 loopDev="$(echo $line | awk '{print $3}')"
596                 loopFs="$(echo $line | awk '{print $4}')"
597                 loopFile="$(echo $line | awk '{print $5}')"
598
599                 BASICMODULES="$BASICMODULES -loop"
600                 find_module "-$loopFs"
601                 BASICMODULES="$BASICMODULES -${loopFs}"
602                 return
603         fi
604
605         if is_lvm "$devpath"; then
606                 find_modules_lvm "$devpath"
607                 return
608         fi
609 }
610
611 firmware_install_module() {
612         local module="$1"
613         local firmware_files="$2"
614
615         debug "Adding Firmwares ($firmware_files) to initrd for module $module"
616         # firmware not yet installed
617         if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
618                 inst_d /lib/firmware
619 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
620 #!/bin/sh -e
621 echo 1 > /sys$DEVPATH/loading
622 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
623 echo 0 > /sys$DEVPATH/loading
624 exit 0
625 EOF
626                 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
627         fi
628
629         for firmware in $firmware_files; do
630                 if [ -f "/lib/firmware/$kernel/$firmware" ]; then
631                         FIRMWAREDIR=${firmware%/*}
632                         [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
633                         inst /lib/firmware/$kernel/$firmware /lib/firmware/$firmware
634                 elif [ -f "/lib/firmware/$firmware" ]; then
635                         FIRMWAREDIR=${firmware%/*}
636                         [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
637                         inst /lib/firmware/$firmware /lib/firmware/$firmware
638                 else
639                         warn "Possible missing firmware file /lib/firmware/$firmware or /lib/firmware/$kernel/$firmware for module $module."
640                 fi
641         done
642
643         mount_sys
644         echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
645 }
646
647 modules_install() {
648         local modules="$1"
649         local mod
650
651         for mod in $modules; do
652                 MODULEDIR=${mod%/*}
653                 inst_d "/lib/modules/$kernel/$MODULEDIR"
654                 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
655                 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
656                 if [ "$STRIP" ] && [ -x "$STRIP" ]; then
657                         $STRIP -g --remove-section=.comment "$DESTDIR/lib/modules/$kernel/${mod%.gz}"
658                 fi
659         done
660 }
661
662 modules_add_linuxrc() {
663         local mod modpath
664
665         for mod in "$@"; do
666                 # module path without optional compression
667                 modpath=${mod%.gz}
668
669                 # name of the module
670                 local module=${modpath##*/}; module=${module%$modext}
671                 local options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
672                 local genericname=$(echo $module | tr - _)
673                 local usleep=$(eval echo \$MODULE_${genericname}_USLEEP)
674                 local firmware=$(eval echo \$MODULE_${genericname}_FIRMWARE)
675
676                 if [ "$module" = "scsi_mod" -a "$kernel_version_long" -ge "002006030" ]; then
677                         options="scan=sync $options"
678                 fi
679
680                 if [ -n "$verbose" ]; then
681                         s=""
682                         if [ "$options" ]; then
683                                 s="$s with options [$options]"
684                         fi
685                         if [ "$usleep" ]; then
686                                 s="$s and $usleep usleep"
687                         fi
688                         debug "Loading module [$module]$s"
689                 fi
690
691                 if [ -n "$firmware" ]; then
692                         firmware_install_module "$module" "$firmware"
693                 else
694                         for file in $(find_firmware "$module"); do
695                                 firmware_install_module "$module" "$file"
696                         done
697                 fi
698
699                 echo "insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
700                 if [ -n "$usleep" ]; then
701                         echo "usleep $usleep" | add_linuxrc
702                 fi
703                 if [ "$module" = "scsi_wait_scan" ]; then
704                         if [ "$(busybox_applet rmmod 2>/dev/null; echo $?)" = 0 ]; then
705                                 echo "rmmod scsi_wait_scan" | add_linuxrc
706                         fi
707                 fi
708
709         done
710 }
711
712 # Generates /dev nodes based on /proc/partitions information.
713 # Needs /proc mounted.
714 # Can be called multiple times.
715 initrd_gen_devices() {
716         if is_yes "$proc_partitions"; then
717                 return
718         fi
719         proc_partitions=yes
720
721         mount_dev
722         add_linuxrc <<-'EOF'
723                 : 'Making device nodes'
724                 cat /proc/partitions | (
725                         # ignore first two lines: header, empty line
726                         read b; read b
727
728                         while read major minor blocks dev rest; do
729                                 node=/dev/$dev
730                                 mkdir -p ${node%/*}
731                                 [ -e $node ] || mknod $node b $major $minor
732                         done
733                 )
734         EOF
735 }
736
737
738 initrd_gen_setrootdev() {
739         debug "Adding rootfs finding based on kernel cmdline root= option support."
740         busybox_applet ls
741         add_linuxrc <<-'EOF'
742                 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
743                         rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
744                         # fallback to ls
745                         if [ -z "$rootnr" ]; then
746                                 rootnr="$(busybox ls -lL ${ROOT} | busybox awk '{if (/^b/) { print 256 * $3 + $4; }}')"
747                         fi
748                         if [ -n "$rootnr" ]; then
749                                 echo "$rootnr" > /proc/sys/kernel/real-root-dev
750                         fi
751                 fi
752         EOF
753 }
754
755 initrd_gen_initramfs_switchroot() {
756         inst_d /newroot
757         if [ "$rootdev" = "/dev/nfs" ]; then
758                 echo "rootfs on NFS root=/dev/nfs"
759         else
760                 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
761         fi
762
763         # parse 'root=xxx' kernel commandline
764         # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
765         add_linuxrc <<-'EOF'
766                 device=/dev/no_partition_found
767                 eval "$(busybox awk -v c="$ROOT" '
768                         BEGIN {
769                                 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
770                                 num_pattern = "[0-9a-f]" num_pattern_short;
771                                 dev_pattern = "[hms][a-z][a-z]([0-9])+";
772                                 partition = "no_partition_found";
773                                 min = -1; maj = -1;
774
775                                 sub("^0x", "", c);
776                                 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
777                                 if (c ~ "^" num_pattern  "$") {
778                                         maj = sprintf("%s",substr(c,1,2));
779                                         min = sprintf("%s",substr(c,3));
780                                 }
781                                 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
782                                 if (c ~ "^" dev_pattern "$") partition = c;
783                         }
784
785                         $4 ~ partition { maj = $1; min = $2; }
786                         $1 ~ maj && $2 ~ min { partition = $4; }
787
788                         END {
789                                 if (maj >= 0 && min >= 0) {
790                                         printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
791                                 }
792                         }
793                         ' /proc/partitions)"
794                 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
795                         mknod $device b $maj $min
796                 fi
797         EOF
798
799         add_linuxrc <<-EOF
800                 rootdev=$rootdev
801                 rootfs=$rootFs
802         EOF
803
804         add_linuxrc <<-'EOF'
805                 if [ "$device" = '/dev/no_partition_found' ]; then
806                         device=$rootdev
807                 fi
808
809                 [ -n "$ROOTFSFLAGS" ] && ROOTFSFLAGS="-o $ROOTFSFLAGS"
810
811                 mount -t $rootfs -r $device $ROOTFSFLAGS /newroot || echo "Mount of rootfs failed."
812                 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
813                 if [ -z "$init" -o ! -x "/newroot$init" ]; then
814                         init=/sbin/init
815                 fi
816         EOF
817
818         umount_all
819         busybox_applet switch_root
820         add_linuxrc <<-'EOF'
821                 exec switch_root /newroot $init ${1:+"$@"}
822
823                 echo "Error! initramfs should not reach this place."
824                 echo "It probably means you've got old version of busybox, with broken"
825                 echo "initramfs support. Trying to boot anyway, but won't promise anything."
826
827                 exec chroot /newroot $init ${1:+"$@"}
828
829                 echo "Failed to chroot!"
830                 debugshell
831         EOF
832         # we need /init being real file, not symlink, otherwise the initramfs will
833         # not be ran by pid 1 which is required for switch_root
834         mv $DESTDIR/linuxrc $DESTDIR/init
835         ln -s init $DESTDIR/linuxrc
836 }
837
838 # find if $symbol exists in System.map $mapfile
839 sym_exists() {
840         local mapfile="$1"
841         local symbol="$2"
842         if [ ! -f $mapfile ]; then
843                 # missing mapfile (not a pld kernel?)
844                 return 1
845         fi
846
847         awk -vc=1 -vsymbol="$symbol" '$2 == "T" && $3 == symbol {c = 0} END {exit c}' $mapfile
848 }
849
850 # find best compressor (or forced one) for initrd
851 find_compressor() {
852         local mode="$1"
853         # fastest initrd decompression speed is first
854         local compressors='lzo gzip xz lzma bzip2'
855
856         # a specified one, take it
857         if ! is_yes "$mode"; then
858                 compressors="$mode"
859         fi
860
861         debug "finding compressor: $compressors (via $mode)"
862         # check for compressor validity
863         local c prog map=/boot/System.map-$kernel
864         for c in $compressors; do
865                 case $c in
866                 xz)
867                         sym=unxz
868                         prog=/usr/bin/xz
869                         ;;
870                 lzma)
871                         sym=unlzma
872                         prog=/usr/bin/xz
873                         ;;
874                 bzip2)
875                         sym=bzip2
876                         prog=/usr/bin/bzip2
877                         ;;
878                 gzip)
879                         sym=gunzip
880                         prog=/bin/gzip
881                         ;;
882                 lzo)
883                         sym=unlzo
884                         prog=/usr/bin/lzop
885                         ;;
886                 none|no)
887                         # any existing sym will work
888                         sym=initrd_load
889                         prog=/bin/cat
890                         ;;
891                 *)
892                         die "Unknown compressor $c"
893                         ;;
894                 esac
895                 if sym_exists $map $sym && [ -x $prog ]; then
896                         echo $c
897                         return
898                 fi
899         done
900
901         debug "using gzip for compressor (fallback)"
902         echo gzip
903 }
904
905 # compresses kernel image image
906 # in function so we could retry with other compressor on failure
907 compress_image() {
908         local compressor="$1" IMAGE="$2" target="$3" tmp
909         tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
910
911         case "$compressor" in
912         xz)
913                 # don't use -9 here since kernel won't understand it
914                 xz --format=xz --check=crc32 --lzma2=preset=6e,dict=1MiB < "$IMAGE" > "$tmp" || return $?
915                 ;;
916         lzma)
917                 xz --format=lzma -9 < "$IMAGE" > "$tmp" || return $?
918                 ;;
919         bzip2)
920                 bzip2 -9 < "$IMAGE" > "$tmp" || return $?
921                 ;;
922         gzip)
923                 gzip -9 < "$IMAGE" > "$tmp" || return $?
924                 ;;
925         lzo)
926                 lzop -9 < "$IMAGE" > "$tmp" || return $?
927                 ;;
928         none|no)
929                 cat < "$IMAGE" > "$tmp" || return $?
930                 ;;
931         esac
932
933         mv -f "$tmp" "$target"
934 }
935
936 if [ -r /etc/sysconfig/geninitrd ]; then
937         . /etc/sysconfig/geninitrd
938 fi
939
940 if [ ! -f /proc/mounts ]; then
941         warn "/proc filesystem not mounted, may cause wrong results or failure."
942 fi
943
944 geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs sata scsi usbkbd
945
946 while [ $# -gt 0 ]; do
947         case $1 in
948         --fstab=*)
949                 fstab=${1#--fstab=}
950                 ;;
951         --fstab)
952                 fstab=$2
953                 shift
954                 ;;
955         --modules-conf=*)
956                 modulefile=${1#--modules-conf=}
957                 ;;
958         --modules-conf)
959                 modulefile=$2
960                 shift
961                 ;;
962         --with-bootsplash)
963                 BOOT_SPLASH=yes
964                 ;;
965         --without-bootsplash)
966                 BOOT_SPLASH=no
967                 ;;
968         --with-fbsplash)
969                 FB_SPLASH=yes
970                 ;;
971         --without-fbsplash)
972                 FB_SPLASH=no
973                 ;;
974         --with-fbcondecor)
975                 FB_CON_DECOR=yes
976                 ;;
977         --without-fbcondecor)
978                 FB_CON_DECOR=no
979                 ;;
980         --with-suspend)
981                 USE_SUSPEND=yes
982                 ;;
983         --without-suspend)
984                 USE_SUSPEND=no
985                 ;;
986         --with-suspend2 | --with-tuxonice)
987                 USE_TUXONICE=yes
988                 ;;
989         --without-suspend2 | --without-tuxonice)
990                 USE_TUXONICE=no
991                 ;;
992         --lvmversion=*)
993                 LVMTOOLSVERSION=${1#--lvmversion=}
994                 ;;
995         --lvmtoolsversion=*)
996                 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
997                 ;;
998         --lvmtoolsversion|--lvmversion)
999                 LVMTOOLSVERSION=$2
1000                 shift
1001                 ;;
1002         --without-udev)
1003                 USE_UDEV=no
1004                 ;;
1005         --with-udev)
1006                 USE_UDEV=yes
1007                 ;;
1008         --without-dmraid)
1009                 USE_DMRAID=no
1010                 ;;
1011         --without-multipath)
1012                 USE_MULTIPATH=no
1013                 ;;
1014         --with-multipath=*)
1015                 USE_MULTIPATH=${1#--with-multipath=}
1016                 ;;
1017         --without-blkid)
1018                 USE_BLKID=no
1019                 ;;
1020         --without-luks)
1021                 USE_LUKS=no
1022                 ;;
1023         --with=*)
1024                 BASICMODULES="$BASICMODULES ${1#--with=}"
1025                 ;;
1026         --with)
1027                 BASICMODULES="$BASICMODULES $2"
1028                 shift
1029                 ;;
1030         --version)
1031                 echo "$PROGRAM: version $VERSION"
1032                 exit 0
1033                 ;;
1034         -v)
1035                 verbose=-v
1036                 ;;
1037         --compress)
1038                 COMPRESS=$2
1039                 ;;
1040         --compress=*)
1041                 COMPRESS="${1#--compress=}"
1042                 ;;
1043         --nocompress)
1044                 COMPRESS=no
1045                 ;;
1046         --nostrip)
1047                 STRIP=
1048                 ;;
1049         --strip=*)
1050                 STRIP="${1#--strip=}"
1051                 ;;
1052         --strip)
1053                 STRIP=$2
1054                 shift
1055                 ;;
1056         --ifneeded)
1057                 ifneeded=1
1058                 ;;
1059         -f)
1060                 force=1
1061                 ;;
1062         --preload=*)
1063                 PREMODS="$PREMODS ${1#--preload=}"
1064                 ;;
1065         --preload)
1066                 PREMODS="$PREMODS $2"
1067                 shift
1068                 ;;
1069         --fs=* | --fs)
1070                 die "--fs option is obsoleted. Use --initrdfs instead"
1071                 ;;
1072         --initrdfs=*)
1073                 INITRDFS=${1#--initrdfs=}
1074                 ;;
1075         --initrdfs)
1076                 INITRDFS=$2
1077                 shift
1078                 ;;
1079         --image-version)
1080                 img_vers=yes
1081                 ;;
1082         --ide-only-root)
1083                 ide_only_root="yes"
1084                 ;;
1085         *)
1086                 if [ -z "$target" ]; then
1087                         target="$1"
1088                 elif [ -z "$kernel" ]; then
1089                         kernel="$1"
1090                 else
1091                         usage
1092                         exit 1
1093                 fi
1094                 ;;
1095         esac
1096
1097         shift
1098 done
1099
1100 if [ -z "$target" -o -z "$kernel" ]; then
1101         usage
1102         exit 1
1103 fi
1104
1105 # main()
1106 if [ "$(id -u)" != 0 ]; then
1107         die "You need to be root to generate initrd"
1108 fi
1109
1110 if [ -d /lib64 -a -d /usr/lib64 ]; then
1111         _lib=lib64
1112 else
1113         _lib=lib
1114 fi
1115
1116 initrd_dir=/usr/$_lib/initrd
1117 kernel_version=$(echo "$kernel" | awk -F. '{gsub(/[_-].*/, "", $0); print sprintf("%03d%03d",$1,$2)}')
1118 kernel_version_long=$(echo "$kernel" | awk -F. '{gsub(/[_-].*/, "", $0); print sprintf("%03d%03d%03d",$1,$2,$3)}')
1119
1120 debug "# $GENINITRD_RCSID (geninitrd)"
1121 debug "Using _lib: $_lib"
1122 debug "Using initrd_dir: $initrd_dir"
1123
1124 busybox=$(find_tool $initrd_dir/busybox $initrd_dir/initrd-busybox /bin/initrd-busybox) || die "Couldn't find busybox suitable for initrd"
1125
1126 # we setup mods after parsing command line args
1127 geninitrd_setup_mods
1128
1129 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1130         warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1131 fi
1132
1133 if [ -z "$INITRDFS" ]; then
1134         if [ -n "$FS" ]; then
1135                 # FS= can came only via /etc/sysconfig/geninitrd likely?
1136                 die "FS configuration option is obsoleted. Use INITRDFS instead"
1137         fi
1138
1139         # default value
1140         if [ "$kernel_version" -ge "002005" ]; then
1141                 INITRDFS="initramfs"
1142         else
1143                 INITRDFS="rom"
1144         fi
1145 fi
1146
1147 case "$INITRDFS" in
1148   ext2)
1149         [ -x /sbin/mke2fs ] || die "/sbin/mke2fs is missing"
1150         ;;
1151   rom|romfs)
1152         [ -x /sbin/genromfs ] || die "/sbin/genromfs is missing"
1153         ;;
1154   cram|cramfs)
1155         [ -x /sbin/mkcramfs ] || die "/sbin/mkcramfs is missing"
1156         ;;
1157   initramfs)
1158         [ -x /bin/cpio ] || die "/bin/cpio is missing"
1159         [ -x /usr/bin/find ] || die "/usr/bin/find is missing"
1160         ;;
1161   *)
1162         die "Filesystem $INITRDFS on initrd is not supported"
1163         ;;
1164 esac
1165
1166 if [ -L "$target" ]; then
1167         target=$(readlink -f "$target")
1168 fi
1169
1170 if [ -n "$img_vers" ]; then
1171         target="$target-$kernel"
1172 fi
1173
1174 if [ -z "$force" -a -f "$target" ]; then
1175         die "$target already exists."
1176 fi
1177
1178 if [ ! -d "/lib/modules/$kernel" ]; then
1179         die "/lib/modules/$kernel is not a directory."
1180 fi
1181
1182 if [ "$kernel_version" -ge "002005" ]; then
1183         modext=".ko"
1184 fi
1185
1186 cache_modprobe_conf
1187
1188 for n in $PREMODS; do
1189         find_module "$n"
1190 done
1191
1192 if [ "$FBMODULE" ]; then
1193         find_module "$FBMODULE"
1194 fi
1195
1196 # autodetect USB keyboards
1197 find_modules_usbkbd
1198
1199 # allow forcing loading SCSI and/or IDE modules
1200 # XXX: where ADDSCSI cames from? drop?
1201 if is_yes "$ADDSCSI"; then
1202         find_modules_scsi
1203 fi
1204
1205 # autodetect SATA modules
1206 find_modules_sata
1207
1208 # XXX: where ADDIDE cames from? drop?
1209 if is_yes "$ADDIDE"; then
1210         find_modules_ide
1211 fi
1212
1213 if is_yes "$USE_SUSPEND"; then
1214         find_modules_suspend
1215 fi
1216
1217 find_root "$fstab" || exit
1218 debug "Using $rootdev as device for rootfs"
1219
1220 find_modules_for_devpath "$rootdev"
1221
1222 # if USE_MULTIPATH is path to device, scan that too
1223 # this is to bootstrap multipath setup into initrd.
1224 if ! is_no "$USE_MULTIPATH" && ! is_yes "$USE_MULTIPATH"; then
1225         find_modules_multipath $USE_MULTIPATH
1226 fi
1227
1228 find_module "-$rootFs"
1229
1230 for n in $BASICMODULES; do
1231         find_module "$n"
1232 done
1233
1234 if is_yes "$USE_TUXONICE"; then
1235         find_module "-lzf"
1236 fi
1237
1238 find_modules_fbsplash
1239
1240 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1241         debug "No modules are needed -- not building initrd image."
1242         exit 0
1243 fi
1244
1245 debug "Building initrd..."
1246 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
1247 RCFILE="$DESTDIR/linuxrc"
1248 > "$RCFILE"
1249 chmod a+rx "$RCFILE"
1250 ln -s linuxrc $DESTDIR/init
1251
1252 # create dirs that we really need
1253 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,run,sys}
1254
1255 modules_install "$MODULES"
1256
1257 # mknod'ing the devices instead of copying them works both with and
1258 # without devfs...
1259 mknod "$DESTDIR/dev/console" c 5 1
1260 mknod "$DESTDIR/dev/null" c 1 3
1261 mknod "$DESTDIR/dev/zero" c 1 5
1262 mknod "$DESTDIR/dev/random" c 1 8
1263 mknod "$DESTDIR/dev/urandom" c 1 9
1264
1265 inst_exec $busybox /bin/busybox
1266 ln -s busybox $DESTDIR/bin/sh
1267 # for older busyboxes who had /bin/initrd-busybox as EXEPATH
1268 ln -s busybox $DESTDIR/bin/initrd-busybox
1269
1270 add_linuxrc <<EOF
1271 #!/bin/sh
1272 # initrd generated by:
1273 # $GENINITRD_RCSID
1274
1275 EOF
1276 mount_proc
1277 add_linuxrc <<-'EOF'
1278         read CMDLINE < /proc/cmdline; export CMDLINE
1279
1280         for arg in $CMDLINE; do
1281                 if [ "${arg}" = "debuginitrd" ]; then
1282                         DEBUGINITRD=yes
1283                 fi
1284                 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1285                         DEBUGINITRD=${arg##debuginitrd=}
1286                 fi
1287                 if [ "${arg##root=}" != "${arg}" ]; then
1288                         ROOT=${arg##root=}
1289                 fi
1290                 if [ "${arg##rootfsflags=}" != "${arg}" ]; then
1291                         ROOTFSFLAGS=${arg##rootfsflags=}
1292                 fi
1293         done
1294
1295         # make debugshell() invoke subshell if $DEBUGINITRD=sh
1296         if [ "$DEBUGINITRD" = "sh" ]; then
1297                 debugshell() {
1298 EOF
1299 if is_yes "$RUN_SULOGIN_ON_ERR"; then
1300 add_linuxrc <<-'EOF'
1301         echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1302 EOF
1303 else
1304 add_linuxrc <<-'EOF'
1305         sh
1306 EOF
1307 fi
1308 add_linuxrc <<-'EOF'
1309                 }
1310         else
1311                 debugshell() {
1312                         :
1313                 }
1314         fi
1315
1316         if [ "$DEBUGINITRD" ]; then
1317                 set -x
1318         fi
1319 EOF
1320
1321 modules_add_linuxrc $MODULES
1322
1323 # TODO: rewrite for busybox
1324 #if [ -n "$loopDev" ]; then
1325 #       if [ ! -d /initrd ]; then
1326 #               mkdir /initrd
1327 #       fi
1328 #
1329 #       cp -a "$loopDev" "$DESTDIR/dev"
1330 #       cp -a "$rootdev" "$DESTDIR/dev"
1331 #       echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1332 #       echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1333 #       echo "echo Setting up loopback device $rootdev" >> $RCFILE
1334 #       echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1335 #fi
1336
1337 if is_yes "$USE_UDEV"; then
1338         initrd_gen_udev
1339 fi
1340
1341 find_modules_uvesafb
1342 initrd_gen_uvesafb
1343
1344 initrd_gen_luks
1345 initrd_gen_dmraid
1346 initrd_gen_multipath
1347 initrd_gen_blkid
1348
1349 if is_yes "$have_nfs"; then
1350         initrd_gen_nfs
1351 else
1352         initrd_gen_md
1353         initrd_gen_lvm
1354         initrd_gen_luks
1355         initrd_gen_setrootdev
1356 fi
1357
1358 initrd_gen_tuxonice
1359 initrd_gen_suspend
1360
1361 # additional devs always needed
1362 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
1363
1364 initrd_gen_stop_udevd
1365 initrd_gen_stop_uvesafb
1366
1367 if [ "$INITRDFS" = "initramfs" ]; then
1368         initrd_gen_initramfs_switchroot
1369 else
1370         umount_all
1371 fi
1372
1373 initrd_gen_fbsplash
1374 initrd_gen_fbcondecor
1375
1376 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
1377
1378 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
1379 debug "image size: $IMAGESIZE KiB ($DESTDIR)"
1380
1381 debug "Creating $INITRDFS image $IMAGE"
1382 case "$INITRDFS" in
1383   ext2)
1384         dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1385         # NOTE: ext2 label is max 16 chars
1386         mke2fs -q -F -b 1024 -m 0 -L "PLD/$kernel" "$IMAGE" 2>/dev/null 1>&2
1387         tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1388
1389         local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
1390         debug "Mounting ext2 image $IMAGE to $tmpmnt"
1391         mount -o loop -t ext2 "$IMAGE" "$tmpmnt" || die "mount failed, check dmesg(1)"
1392         # We don't need this directory, so let's save space
1393         rm -rf "$tmpmnt"/lost+found
1394
1395         debug "Copy recursively $DESTDIR -> $tmpmnt"
1396         cp -a $DESTDIR/* $tmpmnt
1397         umount "$IMAGE"
1398         rmdir "$tmpmnt"
1399
1400         ;;
1401   rom|romfs)
1402         genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD Linux/$kernel (geninitrd/$VERSION)"
1403         ;;
1404   cram|cramfs)
1405         mkcramfs "$DESTDIR" "$IMAGE"
1406         ;;
1407   initramfs)
1408         (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
1409         ;;
1410   *)
1411         die "Filesystem $INITRDFS not supported by $PROGRAM"
1412 esac
1413
1414 CONFIG_BLK_DEV_RAM_SIZE=$(ikconfig | awk -F= '/^CONFIG_BLK_DEV_RAM_SIZE/{print $2}')
1415 if [ -z "$CONFIG_BLK_DEV_RAM_SIZE" ]; then
1416         CONFIG_BLK_DEV_RAM_SIZE=4096
1417 fi
1418
1419 if [ "$IMAGESIZE" -gt $CONFIG_BLK_DEV_RAM_SIZE ]; then
1420         warn "Your image size is larger than $CONFIG_BLK_DEV_RAM_SIZE, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1421 fi
1422
1423 if ! is_no "$COMPRESS"; then
1424         compressor=$(find_compressor "$COMPRESS")
1425         debug "Compressing $target with $compressor"
1426
1427         # TODO: the image name (specified from kernel.spec) already contains
1428         # extension, which is .gz most of the time.
1429         compress_image "$compressor" "$IMAGE" "$target" || {
1430                 if [ $compressor != gzip ]; then
1431                         warn "Could not compress with $compressor, retrying with gzip"
1432                         compress_image gzip "$IMAGE" "$target" || die "compress failed with gzip" $?
1433                 else
1434                         die "Could not compress image with $compressor"
1435                 fi
1436         }
1437 else
1438         cp -a "$IMAGE" "$target"
1439 fi
1440
1441 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
1442 initrd_gen_bootsplash "$target"
1443
1444 rm -rf "$DESTDIR" "$IMAGE"
1445
1446 # vim:ts=4:sw=4:noet:fdm=marker
This page took 0.153413 seconds and 4 git commands to generate.