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 echo $1|awk -F/ '{print substr($0, 0, length($0) - length($NF));}'
73 typeset mods module f level depfile first
75 depfile=/lib/modules/$kernel/modules.dep
77 if [ -f $depfile ] ; then
80 echo "Error: no $depfile ! Run depmod and rerun geninitrd." 1>&2
84 # prepend / if no path given, append $modext.gz if not given,
87 module=$(echo "$2" | \
88 awk '/\// {print;next} {print "/" $0}' | \
89 awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
90 awk '{gsub("/","\\/");print}')
93 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
95 /(.*)/ { gsub(/\\/," "); if (here) print }
99 if [ "$mods" = "" ] ; then
100 module=$(echo "$module" | \
101 awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
105 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
107 /(.*)/ { gsub(/\\/," "); if (here) print }
110 if [ "$mods" = "" ] ; then
111 if [ "$1" != silent ] ; then
112 echo "$origmodule: module not found in $depfile" 1>&2
114 if ! is_no "$EXIT_IF_MISSING" ; then
117 echo "If $origmodule isn't compiled in kernel then this initrd may not start your system". 1>&2
122 if [ "$level" = "" ] ; then
125 level=$(awk "BEGIN{print $level + 1}")
126 if [ $level -gt 20 ] ; then
127 echo "$origmodule: cycle in $depfile" 1>&2
133 if [ "$first" = "" ] ; then
136 find_depmod $1 $f $level
147 if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
148 if [ -n "$skiperrors" ]; then
152 echo "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" 1>&2
156 # only need to add each module once
158 tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
159 if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
160 MODULES="$MODULES $fmPath"
168 if [ "$(echo $modName | awk '{print(substr($0,1,1));}')" = "-" ]; then
170 modName="$(echo $modName | awk '{print(substr($0,2));}')"
174 if [ "$modName" = "pluto" ]; then
178 if [ "$modName" = "fcal" ]; then
183 if [ -n "$skiperrors" ]; then
184 allModulesToFind=`find_depmod silent $modName`
186 allModulesToFind=`find_depmod normal $modName`
187 if [ $? != 0 ] ; then
192 for mod in $allModulesToFind ; do
194 awk '{sub(/^\/lib\/modules\/[^\/]*\//,"");print}')
195 addmodule $mod "$skiperrors"
200 if [ "$#" != "2" ];then
201 echo "usage: inst <file> <destination>"
204 [ -n "$verbose" ] && echo "$1 -> $2"
209 /sbin/e2label $1 2> /dev/null
213 /sbin/tune2fs -l $1 2> /dev/null | awk -F: '/UUID:/ {gsub(" ",""); print $2}'
217 /usr/sbin/xfs_db -x -p xfs_admin -c label -r "$1"|awk -F= '{sub("^\"","", $2); sub("\"$", "", $2); print $2}'
222 /usr/sbin/xfs_db -x -p xfs_admin -c uuid -r "$1"|awk -F= '{print $2}'
226 eval `awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab`
229 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
230 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
231 if [ -n "$rootdev2" ] ; then
236 if [ "$rootdev_found." != "1." ] ; then
239 if [ ! -x /sbin/e2label ] ; then
240 echo "/sbin/e2label is missing" 1>&2
243 get_label="get_label_ext2"
246 if [ ! -x /usr/sbin/xfs_db ] ; then
247 echo "/usr/sbin/xfs_db is missing" 1>&2
250 get_label="get_label_xfs"
253 echo "LABEL on $rootFs in not supported by geninitrd" 1>&2
257 if [ ! -r /proc/partitions ] ; then
258 echo '/proc/partitions is not readable'; 1>&2
261 label=${rootdev#"LABEL="}
262 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
263 if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
264 if [ -n "$verbose" ] ; then
265 echo "Using $dev as device for rootfs"
272 if [ "$rootdev_found." != "1." ] ; then
273 echo "geninitrd can't find real device for LABEL=$label" 1>&2
279 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
280 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
281 if [ -n "$rootdev2" ] ; then
286 if [ "$rootdev_found." != "1." ] ; then
289 if [ ! -x /sbin/tune2fs ] ; then
290 echo "/sbin/tune2fs is missing" 1>&2
293 get_uuid="get_uuid_ext2"
296 if [ ! -x /usr/sbin/xfs_db ] ; then
297 echo "/usr/sbin/xfs_db is missing" 1>&2
300 get_label="get_uuid_xfs"
303 echo "UUID on $rootFs in not supported by geninitrd" 1>&2
307 if [ ! -r /proc/partitions ] ; then
308 echo '/proc/partitions is not readable'; 1>&2
311 uuid=${rootdev#"UUID="}
312 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
313 if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
314 if [ -n "$verbose" ] ; then
315 echo "Using $dev as device for rootfs"
322 if [ "$rootdev_found" != 1 ] ; then
323 echo "geninitrd can't find real device for UUID=$uuid" 1>&2
332 find_modules_softraid() {
333 if [ -f /etc/mdadm.conf ] ; then
334 [ -n "$verbose" ] && echo "Finding RAID details using mdadm for rootdev=$1"
335 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | \
336 awk -v rootdev="$1" '
341 rootdev_devfs = rootdev;
342 if (rootdev ~ /\/dev\/md\/[0-9]/) {
343 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
348 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
350 gsub(/level=/,NUL,raidlevel);
351 if (raidlevel ~ /^raid([0-6]|10)/) {
352 gsub(/raid/,NUL,raidlevel);
356 if (x ~ /devices=/) {
358 gsub(".*devices=", NUL, dev_list);
359 gsub(",", " ", dev_list);
365 print "raidfound=" found;
366 print "raidlevel=" raidlevel;
367 print "dev_list=\"" dev_list "\"";
371 if [ "$raidfound" != "yes" -a -f /etc/raidtab ]; then
372 echo "ERROR: raidtools are not longer supported. Please migrate to mdadm setup!" 1>&2
376 if is_yes "$raidfound" ; then
379 findmodule "raid$raidlevel"
385 echo "raid level $number (in mdadm config) not recognized" 1>&2
389 echo "ERROR: RAID devices not found for \"$1\", check your configuration!" 1>&2
393 rootdev_nr=$(( $rootdev_nr + 1 ))
394 eval "rootdev${rootdev_nr}=\"$1\""
395 eval "dev_list${rootdev_nr}=\"${dev_list}\""
397 for device in $dev_list; do
398 find_modules_for $device
402 find_modules_scsi() {
403 for n in $PRESCSIMODS; do
404 if [ "X$n" = "Xunknown" ] ; then
405 if [ -f "$modulefile" ]; then
406 scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
407 for n in $scsimodules; do
408 # for now allow scsi modules to come from anywhere. There are some
409 # RAID controllers with drivers in block
422 rootdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')"
423 if [ "$pack_version_long" -lt "002004021" ]; then
424 [ -n "$verbose" ] && echo "Finding IDE modules for kernels <= 2.4.20"
425 for n in $PREIDEMODSOLD; do
430 for n in $PREIDEMODS; do
431 if [ "X$n" = "Xunknown" ] ; then
432 if [ -f "$modulefile" ]; then
433 [ -n "$verbose" ] && echo "Finding IDE modules using ide_hostadapter"
434 idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
435 for na in $idemodules; do
441 if [ "$tryauto" -eq 1 ]; then
442 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
443 [ -n "$verbose" ] && echo "Finding IDE modules using PCI ID database"
444 if is_yes "${ide_only_root}"; then
445 if [ -f /sys/block/${rootdev}/device/../../vendor -a -f /sys/block/${rootdev}/device/../../device ] ; then
446 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../vendor)"
447 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../device)"
448 searchpciid="${vendorid}${deviceid}"
449 elif [ -f /proc/ide/${rootdev}/../config ]; then
450 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootdev}/../config)"
453 if [ -z "${searchpciid}" ]; then
454 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
457 for nb in $searchpciid; do
458 eval `awk -v pciid="$nb" 'BEGIN {
467 compmod = $1 ""; # make sure comparison type will be string
468 # cause pci IDs are hexadecimal numeric
469 if (compmod == pciid) {
471 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
478 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
479 }' /usr/share/pci-database/ide.pci`
480 [ -n "$module" ] && idemodules="$idemodules $module"
482 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
484 for nc in idemodules; do
485 new_idemodules="$nc $new_idemodules"
487 idemodules="${new_idemodules}"
489 if [ -z "$idemodules" ]; then
490 echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic."
491 idemodules="ide-generic"
493 for nd in $idemodules; do
497 [ -r /usr/share/pci-database/ide.pci ] || echo "WARNING: /usr/share/pci-database/ide.pci missing."
498 [ -r /proc/bus/pci/devices ] || echo "WARNING: /proc/bus/pci/devices missing."
499 echo "Automatic IDE modules finding not available."
509 # return true if node is lvm node
512 if [ ! -e "$node" ]; then
516 # block-major-58 is lvm1
517 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
521 [ -n "$verbose" ] && echo "$node is LVM1 node"
526 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
528 if [ $rc -gt 127 ]; then
529 # lvdisplay terminated by signal! most likely it segfaulted.
530 echo >&2 "ERROR: Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
535 [ -n "$verbose" ] && echo "$node is lvm2 node"
537 [ -n "$verbose" ] && echo "$node is not any lvm node"
544 echo "ERROR: no argument passed to find_modules_for() - is your /etc/fstab correct?" >&2
546 elif is_yes "`echo "$1" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
547 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then
548 echo "ERROR: root on NFS but /usr/bin/pcidev not found." >&2
549 echo "Please install correct pci-database package and rerun $0." >&2
552 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
553 for m in $NFS_ETH_MODULES; do
559 echo "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel" >&2
560 echo "or you will have problems like init(xx) being child process of swapper(1)." >&2
561 elif is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
562 find_modules_softraid "$1"
563 elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
565 elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
566 find_modules_ide "$1"
567 elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
569 elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
570 findmodule "cpqarray"
571 elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
573 elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
576 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
577 if -n "$ataraidmodules" ; then
578 # FIXME: think about modules compiled in kernel
579 echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
580 echo "Please set it and run $0 again."
583 for n in $ataraidmodules; do
586 # check to see if we need to set up a loopback filesystem
587 elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
588 echo "Sorry, root on loop device isn't supported." 1>&2
590 # TODO: rewrite for bsp and make nfs ready
591 if [ ! -x /sbin/losetup ]; then
592 echo "losetup is missing"
595 key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
596 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
597 echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
598 echo "for this device. Consult the geninitrd man page for more information" 1>&2
602 line="`awk '/'$key'/ { print $0; }' $fstab`"
603 loopDev="$(echo $line | awk '{print $3}')"
604 loopFs="$(echo $line | awk '{print $4}')"
605 loopFile="$(echo $line | awk '{print $5}')"
607 BASICMODULES="$BASICMODULES -loop"
608 findmodule "-$loopFs"
609 BASICMODULES="$BASICMODULES -${loopFs}"
610 elif _check_lvm "$1"; then
611 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then
612 echo "ERROR: root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found." >&2
613 echo "Please install lvm(2) and lvm(2)-initrd package and rerun $0." >&2
616 if [ -z "$LVMTOOLSVERSION" ] ; then
617 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}')
618 if [ -z "$LVMTOOLSVERSION" ] ; then
619 echo "ERROR: Can't determine LVM tools version. Please set LVMTOOLSVERSION" >&2
620 echo "and rerun $0." >&2
624 if [ -z "$PVDEVICES" ] ; then
625 VGVOLUME=$(/sbin/lvdisplay -c "$1" 2> /dev/null | awk -F":" ' { print $2 } ')
626 PVDEVICES=$(/sbin/pvdisplay -c | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
628 if [ -n "$PVDEVICES" ] ; then
629 for device in $PVDEVICES; do
630 find_modules_for $device
633 echo "ERROR: I wasn't able to find PV (via lvdisplay and pvdisplay)." >&2
634 echo "You can try to set PVDEVICES in /etc/sysconfig/geninitrd." >&2
637 if [ "$LVMTOOLSVERSION" = "2" ]; then
639 elif [ "$LVMTOOLSVERSION" = "1" ]; then
641 findmodule "-lvm-mod"
643 echo "ERROR: LVM version $LVMTOOLSVERSION is not supported yet." >&2
646 [ -n "$verbose" ] && echo "LVM $LVMTOOLSVERSION enabled"
654 for mod in $modules; do
655 MODULEDIR="`my_dirname "$mod"`"
656 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
657 cp $verbose -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
658 gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
662 modules_add_linuxrc() {
666 for mod in $modules; do
667 MODULE2="`my_dirname "$mod"`"
668 NAME2=`basename "$mod" .gz`
669 MODULE2=$MODULE2/$NAME2
670 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
671 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
673 sleep_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ')
674 sleep_var="$(eval echo \$MODULE_${sleep_module}_USLEEP)"
676 if [ -n "$verbose" ]; then
677 echo -n "Loading module [$module] "
678 if [ -n "$options" ] ; then
679 echo -n "with options [$options]"
681 echo -n "without options"
683 if [ -n "$sleep_var" ]; then
684 echo " and $sleep_var usleep."
689 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
690 if [ -n "${sleep_var}" ]; then
691 echo "usleep $sleep_var" >> "$linuxrc"
696 if [ -r /etc/sysconfig/geninitrd ] ; then
697 . /etc/sysconfig/geninitrd
700 if [ -r /etc/sysconfig/bootsplash ] ; then
701 . /etc/sysconfig/bootsplash
704 if [ ! -x /bin/initrd-busybox ] ; then
705 echo "/bin/initrd-busybox is missing !"
708 case "$(uname -m)" in
709 ia64|amd64|x86_64|sparc64)
717 while [ $# -gt 0 ]; do
720 fstab="`echo $1 | awk -F= '{print $2;}'`"
727 modulefile="`echo $1 | awk -F= '{print $2;}'`"
733 --use-raidstart|--with-raidstart)
739 --use-insmod-static|--with-insmod-static)
740 USEINSMODSTATIC="yes"
742 --without-insmod-static)
745 --without-bootsplash)
754 --lvmtoolsversion=|--lvmversion=)
755 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
757 --lvmtoolsversion|--lvmversion)
768 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
771 BASICMODULES="$BASICMODULES $2"
775 echo "geninitrd: version $VERSION"
791 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
794 PREMODS="$PREMODS $2"
798 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
799 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
802 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
807 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
820 if [ -z "$target" ]; then
822 elif [ -z "$kernel" ]; then
833 if [ -z "$target" -o -z "$kernel" ]; then
837 pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
838 pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
840 if [ "x" = "x$INITRDFS" ] ; then
841 if [ "x" = "x$FS" ] ; then
843 # XXX: initramfs blocked for now
844 if [ "1" = " 0" -a "$pack_version" -ge "002005" ] ; then
850 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
855 if [ "$pack_version" -lt "002006" ] ; then
859 [ -z "$USE_UDEV" ] && UDEV_TMPFS=
861 if [ "$pack_version" -ge "002005" ] ; then
866 if is_yes "$USEINSMODSTATIC" ; then
867 insmod="insmod.static"
868 INSMOD="/sbin/insmod.static"
869 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
870 INSMOD="/sbin/insmod.static.modutils"
872 if [ ! -f "$INSMOD" ] ; then
873 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
880 if [ ! -x /sbin/mke2fs ]; then
881 echo "/sbin/mke2fs is missing" 1>&2
886 if [ ! -x /sbin/genromfs ]; then
887 echo "/sbin/genromfs is missing" 1>&2
892 if [ ! -x /sbin/mkcramfs ]; then
893 echo "/sbin/mkcramfs is missing" 1>&2
898 if [ ! -x /bin/cpio ]; then
899 echo "/bin/cpio is missing" 1>&2
902 if [ ! -x /usr/bin/find ]; then
903 echo "/usr/bin/find is missing" 1>&2
908 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
913 if [ -n "$img_vers" ]; then
914 target="$target-$kernel"
917 if [ -z "$force" -a -f "$target" ]; then
918 echo "$target already exists." 1>&2
922 if [ ! -d "/lib/modules/$kernel" ]; then
923 echo "/lib/modules/$kernel is not a directory." 1>&2
927 if is_yes "$USE_SUSPEND"; then
928 if is_yes "$USE_SUSPEND2"; then
929 echo "Suspend2 shouldn't be used in parallel with mainline suspend!." 1>&2
934 if [ ! -f /proc/mounts ]; then
935 echo "WARNING: /proc filesystem not mounted, may cause wrong results or failure." 1>&2
938 if [ "$pack_version" -lt "002005" ]; then
939 modulefile=/etc/modules.conf
940 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
941 modulefile=/etc/conf.modules
944 modulefile=/etc/modprobe.conf
947 for n in $PREMODS; do
951 # allow forcing loading SCSI and/or IDE modules
952 if is_yes "$ADDSCSI" ; then
956 if is_yes "$ADDIDE" ; then
962 org_rootdev="$rootdev1"
964 find_modules_for "$rootdev1"
966 findmodule "-$rootFs"
968 for n in $BASICMODULES; do
972 if is_yes "$USE_SUSPEND2"; then
976 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
977 if [ -n "$verbose" ]; then
978 echo "No modules are needed -- not building initrd image."
983 if [ -n "$verbose" ]; then
984 echo "Using modules: $MODULES"
987 MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
988 IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
989 MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
990 RCFILE="$MNTIMAGE/linuxrc"
992 if [ -f "$MNTIMAGE" ]; then
993 echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
997 if [ -f "$IMAGE" ]; then
998 echo "$IMAGE already exists. Remove it and try again" 1>&2
1002 if [ "$INITRDFS" = "ext2" ] ; then
1003 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1005 # We have to "echo y |" so that it doesn't complain about $IMAGE not
1006 # being a block device
1007 echo y | mke2fs -F "$IMAGE" "$IMAGESIZE" >/dev/null 2>/dev/null
1009 mkdir -p "$MNTPOINT"
1010 mount -o loop -t ext2 "$IMAGE" "$MNTPOINT"
1012 mkdir -p "$MNTPOINT"
1016 mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs,var}
1019 # We don't need this directory, so let's save space
1020 rm -rf "$MNTPOINT"/lost+found
1022 modules_install "$MODULES"
1024 # mknod'ing the devices instead of copying them works both with and
1026 mknod "$MNTIMAGE/dev/console" c 5 1
1027 mknod "$MNTIMAGE/dev/null" c 1 3
1028 mknod "$MNTIMAGE/dev/zero" c 1 5
1031 ln -s /linuxrc $MNTIMAGE/init
1033 inst /bin/initrd-busybox "$MNTIMAGE/bin/sh"
1034 ln -s sh "$MNTIMAGE/bin/busybox"
1036 if is_yes "$USEINSMODSTATIC" ; then
1037 inst "$INSMOD" $MNTIMAGE/bin/insmod.static
1047 modules_add_linuxrc "$MODULES" "$s"
1049 # TODO: rewrite for busybox
1050 #if [ -n "$loopDev" ]; then
1051 # if [ ! -d /initrd ]; then
1055 # cp -a "$loopDev" "$MNTIMAGE/dev"
1056 # cp -a "$rootdev1" "$MNTIMAGE/dev"
1057 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1058 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1059 # echo "echo Setting up loopback device $rootdev1" >> $RCFILE
1060 # echo "losetup $rootdev1 /loopfs$loopFile" >> "$RCFILE"
1063 initrd_gen_suspend() {
1064 if [ ! -x /usr/sbin/resume ]; then
1065 echo "/usr/sbin/resume is missing !"
1068 mkdir -p $MNTIMAGE/etc
1069 mkdir -p $MNTIMAGE/dev
1070 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
1071 cp -HR /dev/snapshot $resume_dev $MNTIMAGE/dev
1072 inst /etc/suspend.conf $MNTIMAGE/etc/suspend.conf
1073 inst /usr/sbin/resume "$MNTIMAGE/bin/resume"
1074 echo "resume" >> "$s"
1077 initrd_gen_suspend2() {
1078 mkdir -p $MNTIMAGE/sys
1079 mkdir -p $MNTIMAGE/proc
1081 mount -t proc none /proc
1082 if [ "\$(awk ' /resume2=/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
1085 echo > /proc/suspend2/do_resume
1092 [ -n "$verbose" ] && echo "Setting up udev..."
1093 mkdir -p $MNTIMAGE/sbin
1094 mkdir -p $MNTIMAGE/proc
1095 mkdir -p $MNTIMAGE/etc/udev
1097 inst /sbin/initrd-udev $MNTIMAGE/sbin/udev
1098 ln -s udev $MNTIMAGE/sbin/udevstart
1099 inst /etc/udev/udev.conf $MNTIMAGE/etc/udev/udev.conf
1101 ln -s udev $MNTIMAGE/sbin/hotplug
1103 if is_yes "$USE_UDEV"; then
1104 if is_yes "$UDEV_TMPFS"; then
1107 mount -o mode=0755 -t tmpfs none /dev
1108 mknod /dev/console c 5 1
1109 mknod /dev/null c 1 3
1110 mknod /dev/zero c 1 5
1116 mount -t proc none /proc
1119 echo -n "/sbin/hotplug" > /proc/sys/kernel/hotplug
1125 initrd_gen_dmraid() {
1126 if [ ! -x /sbin/dmraid-initrd ] ; then
1127 echo "/sbin/dmraid-initrd is missing missing !"
1131 if [ ! -x $MNTIMAGE/sbin/udev ]; then
1132 echo "udev is needed on target initrd for dmraid to work!"
1136 mkdir -p "$MNTIMAGE/sbin"
1137 inst /sbin/dmraid-initrd $MNTIMAGE/sbin/dmraid
1139 mount -t proc none /proc
1140 mount -t sysfs none /sys
1141 # 2 secs was enough for my system to initialize. but really this is udev issue?
1150 initrd_gen_softraid() {
1151 [ -n "$verbose" ] && echo "Setting up mdadm..."
1153 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ] ; then
1154 echo "/sbin/mdadm or /sbin/initrd-mdassemble is missing !"
1158 inst /sbin/initrd-mdassemble "$MNTIMAGE/bin/mdassemble"
1161 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf)
1162 for ex_dev in $dev_list_extra; do
1163 echo "DEVICE $ex_dev" >> "$MNTIMAGE/etc/mdadm.conf"
1166 for nr in `seq 1 $rootdev_nr`; do
1167 eval cr_rootdev="\$rootdev${nr}"
1168 eval cr_dev_list="\$dev_list${nr}"
1169 [ -n "$verbose" ] && echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1171 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1173 echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf"
1174 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1175 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev)
1176 if [ -n "$cr_md_conf" ]; then
1177 echo "$cr_md_conf" >> "$MNTIMAGE/etc/mdadm.conf"
1179 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf"
1182 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1183 # mkdir in case of devfs name
1184 mkdir -p $MNTIMAGE/`my_dirname $f`
1185 [ -e "$MNTIMAGE/$f" ] && continue
1186 [ -n "$verbose" ] && echo "copying $f"
1187 # this works fine with and without devfs
1188 cp -HR $f $MNTIMAGE/$f
1192 echo "mdassemble" >> "$s"
1194 # needed to determine md-version
1195 if [ "$do_md0" -eq 1 ] ; then
1196 mknod $MNTIMAGE/dev/md0 b 9 0
1201 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1202 # have problems like init(XX) being child process of swapper(1).
1203 [ -n "$verbose" ] && echo "Adding rootfs on NFS support to initrd (dhcp)"
1204 mknod "$MNTIMAGE/dev/urandom" c 1 8
1205 mkdir "$MNTIMAGE/newroot"
1206 echo "ifconfig lo 127.0.0.1 up" >> "$s"
1207 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
1208 echo "ifconfig eth0 0.0.0.0 up" >> "$s"
1209 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s"
1210 cat << EOF > "$MNTIMAGE/bin/setdhcp"
1212 [ "\$1" != "bound" ] && exit
1213 [ -n "\$broadcast" ] && BROADCAST="broadcast \$broadcast"
1214 [ -n "\$subnet" ] && NETMASK="netmask \$subnet"
1216 ifconfig \$interface \$ip \$BROADCAST \$NETMASK up
1218 if [ -n "\$router" ]; then
1219 for r in \$router; do
1221 route add default gw \$r dev \$interface
1225 if [ -n "\$rootpath" ]; then
1227 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 \$rootpath /newroot
1231 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1232 echo "All seen variables are listed below:"
1237 chmod 755 "$MNTIMAGE/bin/setdhcp"
1238 echo "cd /newroot" >> "$s"
1239 echo "pivot_root . initrd" >> "$s"
1240 echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1241 echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1245 [ -n "$verbose" ] && echo "Adding LVM support to initrd"
1246 inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
1247 mkdir -p $MNTIMAGE/etc
1248 mkdir -p $MNTIMAGE/tmp
1249 mkdir -p $MNTIMAGE/proc
1250 mkdir -p $MNTIMAGE/newroot
1251 if ! is_yes "$USE_UDEV"; then
1252 mkdir -p $MNTIMAGE/dev/mapper
1253 mknod $MNTIMAGE/dev/mapper/control c 10 63
1254 for device in $PVDEVICES; do
1255 # if LVM on RAID then device might be copied already in gen_softraid
1256 [ -e "$MNTIMAGE/dev/$(basename $device)" ] && continue
1257 cp -HR $device $MNTIMAGE/dev/
1260 echo "mount -t proc none /proc" >> "$s"
1261 echo "mount -t tmpfs none /tmp" >> "$s"
1262 if [ "$LVMTOOLSVERSION" = "1" ] ; then
1263 echo "lvm vgscan -T" >> "$s"
1264 echo "lvm vgchange -T -a y $VGVOLUME" >> "$s"
1265 echo "umount /tmp" >> "$s"
1267 echo "umount /dev" >> "$s"
1268 echo "umount /proc" >> "$s"
1270 echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
1271 echo "global {" > "$MNTIMAGE/etc/lvm.conf"
1272 echo " locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
1273 echo " locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf"
1274 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1275 echo "devices {" >> "$MNTIMAGE/etc/lvm.conf"
1276 echo " sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf"
1277 if is_yes "$raidfound"; then
1278 echo " md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf"
1280 lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf"
1281 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1282 echo "LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure" >> "$s"
1283 echo "LVM_SYSTEM_DIR=/tmp lvm vgchange --ignorelockingfailure -a y $VGVOLUME" >> "$s"
1284 echo "LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure --mknodes" >> "$s"
1285 # Find out major/minor
1286 echo "majmin=\"\`LVM_SYSTEM_DIR=/tmp lvm lvdisplay --ignorelockingfailure -c $org_rootdev\`\"" >> "$s"
1287 echo "majmin=\"\${majmin#*/}\"" >> "$s"
1288 echo "majmin=\"\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}\"" >> "$s"
1289 echo "major=\"\${majmin%:*}\"" >> "$s"
1290 echo "minor=\"\${majmin#*:}\"" >> "$s"
1292 echo "val=\$((256 * \$major + \$minor))" >> "$s"
1293 echo "echo \$val > /proc/sys/kernel/real-root-dev" >> "$s"
1294 echo "umount /tmp" >> "$s"
1295 echo "umount /proc" >> "$s"
1299 initrd_gen_procdata() {
1300 [ -n "$verbose" ] && echo "Adding rootfs finding based on root= option support."
1301 mkdir -p $MNTIMAGE/proc
1304 mount -t proc none /proc
1305 root="\$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,\$0); gsub(/ .*/,NIL,\$0); print \$0; } ' /proc/cmdline)"
1306 if [ -n "\$root" ]; then
1307 rootnr="\$(busybox awk -v root="\$root" ' { if (\$4 == root) { print 256*\$1+\$2; } } ' /proc/partitions)"
1308 if [ -n "\$rootnr" ]; then
1309 echo "\$rootnr" > /proc/sys/kernel/real-root-dev
1319 if is_yes "$USE_UDEV"; then
1323 if is_yes "$USE_SUSPEND"; then
1327 if is_yes "$USE_SUSPEND2"; then
1331 if is_yes "$USE_DMRAID"; then
1335 if is_yes "$usenfs" ; then
1337 elif is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
1339 if is_yes "$uselvm" ; then
1344 elif is_yes "$uselvm" ; then
1350 if [ "$INITRDFS" = "initramfs" ]; then
1351 mkdir -p $MNTIMAGE/newroot
1352 cp -HR $org_rootdev $MNTIMAGE/dev
1353 echo "mount -t $rootFs $org_rootdev /newroot" >> "$s"
1354 echo "switch_root /newroot /sbin/init" >> "$s"
1355 # we need real file, not symlink
1356 rm -f $MNTIMAGE/init
1357 cp -a $MNTIMAGE/linuxrc $MNTIMAGE/init
1362 (cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
1369 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
1372 mkcramfs "$MNTPOINT" "$IMAGE"
1375 (cd $MNTPOINT ; find . | cpio -H newc -o > "$IMAGE")
1378 echo "Filesystem $INITRDFS not supported by $0";
1381 if is_yes "$COMPRESS" ; then
1382 gzip -9 < "$IMAGE" > "$target"
1384 cp -a "$IMAGE" "$target"
1387 if is_yes "$BOOT_SPLASH"; then
1388 if [ ! -x /bin/splash.bin ]; then
1389 echo "Failed to execute /bin/splash.bin. Is bootsplash package installed?" 1>&2
1390 elif [ -z "$THEME" ]; then
1391 echo "Please configure your /etc/sysconfig/bootsplash first." 1>&2
1392 echo "Generating bootsplashes skipped." 1>&2
1394 if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
1395 for res in $BOOT_SPLASH_RESOLUTIONS; do
1396 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1397 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1398 [ -n "$verbose" ] && echo "Added $res $THEME theme to initrd."
1400 echo "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" 1>&2
1404 echo "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." 1>&2
1405 echo "Not adding bootsplash to initrd." 1>&2
1410 rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"