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 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
77 [ -n "$verbose" ] && msg "$*" >&2
80 # aborts program abnormally
87 # find program from specified paths
93 debug "find_tool: found $x"
97 debug "find_tool: did not found any of: $@"
101 # loads geninitrd modules
102 geninitrd_load_mods() {
105 if [ ! -f /lib/geninitrd/mod-$mod.sh ]; then
106 die "$mod geninitrd module can't be loaded"
108 . /lib/geninitrd/mod-$mod.sh
110 if type setup_mod_$mod > /dev/null; then
111 # add to list which need init
112 GENINITRD_MODS="$GENINITRD_MODS $mod"
117 # setup geninitrd modules
118 geninitrd_setup_mods() {
121 for mod in $GENINITRD_MODS; do
126 # append text to /linuxrc
127 # takes STDIN as input
132 # generate code to mount /dev on tmpfs and create initial nodes
133 # can be called multiple times. /dev is cleaned up (umounted) automatically at
136 if [ "$INITRDFS" = "initramfs" ]; then
137 # initramfs is read-write filesystem, no need for tmpfs
141 # we already generated tmpfs code; return
142 if is_yes "$dev_mounted"; then
148 busybox_applet mount mknod mkdir
151 mount -o mode=0755 -t tmpfs none /dev
152 mknod /dev/console c 5 1
153 mknod /dev/null c 1 3
154 mknod /dev/zero c 1 5
155 mknod /dev/urandom c 1 9
161 # generate code to mount /proc on initrd
162 # can be called multiple times
164 if is_yes "$proc_mounted"; then
169 if [ "$INITRDFS" = "initramfs" ]; then
170 # /proc is mounted with initramfs 2.6.22.14 kernel
171 # XXX: remove when it is clear why proc was already mounted
172 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
174 echo "mount -t proc none /proc" | add_linuxrc
178 # generate code to mount /sys on initrd
179 # can be called multiple times
181 if is_yes "$sys_mounted"; then
186 echo "mount -t sysfs none /sys" | add_linuxrc
189 # generate code to mount /tmp on initrd
190 # can be called multiple times
192 if [ "$INITRDFS" = "initramfs" ]; then
193 # initramfs is read-write filesystem, no need for tmpfs
197 if is_yes "$tmp_mounted"; then
202 echo "mount -t tmpfs none /tmp" | add_linuxrc
205 # unmount all mountpoints mounted by geninitrd
209 : Last shell before umounting all and giving control over to real init.
213 if is_yes "$dev_mounted"; then
214 echo 'umount /dev' | add_linuxrc
217 if is_yes "$sys_mounted"; then
218 echo 'umount /sys' | add_linuxrc
221 if is_yes "$tmp_mounted"; then
222 echo 'umount /tmp' | add_linuxrc
225 if is_yes "$proc_mounted"; then
226 echo 'umount /proc' | add_linuxrc
232 # Checks if busybox has support for APPLET(s)
233 # Exits from geninitrd if the support is not present.
235 # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
239 if [ -z "$busybox_functions" ]; then
240 local tmp=$($busybox 2>&1)
242 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
243 if [[ "$tmp" = *applet\ not\ found* ]]; then
245 ln -s $busybox $t/busybox
246 local tmp=$($t/busybox 2>&1)
250 busybox_functions=$(echo "$tmp" | \
251 sed -ne '/Currently defined functions:/,$p' | \
252 xargs | sed -e 's,.*Currently defined functions: ,,'
258 eval have='$'busybox_have_$applet
259 if [ -z "$have" ]; then
260 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
261 if [ "$have" = 0 ]; then
262 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
265 eval busybox_have_$applet=$have
268 if [ $err = 1 ]; then
273 # extract-ikconfig - Extract the .config file from a kernel image
275 # The obscure use of the "tr" filter is to work around older versions of
276 # "grep" that report the byte offset of the line instead of the pattern.
278 # (c) 2009, Dick Streefland <dick@streefland.net>
279 # Licensed under the terms of the GNU General Public License.
281 # Ripped and adjusted for geninitrd from linux-2.6.34/scripts/extract-ikconfig
284 local kofile=$(modinfo -k $kernel -n configs)
290 gzip -dc "$kofile" > $img
297 local cf1='IKCFG_ST\037\213\010'
298 local cf2='0123456789'
301 if pos=$(tr "$cf1\n$cf2" "\n$cf2=" < "$img" | grep -abo "^$cf2"); then
303 tail -c+$(($pos+8)) "$img" | gzip -dcq
308 # Finds module dependencies
312 # Outputs full path to module and it's dependencies
317 # if module is prefixed with dash, we should ignore errors if the module
319 if [ ${module#-} != $module ]; then
324 # This works when user has module-init-tools installed even on 2.4 kernels
326 modprobe=$(modprobe --set-version $kernel --show-depends $module --ignore-install 2>&1)
329 if [ $skiperrors = 1 ]; then
334 if ! is_no "$EXIT_IF_MISSING"; then
335 die "$module: module not found for $kernel kernel"
338 warn "$module: module not found for $kernel kernel"
339 warn "If $module isn't compiled in kernel then this initrd may not start your system."
343 while read insmod modpath options; do
344 [ "$insmod" = "insmod" ] && echo $modpath
351 # no firmware support in 2.4 kernels
352 if [ "$kernel_version_long" -lt "002005048" ]; then
355 echo -n $(NEW_MODINFO=1 modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
360 local mod depmod module=$1
362 depmod=$(find_depmod $module) || exit 1
363 for mod in $depmod; do
364 mod=${mod#/lib/modules/$kernel/}
366 # add each module only once
368 for m in $MODULES; do
369 [ $m = $mod ] && have=1
371 if [ $have = 0 ]; then
372 MODULES="$MODULES $mod"
377 # install a file to temporary mount image.
378 # it will operate recursively (copying directories)
379 # and will symlink destinations if source is symlink.
381 if [ $# -lt 2 ]; then
382 die 'Usage: inst <file> [<file>] <destination>'
385 local src i=0 c=$(($# - 1))
386 while [ $i -lt $c ]; do
393 parentDir=$(dirname $DESTDIR$dest)
394 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
395 debug "+ cp $* $DESTDIR$dest"
396 cp -HR "$@" "$DESTDIR$dest"
401 die 'Usage: inst_d <destination> <destination>'
404 install -d "$DESTDIR$dir"
408 # install executable and it's shared libraries
410 if [ $# -lt 2 ]; then
411 die "Invalid params ($@), Usage: inst_exec <file>[, <file>] <destination>"
413 local src i=0 c=$(($# - 1))
414 while [ $i -lt $c ]; do
424 local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
426 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
428 inst_exec $lib /$_lib
432 # hack for uclibc linked binaries requiring this fixed path
433 # XXX: shouldn't rpath be used here instead so th
434 if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
435 local lib=$DESTDIR/$_lib/libc.so.0
436 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
437 local libdir=$(cd $(dirname "$lib"); pwd)
438 if [ ! -e $DESTDIR$libdir ]; then
439 libdir=$(dirname "$libdir")
441 debug "+ ln -s /$_lib $DESTDIR$libdir"
442 ln -s /$_lib $DESTDIR$libdir
447 # output modules.conf / modprobe.conf
449 echo "$modprobe_conf_cache"
453 # defaults to modprobe -c if not told otherwise, this means include statements
455 cache_modprobe_conf() {
456 if [ "$kernel_version" -lt "002005" ]; then
457 modulefile=/etc/modules.conf
458 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
459 modulefile=/etc/conf.modules
463 if [ -n "$modulefile" ]; then
464 debug "Using $modulefile for modules config"
465 modprobe_conf_cache=$(cat $modulefile)
467 debug "Using modprobe -c to get modules config"
468 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
472 # find modules for $devpath
473 find_modules_for_devpath() {
475 if [ -z "$devpath" ]; then
476 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
479 if [[ "$devpath" = /dev/dm-* ]]; then
480 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
481 devpath=$(dm_longname "$devpath")
484 if [ -L "$devpath" ] && ! is_lvm "$devpath"; then
485 # sanitize things like:
486 # /dev/block/104:2 -> /dev/cciss/c0d0p2
487 devpath=$(readlink -f "$devpath")
490 debug "Finding modules for device path $devpath"
492 if is_luks "$devpath"; then
493 find_modules_luks "$devpath"
497 if is_nfs "$devpath"; then
498 find_modules_nfs "$devpath"
502 if is_md "$devpath"; then
503 find_modules_md "$devpath"
507 if is_multipath "$devpath"; then
508 if find_modules_multipath "$devpath"; then
515 if is_dmraid "$devpath"; then
516 if find_modules_dmraid "$devpath"; then
522 if is_scsi "$devpath"; then
523 find_modules_scsi "$devpath"
527 if is_ide "$devpath"; then
528 find_modules_ide "$devpath"
532 if [[ "$devpath" == /dev/rd/* ]]; then
538 if [[ "$devpath" == /dev/ida/* ]]; then
539 find_module "cpqarray"
540 rootdev_add=/dev/ida/
544 if [[ "$devpath" == /dev/cciss/* ]]; then
546 rootdev_add=/dev/cciss/
550 if [[ "$devpath" == /dev/ataraid/* ]]; then
552 find_module "ataraid"
553 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
554 if [ -n "$ataraidmodules" ]; then
555 # FIXME: think about modules compiled in kernel
556 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
558 for n in $ataraidmodules; do
561 rootdev_add=/dev/ataraid/
565 # check to see if we need to set up a loopback filesystem
566 if [[ "$devpath" == /dev/loop* ]]; then
567 die "Sorry, root on loop device isn't supported."
568 # TODO: rewrite for bsp and make nfs ready
569 if [ ! -x /sbin/losetup ]; then
570 die "losetup is missing"
572 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
573 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
574 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"
577 line="`awk '/'$key'/ { print $0; }' $fstab`"
578 loopDev="$(echo $line | awk '{print $3}')"
579 loopFs="$(echo $line | awk '{print $4}')"
580 loopFile="$(echo $line | awk '{print $5}')"
582 BASICMODULES="$BASICMODULES -loop"
583 find_module "-$loopFs"
584 BASICMODULES="$BASICMODULES -${loopFs}"
588 if is_lvm "$devpath"; then
589 find_modules_lvm "$devpath"
594 firmware_install_module() {
596 local firmware_files="$2"
598 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
599 # firmware not yet installed
600 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
602 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
604 echo 1 > /sys$DEVPATH/loading
605 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
606 echo 0 > /sys$DEVPATH/loading
609 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
612 for firmware in $firmware_files; do
613 if [ -f "/lib/firmware/$kernel/$firmware" ]; then
614 FIRMWAREDIR=${firmware%/*}
615 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
616 inst /lib/firmware/$kernel/$firmware /lib/firmware/$firmware
617 elif [ -f "/lib/firmware/$firmware" ]; then
618 FIRMWAREDIR=${firmware%/*}
619 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
620 inst /lib/firmware/$firmware /lib/firmware/$firmware
622 die "firmware file /lib/firmware/$firmware nor /lib/firmware/$kernel/$firmware found."
627 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
634 for mod in $modules; do
636 inst_d "/lib/modules/$kernel/$MODULEDIR"
637 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
638 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
642 modules_add_linuxrc() {
646 # module path without optional compression
650 local module=${modpath##*/}; module=${module%$modext}
651 local options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
652 local genericname=$(echo $module | tr - _)
653 local usleep=$(eval echo \$MODULE_${genericname}_USLEEP)
654 local firmware=$(eval echo \$MODULE_${genericname}_FIRMWARE)
656 if [ "$module" = "scsi_mod" -a "$kernel_version_long" -ge "002006030" ]; then
657 options="scan=sync $options"
660 if [ -n "$verbose" ]; then
662 if [ "$options" ]; then
663 s="$s with options [$options]"
665 if [ "$usleep" ]; then
666 s="$s and $usleep usleep"
668 debug "Loading module [$module]$s"
671 if [ -n "$firmware" ]; then
672 firmware_install_module "$module" "$firmware"
674 for file in $(find_firmware "$module"); do
675 firmware_install_module "$module" "$file"
679 echo "insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
680 if [ -n "$usleep" ]; then
681 echo "usleep $usleep" | add_linuxrc
683 if [ "$module" = "scsi_wait_scan" ]; then
684 if [ "$(busybox_applet rmmod 2>/dev/null; echo $?)" = 0 ]; then
685 echo "rmmod scsi_wait_scan" | add_linuxrc
692 # Generates /dev nodes based on /proc/partitions information.
693 # Needs /proc mounted.
694 # Can be called multiple times.
695 initrd_gen_devices() {
696 if is_yes "$proc_partitions"; then
703 : 'Making device nodes'
704 cat /proc/partitions | (
705 # ignore first two lines: header, empty line
708 while read major minor blocks dev rest; do
711 [ -e $node ] || mknod $node b $major $minor
718 initrd_gen_setrootdev() {
719 debug "Adding rootfs finding based on kernel cmdline root= option support."
721 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
722 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
723 if [ -n "$rootnr" ]; then
724 echo "$rootnr" > /proc/sys/kernel/real-root-dev
730 initrd_gen_initramfs_switchroot() {
732 if [ "$rootdev" = "/dev/nfs" ]; then
733 echo "rootfs on NFS root=/dev/nfs"
735 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
738 # parse 'root=xxx' kernel commandline
739 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
741 device=/dev/no_partition_found
742 eval "$(busybox awk -v c="$ROOT" '
744 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
745 num_pattern = "[0-9a-f]" num_pattern_short;
746 dev_pattern = "[hms][a-z][a-z]([0-9])+";
747 partition = "no_partition_found";
751 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
752 if (c ~ "^" num_pattern "$") {
753 maj = sprintf("%s",substr(c,1,2));
754 min = sprintf("%s",substr(c,3));
756 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
757 if (c ~ "^" dev_pattern "$") partition = c;
760 $4 ~ partition { maj = $1; min = $2; }
761 $1 ~ maj && $2 ~ min { partition = $4; }
764 if (maj >= 0 && min >= 0) {
765 printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
769 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
770 mknod $device b $maj $min
780 if [ "$device" = '/dev/no_partition_found' ]; then
784 mount -t $rootfs -r $device /newroot
785 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
786 if [ -z "$init" -o ! -x "/newroot$init" ]; then
792 busybox_applet switch_root
794 exec switch_root /newroot $init ${1:+"$@"}
796 echo "Error! initramfs should not reach this place."
797 echo "It probably means you've got old version of busybox, with broken"
798 echo "initramfs support. Trying to boot anyway, but won't promise anything."
800 exec chroot /newroot $init ${1:+"$@"}
802 echo "Failed to chroot!"
804 # we need /init being real file, not symlink, otherwise the initramfs will
805 # not be ran by pid 1 which is required for switch_root
806 mv $DESTDIR/linuxrc $DESTDIR/init
807 ln -s init $DESTDIR/linuxrc
810 # find if $symbol exists in System.map $mapfile
814 if [ ! -f $mapfile ]; then
815 # missing mapfile (not a pld kernel?)
819 awk -vc=1 -vsymbol="$symbol" '$2 == "T" && $3 == symbol {c = 0} END {exit c}' $mapfile
822 # find best compressor (or forced one) for initrd
825 # the best compressor list
826 local compressors='xz lzma bzip2 gzip'
828 # a specified one, take it
829 if ! is_yes "$mode"; then
833 debug "finding compressor: $compressors (via $mode)"
834 # check for compressor validity
835 local c prog map=/boot/System.map-$kernel
836 for c in $compressors; do
855 die "Unknown compressor $c"
858 if sym_exists $map $sym && [ -x $prog ]; then
864 debug "using gzip for compressor (fallback)"
868 if [ -r /etc/sysconfig/geninitrd ]; then
869 . /etc/sysconfig/geninitrd
872 if [ ! -f /proc/mounts ]; then
873 warn "/proc filesystem not mounted, may cause wrong results or failure."
876 geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs scsi
878 while [ $# -gt 0 ]; do
888 modulefile=${1#--modules-conf=}
897 --without-bootsplash)
909 --without-fbcondecor)
918 --with-suspend2 | --with-tuxonice)
921 --without-suspend2 | --without-tuxonice)
925 LVMTOOLSVERSION=${1#--lvmversion=}
928 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
930 --lvmtoolsversion|--lvmversion)
947 USE_MULTIPATH=${1#--with-multipath=}
956 BASICMODULES="$BASICMODULES ${1#--with=}"
959 BASICMODULES="$BASICMODULES $2"
963 echo "$PROGRAM: version $VERSION"
973 COMPRESS="${1#--compress=}"
985 PREMODS="$PREMODS ${1#--preload=}"
988 PREMODS="$PREMODS $2"
992 die "--fs option is obsoleted. Use --initrdfs instead"
995 INITRDFS=${1#--initrdfs=}
1008 if [ -z "$target" ]; then
1010 elif [ -z "$kernel" ]; then
1022 if [ -z "$target" -o -z "$kernel" ]; then
1028 if [ "$(id -u)" != 0 ]; then
1029 die "You need to be root to generate initrd"
1032 if [ -d /lib64 -a -d /usr/lib64 ]; then
1038 initrd_dir=/usr/$_lib/initrd
1039 kernel_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1040 kernel_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
1043 debug "Using _lib: $_lib"
1044 debug "Using initrd_dir: $initrd_dir"
1046 busybox=$(find_tool $initrd_dir/busybox $initrd_dir/initrd-busybox /bin/initrd-busybox) || die "Couldn't find busybox suitable for initrd"
1048 # we setup mods after parsing command line args
1049 geninitrd_setup_mods
1051 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1052 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1055 if [ -z "$INITRDFS" ]; then
1056 if [ -n "$FS" ]; then
1057 # FS= can came only via /etc/sysconfig/geninitrd likely?
1058 die "FS configuration option is obsoleted. Use INITRDFS instead"
1062 if [ "$kernel_version" -ge "002005" ]; then
1063 INITRDFS="initramfs"
1071 [ -x /sbin/mke2fs ] || die "/sbin/mke2fs is missing"
1074 [ -x /sbin/genromfs ] || die "/sbin/genromfs is missing"
1077 [ -x /sbin/mkcramfs ] || die "/sbin/mkcramfs is missing"
1080 [ -x /bin/cpio ] || die "/bin/cpio is missing"
1081 [ -x /usr/bin/find ] || die "/usr/bin/find is missing"
1084 die "Filesystem $INITRDFS on initrd is not supported"
1088 if [ -L "$target" ]; then
1089 target=$(readlink -f "$target")
1092 if [ -n "$img_vers" ]; then
1093 target="$target-$kernel"
1096 if [ -z "$force" -a -f "$target" ]; then
1097 die "$target already exists."
1100 if [ ! -d "/lib/modules/$kernel" ]; then
1101 die "/lib/modules/$kernel is not a directory."
1104 if [ "$kernel_version" -ge "002005" ]; then
1110 for n in $PREMODS; do
1114 if [ "$FBMODULE" ]; then
1115 find_module "$FBMODULE"
1118 # allow forcing loading SCSI and/or IDE modules
1119 # XXX: where ADDSCSI cames from? drop?
1120 if is_yes "$ADDSCSI"; then
1124 # autodetect XATA modules
1127 # XXX: where ADDIDE cames from? drop?
1128 if is_yes "$ADDIDE"; then
1132 if is_yes "$USE_SUSPEND"; then
1133 find_modules_suspend
1136 find_root "$fstab" || exit
1137 debug "Using $rootdev as device for rootfs"
1139 find_modules_for_devpath "$rootdev"
1141 # if USE_MULTIPATH is path to device, scan that too
1142 # this is to bootstrap multipath setup into initrd.
1143 if ! is_no "$USE_MULTIPATH" && ! is_yes "$USE_MULTIPATH"; then
1144 find_modules_multipath $USE_MULTIPATH
1147 find_module "-$rootFs"
1149 for n in $BASICMODULES; do
1153 if is_yes "$USE_TUXONICE"; then
1157 find_modules_fbsplash
1159 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1160 debug "No modules are needed -- not building initrd image."
1164 debug "Building initrd..."
1165 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
1166 RCFILE="$DESTDIR/linuxrc"
1168 chmod a+rx "$RCFILE"
1169 ln -s linuxrc $DESTDIR/init
1171 # create dirs that we really need
1172 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
1174 modules_install "$MODULES"
1176 # mknod'ing the devices instead of copying them works both with and
1178 mknod "$DESTDIR/dev/console" c 5 1
1179 mknod "$DESTDIR/dev/null" c 1 3
1180 mknod "$DESTDIR/dev/zero" c 1 5
1181 mknod "$DESTDIR/dev/urandom" c 1 9
1183 inst_exec $busybox /bin/busybox
1184 ln -s busybox $DESTDIR/bin/sh
1185 # for older busyboxes who had /bin/initrd-busybox as EXEPATH
1186 ln -s busybox $DESTDIR/bin/initrd-busybox
1190 # initrd generated by:
1195 add_linuxrc <<-'EOF'
1196 read CMDLINE < /proc/cmdline; export CMDLINE
1198 for arg in $CMDLINE; do
1199 if [ "${arg}" = "debuginitrd" ]; then
1202 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1203 DEBUGINITRD=${arg##debuginitrd=}
1205 if [ "${arg##root=}" != "${arg}" ]; then
1210 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1211 if [ "$DEBUGINITRD" = "sh" ]; then
1214 if is_yes "$RUN_SULOGIN_ON_ERR"; then
1215 add_linuxrc <<-'EOF'
1216 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1219 add_linuxrc <<-'EOF'
1223 add_linuxrc <<-'EOF'
1231 if [ "$DEBUGINITRD" ]; then
1236 modules_add_linuxrc $MODULES
1238 # TODO: rewrite for busybox
1239 #if [ -n "$loopDev" ]; then
1240 # if [ ! -d /initrd ]; then
1244 # cp -a "$loopDev" "$DESTDIR/dev"
1245 # cp -a "$rootdev" "$DESTDIR/dev"
1246 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1247 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1248 # echo "echo Setting up loopback device $rootdev" >> $RCFILE
1249 # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1252 if is_yes "$USE_UDEV"; then
1256 if is_yes "$USE_TUXONICE"; then
1260 find_modules_uvesafb
1263 if is_yes "$have_luks"; then
1267 if is_yes "$have_dmraid"; then
1271 if is_yes "$have_multipath"; then
1272 initrd_gen_multipath
1275 if is_yes "$USE_BLKID"; then
1279 if is_yes "$have_nfs"; then
1281 elif is_yes "$have_md"; then
1283 if is_yes "$have_lvm"; then
1286 initrd_gen_setrootdev
1288 elif is_yes "$have_lvm"; then
1291 initrd_gen_setrootdev
1294 if is_yes "$USE_SUSPEND"; then
1298 # additional devs always needed
1299 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
1301 if is_yes "$USE_UDEV"; then
1302 initrd_gen_stop_udevd
1305 if [ "$INITRDFS" = "initramfs" ]; then
1306 initrd_gen_initramfs_switchroot
1311 if is_yes "$FB_SPLASH"; then
1315 if is_yes "$FB_CON_DECOR"; then
1316 initrd_gen_fbcondecor
1319 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
1321 debug "Creating $INITRDFS image $IMAGE"
1324 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1325 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1326 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1328 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
1329 debug "Mounting ext2 image $IMAGE to $tmpmnt"
1330 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1331 # We don't need this directory, so let's save space
1332 rm -rf "$tmpmnt"/lost+found
1334 debug "Copy recursively $DESTDIR -> $tmpmnt"
1335 cp -a $DESTDIR/* $tmpmnt
1341 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
1344 mkcramfs "$DESTDIR" "$IMAGE"
1347 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
1350 die "Filesystem $INITRDFS not supported by $PROGRAM"
1353 CONFIG_BLK_DEV_RAM_SIZE=$(extract-ikconfig | awk -F= '/^CONFIG_BLK_DEV_RAM_SIZE/{print $2}')
1354 if [ -z "$CONFIG_BLK_DEV_RAM_SIZE" ]; then
1355 CONFIG_BLK_DEV_RAM_SIZE=4096
1358 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
1359 debug "image size: $IMAGESIZE KiB ($DESTDIR)"
1360 if [ "$IMAGESIZE" -gt $CONFIG_BLK_DEV_RAM_SIZE ]; then
1361 warn "Your image size is larger than $CONFIG_BLK_DEV_RAM_SIZE, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1364 if ! is_no "$COMPRESS"; then
1365 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
1366 compressor=$(find_compressor "$COMPRESS")
1367 debug "Compressing $target with $compressor"
1369 # TODO: the image name (specified from kernel.spec) already contains
1370 # extension, which is .gz most of the time.
1371 case "$compressor" in
1373 # don't use -9 here since kernel won't understand it
1374 xz --format=xz --check=crc32 --lzma2=preset=6e,dict=1MiB < "$IMAGE" > "$tmp"
1377 xz --format=lzma -9 < "$IMAGE" > "$tmp"
1380 bzip2 -9 < "$IMAGE" > "$tmp"
1383 gzip -9 < "$IMAGE" > "$tmp"
1386 mv -f "$tmp" "$target"
1388 cp -a "$IMAGE" "$target"
1391 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
1392 if is_yes "$BOOT_SPLASH"; then
1393 initrd_gen_bootsplash "$target"
1396 rm -rf "$DESTDIR" "$IMAGE"
1398 # vim:ts=4:sw=4:noet:fdm=marker