5 # by Jacek Konieczny <jajcus@pld-linux.org>
7 # based on mkinitrd from RedHat
13 VERSION="`echo "$RCSID"|awk '{print $3}'`"
15 . /etc/rc.d/init.d/functions
18 # INITRDFS is set later (catch obsoleted FS option)
27 # it should be safe to remove scsi_mod from here, but I'm not sure...
28 PRESCSIMODS="-scsi_mod unknown -sd_mod"
29 PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
30 PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
42 # default bootsplash is off, if it have to be on, install bootsplash package
45 # is /dev on tmpfs. internal variable
48 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udev ]; then
53 if [ -x /sbin/dmraid-initrd ]; then
58 echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
59 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
60 echo " [--initrdfs=rom|ext2|cram] [--modules-conf=<modules.conf>]"
61 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
62 echo " [--without-bootsplash] [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
63 echo " [--without-suspend] [--without-suspend2] [--without-dmraid]"
64 echo " <initrd-image> <kernel-version>"
65 echo " (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)"
71 typeset mods module f level depfile first
73 depfile=/lib/modules/$kernel/modules.dep
75 if [ -f $depfile ] ; then
78 echo "Error: no $depfile ! Run depmod and rerun geninitrd." 1>&2
82 # prepend / if no path given, append $modext.gz if not given,
85 module=$(echo "$2" | \
86 awk '/\// {print;next} {print "/" $0}' | \
87 awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
88 awk '{gsub("/","\\/");print}')
91 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
93 /(.*)/ { gsub(/\\/," "); if (here) print }
97 if [ "$mods" = "" ] ; then
98 module=$(echo "$module" | \
99 awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
103 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
105 /(.*)/ { gsub(/\\/," "); if (here) print }
108 if [ "$mods" = "" ] ; then
109 if [ "$1" != silent ] ; then
110 echo "$origmodule: module not found in $depfile" 1>&2
112 if ! is_no "$EXIT_IF_MISSING" ; then
115 echo "If $origmodule isn't compiled in kernel then this initrd may not start your system". 1>&2
120 if [ "$level" = "" ] ; then
123 level=$(awk "BEGIN{print $level + 1}")
124 if [ $level -gt 20 ] ; then
125 echo "$origmodule: cycle in $depfile" 1>&2
131 if [ "$first" = "" ] ; then
134 find_depmod $1 $f $level
145 if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
146 if [ -n "$skiperrors" ]; then
150 echo "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" 1>&2
154 # only need to add each module once
156 tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
157 if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
158 MODULES="$MODULES $fmPath"
166 if [ "$(echo $modName | awk '{print(substr($0,1,1));}')" = "-" ]; then
168 modName="$(echo $modName | awk '{print(substr($0,2));}')"
172 if [ "$modName" = "pluto" ]; then
176 if [ "$modName" = "fcal" ]; then
181 if [ -n "$skiperrors" ]; then
182 allModulesToFind=`find_depmod silent $modName`
184 allModulesToFind=`find_depmod normal $modName`
185 if [ $? != 0 ] ; then
190 for mod in $allModulesToFind ; do
191 mod=$(echo $mod | awk '{sub(/^\/lib\/modules\/[^\/]*\//,"");print}')
192 addmodule $mod "$skiperrors"
197 if [ "$#" != "2" ];then
198 echo "usage: inst <file> <destination>"
201 [ -n "$verbose" ] && echo "$1 -> $2"
206 /sbin/e2label $1 2> /dev/null
210 /sbin/tune2fs -l $1 2> /dev/null | awk -F: '/UUID:/ {gsub(" ",""); print $2}'
214 /usr/sbin/xfs_db -x -p xfs_admin -c label -r "$1"|awk -F= '{sub("^\"","", $2); sub("\"$", "", $2); print $2}'
219 /usr/sbin/xfs_admin -u "$1" 2>/dev/null | awk -F= '{print $2}' | xargs
223 eval `awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab`
226 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
227 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
228 if [ -n "$rootdev2" ] ; then
233 if [ "$rootdev_found." != "1." ] ; then
236 if [ ! -x /sbin/e2label ] ; then
237 echo "/sbin/e2label is missing" 1>&2
240 get_label="get_label_ext2"
243 if [ ! -x /usr/sbin/xfs_db ] ; then
244 echo "/usr/sbin/xfs_db is missing" 1>&2
247 get_label="get_label_xfs"
250 echo "LABEL on $rootFs in not supported by geninitrd" 1>&2
254 if [ ! -r /proc/partitions ] ; then
255 echo '/proc/partitions is not readable'; 1>&2
258 label=${rootdev#"LABEL="}
259 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
260 if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
261 if [ -n "$verbose" ] ; then
262 echo "Using $dev as device for rootfs"
269 if [ "$rootdev_found." != "1." ] ; then
270 echo "geninitrd can't find real device for LABEL=$label" 1>&2
276 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
277 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
278 if [ -n "$rootdev2" ] ; then
283 if [ "$rootdev_found." != "1." ] ; then
286 if [ ! -x /sbin/tune2fs ] ; then
287 echo "/sbin/tune2fs is missing" 1>&2
290 get_uuid="get_uuid_ext2"
293 if [ ! -x /usr/sbin/xfs_db ] ; then
294 echo "/usr/sbin/xfs_db is missing" 1>&2
297 get_uuid="get_uuid_xfs"
300 echo "UUID on $rootFs in not supported by geninitrd" 1>&2
304 if [ ! -r /proc/partitions ] ; then
305 echo '/proc/partitions is not readable'; 1>&2
308 uuid=${rootdev#"UUID="}
309 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
310 if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
311 if [ -n "$verbose" ] ; then
312 echo "Using $dev as device for rootfs"
319 if [ "$rootdev_found" != 1 ] ; then
320 echo "geninitrd can't find real device for UUID=$uuid" 1>&2
329 find_modules_softraid() {
330 if [ -f /etc/mdadm.conf ]; then
331 [ -n "$verbose" ] && echo "Finding RAID details using mdadm for rootdev=$1"
332 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
337 rootdev_devfs = rootdev;
338 if (rootdev ~ /\/dev\/md\/[0-9]/) {
339 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
344 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
346 gsub(/level=/,NUL,raidlevel);
347 if (raidlevel ~ /^raid([0-6]|10)/) {
348 gsub(/raid/,NUL,raidlevel);
352 if (x ~ /devices=/) {
354 gsub(".*devices=", NUL, dev_list);
355 gsub(",", " ", dev_list);
361 print "raidfound=" found;
362 print "raidlevel=" raidlevel;
363 print "dev_list=\"" dev_list "\"";
367 if [ "$raidfound" != "yes" -a -f /etc/raidtab ]; then
368 echo "ERROR: raidtools are not longer supported. Please migrate to mdadm setup!" 1>&2
372 if is_yes "$raidfound" ; then
375 findmodule "raid$raidlevel"
381 echo "raid level $number (in mdadm config) not recognized" 1>&2
385 echo "ERROR: RAID devices not found for \"$1\", check your configuration!" 1>&2
389 rootdev_nr=$(( $rootdev_nr + 1 ))
390 eval "rootdev${rootdev_nr}=\"$1\""
391 eval "dev_list${rootdev_nr}=\"${dev_list}\""
393 for device in $dev_list; do
394 find_modules_for $device
398 find_modules_scsi() {
399 for n in $PRESCSIMODS; do
400 if [ "X$n" = "Xunknown" ] ; then
401 if [ -f "$modulefile" ]; then
402 scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
403 for n in $scsimodules; do
404 # for now allow scsi modules to come from anywhere. There are some
405 # RAID controllers with drivers in block
418 rootdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')"
419 if [ "$pack_version_long" -lt "002004021" ]; then
420 [ -n "$verbose" ] && echo "Finding IDE modules for kernels <= 2.4.20"
421 for n in $PREIDEMODSOLD; do
426 for n in $PREIDEMODS; do
427 if [ "X$n" = "Xunknown" ] ; then
428 if [ -f "$modulefile" ]; then
429 [ -n "$verbose" ] && echo "Finding IDE modules using ide_hostadapter"
430 idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
431 for na in $idemodules; do
437 if [ "$tryauto" -eq 1 ]; then
439 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
440 [ -n "$verbose" ] && echo "Finding IDE modules using PCI ID database"
441 # Finding IDE modules using PCI ID database {{{
442 if is_yes "${ide_only_root}"; then
443 if [ -f /sys/block/${rootdev}/device/../../vendor -a -f /sys/block/${rootdev}/device/../../device ]; then
444 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../vendor)"
445 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../device)"
446 searchpciid="${vendorid}${deviceid}"
447 elif [ -f /proc/ide/${rootdev}/../config ]; then
448 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootdev}/../config)"
452 if [ -z "${searchpciid}" ]; then
453 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
458 for nb in $searchpciid; do
459 eval `awk -v pciid="$nb" '{
465 compmod = $1 ""; # make sure comparison type will be string
466 # cause pci IDs are hexadecimal numeric
467 if (compmod == pciid) {
469 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
476 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
477 }' /usr/share/pci-database/ide.pci`
478 [ -n "$module" ] && idemodules="$idemodules $module"
480 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
482 for nc in idemodules; do
483 new_idemodules="$nc $new_idemodules"
485 idemodules="${new_idemodules}"
488 if [ -z "$idemodules" ]; then
489 echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic."
490 idemodules="ide-generic"
494 for nd in $idemodules; do
500 [ -r /usr/share/pci-database/ide.pci ] || echo "WARNING: /usr/share/pci-database/ide.pci missing."
501 [ -r /proc/bus/pci/devices ] || echo "WARNING: /proc/bus/pci/devices missing."
502 echo "Automatic IDE modules finding not available."
513 # return true if node is lvm node
516 if [ ! -e "$node" ]; then
517 echo "WARNING: check_lvm(): node $node doesn't exists!" 1>&2
521 # block-major-58 is lvm1
522 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
526 [ -n "$verbose" ] && echo "$node is LVM1 node"
531 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
533 if [ $rc -gt 127 ]; then
534 # lvdisplay terminated by signal! most likely it segfaulted.
535 echo >&2 "ERROR: Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
540 [ -n "$verbose" ] && echo "$node is lvm2 node"
542 [ -n "$verbose" ] && echo "$node is not any lvm node"
549 echo "ERROR: no argument passed to find_modules_for() - is your /etc/fstab correct?" >&2
552 elif is_yes "`echo "$1" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
553 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then
554 echo "ERROR: root on NFS but /usr/bin/pcidev not found." >&2
555 echo "Please install correct pci-database package and rerun $0." >&2
558 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
559 for m in $NFS_ETH_MODULES; do
565 echo "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel" >&2
566 echo "or you will have problems like init(xx) being child process of swapper(1)." >&2
567 elif is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
568 find_modules_softraid "$1"
569 elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
571 elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
572 find_modules_ide "$1"
573 elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
575 elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
576 findmodule "cpqarray"
577 elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
579 elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
582 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
583 if -n "$ataraidmodules" ; then
584 # FIXME: think about modules compiled in kernel
585 echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
586 echo "Please set it and run $0 again."
589 for n in $ataraidmodules; do
592 # check to see if we need to set up a loopback filesystem
593 elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
594 echo "Sorry, root on loop device isn't supported." 1>&2
596 # TODO: rewrite for bsp and make nfs ready
597 if [ ! -x /sbin/losetup ]; then
598 echo "losetup is missing"
601 key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
602 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
603 echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
604 echo "for this device. Consult the geninitrd man page for more information" 1>&2
608 line="`awk '/'$key'/ { print $0; }' $fstab`"
609 loopDev="$(echo $line | awk '{print $3}')"
610 loopFs="$(echo $line | awk '{print $4}')"
611 loopFile="$(echo $line | awk '{print $5}')"
613 BASICMODULES="$BASICMODULES -loop"
614 findmodule "-$loopFs"
615 BASICMODULES="$BASICMODULES -${loopFs}"
616 elif _check_lvm "$1"; then
617 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then
618 echo "ERROR: root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found." >&2
619 echo "Please install lvm(2) and lvm(2)-initrd package and rerun $0." >&2
622 if [ -z "$LVMTOOLSVERSION" ] ; then
623 LVMTOOLSVERSION=$(/sbin/initrd-lvm vgchange --version 2>/dev/null|head -n 1|awk '{gsub("vgchange: Logical Volume Manager ",NIL); gsub("LVM version: ",NIL); gsub(/\..*/,NIL); print $1}')
624 if [ -z "$LVMTOOLSVERSION" ] ; then
625 echo "ERROR: Can't determine LVM tools version. Please set LVMTOOLSVERSION" >&2
626 echo "and rerun $0." >&2
630 if [ -z "$PVDEVICES" ] ; then
631 VGVOLUME=$(/sbin/lvdisplay -c "$1" 2> /dev/null | awk -F":" ' { print $2 } ')
632 PVDEVICES=$(/sbin/pvdisplay -c | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
634 if [ -n "$PVDEVICES" ] ; then
635 for device in $PVDEVICES; do
636 find_modules_for $device
639 echo "ERROR: I wasn't able to find PV (via lvdisplay and pvdisplay)." >&2
640 echo "You can try to set PVDEVICES in /etc/sysconfig/geninitrd." >&2
643 if [ "$LVMTOOLSVERSION" = "2" ]; then
645 elif [ "$LVMTOOLSVERSION" = "1" ]; then
647 findmodule "-lvm-mod"
649 echo "ERROR: LVM version $LVMTOOLSVERSION is not supported yet." >&2
652 [ -n "$verbose" ] && echo "LVM $LVMTOOLSVERSION enabled"
657 firmware_install_module_pre() {
662 [ -n "$verbose" ] && echo "Adding Firmwares ($firmware_files) to initrd for module $module"
663 mkdir -p $MNTIMAGE/proc
664 mkdir -p $MNTIMAGE/sys
665 # firmware not yet installed
666 if [ ! -f "$MNTIMAGE/lib/firmware/firmware.sh" ]; then
667 mkdir -p $MNTIMAGE/lib/firmware
668 cat << 'EOF' >> "$MNTIMAGE/lib/firmware/firmware.sh"
670 echo 1 > /sys$DEVPATH/loading
671 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
672 echo 0 > /sys$DEVPATH/loading
675 chmod 755 "$MNTIMAGE/lib/firmware/firmware.sh"
678 for firmware in $firmware_files; do
679 inst "/lib/firmware/$firmware" "$MNTIMAGE/lib/firmware/$firmware"
682 echo "mount -t proc none /proc" >> "$linuxrc"
683 echo "mount -t sysfs none /sys" >> "$linuxrc"
684 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" >> "$linuxrc"
687 firmware_install_module_post() {
691 echo "umount /sys" >> "$linuxrc"
692 echo "umount /proc" >> "$linuxrc"
698 for mod in $modules; do
699 MODULEDIR="`dirname "$mod"`"
700 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
701 cp -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
702 gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
706 modules_add_linuxrc() {
710 for mod in $modules; do
711 MODULE2="`dirname "$mod"`"
712 NAME2=`basename "$mod" .gz`
713 MODULE2=$MODULE2/$NAME2
714 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
715 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
717 generic_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ')
718 sleep_var="$(eval echo \$MODULE_${generic_module}_USLEEP)"
719 firmware_var="$(eval echo \$MODULE_${generic_module}_FIRMWARE)"
721 if [ -n "$verbose" ]; then
722 echo -n "Loading module [$module] "
723 if [ -n "$options" ] ; then
724 echo -n "with options [$options]"
726 echo -n "without options"
728 if [ -n "$sleep_var" ]; then
729 echo " and $sleep_var usleep."
735 if [ -n "$firmware_var" ]; then
736 firmware_install_module_pre "$module" "$linuxrc" "$firmware_var"
738 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
739 if [ -n "${sleep_var}" ]; then
740 echo "usleep $sleep_var" >> "$linuxrc"
742 if [ -n "$firmware_var" ]; then
743 firmware_install_module_post "$module" "$linuxrc" "$firmware_var"
748 if [ -r /etc/sysconfig/geninitrd ] ; then
749 . /etc/sysconfig/geninitrd
752 if [ -r /etc/sysconfig/bootsplash ] ; then
753 . /etc/sysconfig/bootsplash
756 if [ ! -x /bin/initrd-busybox ] ; then
757 echo "/bin/initrd-busybox is missing !"
761 while [ $# -gt 0 ]; do
764 fstab="`echo $1 | awk -F= '{print $2;}'`"
771 modulefile="`echo $1 | awk -F= '{print $2;}'`"
777 --use-raidstart|--with-raidstart)
783 --use-insmod-static|--with-insmod-static)
784 USEINSMODSTATIC="yes"
786 --without-insmod-static)
789 --without-bootsplash)
798 --lvmtoolsversion=|--lvmversion=)
799 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
801 --lvmtoolsversion|--lvmversion)
815 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
818 BASICMODULES="$BASICMODULES $2"
822 echo "geninitrd: version $VERSION"
838 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
841 PREMODS="$PREMODS $2"
845 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
846 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
849 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
854 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
867 if [ -z "$target" ]; then
869 elif [ -z "$kernel" ]; then
880 if [ -z "$target" -o -z "$kernel" ]; then
884 pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
885 pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
887 if [ "x" = "x$INITRDFS" ] ; then
888 if [ "x" = "x$FS" ] ; then
890 # XXX: initramfs blocked for now
891 if [ "1" = " 0" -a "$pack_version" -ge "002005" ] ; then
897 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
902 if [ "$pack_version" -lt "002006" ] ; then
907 if [ "$pack_version" -ge "002005" ] ; then
912 if is_yes "$USEINSMODSTATIC" ; then
913 insmod="insmod.static"
914 INSMOD="/sbin/insmod.static"
915 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
916 INSMOD="/sbin/insmod.static.modutils"
918 if [ ! -f "$INSMOD" ] ; then
919 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
926 if [ ! -x /sbin/mke2fs ]; then
927 echo "/sbin/mke2fs is missing" 1>&2
932 if [ ! -x /sbin/genromfs ]; then
933 echo "/sbin/genromfs is missing" 1>&2
938 if [ ! -x /sbin/mkcramfs ]; then
939 echo "/sbin/mkcramfs is missing" 1>&2
944 if [ ! -x /bin/cpio ]; then
945 echo "/bin/cpio is missing" 1>&2
948 if [ ! -x /usr/bin/find ]; then
949 echo "/usr/bin/find is missing" 1>&2
954 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
959 if [ -n "$img_vers" ]; then
960 target="$target-$kernel"
963 if [ -z "$force" -a -f "$target" ]; then
964 echo "$target already exists." 1>&2
968 if [ ! -d "/lib/modules/$kernel" ]; then
969 echo "/lib/modules/$kernel is not a directory." 1>&2
973 if is_yes "$USE_SUSPEND"; then
974 if is_yes "$USE_SUSPEND2"; then
975 echo "Suspend2 shouldn't be used in parallel with mainline suspend!." 1>&2
980 if [ ! -f /proc/mounts ]; then
981 echo "WARNING: /proc filesystem not mounted, may cause wrong results or failure." 1>&2
984 if [ "$pack_version" -lt "002005" ]; then
985 modulefile=/etc/modules.conf
986 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
987 modulefile=/etc/conf.modules
990 modulefile=/etc/modprobe.conf
993 for n in $PREMODS; do
997 # allow forcing loading SCSI and/or IDE modules
998 if is_yes "$ADDSCSI" ; then
1002 if is_yes "$ADDIDE" ; then
1008 org_rootdev="$rootdev1"
1010 find_modules_for "$rootdev1"
1012 findmodule "-$rootFs"
1014 for n in $BASICMODULES; do
1018 if is_yes "$USE_SUSPEND2"; then
1022 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1023 if [ -n "$verbose" ]; then
1024 echo "No modules are needed -- not building initrd image."
1029 if [ -n "$verbose" ]; then
1030 echo "Using modules: $MODULES"
1033 MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
1034 IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
1035 MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
1036 RCFILE="$MNTIMAGE/linuxrc"
1038 if [ -f "$MNTIMAGE" ]; then
1039 echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
1043 if [ -f "$IMAGE" ]; then
1044 echo "$IMAGE already exists. Remove it and try again" 1>&2
1048 mkdir -p "$MNTPOINT"
1051 mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs,var}
1054 # We don't need this directory, so let's save space
1055 rm -rf "$MNTPOINT"/lost+found
1057 modules_install "$MODULES"
1059 # mknod'ing the devices instead of copying them works both with and
1061 mknod "$MNTIMAGE/dev/console" c 5 1
1062 mknod "$MNTIMAGE/dev/null" c 1 3
1063 mknod "$MNTIMAGE/dev/zero" c 1 5
1066 ln -s /linuxrc $MNTIMAGE/init
1068 inst /bin/initrd-busybox "$MNTIMAGE/bin/initrd-busybox"
1069 ln -s initrd-busybox "$MNTIMAGE/bin/sh"
1070 ln -s initrd-busybox "$MNTIMAGE/bin/busybox" # for older busyboxes who had /bin/busybox as EXEPATH
1072 if is_yes "$USEINSMODSTATIC" ; then
1073 inst "$INSMOD" $MNTIMAGE/bin/insmod.static
1083 modules_add_linuxrc "$MODULES" "$s"
1085 # TODO: rewrite for busybox
1086 #if [ -n "$loopDev" ]; then
1087 # if [ ! -d /initrd ]; then
1091 # cp -a "$loopDev" "$MNTIMAGE/dev"
1092 # cp -a "$rootdev1" "$MNTIMAGE/dev"
1093 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1094 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1095 # echo "echo Setting up loopback device $rootdev1" >> $RCFILE
1096 # echo "losetup $rootdev1 /loopfs$loopFile" >> "$RCFILE"
1099 initrd_gen_suspend() {
1100 if [ ! -x /usr/sbin/resume ]; then
1101 echo "/usr/sbin/resume is missing !"
1104 mkdir -p $MNTIMAGE/etc
1105 mkdir -p $MNTIMAGE/dev
1106 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
1107 cp -HR /dev/snapshot $resume_dev $MNTIMAGE/dev
1108 inst /etc/suspend.conf $MNTIMAGE/etc/suspend.conf
1109 inst /usr/sbin/resume "$MNTIMAGE/bin/resume"
1110 echo "resume" >> "$s"
1113 initrd_gen_suspend2() {
1114 mkdir -p $MNTIMAGE/sys
1115 mkdir -p $MNTIMAGE/proc
1116 cat << 'EOF' >> "$s"
1117 mount -t proc none /proc
1118 if [ "$(awk ' /resume2=/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
1121 echo > /proc/suspend2/do_resume
1127 initrd_gen_tmpfs_dev() {
1131 mount -o mode=0755 -t tmpfs none /dev
1132 mknod /dev/console c 5 1
1133 mknod /dev/null c 1 3
1134 mknod /dev/zero c 1 5
1141 [ -n "$verbose" ] && echo "Setting up udev..."
1142 mkdir -p $MNTIMAGE/sbin
1143 mkdir -p $MNTIMAGE/proc
1144 mkdir -p $MNTIMAGE/etc/udev
1145 mkdir -p $MNTIMAGE/sys
1147 inst /sbin/initrd-udev $MNTIMAGE/sbin/udev
1148 ln -s udev $MNTIMAGE/sbin/udevstart
1149 inst /etc/udev/udev.conf $MNTIMAGE/etc/udev/udev.conf
1151 ln -s udev $MNTIMAGE/sbin/hotplug
1153 if is_yes "$USE_UDEV"; then
1154 initrd_gen_tmpfs_dev >> "$s"
1156 mount -t proc none /proc
1157 mount -t sysfs none /sys
1160 echo -n /sbin/hotplug > /proc/sys/kernel/hotplug
1167 initrd_gen_dmraid() {
1168 if [ ! -x /sbin/dmraid-initrd ] ; then
1169 echo "/sbin/dmraid-initrd is missing missing !"
1173 # AFAIR it just needs tmpfs on /dev.
1174 if [ ! -x $MNTIMAGE/sbin/udev ]; then
1175 echo "udev is needed on target initrd for dmraid to work!"
1179 mkdir -p "$MNTIMAGE/sbin"
1180 inst /sbin/dmraid-initrd $MNTIMAGE/sbin/dmraid
1182 mount -t proc none /proc
1183 mount -t sysfs none /sys
1184 # 2 secs was enough for my system to initialize. but really this is udev issue?
1186 : 'Activating Device-Mapper RAID(s)'
1194 initrd_gen_softraid() {
1195 [ -n "$verbose" ] && echo "Setting up mdadm..."
1197 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ] ; then
1198 echo "/sbin/mdadm or /sbin/initrd-mdassemble is missing !"
1202 inst /sbin/initrd-mdassemble "$MNTIMAGE/bin/mdassemble"
1205 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf)
1206 for ex_dev in $dev_list_extra; do
1207 echo "DEVICE $ex_dev" >> "$MNTIMAGE/etc/mdadm.conf"
1210 for nr in `seq 1 $rootdev_nr`; do
1211 eval cr_rootdev="\$rootdev${nr}"
1212 eval cr_dev_list="\$dev_list${nr}"
1213 [ -n "$verbose" ] && echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1215 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1217 echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf"
1218 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1219 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev)
1220 if [ -n "$cr_md_conf" ]; then
1221 echo "$cr_md_conf" >> "$MNTIMAGE/etc/mdadm.conf"
1223 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf"
1226 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1227 # mkdir in case of devfs name
1228 mkdir -p $MNTIMAGE/`dirname $f`
1229 [ -e "$MNTIMAGE/$f" ] && continue
1230 [ -n "$verbose" ] && echo "copying $f"
1231 # this works fine with and without devfs
1232 cp -HR $f $MNTIMAGE/$f
1236 echo "mdassemble" >> "$s"
1238 # needed to determine md-version
1239 if [ "$do_md0" -eq 1 ] ; then
1240 mknod $MNTIMAGE/dev/md0 b 9 0
1245 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1246 # have problems like init(XX) being child process of swapper(1).
1247 [ -n "$verbose" ] && echo "Adding rootfs on NFS support to initrd (dhcp)"
1248 mknod "$MNTIMAGE/dev/urandom" c 1 8
1249 mkdir "$MNTIMAGE/newroot"
1250 mkdir "$MNTIMAGE/proc"
1251 echo "ifconfig lo 127.0.0.1 up" >> "$s"
1252 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
1253 echo "ifconfig eth0 0.0.0.0 up" >> "$s"
1254 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s"
1255 cat << 'EOF' > "$MNTIMAGE/bin/setdhcp"
1257 [ "$1" != "bound" ] && exit
1258 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1259 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1261 ifconfig $interface $ip $BROADCAST $NETMASK up
1263 if [ -n "$router" ]; then
1264 for r in $router; do
1266 route add default gw $r dev $interface
1271 mount -t proc none /proc
1272 for o in $(cat /proc/cmdline); do
1275 rootpath=${o#nfsroot=}
1281 if [ -n "$rootpath" ]; then
1283 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1287 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1288 echo "All seen variables are listed below:"
1293 chmod 755 "$MNTIMAGE/bin/setdhcp"
1294 echo "cd /newroot" >> "$s"
1295 echo "pivot_root . initrd" >> "$s"
1296 echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1297 echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1301 [ -n "$verbose" ] && echo "Adding LVM support to initrd"
1302 inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
1303 mkdir -p $MNTIMAGE/etc
1304 mkdir -p $MNTIMAGE/tmp
1305 mkdir -p $MNTIMAGE/proc
1306 mkdir -p $MNTIMAGE/newroot
1308 # always make /dev on tmpfs for LVM2
1309 if [ "$LVMTOOLSVERSION" = "2" ] && ! is_yes "$tmpfs_dev"; then
1310 initrd_gen_tmpfs_dev >> "$s"
1313 if ! is_yes "$tmpfs_dev"; then
1314 mkdir -p $MNTIMAGE/dev/mapper
1315 mknod $MNTIMAGE/dev/mapper/control c 10 63
1316 for device in $PVDEVICES; do
1317 # if LVM on RAID then device might be copied already in gen_softraid
1318 [ -e "$MNTIMAGE/dev/$(basename $device)" ] && continue
1319 cp -HR $device $MNTIMAGE/dev/
1322 echo "mount -t proc none /proc" >> "$s"
1323 echo "mount -t tmpfs none /tmp" >> "$s"
1324 if [ "$LVMTOOLSVERSION" = "1" ] ; then
1325 echo "lvm vgscan -T" >> "$s"
1326 echo "lvm vgchange -T -a y $VGVOLUME" >> "$s"
1327 echo "umount /tmp" >> "$s"
1329 echo "umount /dev" >> "$s"
1330 echo "umount /proc" >> "$s"
1332 echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
1333 echo "global {" > "$MNTIMAGE/etc/lvm.conf"
1334 echo " locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
1335 echo " locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf"
1336 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1337 echo "devices {" >> "$MNTIMAGE/etc/lvm.conf"
1338 echo " sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf"
1339 if is_yes "$raidfound"; then
1340 echo " md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf"
1342 lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf"
1343 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1346 : 'Making device nodes'
1349 # ignore first two lines, header and empty line
1352 while read major minor blocks dev; do
1353 mknod /dev/\$dev b \$major \$minor
1355 ) < /proc/partitions
1357 # disable noise from lvm accessing devices that aren't ready.
1358 printk=\$(cat /proc/sys/kernel/printk)
1359 echo 0 > /proc/sys/kernel/printk
1362 : 'Scanning for Volume Groups'
1363 LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure 2>/dev/null
1365 : 'Activating Volume Groups'
1366 LVM_SYSTEM_DIR=/tmp lvm vgchange --ignorelockingfailure -a y $VGVOLUME 2>/dev/null
1368 echo "\$printk" > /proc/sys/kernel/printk
1370 # Find out major/minor
1371 majmin="\$(LVM_SYSTEM_DIR=/tmp lvm lvdisplay --ignorelockingfailure -c $org_rootdev 2>/dev/null)"
1372 majmin="\${majmin#*/}"
1373 majmin="\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}"
1374 major="\${majmin%:*}"
1375 minor="\${majmin#*:}"
1377 val=\$((256 * \$major + \$minor))
1378 echo \$val > /proc/sys/kernel/real-root-dev
1385 initrd_gen_procdata() {
1386 [ -n "$verbose" ] && echo "Adding rootfs finding based on root= option support."
1387 mkdir -p $MNTIMAGE/proc
1388 cat << 'EOF' >> "$s"
1390 mount -t proc none /proc
1391 root="$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ' /proc/cmdline)"
1392 if [ -n "$root" ]; then
1393 rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)"
1394 if [ -n "$rootnr" ]; then
1395 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1405 if is_yes "$USE_UDEV"; then
1409 if is_yes "$USE_SUSPEND"; then
1413 if is_yes "$USE_SUSPEND2"; then
1417 if is_yes "$USE_DMRAID"; then
1421 if is_yes "$usenfs" ; then
1423 elif is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
1425 if is_yes "$uselvm" ; then
1430 elif is_yes "$uselvm" ; then
1436 if [ "$INITRDFS" = "initramfs" ]; then
1437 mkdir -p $MNTIMAGE/newroot
1438 cp -HR $org_rootdev $MNTIMAGE/dev
1439 echo "mount -t $rootFs $org_rootdev /newroot" >> "$s"
1440 echo "switch_root /newroot /sbin/init" >> "$s"
1441 # we need real file, not symlink
1442 rm -f $MNTIMAGE/init
1443 cp -a $MNTIMAGE/linuxrc $MNTIMAGE/init
1448 (cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
1452 IMAGESIZE=$(du -ks $MNTPOINT | awk '{print int(($1+1023)/1024)*1024}')
1453 [ "$verbose" ] && echo "ext2 image size: $IMAGESIZE ($MNTPOINT)"
1454 if [ "$IMAGESIZE" -gt 4096 ]; then
1455 echo >&2 "$0: Your image size is larger than 4096, You should add ramdisk_size=$IMAGESIZE to your kernel commandline!"
1458 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1459 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1460 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1462 tmpmnt="`mktemp -d /tmp/initrd.mnte2-XXXXXX`"
1463 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1465 (cd "$MNTPOINT"; tar cf - .) | (cd "$tmpmnt"; tar xf -)
1470 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
1473 mkcramfs "$MNTPOINT" "$IMAGE"
1476 (cd $MNTPOINT ; find . | cpio -H newc -o > "$IMAGE")
1479 echo "Filesystem $INITRDFS not supported by $0";
1482 if is_yes "$COMPRESS" ; then
1483 gzip -9 < "$IMAGE" > "$target"
1485 cp -a "$IMAGE" "$target"
1488 if is_yes "$BOOT_SPLASH"; then
1489 if [ ! -x /bin/splash.bin ]; then
1490 echo "Failed to execute /bin/splash.bin. Is bootsplash package installed?" 1>&2
1491 elif [ -z "$THEME" ]; then
1492 echo "Please configure your /etc/sysconfig/bootsplash first." 1>&2
1493 echo "Generating bootsplashes skipped." 1>&2
1495 if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
1496 for res in $BOOT_SPLASH_RESOLUTIONS; do
1497 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1498 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1499 [ -n "$verbose" ] && echo "Added $res $THEME theme to initrd."
1501 echo "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" 1>&2
1505 echo "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." 1>&2
1506 echo "Not adding bootsplash to initrd." 1>&2
1511 rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"
1513 # vim:ts=4:sw=4:noet:fdm=marker