7 # based on mkinitrd from RedHat Linux
10 RCSID='$Revision$ $Date$'
11 R=${RCSID#* *}; VERSION=${R%% *}
14 . /etc/rc.d/init.d/functions
15 . /lib/geninitrd/functions
16 . /etc/sysconfig/system
18 # list of geninitrd modules which need setup routine after commandline args parsing
30 # device node for rootfs from fstab
40 # is /tmp mounted on tmpfs
43 # are /dev nodes already created from /proc/devices info?
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]"
51 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
52 echo " [--with-bootsplash] [--without-bootsplash]"
53 echo " [--with-fbsplash] [--without-fbsplash]"
54 echo " [--with-fbcondecor] [--without-fbcondecor]"
55 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
56 echo " [--with-suspend] [--without-suspend]"
57 echo " [--with-tuxonice] [--without-tuxonice]"
58 echo " [--without-dmraid]"
59 echo " [--with-multipath=DEVPATH] [--without-multipath]"
60 echo " [--without-blkid] [--without-luks]"
61 echo " <initrd-image> <kernel-version>"
64 for kernel_ver in $(ls -1 /lib/modules); do
65 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$kernel_ver.gz $kernel_ver"
79 [ -n "$verbose" ] && msg "$*" >&2
82 # aborts program abnormally
89 # find program from specified paths
95 debug "find_tool: found $x"
99 debug "find_tool: did not found any of: $@"
103 # loads geninitrd modules
104 geninitrd_load_mods() {
107 if [ ! -f /lib/geninitrd/mod-$mod.sh ]; then
108 die "$mod geninitrd module can't be loaded"
110 . /lib/geninitrd/mod-$mod.sh
112 if type setup_mod_$mod > /dev/null; then
113 # add to list which need init
114 GENINITRD_MODS="$GENINITRD_MODS $mod"
119 # setup geninitrd modules
120 geninitrd_setup_mods() {
123 for mod in $GENINITRD_MODS; do
128 # append text to /linuxrc
129 # takes STDIN as input
134 # generate code to mount /dev on tmpfs and create initial nodes
135 # can be called multiple times. /dev is cleaned up (umounted) automatically at
138 if [ "$INITRDFS" = "initramfs" ]; then
139 # initramfs is read-write filesystem, no need for tmpfs
143 # we already generated tmpfs code; return
144 if is_yes "$dev_mounted"; then
150 busybox_applet mount mknod mkdir
153 mount -o mode=0755 -t tmpfs none /dev
154 mknod /dev/console c 5 1
155 mknod /dev/null c 1 3
156 mknod /dev/zero c 1 5
157 mknod /dev/urandom c 1 9
163 # generate code to mount /proc on initrd
164 # can be called multiple times
166 if is_yes "$proc_mounted"; then
171 if [ "$INITRDFS" = "initramfs" ]; then
172 # /proc is mounted with initramfs 2.6.22.14 kernel
173 # XXX: remove when it is clear why proc was already mounted
174 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
176 echo "mount -t proc none /proc" | add_linuxrc
180 # generate code to mount /sys on initrd
181 # can be called multiple times
183 if is_yes "$sys_mounted"; then
188 echo "mount -t sysfs none /sys" | add_linuxrc
191 # generate code to mount /tmp on initrd
192 # can be called multiple times
194 if [ "$INITRDFS" = "initramfs" ]; then
195 # initramfs is read-write filesystem, no need for tmpfs
199 if is_yes "$tmp_mounted"; then
204 echo "mount -t tmpfs none /tmp" | add_linuxrc
207 # unmount all mountpoints mounted by geninitrd
211 : Last shell before umounting all and giving control over to real init.
215 if is_yes "$dev_mounted"; then
216 echo 'umount /dev' | add_linuxrc
219 if is_yes "$sys_mounted"; then
220 echo 'umount /sys' | add_linuxrc
223 if is_yes "$tmp_mounted"; then
224 echo 'umount /tmp' | add_linuxrc
227 if is_yes "$proc_mounted"; then
228 echo 'umount /proc' | add_linuxrc
234 # Checks if busybox has support for APPLET(s)
235 # Exits from geninitrd if the support is not present.
237 # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
241 if [ -z "$busybox_functions" ]; then
242 local tmp=$($busybox 2>&1)
244 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
245 if [[ "$tmp" = *applet\ not\ found* ]]; then
247 ln -s $busybox $t/busybox
248 local tmp=$($t/busybox 2>&1)
252 busybox_functions=$(echo "$tmp" | \
253 sed -ne '/Currently defined functions:/,$p' | \
254 xargs | sed -e 's,.*Currently defined functions: ,,'
260 eval have='$'busybox_have_$applet
261 if [ -z "$have" ]; then
262 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
263 if [ "$have" = 0 ]; then
264 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
267 eval busybox_have_$applet=$have
270 if [ $err = 1 ]; then
275 # extract-ikconfig - Extract the .config file from a kernel image
277 # The obscure use of the "tr" filter is to work around older versions of
278 # "grep" that report the byte offset of the line instead of the pattern.
280 # (c) 2009, Dick Streefland <dick@streefland.net>
281 # Licensed under the terms of the GNU General Public License.
283 # Ripped and adjusted for geninitrd from linux-2.6.34/scripts/extract-ikconfig
286 local kofile=$(modinfo -k $kernel -n configs)
292 gzip -dc "$kofile" > $img
299 local cf1='IKCFG_ST\037\213\010'
300 local cf2='0123456789'
303 if pos=$(tr "$cf1\n$cf2" "\n$cf2=" < "$img" | grep -abo "^$cf2"); then
305 tail -c+$(($pos+8)) "$img" | gzip -dcq
310 # Finds module dependencies
314 # Outputs full path to module and it's dependencies
319 # if module is prefixed with dash, we should ignore errors if the module
321 if [ ${module#-} != $module ]; then
326 # This works when user has module-init-tools installed even on 2.4 kernels
328 modprobe=$(modprobe --set-version $kernel --show-depends $module --ignore-install 2>&1)
331 if [ $skiperrors = 1 ]; then
336 if ! is_no "$EXIT_IF_MISSING"; then
337 die "$module: module not found for $kernel kernel"
340 warn "$module: module not found for $kernel kernel"
341 warn "If $module isn't compiled in kernel then this initrd may not start your system."
345 while read insmod modpath options; do
346 [ "$insmod" = "insmod" ] && echo $modpath
353 # no firmware support in 2.4 kernels
354 if [ "$kernel_version_long" -lt "002005048" ]; then
357 echo -n $(NEW_MODINFO=1 modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
362 local mod depmod module=$1
364 depmod=$(find_depmod $module) || exit 1
365 for mod in $depmod; do
366 mod=${mod#/lib/modules/$kernel/}
368 # add each module only once
370 for m in $MODULES; do
371 [ $m = $mod ] && have=1
373 if [ $have = 0 ]; then
374 MODULES="$MODULES $mod"
379 # install a file to temporary mount image.
380 # it will operate recursively (copying directories)
381 # and will symlink destinations if source is symlink.
383 if [ $# -lt 2 ]; then
384 die 'Usage: inst <file> [<file>] <destination>'
387 local src i=0 c=$(($# - 1))
388 while [ $i -lt $c ]; do
395 parentDir=$(dirname $DESTDIR$dest)
396 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
397 debug "+ cp $* $DESTDIR$dest"
398 cp -HR "$@" "$DESTDIR$dest"
403 die 'Usage: inst_d <destination> <destination>'
406 install -d "$DESTDIR$dir"
410 # install executable and it's shared libraries
412 if [ $# -lt 2 ]; then
413 die "Invalid params ($@), Usage: inst_exec <file>[, <file>] <destination>"
415 local src i=0 c=$(($# - 1))
416 while [ $i -lt $c ]; do
426 local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
428 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
430 inst_exec $lib /$_lib
434 # hack for uclibc linked binaries requiring this fixed path
435 # XXX: shouldn't rpath be used here instead so th
436 if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
437 local lib=$DESTDIR/$_lib/libc.so.0
438 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
439 local libdir=$(cd $(dirname "$lib"); pwd)
440 if [ ! -e $DESTDIR$libdir ]; then
441 libdir=$(dirname "$libdir")
443 debug "+ ln -s /$_lib $DESTDIR$libdir"
444 ln -s /$_lib $DESTDIR$libdir
449 # output modules.conf / modprobe.conf
451 echo "$modprobe_conf_cache"
455 # defaults to modprobe -c if not told otherwise, this means include statements
457 cache_modprobe_conf() {
458 if [ "$kernel_version" -lt "002005" ]; then
459 modulefile=/etc/modules.conf
460 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
461 modulefile=/etc/conf.modules
465 if [ -n "$modulefile" ]; then
466 debug "Using $modulefile for modules config"
467 modprobe_conf_cache=$(cat $modulefile)
469 debug "Using modprobe -c to get modules config"
470 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
474 # find modules for $devpath
475 find_modules_for_devpath() {
477 if [ -z "$devpath" ]; then
478 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
481 if [[ "$devpath" = /dev/dm-* ]]; then
482 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
483 devpath=$(dm_longname "$devpath")
486 if [ -L "$devpath" ] && ! is_lvm "$devpath"; then
487 # sanitize things like:
488 # /dev/block/104:2 -> /dev/cciss/c0d0p2
489 devpath=$(readlink -f "$devpath")
492 debug "Finding modules for device path $devpath"
494 if is_luks "$devpath"; then
495 find_modules_luks "$devpath"
499 if is_nfs "$devpath"; then
500 find_modules_nfs "$devpath"
504 if is_md "$devpath"; then
505 find_modules_md "$devpath"
509 if is_multipath "$devpath"; then
510 if find_modules_multipath "$devpath"; then
517 if is_dmraid "$devpath"; then
518 if find_modules_dmraid "$devpath"; then
524 if is_scsi "$devpath"; then
525 find_modules_scsi "$devpath"
529 if is_ide "$devpath"; then
530 find_modules_ide "$devpath"
534 if [[ "$devpath" == /dev/rd/* ]]; then
540 if [[ "$devpath" == /dev/ida/* ]]; then
541 find_module "cpqarray"
542 rootdev_add=/dev/ida/
546 if [[ "$devpath" == /dev/cciss/* ]]; then
548 rootdev_add=/dev/cciss/
552 if [[ "$devpath" == /dev/ataraid/* ]]; then
554 find_module "ataraid"
555 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
556 if [ -n "$ataraidmodules" ]; then
557 # FIXME: think about modules compiled in kernel
558 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
560 for n in $ataraidmodules; do
563 rootdev_add=/dev/ataraid/
567 # check to see if we need to set up a loopback filesystem
568 if [[ "$devpath" == /dev/loop* ]]; then
569 die "Sorry, root on loop device isn't supported."
570 # TODO: rewrite for bsp and make nfs ready
571 if [ ! -x /sbin/losetup ]; then
572 die "losetup is missing"
574 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
575 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
576 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"
579 line="`awk '/'$key'/ { print $0; }' $fstab`"
580 loopDev="$(echo $line | awk '{print $3}')"
581 loopFs="$(echo $line | awk '{print $4}')"
582 loopFile="$(echo $line | awk '{print $5}')"
584 BASICMODULES="$BASICMODULES -loop"
585 find_module "-$loopFs"
586 BASICMODULES="$BASICMODULES -${loopFs}"
590 if is_lvm "$devpath"; then
591 find_modules_lvm "$devpath"
596 firmware_install_module() {
598 local firmware_files="$2"
600 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
601 # firmware not yet installed
602 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
604 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
606 echo 1 > /sys$DEVPATH/loading
607 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
608 echo 0 > /sys$DEVPATH/loading
611 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
614 for firmware in $firmware_files; do
615 if [ -f "/lib/firmware/$kernel/$firmware" ]; then
616 FIRMWAREDIR=${firmware%/*}
617 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
618 inst /lib/firmware/$kernel/$firmware /lib/firmware/$firmware
619 elif [ -f "/lib/firmware/$firmware" ]; then
620 FIRMWAREDIR=${firmware%/*}
621 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
622 inst /lib/firmware/$firmware /lib/firmware/$firmware
624 die "firmware file /lib/firmware/$firmware nor /lib/firmware/$kernel/$firmware found."
629 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
636 for mod in $modules; do
638 inst_d "/lib/modules/$kernel/$MODULEDIR"
639 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
640 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
644 modules_add_linuxrc() {
648 # module path without optional compression
652 local module=${modpath##*/}; module=${module%$modext}
653 local options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
654 local genericname=$(echo $module | tr - _)
655 local usleep=$(eval echo \$MODULE_${genericname}_USLEEP)
656 local firmware=$(eval echo \$MODULE_${genericname}_FIRMWARE)
658 if [ "$module" = "scsi_mod" -a "$kernel_version_long" -ge "002006030" ]; then
659 options="scan=sync $options"
662 if [ -n "$verbose" ]; then
664 if [ "$options" ]; then
665 s="$s with options [$options]"
667 if [ "$usleep" ]; then
668 s="$s and $usleep usleep"
670 debug "Loading module [$module]$s"
673 if [ -n "$firmware" ]; then
674 firmware_install_module "$module" "$firmware"
676 for file in $(find_firmware "$module"); do
677 firmware_install_module "$module" "$file"
681 echo "insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
682 if [ -n "$usleep" ]; then
683 echo "usleep $usleep" | add_linuxrc
685 if [ "$module" = "scsi_wait_scan" ]; then
686 if [ "$(busybox_applet rmmod 2>/dev/null; echo $?)" = 0 ]; then
687 echo "rmmod scsi_wait_scan" | add_linuxrc
694 # Generates /dev nodes based on /proc/partitions information.
695 # Needs /proc mounted.
696 # Can be called multiple times.
697 initrd_gen_devices() {
698 if is_yes "$proc_partitions"; then
705 : 'Making device nodes'
706 cat /proc/partitions | (
707 # ignore first two lines: header, empty line
710 while read major minor blocks dev rest; do
713 [ -e $node ] || mknod $node b $major $minor
720 initrd_gen_setrootdev() {
721 debug "Adding rootfs finding based on kernel cmdline root= option support."
723 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
724 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
725 if [ -n "$rootnr" ]; then
726 echo "$rootnr" > /proc/sys/kernel/real-root-dev
732 initrd_gen_initramfs_switchroot() {
734 if [ "$rootdev" = "/dev/nfs" ]; then
735 echo "rootfs on NFS root=/dev/nfs"
737 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
740 # parse 'root=xxx' kernel commandline
741 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
743 device=/dev/no_partition_found
744 eval "$(busybox awk -v c="$ROOT" '
746 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
747 num_pattern = "[0-9a-f]" num_pattern_short;
748 dev_pattern = "[hms][a-z][a-z]([0-9])+";
749 partition = "no_partition_found";
753 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
754 if (c ~ "^" num_pattern "$") {
755 maj = sprintf("%s",substr(c,1,2));
756 min = sprintf("%s",substr(c,3));
758 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
759 if (c ~ "^" dev_pattern "$") partition = c;
762 $4 ~ partition { maj = $1; min = $2; }
763 $1 ~ maj && $2 ~ min { partition = $4; }
766 if (maj >= 0 && min >= 0) {
767 printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
771 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
772 mknod $device b $maj $min
782 if [ "$device" = '/dev/no_partition_found' ]; then
786 mount -t $rootfs -r $device /newroot
787 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
788 if [ -z "$init" -o ! -x "/newroot$init" ]; then
794 busybox_applet switch_root
796 exec switch_root /newroot $init ${1:+"$@"}
798 echo "Error! initramfs should not reach this place."
799 echo "It probably means you've got old version of busybox, with broken"
800 echo "initramfs support. Trying to boot anyway, but won't promise anything."
802 exec chroot /newroot $init ${1:+"$@"}
804 echo "Failed to chroot!"
806 # we need /init being real file, not symlink, otherwise the initramfs will
807 # not be ran by pid 1 which is required for switch_root
808 mv $DESTDIR/linuxrc $DESTDIR/init
809 ln -s init $DESTDIR/linuxrc
812 # find if $symbol exists in System.map $mapfile
816 if [ ! -f $mapfile ]; then
817 # missing mapfile (not a pld kernel?)
821 awk -vc=1 -vsymbol="$symbol" '$2 == "T" && $3 == symbol {c = 0} END {exit c}' $mapfile
824 # find best compressor (or forced one) for initrd
827 # the best compressor list
828 local compressors='xz lzma bzip2 gzip'
830 # a specified one, take it
831 if ! is_yes "$mode"; then
835 debug "finding compressor: $compressors (via $mode)"
836 # check for compressor validity
837 local c prog map=/boot/System.map-$kernel
838 for c in $compressors; do
857 die "Unknown compressor $c"
860 if sym_exists $map $sym && [ -x $prog ]; then
866 debug "using gzip for compressor (fallback)"
870 if [ -r /etc/sysconfig/geninitrd ]; then
871 . /etc/sysconfig/geninitrd
874 if [ ! -f /proc/mounts ]; then
875 warn "/proc filesystem not mounted, may cause wrong results or failure."
878 geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs scsi
880 while [ $# -gt 0 ]; do
890 modulefile=${1#--modules-conf=}
899 --without-bootsplash)
911 --without-fbcondecor)
920 --with-suspend2 | --with-tuxonice)
923 --without-suspend2 | --without-tuxonice)
927 LVMTOOLSVERSION=${1#--lvmversion=}
930 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
932 --lvmtoolsversion|--lvmversion)
949 USE_MULTIPATH=${1#--with-multipath=}
958 BASICMODULES="$BASICMODULES ${1#--with=}"
961 BASICMODULES="$BASICMODULES $2"
965 echo "$PROGRAM: version $VERSION"
975 COMPRESS="${1#--compress=}"
987 PREMODS="$PREMODS ${1#--preload=}"
990 PREMODS="$PREMODS $2"
994 die "--fs option is obsoleted. Use --initrdfs instead"
997 INITRDFS=${1#--initrdfs=}
1010 if [ -z "$target" ]; then
1012 elif [ -z "$kernel" ]; then
1024 if [ -z "$target" -o -z "$kernel" ]; then
1030 if [ "$(id -u)" != 0 ]; then
1031 die "You need to be root to generate initrd"
1034 if [ -d /lib64 -a -d /usr/lib64 ]; then
1040 initrd_dir=/usr/$_lib/initrd
1041 kernel_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1042 kernel_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
1045 debug "Using _lib: $_lib"
1046 debug "Using initrd_dir: $initrd_dir"
1048 busybox=$(find_tool $initrd_dir/busybox $initrd_dir/initrd-busybox /bin/initrd-busybox) || die "Couldn't find busybox suitable for initrd"
1050 # we setup mods after parsing command line args
1051 geninitrd_setup_mods
1053 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1054 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1057 if [ -z "$INITRDFS" ]; then
1058 if [ -n "$FS" ]; then
1059 # FS= can came only via /etc/sysconfig/geninitrd likely?
1060 die "FS configuration option is obsoleted. Use INITRDFS instead"
1064 if [ "$kernel_version" -ge "002005" ]; then
1065 INITRDFS="initramfs"
1073 [ -x /sbin/mke2fs ] || die "/sbin/mke2fs is missing"
1076 [ -x /sbin/genromfs ] || die "/sbin/genromfs is missing"
1079 [ -x /sbin/mkcramfs ] || die "/sbin/mkcramfs is missing"
1082 [ -x /bin/cpio ] || die "/bin/cpio is missing"
1083 [ -x /usr/bin/find ] || die "/usr/bin/find is missing"
1086 die "Filesystem $INITRDFS on initrd is not supported"
1090 if [ -L "$target" ]; then
1091 target=$(readlink -f "$target")
1094 if [ -n "$img_vers" ]; then
1095 target="$target-$kernel"
1098 if [ -z "$force" -a -f "$target" ]; then
1099 die "$target already exists."
1102 if [ ! -d "/lib/modules/$kernel" ]; then
1103 die "/lib/modules/$kernel is not a directory."
1106 if [ "$kernel_version" -ge "002005" ]; then
1112 for n in $PREMODS; do
1116 if [ "$FBMODULE" ]; then
1117 find_module "$FBMODULE"
1120 # allow forcing loading SCSI and/or IDE modules
1121 # XXX: where ADDSCSI cames from? drop?
1122 if is_yes "$ADDSCSI"; then
1126 # autodetect SATA modules
1129 # XXX: where ADDIDE cames from? drop?
1130 if is_yes "$ADDIDE"; then
1134 if is_yes "$USE_SUSPEND"; then
1135 find_modules_suspend
1138 find_root "$fstab" || exit
1139 debug "Using $rootdev as device for rootfs"
1141 find_modules_for_devpath "$rootdev"
1143 # if USE_MULTIPATH is path to device, scan that too
1144 # this is to bootstrap multipath setup into initrd.
1145 if ! is_no "$USE_MULTIPATH" && ! is_yes "$USE_MULTIPATH"; then
1146 find_modules_multipath $USE_MULTIPATH
1149 find_module "-$rootFs"
1151 for n in $BASICMODULES; do
1155 if is_yes "$USE_TUXONICE"; then
1159 find_modules_fbsplash
1161 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1162 debug "No modules are needed -- not building initrd image."
1166 debug "Building initrd..."
1167 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
1168 RCFILE="$DESTDIR/linuxrc"
1170 chmod a+rx "$RCFILE"
1171 ln -s linuxrc $DESTDIR/init
1173 # create dirs that we really need
1174 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
1176 modules_install "$MODULES"
1178 # mknod'ing the devices instead of copying them works both with and
1180 mknod "$DESTDIR/dev/console" c 5 1
1181 mknod "$DESTDIR/dev/null" c 1 3
1182 mknod "$DESTDIR/dev/zero" c 1 5
1183 mknod "$DESTDIR/dev/urandom" c 1 9
1185 inst_exec $busybox /bin/busybox
1186 ln -s busybox $DESTDIR/bin/sh
1187 # for older busyboxes who had /bin/initrd-busybox as EXEPATH
1188 ln -s busybox $DESTDIR/bin/initrd-busybox
1192 # initrd generated by:
1197 add_linuxrc <<-'EOF'
1198 read CMDLINE < /proc/cmdline; export CMDLINE
1200 for arg in $CMDLINE; do
1201 if [ "${arg}" = "debuginitrd" ]; then
1204 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1205 DEBUGINITRD=${arg##debuginitrd=}
1207 if [ "${arg##root=}" != "${arg}" ]; then
1212 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1213 if [ "$DEBUGINITRD" = "sh" ]; then
1216 if is_yes "$RUN_SULOGIN_ON_ERR"; then
1217 add_linuxrc <<-'EOF'
1218 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1221 add_linuxrc <<-'EOF'
1225 add_linuxrc <<-'EOF'
1233 if [ "$DEBUGINITRD" ]; then
1238 modules_add_linuxrc $MODULES
1240 # TODO: rewrite for busybox
1241 #if [ -n "$loopDev" ]; then
1242 # if [ ! -d /initrd ]; then
1246 # cp -a "$loopDev" "$DESTDIR/dev"
1247 # cp -a "$rootdev" "$DESTDIR/dev"
1248 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1249 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1250 # echo "echo Setting up loopback device $rootdev" >> $RCFILE
1251 # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1254 if is_yes "$USE_UDEV"; then
1258 if is_yes "$USE_TUXONICE"; then
1262 find_modules_uvesafb
1265 if is_yes "$have_luks"; then
1269 if is_yes "$have_dmraid"; then
1273 if is_yes "$have_multipath"; then
1274 initrd_gen_multipath
1277 if is_yes "$USE_BLKID"; then
1281 if is_yes "$have_nfs"; then
1283 elif is_yes "$have_md"; then
1285 if is_yes "$have_lvm"; then
1288 initrd_gen_setrootdev
1290 elif is_yes "$have_lvm"; then
1293 initrd_gen_setrootdev
1296 if is_yes "$USE_SUSPEND"; then
1300 # additional devs always needed
1301 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
1303 if is_yes "$USE_UDEV"; then
1304 initrd_gen_stop_udevd
1307 if [ "$INITRDFS" = "initramfs" ]; then
1308 initrd_gen_initramfs_switchroot
1313 if is_yes "$FB_SPLASH"; then
1317 if is_yes "$FB_CON_DECOR"; then
1318 initrd_gen_fbcondecor
1321 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
1323 debug "Creating $INITRDFS image $IMAGE"
1326 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1327 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1328 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1330 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
1331 debug "Mounting ext2 image $IMAGE to $tmpmnt"
1332 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1333 # We don't need this directory, so let's save space
1334 rm -rf "$tmpmnt"/lost+found
1336 debug "Copy recursively $DESTDIR -> $tmpmnt"
1337 cp -a $DESTDIR/* $tmpmnt
1343 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
1346 mkcramfs "$DESTDIR" "$IMAGE"
1349 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
1352 die "Filesystem $INITRDFS not supported by $PROGRAM"
1355 CONFIG_BLK_DEV_RAM_SIZE=$(extract-ikconfig | awk -F= '/^CONFIG_BLK_DEV_RAM_SIZE/{print $2}')
1356 if [ -z "$CONFIG_BLK_DEV_RAM_SIZE" ]; then
1357 CONFIG_BLK_DEV_RAM_SIZE=4096
1360 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
1361 debug "image size: $IMAGESIZE KiB ($DESTDIR)"
1362 if [ "$IMAGESIZE" -gt $CONFIG_BLK_DEV_RAM_SIZE ]; then
1363 warn "Your image size is larger than $CONFIG_BLK_DEV_RAM_SIZE, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1366 if ! is_no "$COMPRESS"; then
1367 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
1368 compressor=$(find_compressor "$COMPRESS")
1369 debug "Compressing $target with $compressor"
1371 # TODO: the image name (specified from kernel.spec) already contains
1372 # extension, which is .gz most of the time.
1373 case "$compressor" in
1375 # don't use -9 here since kernel won't understand it
1376 xz --format=xz --check=crc32 --lzma2=preset=6e,dict=1MiB < "$IMAGE" > "$tmp"
1379 xz --format=lzma -9 < "$IMAGE" > "$tmp"
1382 bzip2 -9 < "$IMAGE" > "$tmp"
1385 gzip -9 < "$IMAGE" > "$tmp"
1388 mv -f "$tmp" "$target"
1390 cp -a "$IMAGE" "$target"
1393 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
1394 if is_yes "$BOOT_SPLASH"; then
1395 initrd_gen_bootsplash "$target"
1398 rm -rf "$DESTDIR" "$IMAGE"
1400 # vim:ts=4:sw=4:noet:fdm=marker