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
193 mod=$(echo $mod | awk '{sub(/^\/lib\/modules\/[^\/]*\//,"");print}')
194 addmodule $mod "$skiperrors"
199 if [ "$#" != "2" ];then
200 echo "usage: inst <file> <destination>"
203 [ -n "$verbose" ] && echo "$1 -> $2"
208 /sbin/e2label $1 2> /dev/null
212 /sbin/tune2fs -l $1 2> /dev/null | awk -F: '/UUID:/ {gsub(" ",""); print $2}'
216 /usr/sbin/xfs_db -x -p xfs_admin -c label -r "$1"|awk -F= '{sub("^\"","", $2); sub("\"$", "", $2); print $2}'
221 /usr/sbin/xfs_db -x -p xfs_admin -c uuid -r "$1"|awk -F= '{print $2}'
225 eval `awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab`
228 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
229 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
230 if [ -n "$rootdev2" ] ; then
235 if [ "$rootdev_found." != "1." ] ; then
238 if [ ! -x /sbin/e2label ] ; then
239 echo "/sbin/e2label is missing" 1>&2
242 get_label="get_label_ext2"
245 if [ ! -x /usr/sbin/xfs_db ] ; then
246 echo "/usr/sbin/xfs_db is missing" 1>&2
249 get_label="get_label_xfs"
252 echo "LABEL on $rootFs in not supported by geninitrd" 1>&2
256 if [ ! -r /proc/partitions ] ; then
257 echo '/proc/partitions is not readable'; 1>&2
260 label=${rootdev#"LABEL="}
261 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
262 if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
263 if [ -n "$verbose" ] ; then
264 echo "Using $dev as device for rootfs"
271 if [ "$rootdev_found." != "1." ] ; then
272 echo "geninitrd can't find real device for LABEL=$label" 1>&2
278 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
279 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
280 if [ -n "$rootdev2" ] ; then
285 if [ "$rootdev_found." != "1." ] ; then
288 if [ ! -x /sbin/tune2fs ] ; then
289 echo "/sbin/tune2fs is missing" 1>&2
292 get_uuid="get_uuid_ext2"
295 if [ ! -x /usr/sbin/xfs_db ] ; then
296 echo "/usr/sbin/xfs_db is missing" 1>&2
299 get_label="get_uuid_xfs"
302 echo "UUID on $rootFs in not supported by geninitrd" 1>&2
306 if [ ! -r /proc/partitions ] ; then
307 echo '/proc/partitions is not readable'; 1>&2
310 uuid=${rootdev#"UUID="}
311 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
312 if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
313 if [ -n "$verbose" ] ; then
314 echo "Using $dev as device for rootfs"
321 if [ "$rootdev_found" != 1 ] ; then
322 echo "geninitrd can't find real device for UUID=$uuid" 1>&2
331 find_modules_softraid() {
332 if [ -f /etc/mdadm.conf ]; then
333 [ -n "$verbose" ] && echo "Finding RAID details using mdadm for rootdev=$1"
334 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
339 rootdev_devfs = rootdev;
340 if (rootdev ~ /\/dev\/md\/[0-9]/) {
341 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
346 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
348 gsub(/level=/,NUL,raidlevel);
349 if (raidlevel ~ /^raid([0-6]|10)/) {
350 gsub(/raid/,NUL,raidlevel);
354 if (x ~ /devices=/) {
356 gsub(".*devices=", NUL, dev_list);
357 gsub(",", " ", dev_list);
363 print "raidfound=" found;
364 print "raidlevel=" raidlevel;
365 print "dev_list=\"" dev_list "\"";
369 if [ "$raidfound" != "yes" -a -f /etc/raidtab ]; then
370 echo "ERROR: raidtools are not longer supported. Please migrate to mdadm setup!" 1>&2
374 if is_yes "$raidfound" ; then
377 findmodule "raid$raidlevel"
383 echo "raid level $number (in mdadm config) not recognized" 1>&2
387 echo "ERROR: RAID devices not found for \"$1\", check your configuration!" 1>&2
391 rootdev_nr=$(( $rootdev_nr + 1 ))
392 eval "rootdev${rootdev_nr}=\"$1\""
393 eval "dev_list${rootdev_nr}=\"${dev_list}\""
395 for device in $dev_list; do
396 find_modules_for $device
400 find_modules_scsi() {
401 for n in $PRESCSIMODS; do
402 if [ "X$n" = "Xunknown" ] ; then
403 if [ -f "$modulefile" ]; then
404 scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
405 for n in $scsimodules; do
406 # for now allow scsi modules to come from anywhere. There are some
407 # RAID controllers with drivers in block
420 rootdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')"
421 if [ "$pack_version_long" -lt "002004021" ]; then
422 [ -n "$verbose" ] && echo "Finding IDE modules for kernels <= 2.4.20"
423 for n in $PREIDEMODSOLD; do
428 for n in $PREIDEMODS; do
429 if [ "X$n" = "Xunknown" ] ; then
430 if [ -f "$modulefile" ]; then
431 [ -n "$verbose" ] && echo "Finding IDE modules using ide_hostadapter"
432 idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
433 for na in $idemodules; do
439 if [ "$tryauto" -eq 1 ]; then
441 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
442 [ -n "$verbose" ] && echo "Finding IDE modules using PCI ID database"
443 # 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)"
454 if [ -z "${searchpciid}" ]; then
455 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
460 for nb in $searchpciid; do
461 eval `awk -v pciid="$nb" '{
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}"
490 if [ -z "$idemodules" ]; then
491 echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic."
492 idemodules="ide-generic"
496 for nd in $idemodules; do
502 [ -r /usr/share/pci-database/ide.pci ] || echo "WARNING: /usr/share/pci-database/ide.pci missing."
503 [ -r /proc/bus/pci/devices ] || echo "WARNING: /proc/bus/pci/devices missing."
504 echo "Automatic IDE modules finding not available."
515 # return true if node is lvm node
518 if [ ! -e "$node" ]; then
522 # block-major-58 is lvm1
523 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
527 [ -n "$verbose" ] && echo "$node is LVM1 node"
532 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
534 if [ $rc -gt 127 ]; then
535 # lvdisplay terminated by signal! most likely it segfaulted.
536 echo >&2 "ERROR: Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
541 [ -n "$verbose" ] && echo "$node is lvm2 node"
543 [ -n "$verbose" ] && echo "$node is not any lvm node"
550 echo "ERROR: no argument passed to find_modules_for() - is your /etc/fstab correct?" >&2
553 elif is_yes "`echo "$1" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
554 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then
555 echo "ERROR: root on NFS but /usr/bin/pcidev not found." >&2
556 echo "Please install correct pci-database package and rerun $0." >&2
559 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
560 for m in $NFS_ETH_MODULES; do
566 echo "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel" >&2
567 echo "or you will have problems like init(xx) being child process of swapper(1)." >&2
568 elif is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
569 find_modules_softraid "$1"
570 elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
572 elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
573 find_modules_ide "$1"
574 elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
576 elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
577 findmodule "cpqarray"
578 elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
580 elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
583 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
584 if -n "$ataraidmodules" ; then
585 # FIXME: think about modules compiled in kernel
586 echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
587 echo "Please set it and run $0 again."
590 for n in $ataraidmodules; do
593 # check to see if we need to set up a loopback filesystem
594 elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
595 echo "Sorry, root on loop device isn't supported." 1>&2
597 # TODO: rewrite for bsp and make nfs ready
598 if [ ! -x /sbin/losetup ]; then
599 echo "losetup is missing"
602 key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
603 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
604 echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
605 echo "for this device. Consult the geninitrd man page for more information" 1>&2
609 line="`awk '/'$key'/ { print $0; }' $fstab`"
610 loopDev="$(echo $line | awk '{print $3}')"
611 loopFs="$(echo $line | awk '{print $4}')"
612 loopFile="$(echo $line | awk '{print $5}')"
614 BASICMODULES="$BASICMODULES -loop"
615 findmodule "-$loopFs"
616 BASICMODULES="$BASICMODULES -${loopFs}"
617 elif _check_lvm "$1"; then
618 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then
619 echo "ERROR: root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found." >&2
620 echo "Please install lvm(2) and lvm(2)-initrd package and rerun $0." >&2
623 if [ -z "$LVMTOOLSVERSION" ] ; then
624 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}')
625 if [ -z "$LVMTOOLSVERSION" ] ; then
626 echo "ERROR: Can't determine LVM tools version. Please set LVMTOOLSVERSION" >&2
627 echo "and rerun $0." >&2
631 if [ -z "$PVDEVICES" ] ; then
632 VGVOLUME=$(/sbin/lvdisplay -c "$1" 2> /dev/null | awk -F":" ' { print $2 } ')
633 PVDEVICES=$(/sbin/pvdisplay -c | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
635 if [ -n "$PVDEVICES" ] ; then
636 for device in $PVDEVICES; do
637 find_modules_for $device
640 echo "ERROR: I wasn't able to find PV (via lvdisplay and pvdisplay)." >&2
641 echo "You can try to set PVDEVICES in /etc/sysconfig/geninitrd." >&2
644 if [ "$LVMTOOLSVERSION" = "2" ]; then
646 elif [ "$LVMTOOLSVERSION" = "1" ]; then
648 findmodule "-lvm-mod"
650 echo "ERROR: LVM version $LVMTOOLSVERSION is not supported yet." >&2
653 [ -n "$verbose" ] && echo "LVM $LVMTOOLSVERSION enabled"
661 for mod in $modules; do
662 MODULEDIR="`my_dirname "$mod"`"
663 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
664 cp $verbose -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
665 gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
669 modules_add_linuxrc() {
673 for mod in $modules; do
674 MODULE2="`my_dirname "$mod"`"
675 NAME2=`basename "$mod" .gz`
676 MODULE2=$MODULE2/$NAME2
677 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
678 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
680 sleep_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ')
681 sleep_var="$(eval echo \$MODULE_${sleep_module}_USLEEP)"
683 if [ -n "$verbose" ]; then
684 echo -n "Loading module [$module] "
685 if [ -n "$options" ] ; then
686 echo -n "with options [$options]"
688 echo -n "without options"
690 if [ -n "$sleep_var" ]; then
691 echo " and $sleep_var usleep."
697 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
698 if [ -n "${sleep_var}" ]; then
699 echo "usleep $sleep_var" >> "$linuxrc"
704 if [ -r /etc/sysconfig/geninitrd ] ; then
705 . /etc/sysconfig/geninitrd
708 if [ -r /etc/sysconfig/bootsplash ] ; then
709 . /etc/sysconfig/bootsplash
712 if [ ! -x /bin/initrd-busybox ] ; then
713 echo "/bin/initrd-busybox is missing !"
716 case "$(uname -m)" in
717 ia64|amd64|x86_64|sparc64)
725 while [ $# -gt 0 ]; do
728 fstab="`echo $1 | awk -F= '{print $2;}'`"
735 modulefile="`echo $1 | awk -F= '{print $2;}'`"
741 --use-raidstart|--with-raidstart)
747 --use-insmod-static|--with-insmod-static)
748 USEINSMODSTATIC="yes"
750 --without-insmod-static)
753 --without-bootsplash)
762 --lvmtoolsversion=|--lvmversion=)
763 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
765 --lvmtoolsversion|--lvmversion)
776 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
779 BASICMODULES="$BASICMODULES $2"
783 echo "geninitrd: version $VERSION"
799 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
802 PREMODS="$PREMODS $2"
806 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
807 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
810 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
815 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
828 if [ -z "$target" ]; then
830 elif [ -z "$kernel" ]; then
841 if [ -z "$target" -o -z "$kernel" ]; then
845 pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
846 pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
848 if [ "x" = "x$INITRDFS" ] ; then
849 if [ "x" = "x$FS" ] ; then
851 # XXX: initramfs blocked for now
852 if [ "1" = " 0" -a "$pack_version" -ge "002005" ] ; then
858 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
863 if [ "$pack_version" -lt "002006" ] ; then
867 [ -z "$USE_UDEV" ] && UDEV_TMPFS=
869 if [ "$pack_version" -ge "002005" ] ; then
874 if is_yes "$USEINSMODSTATIC" ; then
875 insmod="insmod.static"
876 INSMOD="/sbin/insmod.static"
877 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
878 INSMOD="/sbin/insmod.static.modutils"
880 if [ ! -f "$INSMOD" ] ; then
881 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
888 IMAGESIZE=$((IMAGESIZE + 100))
889 if [ ! -x /sbin/mke2fs ]; then
890 echo "/sbin/mke2fs is missing" 1>&2
895 if [ ! -x /sbin/genromfs ]; then
896 echo "/sbin/genromfs is missing" 1>&2
901 if [ ! -x /sbin/mkcramfs ]; then
902 echo "/sbin/mkcramfs is missing" 1>&2
907 if [ ! -x /bin/cpio ]; then
908 echo "/bin/cpio is missing" 1>&2
911 if [ ! -x /usr/bin/find ]; then
912 echo "/usr/bin/find is missing" 1>&2
917 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
922 if [ -n "$img_vers" ]; then
923 target="$target-$kernel"
926 if [ -z "$force" -a -f "$target" ]; then
927 echo "$target already exists." 1>&2
931 if [ ! -d "/lib/modules/$kernel" ]; then
932 echo "/lib/modules/$kernel is not a directory." 1>&2
936 if is_yes "$USE_SUSPEND"; then
937 if is_yes "$USE_SUSPEND2"; then
938 echo "Suspend2 shouldn't be used in parallel with mainline suspend!." 1>&2
943 if [ ! -f /proc/mounts ]; then
944 echo "WARNING: /proc filesystem not mounted, may cause wrong results or failure." 1>&2
947 if [ "$pack_version" -lt "002005" ]; then
948 modulefile=/etc/modules.conf
949 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
950 modulefile=/etc/conf.modules
953 modulefile=/etc/modprobe.conf
956 for n in $PREMODS; do
960 # allow forcing loading SCSI and/or IDE modules
961 if is_yes "$ADDSCSI" ; then
965 if is_yes "$ADDIDE" ; then
971 org_rootdev="$rootdev1"
973 find_modules_for "$rootdev1"
975 findmodule "-$rootFs"
977 for n in $BASICMODULES; do
981 if is_yes "$USE_SUSPEND2"; then
985 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
986 if [ -n "$verbose" ]; then
987 echo "No modules are needed -- not building initrd image."
992 if [ -n "$verbose" ]; then
993 echo "Using modules: $MODULES"
996 MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
997 IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
998 MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
999 RCFILE="$MNTIMAGE/linuxrc"
1001 if [ -f "$MNTIMAGE" ]; then
1002 echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
1006 if [ -f "$IMAGE" ]; then
1007 echo "$IMAGE already exists. Remove it and try again" 1>&2
1011 if [ "$INITRDFS" = "ext2" ] ; then
1012 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1013 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1014 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1016 mkdir -p "$MNTPOINT"
1017 mount -o loop -t ext2 "$IMAGE" "$MNTPOINT"
1019 mkdir -p "$MNTPOINT"
1023 mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs,var}
1026 # We don't need this directory, so let's save space
1027 rm -rf "$MNTPOINT"/lost+found
1029 modules_install "$MODULES"
1031 # mknod'ing the devices instead of copying them works both with and
1033 mknod "$MNTIMAGE/dev/console" c 5 1
1034 mknod "$MNTIMAGE/dev/null" c 1 3
1035 mknod "$MNTIMAGE/dev/zero" c 1 5
1038 ln -s /linuxrc $MNTIMAGE/init
1040 inst /bin/initrd-busybox "$MNTIMAGE/bin/sh"
1041 ln -s sh "$MNTIMAGE/bin/busybox"
1043 if is_yes "$USEINSMODSTATIC" ; then
1044 inst "$INSMOD" $MNTIMAGE/bin/insmod.static
1054 modules_add_linuxrc "$MODULES" "$s"
1056 # TODO: rewrite for busybox
1057 #if [ -n "$loopDev" ]; then
1058 # if [ ! -d /initrd ]; then
1062 # cp -a "$loopDev" "$MNTIMAGE/dev"
1063 # cp -a "$rootdev1" "$MNTIMAGE/dev"
1064 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1065 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1066 # echo "echo Setting up loopback device $rootdev1" >> $RCFILE
1067 # echo "losetup $rootdev1 /loopfs$loopFile" >> "$RCFILE"
1070 initrd_gen_suspend() {
1071 if [ ! -x /usr/sbin/resume ]; then
1072 echo "/usr/sbin/resume is missing !"
1075 mkdir -p $MNTIMAGE/etc
1076 mkdir -p $MNTIMAGE/dev
1077 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
1078 cp -HR /dev/snapshot $resume_dev $MNTIMAGE/dev
1079 inst /etc/suspend.conf $MNTIMAGE/etc/suspend.conf
1080 inst /usr/sbin/resume "$MNTIMAGE/bin/resume"
1081 echo "resume" >> "$s"
1084 initrd_gen_suspend2() {
1085 mkdir -p $MNTIMAGE/sys
1086 mkdir -p $MNTIMAGE/proc
1087 cat << 'EOF' >> "$s"
1088 mount -t proc none /proc
1089 if [ "$(awk ' /resume2=/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
1092 echo > /proc/suspend2/do_resume
1099 [ -n "$verbose" ] && echo "Setting up udev..."
1100 mkdir -p $MNTIMAGE/sbin
1101 mkdir -p $MNTIMAGE/proc
1102 mkdir -p $MNTIMAGE/etc/udev
1104 inst /sbin/initrd-udev $MNTIMAGE/sbin/udev
1105 ln -s udev $MNTIMAGE/sbin/udevstart
1106 inst /etc/udev/udev.conf $MNTIMAGE/etc/udev/udev.conf
1108 ln -s udev $MNTIMAGE/sbin/hotplug
1110 if is_yes "$USE_UDEV"; then
1111 if is_yes "$UDEV_TMPFS"; then
1114 mount -o mode=0755 -t tmpfs none /dev
1115 mknod /dev/console c 5 1
1116 mknod /dev/null c 1 3
1117 mknod /dev/zero c 1 5
1123 mount -t proc none /proc
1126 echo -n "/sbin/hotplug" > /proc/sys/kernel/hotplug
1132 initrd_gen_dmraid() {
1133 if [ ! -x /sbin/dmraid-initrd ] ; then
1134 echo "/sbin/dmraid-initrd is missing missing !"
1138 if [ ! -x $MNTIMAGE/sbin/udev ]; then
1139 echo "udev is needed on target initrd for dmraid to work!"
1143 mkdir -p "$MNTIMAGE/sbin"
1144 inst /sbin/dmraid-initrd $MNTIMAGE/sbin/dmraid
1146 mount -t proc none /proc
1147 mount -t sysfs none /sys
1148 # 2 secs was enough for my system to initialize. but really this is udev issue?
1150 echo 'Activating Device-Mapper RAID(s)'
1158 initrd_gen_softraid() {
1159 [ -n "$verbose" ] && echo "Setting up mdadm..."
1161 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ] ; then
1162 echo "/sbin/mdadm or /sbin/initrd-mdassemble is missing !"
1166 inst /sbin/initrd-mdassemble "$MNTIMAGE/bin/mdassemble"
1169 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf)
1170 for ex_dev in $dev_list_extra; do
1171 echo "DEVICE $ex_dev" >> "$MNTIMAGE/etc/mdadm.conf"
1174 for nr in `seq 1 $rootdev_nr`; do
1175 eval cr_rootdev="\$rootdev${nr}"
1176 eval cr_dev_list="\$dev_list${nr}"
1177 [ -n "$verbose" ] && echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1179 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1181 echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf"
1182 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1183 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev)
1184 if [ -n "$cr_md_conf" ]; then
1185 echo "$cr_md_conf" >> "$MNTIMAGE/etc/mdadm.conf"
1187 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf"
1190 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1191 # mkdir in case of devfs name
1192 mkdir -p $MNTIMAGE/`my_dirname $f`
1193 [ -e "$MNTIMAGE/$f" ] && continue
1194 [ -n "$verbose" ] && echo "copying $f"
1195 # this works fine with and without devfs
1196 cp -HR $f $MNTIMAGE/$f
1200 echo "mdassemble" >> "$s"
1202 # needed to determine md-version
1203 if [ "$do_md0" -eq 1 ] ; then
1204 mknod $MNTIMAGE/dev/md0 b 9 0
1209 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1210 # have problems like init(XX) being child process of swapper(1).
1211 [ -n "$verbose" ] && echo "Adding rootfs on NFS support to initrd (dhcp)"
1212 mknod "$MNTIMAGE/dev/urandom" c 1 8
1213 mkdir "$MNTIMAGE/newroot"
1214 mkdir "$MNTIMAGE/proc"
1215 echo "ifconfig lo 127.0.0.1 up" >> "$s"
1216 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
1217 echo "ifconfig eth0 0.0.0.0 up" >> "$s"
1218 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s"
1219 cat << 'EOF' > "$MNTIMAGE/bin/setdhcp"
1221 [ "$1" != "bound" ] && exit
1222 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1223 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1225 ifconfig $interface $ip $BROADCAST $NETMASK up
1227 if [ -n "$router" ]; then
1228 for r in $router; do
1230 route add default gw $r dev $interface
1235 mount -t proc none /proc
1236 for o in $(cat /proc/cmdline); do
1239 rootpath=${o#nfsroot=}
1245 if [ -n "$rootpath" ]; then
1247 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1251 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1252 echo "All seen variables are listed below:"
1257 chmod 755 "$MNTIMAGE/bin/setdhcp"
1258 echo "cd /newroot" >> "$s"
1259 echo "pivot_root . initrd" >> "$s"
1260 echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1261 echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1265 [ -n "$verbose" ] && echo "Adding LVM support to initrd"
1266 inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
1267 mkdir -p $MNTIMAGE/etc
1268 mkdir -p $MNTIMAGE/tmp
1269 mkdir -p $MNTIMAGE/proc
1270 mkdir -p $MNTIMAGE/newroot
1271 if ! is_yes "$USE_UDEV"; then
1272 mkdir -p $MNTIMAGE/dev/mapper
1273 mknod $MNTIMAGE/dev/mapper/control c 10 63
1274 for device in $PVDEVICES; do
1275 # if LVM on RAID then device might be copied already in gen_softraid
1276 [ -e "$MNTIMAGE/dev/$(basename $device)" ] && continue
1277 cp -HR $device $MNTIMAGE/dev/
1280 echo "mount -t proc none /proc" >> "$s"
1281 echo "mount -t tmpfs none /tmp" >> "$s"
1282 if [ "$LVMTOOLSVERSION" = "1" ] ; then
1283 echo "lvm vgscan -T" >> "$s"
1284 echo "lvm vgchange -T -a y $VGVOLUME" >> "$s"
1285 echo "umount /tmp" >> "$s"
1287 echo "umount /dev" >> "$s"
1288 echo "umount /proc" >> "$s"
1290 echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
1291 echo "global {" > "$MNTIMAGE/etc/lvm.conf"
1292 echo " locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
1293 echo " locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf"
1294 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1295 echo "devices {" >> "$MNTIMAGE/etc/lvm.conf"
1296 echo " sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf"
1297 if is_yes "$raidfound"; then
1298 echo " md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf"
1300 lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf"
1301 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1304 : 'Scanning for Volume Groups'
1305 LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure
1306 : 'Activating Volume Groups'
1307 LVM_SYSTEM_DIR=/tmp lvm vgchange --ignorelockingfailure -a y $VGVOLUME 2>/dev/null
1309 # Find out major/minor
1310 majmin="\`LVM_SYSTEM_DIR=/tmp lvm lvdisplay --ignorelockingfailure -c $org_rootdev\`"
1311 majmin="\${majmin#*/}"
1312 majmin="\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}"
1313 major="\${majmin%:*}"
1314 minor="\${majmin#*:}"
1316 val=\$((256 * \$major + \$minor))
1317 echo \$val > /proc/sys/kernel/real-root-dev
1324 initrd_gen_procdata() {
1325 [ -n "$verbose" ] && echo "Adding rootfs finding based on root= option support."
1326 mkdir -p $MNTIMAGE/proc
1327 cat << 'EOF' >> "$s"
1329 mount -t proc none /proc
1330 root="$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ' /proc/cmdline)"
1331 if [ -n "$root" ]; then
1332 rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)"
1333 if [ -n "$rootnr" ]; then
1334 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1344 if is_yes "$USE_UDEV"; then
1348 if is_yes "$USE_SUSPEND"; then
1352 if is_yes "$USE_SUSPEND2"; then
1356 if is_yes "$USE_DMRAID"; then
1360 if is_yes "$usenfs" ; then
1362 elif is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
1364 if is_yes "$uselvm" ; then
1369 elif is_yes "$uselvm" ; then
1375 if [ "$INITRDFS" = "initramfs" ]; then
1376 mkdir -p $MNTIMAGE/newroot
1377 cp -HR $org_rootdev $MNTIMAGE/dev
1378 echo "mount -t $rootFs $org_rootdev /newroot" >> "$s"
1379 echo "switch_root /newroot /sbin/init" >> "$s"
1380 # we need real file, not symlink
1381 rm -f $MNTIMAGE/init
1382 cp -a $MNTIMAGE/linuxrc $MNTIMAGE/init
1387 (cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
1394 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
1397 mkcramfs "$MNTPOINT" "$IMAGE"
1400 (cd $MNTPOINT ; find . | cpio -H newc -o > "$IMAGE")
1403 echo "Filesystem $INITRDFS not supported by $0";
1406 if is_yes "$COMPRESS" ; then
1407 gzip -9 < "$IMAGE" > "$target"
1409 cp -a "$IMAGE" "$target"
1412 if is_yes "$BOOT_SPLASH"; then
1413 if [ ! -x /bin/splash.bin ]; then
1414 echo "Failed to execute /bin/splash.bin. Is bootsplash package installed?" 1>&2
1415 elif [ -z "$THEME" ]; then
1416 echo "Please configure your /etc/sysconfig/bootsplash first." 1>&2
1417 echo "Generating bootsplashes skipped." 1>&2
1419 if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
1420 for res in $BOOT_SPLASH_RESOLUTIONS; do
1421 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1422 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1423 [ -n "$verbose" ] && echo "Added $res $THEME theme to initrd."
1425 echo "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" 1>&2
1429 echo "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." 1>&2
1430 echo "Not adding bootsplash to initrd." 1>&2
1435 rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"
1437 # vim:ts=4:sw=4:noet:fdm=marker