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 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udev ]; then
51 if [ -x /sbin/dmraid-initrd ]; then
56 echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
57 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
58 echo " [--initrdfs=rom|ext2|cram] [--modules-conf=<modules.conf>]"
59 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
60 echo " [--without-bootsplash] [--lvmtoolsversion=1|2] [--without-udev]"
61 echo " [--without-suspend] [--without-suspend2] [--without-dmraid]"
62 echo " <initrd-image> <kernel-version>"
63 echo " (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)"
69 typeset mods module f level depfile first
71 depfile=/lib/modules/$kernel/modules.dep
73 if [ -f $depfile ] ; then
76 echo "Error: no $depfile ! Run depmod and rerun geninitrd." 1>&2
80 # prepend / if no path given, append $modext.gz if not given,
83 module=$(echo "$2" | \
84 awk '/\// {print;next} {print "/" $0}' | \
85 awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
86 awk '{gsub("/","\\/");print}')
89 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
91 /(.*)/ { gsub(/\\/," "); if (here) print }
95 if [ "$mods" = "" ] ; then
96 module=$(echo "$module" | \
97 awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
101 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
103 /(.*)/ { gsub(/\\/," "); if (here) print }
106 if [ "$mods" = "" ] ; then
107 if [ "$1" != silent ] ; then
108 echo "$origmodule: module not found in $depfile" 1>&2
110 if ! is_no "$EXIT_IF_MISSING" ; then
113 echo "If $origmodule isn't compiled in kernel then this initrd may not start your system". 1>&2
118 if [ "$level" = "" ] ; then
121 level=$(awk "BEGIN{print $level + 1}")
122 if [ $level -gt 20 ] ; then
123 echo "$origmodule: cycle in $depfile" 1>&2
129 if [ "$first" = "" ] ; then
132 find_depmod $1 $f $level
143 if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
144 if [ -n "$skiperrors" ]; then
148 echo "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" 1>&2
152 # only need to add each module once
154 tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
155 if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
156 MODULES="$MODULES $fmPath"
164 if [ "$(echo $modName | awk '{print(substr($0,1,1));}')" = "-" ]; then
166 modName="$(echo $modName | awk '{print(substr($0,2));}')"
170 if [ "$modName" = "pluto" ]; then
174 if [ "$modName" = "fcal" ]; then
179 if [ -n "$skiperrors" ]; then
180 allModulesToFind=`find_depmod silent $modName`
182 allModulesToFind=`find_depmod normal $modName`
183 if [ $? != 0 ] ; then
188 for mod in $allModulesToFind ; do
189 mod=$(echo $mod | awk '{sub(/^\/lib\/modules\/[^\/]*\//,"");print}')
190 addmodule $mod "$skiperrors"
195 if [ "$#" != "2" ];then
196 echo "usage: inst <file> <destination>"
199 [ -n "$verbose" ] && echo "$1 -> $2"
204 /sbin/e2label $1 2> /dev/null
208 /sbin/tune2fs -l $1 2> /dev/null | awk -F: '/UUID:/ {gsub(" ",""); print $2}'
212 /usr/sbin/xfs_db -x -p xfs_admin -c label -r "$1"|awk -F= '{sub("^\"","", $2); sub("\"$", "", $2); print $2}'
217 /usr/sbin/xfs_db -x -p xfs_admin -c uuid -r "$1"|awk -F= '{print $2}'
221 eval `awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab`
224 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
225 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
226 if [ -n "$rootdev2" ] ; then
231 if [ "$rootdev_found." != "1." ] ; then
234 if [ ! -x /sbin/e2label ] ; then
235 echo "/sbin/e2label is missing" 1>&2
238 get_label="get_label_ext2"
241 if [ ! -x /usr/sbin/xfs_db ] ; then
242 echo "/usr/sbin/xfs_db is missing" 1>&2
245 get_label="get_label_xfs"
248 echo "LABEL on $rootFs in not supported by geninitrd" 1>&2
252 if [ ! -r /proc/partitions ] ; then
253 echo '/proc/partitions is not readable'; 1>&2
256 label=${rootdev#"LABEL="}
257 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
258 if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
259 if [ -n "$verbose" ] ; then
260 echo "Using $dev as device for rootfs"
267 if [ "$rootdev_found." != "1." ] ; then
268 echo "geninitrd can't find real device for LABEL=$label" 1>&2
274 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
275 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
276 if [ -n "$rootdev2" ] ; then
281 if [ "$rootdev_found." != "1." ] ; then
284 if [ ! -x /sbin/tune2fs ] ; then
285 echo "/sbin/tune2fs is missing" 1>&2
288 get_uuid="get_uuid_ext2"
291 if [ ! -x /usr/sbin/xfs_db ] ; then
292 echo "/usr/sbin/xfs_db is missing" 1>&2
295 get_label="get_uuid_xfs"
298 echo "UUID on $rootFs in not supported by geninitrd" 1>&2
302 if [ ! -r /proc/partitions ] ; then
303 echo '/proc/partitions is not readable'; 1>&2
306 uuid=${rootdev#"UUID="}
307 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
308 if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
309 if [ -n "$verbose" ] ; then
310 echo "Using $dev as device for rootfs"
317 if [ "$rootdev_found" != 1 ] ; then
318 echo "geninitrd can't find real device for UUID=$uuid" 1>&2
327 find_modules_softraid() {
328 if [ -f /etc/mdadm.conf ]; then
329 [ -n "$verbose" ] && echo "Finding RAID details using mdadm for rootdev=$1"
330 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
335 rootdev_devfs = rootdev;
336 if (rootdev ~ /\/dev\/md\/[0-9]/) {
337 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
342 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
344 gsub(/level=/,NUL,raidlevel);
345 if (raidlevel ~ /^raid([0-6]|10)/) {
346 gsub(/raid/,NUL,raidlevel);
350 if (x ~ /devices=/) {
352 gsub(".*devices=", NUL, dev_list);
353 gsub(",", " ", dev_list);
359 print "raidfound=" found;
360 print "raidlevel=" raidlevel;
361 print "dev_list=\"" dev_list "\"";
365 if [ "$raidfound" != "yes" -a -f /etc/raidtab ]; then
366 echo "ERROR: raidtools are not longer supported. Please migrate to mdadm setup!" 1>&2
370 if is_yes "$raidfound" ; then
373 findmodule "raid$raidlevel"
379 echo "raid level $number (in mdadm config) not recognized" 1>&2
383 echo "ERROR: RAID devices not found for \"$1\", check your configuration!" 1>&2
387 rootdev_nr=$(( $rootdev_nr + 1 ))
388 eval "rootdev${rootdev_nr}=\"$1\""
389 eval "dev_list${rootdev_nr}=\"${dev_list}\""
391 for device in $dev_list; do
392 find_modules_for $device
396 find_modules_scsi() {
397 for n in $PRESCSIMODS; do
398 if [ "X$n" = "Xunknown" ] ; then
399 if [ -f "$modulefile" ]; then
400 scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
401 for n in $scsimodules; do
402 # for now allow scsi modules to come from anywhere. There are some
403 # RAID controllers with drivers in block
416 rootdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')"
417 if [ "$pack_version_long" -lt "002004021" ]; then
418 [ -n "$verbose" ] && echo "Finding IDE modules for kernels <= 2.4.20"
419 for n in $PREIDEMODSOLD; do
424 for n in $PREIDEMODS; do
425 if [ "X$n" = "Xunknown" ] ; then
426 if [ -f "$modulefile" ]; then
427 [ -n "$verbose" ] && echo "Finding IDE modules using ide_hostadapter"
428 idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
429 for na in $idemodules; do
435 if [ "$tryauto" -eq 1 ]; then
437 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
438 [ -n "$verbose" ] && echo "Finding IDE modules using PCI ID database"
439 # Finding IDE modules using PCI ID database {{{
440 if is_yes "${ide_only_root}"; then
441 if [ -f /sys/block/${rootdev}/device/../../vendor -a -f /sys/block/${rootdev}/device/../../device ]; then
442 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../vendor)"
443 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../device)"
444 searchpciid="${vendorid}${deviceid}"
445 elif [ -f /proc/ide/${rootdev}/../config ]; then
446 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootdev}/../config)"
450 if [ -z "${searchpciid}" ]; then
451 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
456 for nb in $searchpciid; do
457 eval `awk -v pciid="$nb" '{
463 compmod = $1 ""; # make sure comparison type will be string
464 # cause pci IDs are hexadecimal numeric
465 if (compmod == pciid) {
467 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
474 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
475 }' /usr/share/pci-database/ide.pci`
476 [ -n "$module" ] && idemodules="$idemodules $module"
478 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
480 for nc in idemodules; do
481 new_idemodules="$nc $new_idemodules"
483 idemodules="${new_idemodules}"
486 if [ -z "$idemodules" ]; then
487 echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic."
488 idemodules="ide-generic"
492 for nd in $idemodules; do
498 [ -r /usr/share/pci-database/ide.pci ] || echo "WARNING: /usr/share/pci-database/ide.pci missing."
499 [ -r /proc/bus/pci/devices ] || echo "WARNING: /proc/bus/pci/devices missing."
500 echo "Automatic IDE modules finding not available."
511 # return true if node is lvm node
514 if [ ! -e "$node" ]; then
515 echo "WARNING: check_lvm(): node $node doesn't exists!" 1>&2
519 # block-major-58 is lvm1
520 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
524 [ -n "$verbose" ] && echo "$node is LVM1 node"
529 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
531 if [ $rc -gt 127 ]; then
532 # lvdisplay terminated by signal! most likely it segfaulted.
533 echo >&2 "ERROR: Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
538 [ -n "$verbose" ] && echo "$node is lvm2 node"
540 [ -n "$verbose" ] && echo "$node is not any lvm node"
547 echo "ERROR: no argument passed to find_modules_for() - is your /etc/fstab correct?" >&2
550 elif is_yes "`echo "$1" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
551 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then
552 echo "ERROR: root on NFS but /usr/bin/pcidev not found." >&2
553 echo "Please install correct pci-database package and rerun $0." >&2
556 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
557 for m in $NFS_ETH_MODULES; do
563 echo "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel" >&2
564 echo "or you will have problems like init(xx) being child process of swapper(1)." >&2
565 elif is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
566 find_modules_softraid "$1"
567 elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
569 elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
570 find_modules_ide "$1"
571 elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
573 elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
574 findmodule "cpqarray"
575 elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
577 elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
580 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
581 if -n "$ataraidmodules" ; then
582 # FIXME: think about modules compiled in kernel
583 echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
584 echo "Please set it and run $0 again."
587 for n in $ataraidmodules; do
590 # check to see if we need to set up a loopback filesystem
591 elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
592 echo "Sorry, root on loop device isn't supported." 1>&2
594 # TODO: rewrite for bsp and make nfs ready
595 if [ ! -x /sbin/losetup ]; then
596 echo "losetup is missing"
599 key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
600 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
601 echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
602 echo "for this device. Consult the geninitrd man page for more information" 1>&2
606 line="`awk '/'$key'/ { print $0; }' $fstab`"
607 loopDev="$(echo $line | awk '{print $3}')"
608 loopFs="$(echo $line | awk '{print $4}')"
609 loopFile="$(echo $line | awk '{print $5}')"
611 BASICMODULES="$BASICMODULES -loop"
612 findmodule "-$loopFs"
613 BASICMODULES="$BASICMODULES -${loopFs}"
614 elif _check_lvm "$1"; then
615 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then
616 echo "ERROR: root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found." >&2
617 echo "Please install lvm(2) and lvm(2)-initrd package and rerun $0." >&2
620 if [ -z "$LVMTOOLSVERSION" ] ; then
621 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}')
622 if [ -z "$LVMTOOLSVERSION" ] ; then
623 echo "ERROR: Can't determine LVM tools version. Please set LVMTOOLSVERSION" >&2
624 echo "and rerun $0." >&2
628 if [ -z "$PVDEVICES" ] ; then
629 VGVOLUME=$(/sbin/lvdisplay -c "$1" 2> /dev/null | awk -F":" ' { print $2 } ')
630 PVDEVICES=$(/sbin/pvdisplay -c | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
632 if [ -n "$PVDEVICES" ] ; then
633 for device in $PVDEVICES; do
634 find_modules_for $device
637 echo "ERROR: I wasn't able to find PV (via lvdisplay and pvdisplay)." >&2
638 echo "You can try to set PVDEVICES in /etc/sysconfig/geninitrd." >&2
641 if [ "$LVMTOOLSVERSION" = "2" ]; then
643 elif [ "$LVMTOOLSVERSION" = "1" ]; then
645 findmodule "-lvm-mod"
647 echo "ERROR: LVM version $LVMTOOLSVERSION is not supported yet." >&2
650 [ -n "$verbose" ] && echo "LVM $LVMTOOLSVERSION enabled"
655 firmware_install_module_pre() {
660 [ -n "$verbose" ] && echo "Adding Firmwares ($firmware_files) to initrd for module $module"
661 mkdir -p $MNTIMAGE/proc
662 mkdir -p $MNTIMAGE/sys
663 # firmware not yet installed
664 if [ ! -f "$MNTIMAGE/lib/firmware/firmware.sh" ]; then
665 mkdir -p $MNTIMAGE/lib/firmware
666 cat << 'EOF' >> "$MNTIMAGE/lib/firmware/firmware.sh"
668 echo 1 > /sys$DEVPATH/loading
669 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
670 echo 0 > /sys$DEVPATH/loading
673 chmod 755 "$MNTIMAGE/lib/firmware/firmware.sh"
676 for firmware in $firmware_files; do
677 inst "/lib/firmware/$firmware" "$MNTIMAGE/lib/firmware/$firmware"
680 echo "mount -t proc none /proc" >> "$linuxrc"
681 echo "mount -t sysfs none /sys" >> "$linuxrc"
682 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" >> "$linuxrc"
685 firmware_install_module_post() {
689 echo "umount /sys" >> "$linuxrc"
690 echo "umount /proc" >> "$linuxrc"
696 for mod in $modules; do
697 MODULEDIR="`dirname "$mod"`"
698 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
699 cp $verbose -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
700 gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
704 modules_add_linuxrc() {
708 for mod in $modules; do
709 MODULE2="`dirname "$mod"`"
710 NAME2=`basename "$mod" .gz`
711 MODULE2=$MODULE2/$NAME2
712 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
713 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
715 generic_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ')
716 sleep_var="$(eval echo \$MODULE_${generic_module}_USLEEP)"
717 firmware_var="$(eval echo \$MODULE_${generic_module}_FIRMWARE)"
719 if [ -n "$verbose" ]; then
720 echo -n "Loading module [$module] "
721 if [ -n "$options" ] ; then
722 echo -n "with options [$options]"
724 echo -n "without options"
726 if [ -n "$sleep_var" ]; then
727 echo " and $sleep_var usleep."
733 if [ -n "$firmware_var" ]; then
734 firmware_install_module_pre "$module" "$linuxrc" "$firmware_var"
736 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
737 if [ -n "${sleep_var}" ]; then
738 echo "usleep $sleep_var" >> "$linuxrc"
740 if [ -n "$firmware_var" ]; then
741 firmware_install_module_post "$module" "$linuxrc" "$firmware_var"
746 if [ -r /etc/sysconfig/geninitrd ] ; then
747 . /etc/sysconfig/geninitrd
750 if [ -r /etc/sysconfig/bootsplash ] ; then
751 . /etc/sysconfig/bootsplash
754 if [ ! -x /bin/initrd-busybox ] ; then
755 echo "/bin/initrd-busybox is missing !"
758 case "$(uname -m)" in
759 ia64|amd64|x86_64|sparc64)
767 while [ $# -gt 0 ]; do
770 fstab="`echo $1 | awk -F= '{print $2;}'`"
777 modulefile="`echo $1 | awk -F= '{print $2;}'`"
783 --use-raidstart|--with-raidstart)
789 --use-insmod-static|--with-insmod-static)
790 USEINSMODSTATIC="yes"
792 --without-insmod-static)
795 --without-bootsplash)
804 --lvmtoolsversion=|--lvmversion=)
805 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
807 --lvmtoolsversion|--lvmversion)
818 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
821 BASICMODULES="$BASICMODULES $2"
825 echo "geninitrd: version $VERSION"
841 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
844 PREMODS="$PREMODS $2"
848 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
849 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
852 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
857 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
870 if [ -z "$target" ]; then
872 elif [ -z "$kernel" ]; then
883 if [ -z "$target" -o -z "$kernel" ]; then
887 pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
888 pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
890 if [ "x" = "x$INITRDFS" ] ; then
891 if [ "x" = "x$FS" ] ; then
893 # XXX: initramfs blocked for now
894 if [ "1" = " 0" -a "$pack_version" -ge "002005" ] ; then
900 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
905 if [ "$pack_version" -lt "002006" ] ; then
909 [ -z "$USE_UDEV" ] && UDEV_TMPFS=
911 if [ "$pack_version" -ge "002005" ] ; then
916 if is_yes "$USEINSMODSTATIC" ; then
917 insmod="insmod.static"
918 INSMOD="/sbin/insmod.static"
919 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
920 INSMOD="/sbin/insmod.static.modutils"
922 if [ ! -f "$INSMOD" ] ; then
923 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
930 IMAGESIZE=$((IMAGESIZE + 2000))
931 if [ ! -x /sbin/mke2fs ]; then
932 echo "/sbin/mke2fs is missing" 1>&2
937 if [ ! -x /sbin/genromfs ]; then
938 echo "/sbin/genromfs is missing" 1>&2
943 if [ ! -x /sbin/mkcramfs ]; then
944 echo "/sbin/mkcramfs is missing" 1>&2
949 if [ ! -x /bin/cpio ]; then
950 echo "/bin/cpio is missing" 1>&2
953 if [ ! -x /usr/bin/find ]; then
954 echo "/usr/bin/find is missing" 1>&2
959 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
964 if [ -n "$img_vers" ]; then
965 target="$target-$kernel"
968 if [ -z "$force" -a -f "$target" ]; then
969 echo "$target already exists." 1>&2
973 if [ ! -d "/lib/modules/$kernel" ]; then
974 echo "/lib/modules/$kernel is not a directory." 1>&2
978 if is_yes "$USE_SUSPEND"; then
979 if is_yes "$USE_SUSPEND2"; then
980 echo "Suspend2 shouldn't be used in parallel with mainline suspend!." 1>&2
985 if [ ! -f /proc/mounts ]; then
986 echo "WARNING: /proc filesystem not mounted, may cause wrong results or failure." 1>&2
989 if [ "$pack_version" -lt "002005" ]; then
990 modulefile=/etc/modules.conf
991 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
992 modulefile=/etc/conf.modules
995 modulefile=/etc/modprobe.conf
998 for n in $PREMODS; do
1002 # allow forcing loading SCSI and/or IDE modules
1003 if is_yes "$ADDSCSI" ; then
1007 if is_yes "$ADDIDE" ; then
1013 org_rootdev="$rootdev1"
1015 find_modules_for "$rootdev1"
1017 findmodule "-$rootFs"
1019 for n in $BASICMODULES; do
1023 if is_yes "$USE_SUSPEND2"; then
1027 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1028 if [ -n "$verbose" ]; then
1029 echo "No modules are needed -- not building initrd image."
1034 if [ -n "$verbose" ]; then
1035 echo "Using modules: $MODULES"
1038 MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
1039 IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
1040 MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
1041 RCFILE="$MNTIMAGE/linuxrc"
1043 if [ -f "$MNTIMAGE" ]; then
1044 echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
1048 if [ -f "$IMAGE" ]; then
1049 echo "$IMAGE already exists. Remove it and try again" 1>&2
1053 if [ "$INITRDFS" = "ext2" ] ; then
1054 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1055 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1056 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1058 mkdir -p "$MNTPOINT"
1059 mount -o loop -t ext2 "$IMAGE" "$MNTPOINT"
1061 mkdir -p "$MNTPOINT"
1065 mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs,var}
1068 # We don't need this directory, so let's save space
1069 rm -rf "$MNTPOINT"/lost+found
1071 modules_install "$MODULES"
1073 # mknod'ing the devices instead of copying them works both with and
1075 mknod "$MNTIMAGE/dev/console" c 5 1
1076 mknod "$MNTIMAGE/dev/null" c 1 3
1077 mknod "$MNTIMAGE/dev/zero" c 1 5
1080 ln -s /linuxrc $MNTIMAGE/init
1082 inst /bin/initrd-busybox "$MNTIMAGE/bin/sh"
1083 ln -s sh "$MNTIMAGE/bin/busybox"
1085 if is_yes "$USEINSMODSTATIC" ; then
1086 inst "$INSMOD" $MNTIMAGE/bin/insmod.static
1096 modules_add_linuxrc "$MODULES" "$s"
1098 # TODO: rewrite for busybox
1099 #if [ -n "$loopDev" ]; then
1100 # if [ ! -d /initrd ]; then
1104 # cp -a "$loopDev" "$MNTIMAGE/dev"
1105 # cp -a "$rootdev1" "$MNTIMAGE/dev"
1106 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1107 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1108 # echo "echo Setting up loopback device $rootdev1" >> $RCFILE
1109 # echo "losetup $rootdev1 /loopfs$loopFile" >> "$RCFILE"
1112 initrd_gen_suspend() {
1113 if [ ! -x /usr/sbin/resume ]; then
1114 echo "/usr/sbin/resume is missing !"
1117 mkdir -p $MNTIMAGE/etc
1118 mkdir -p $MNTIMAGE/dev
1119 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
1120 cp -HR /dev/snapshot $resume_dev $MNTIMAGE/dev
1121 inst /etc/suspend.conf $MNTIMAGE/etc/suspend.conf
1122 inst /usr/sbin/resume "$MNTIMAGE/bin/resume"
1123 echo "resume" >> "$s"
1126 initrd_gen_suspend2() {
1127 mkdir -p $MNTIMAGE/sys
1128 mkdir -p $MNTIMAGE/proc
1129 cat << 'EOF' >> "$s"
1130 mount -t proc none /proc
1131 if [ "$(awk ' /resume2=/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
1134 echo > /proc/suspend2/do_resume
1141 [ -n "$verbose" ] && echo "Setting up udev..."
1142 mkdir -p $MNTIMAGE/sbin
1143 mkdir -p $MNTIMAGE/proc
1144 mkdir -p $MNTIMAGE/etc/udev
1146 inst /sbin/initrd-udev $MNTIMAGE/sbin/udev
1147 ln -s udev $MNTIMAGE/sbin/udevstart
1148 inst /etc/udev/udev.conf $MNTIMAGE/etc/udev/udev.conf
1150 ln -s udev $MNTIMAGE/sbin/hotplug
1152 if is_yes "$USE_UDEV"; then
1153 if is_yes "$UDEV_TMPFS"; then
1156 mount -o mode=0755 -t tmpfs none /dev
1157 mknod /dev/console c 5 1
1158 mknod /dev/null c 1 3
1159 mknod /dev/zero c 1 5
1165 mount -t proc none /proc
1168 echo -n "/sbin/hotplug" > /proc/sys/kernel/hotplug
1174 initrd_gen_dmraid() {
1175 if [ ! -x /sbin/dmraid-initrd ] ; then
1176 echo "/sbin/dmraid-initrd is missing missing !"
1180 if [ ! -x $MNTIMAGE/sbin/udev ]; then
1181 echo "udev is needed on target initrd for dmraid to work!"
1185 mkdir -p "$MNTIMAGE/sbin"
1186 inst /sbin/dmraid-initrd $MNTIMAGE/sbin/dmraid
1188 mount -t proc none /proc
1189 mount -t sysfs none /sys
1190 # 2 secs was enough for my system to initialize. but really this is udev issue?
1192 echo 'Activating Device-Mapper RAID(s)'
1200 initrd_gen_softraid() {
1201 [ -n "$verbose" ] && echo "Setting up mdadm..."
1203 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ] ; then
1204 echo "/sbin/mdadm or /sbin/initrd-mdassemble is missing !"
1208 inst /sbin/initrd-mdassemble "$MNTIMAGE/bin/mdassemble"
1211 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf)
1212 for ex_dev in $dev_list_extra; do
1213 echo "DEVICE $ex_dev" >> "$MNTIMAGE/etc/mdadm.conf"
1216 for nr in `seq 1 $rootdev_nr`; do
1217 eval cr_rootdev="\$rootdev${nr}"
1218 eval cr_dev_list="\$dev_list${nr}"
1219 [ -n "$verbose" ] && echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1221 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1223 echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf"
1224 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1225 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev)
1226 if [ -n "$cr_md_conf" ]; then
1227 echo "$cr_md_conf" >> "$MNTIMAGE/etc/mdadm.conf"
1229 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf"
1232 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1233 # mkdir in case of devfs name
1234 mkdir -p $MNTIMAGE/`dirname $f`
1235 [ -e "$MNTIMAGE/$f" ] && continue
1236 [ -n "$verbose" ] && echo "copying $f"
1237 # this works fine with and without devfs
1238 cp -HR $f $MNTIMAGE/$f
1242 echo "mdassemble" >> "$s"
1244 # needed to determine md-version
1245 if [ "$do_md0" -eq 1 ] ; then
1246 mknod $MNTIMAGE/dev/md0 b 9 0
1251 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1252 # have problems like init(XX) being child process of swapper(1).
1253 [ -n "$verbose" ] && echo "Adding rootfs on NFS support to initrd (dhcp)"
1254 mknod "$MNTIMAGE/dev/urandom" c 1 8
1255 mkdir "$MNTIMAGE/newroot"
1256 mkdir "$MNTIMAGE/proc"
1257 echo "ifconfig lo 127.0.0.1 up" >> "$s"
1258 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
1259 echo "ifconfig eth0 0.0.0.0 up" >> "$s"
1260 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s"
1261 cat << 'EOF' > "$MNTIMAGE/bin/setdhcp"
1263 [ "$1" != "bound" ] && exit
1264 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1265 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1267 ifconfig $interface $ip $BROADCAST $NETMASK up
1269 if [ -n "$router" ]; then
1270 for r in $router; do
1272 route add default gw $r dev $interface
1277 mount -t proc none /proc
1278 for o in $(cat /proc/cmdline); do
1281 rootpath=${o#nfsroot=}
1287 if [ -n "$rootpath" ]; then
1289 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1293 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1294 echo "All seen variables are listed below:"
1299 chmod 755 "$MNTIMAGE/bin/setdhcp"
1300 echo "cd /newroot" >> "$s"
1301 echo "pivot_root . initrd" >> "$s"
1302 echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1303 echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1307 [ -n "$verbose" ] && echo "Adding LVM support to initrd"
1308 inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
1309 mkdir -p $MNTIMAGE/etc
1310 mkdir -p $MNTIMAGE/tmp
1311 mkdir -p $MNTIMAGE/proc
1312 mkdir -p $MNTIMAGE/newroot
1313 if ! is_yes "$USE_UDEV"; 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 : 'Scanning for Volume Groups'
1347 LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure
1348 : 'Activating Volume Groups'
1349 LVM_SYSTEM_DIR=/tmp lvm vgchange --ignorelockingfailure -a y $VGVOLUME 2>/dev/null
1351 # Find out major/minor
1352 majmin="\`LVM_SYSTEM_DIR=/tmp lvm lvdisplay --ignorelockingfailure -c $org_rootdev\`"
1353 majmin="\${majmin#*/}"
1354 majmin="\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}"
1355 major="\${majmin%:*}"
1356 minor="\${majmin#*:}"
1358 val=\$((256 * \$major + \$minor))
1359 echo \$val > /proc/sys/kernel/real-root-dev
1366 initrd_gen_procdata() {
1367 [ -n "$verbose" ] && echo "Adding rootfs finding based on root= option support."
1368 mkdir -p $MNTIMAGE/proc
1369 cat << 'EOF' >> "$s"
1371 mount -t proc none /proc
1372 root="$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ' /proc/cmdline)"
1373 if [ -n "$root" ]; then
1374 rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)"
1375 if [ -n "$rootnr" ]; then
1376 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1386 if is_yes "$USE_UDEV"; then
1390 if is_yes "$USE_SUSPEND"; then
1394 if is_yes "$USE_SUSPEND2"; then
1398 if is_yes "$USE_DMRAID"; then
1402 if is_yes "$usenfs" ; then
1404 elif is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
1406 if is_yes "$uselvm" ; then
1411 elif is_yes "$uselvm" ; then
1417 if [ "$INITRDFS" = "initramfs" ]; then
1418 mkdir -p $MNTIMAGE/newroot
1419 cp -HR $org_rootdev $MNTIMAGE/dev
1420 echo "mount -t $rootFs $org_rootdev /newroot" >> "$s"
1421 echo "switch_root /newroot /sbin/init" >> "$s"
1422 # we need real file, not symlink
1423 rm -f $MNTIMAGE/init
1424 cp -a $MNTIMAGE/linuxrc $MNTIMAGE/init
1429 (cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
1436 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
1439 mkcramfs "$MNTPOINT" "$IMAGE"
1442 (cd $MNTPOINT ; find . | cpio -H newc -o > "$IMAGE")
1445 echo "Filesystem $INITRDFS not supported by $0";
1448 if is_yes "$COMPRESS" ; then
1449 gzip -9 < "$IMAGE" > "$target"
1451 cp -a "$IMAGE" "$target"
1454 if is_yes "$BOOT_SPLASH"; then
1455 if [ ! -x /bin/splash.bin ]; then
1456 echo "Failed to execute /bin/splash.bin. Is bootsplash package installed?" 1>&2
1457 elif [ -z "$THEME" ]; then
1458 echo "Please configure your /etc/sysconfig/bootsplash first." 1>&2
1459 echo "Generating bootsplashes skipped." 1>&2
1461 if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
1462 for res in $BOOT_SPLASH_RESOLUTIONS; do
1463 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1464 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1465 [ -n "$verbose" ] && echo "Added $res $THEME theme to initrd."
1467 echo "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" 1>&2
1471 echo "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." 1>&2
1472 echo "Not adding bootsplash to initrd." 1>&2
1477 rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"
1479 # vim:ts=4:sw=4:noet:fdm=marker