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