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 " [--with-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."
511 echo "ERROR: no argument passed to find_modules_for() - is your /etc/fstab correct?" >&2
513 elif is_yes "`echo "$1" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
514 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then
515 echo "ERROR: root on NFS but /usr/bin/pcidev not found." >&2
516 echo "Please install correct pci-database package and rerun $0." >&2
519 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
520 for m in $NFS_ETH_MODULES; do
526 echo "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel" >&2
527 echo "or you will have problems like init(xx) being child process of swapper(1)." >&2
528 elif is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
529 find_modules_softraid "$1"
530 elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
532 elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
533 find_modules_ide "$1"
534 elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
536 elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
537 findmodule "cpqarray"
538 elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
540 elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
543 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
544 if -n "$ataraidmodules" ; then
545 # FIXME: think about modules compiled in kernel
546 echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
547 echo "Please set it and run $0 again."
550 for n in $ataraidmodules; do
553 # check to see if we need to set up a loopback filesystem
554 elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
555 echo "Sorry, root on loop device isn't supported." 1>&2
557 # TODO: rewrite for bsp and make nfs ready
558 if [ ! -x /sbin/losetup ]; then
559 echo "losetup is missing"
562 key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
563 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
564 echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
565 echo "for this device. Consult the geninitrd man page for more information" 1>&2
569 line="`awk '/'$key'/ { print $0; }' $fstab`"
570 loopDev="$(echo $line | awk '{print $3}')"
571 loopFs="$(echo $line | awk '{print $4}')"
572 loopFile="$(echo $line | awk '{print $5}')"
574 BASICMODULES="$BASICMODULES -loop"
575 findmodule "-$loopFs"
576 BASICMODULES="$BASICMODULES -${loopFs}"
577 # don't have any clue, how is this supposed to work
578 elif [ -e "$1" ] && ls -l "$1" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}' || /sbin/lvm lvdisplay "$1" > /dev/null 2>&1 ; then
579 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then
580 echo "ERROR: root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found." >&2
581 echo "Please install lvm(2) and lvm(2)-initrd package and rerun $0." >&2
584 if [ -z "$LVMTOOLSVERSION" ] ; then
585 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}')
586 if [ -z "$LVMTOOLSVERSION" ] ; then
587 echo "ERROR: Can't determine LVM tools version. Please set LVMTOOLSVERSION" >&2
588 echo "and rerun $0." >&2
592 if [ -z "$PVDEVICES" ] ; then
593 VGVOLUME=$(/sbin/lvdisplay -c "$1" 2> /dev/null | awk -F":" ' { print $2 } ')
594 PVDEVICES=$(/sbin/pvdisplay -c | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
596 if [ -n "$PVDEVICES" ] ; then
597 for device in $PVDEVICES; do
598 find_modules_for $device
601 echo "ERROR: I wasn't able to find PV (via lvdisplay and pvdisplay)." >&2
602 echo "You can try to set PVDEVICES in /etc/sysconfig/geninitrd." >&2
605 if [ "$LVMTOOLSVERSION" = "2" ]; then
607 elif [ "$LVMTOOLSVERSION" = "1" ]; then
609 findmodule "-lvm-mod"
611 echo "ERROR: LVM version $LVMTOOLSVERSION is not supported yet." >&2
621 for mod in $modules; do
622 MODULEDIR="`my_dirname "$mod"`"
623 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
624 cp $verbose -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
625 gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
629 modules_add_linuxrc() {
633 for mod in $modules; do
634 MODULE2="`my_dirname "$mod"`"
635 NAME2=`basename "$mod" .gz`
636 MODULE2=$MODULE2/$NAME2
637 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
638 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
640 sleep_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ')
641 sleep_var="$(eval echo \$MODULE_${sleep_module}_USLEEP)"
643 if [ -n "$verbose" ]; then
644 echo -n "Loading module [$module] "
645 if [ -n "$options" ] ; then
646 echo -n "with options [$options]"
648 echo -n "without options"
650 if [ -n "$sleep_var" ]; then
651 echo " and $sleep_var usleep."
656 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
657 if [ -n "${sleep_var}" ]; then
658 echo "usleep $sleep_var" >> "$linuxrc"
663 if [ -r /etc/sysconfig/geninitrd ] ; then
664 . /etc/sysconfig/geninitrd
667 if [ -r /etc/sysconfig/bootsplash ] ; then
668 . /etc/sysconfig/bootsplash
671 if [ ! -x /bin/initrd-busybox ] ; then
672 echo "/bin/initrd-busybox is missing !"
675 case "$(uname -m)" in
676 ia64|amd64|x86_64|sparc64)
684 while [ $# -gt 0 ]; do
687 fstab="`echo $1 | awk -F= '{print $2;}'`"
694 modulefile="`echo $1 | awk -F= '{print $2;}'`"
700 --use-raidstart|--with-raidstart)
706 --use-insmod-static|--with-insmod-static)
707 USEINSMODSTATIC="yes"
709 --without-insmod-static)
712 --without-bootsplash)
721 --lvmtoolsversion=|--lvmversion=)
722 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
724 --lvmtoolsversion|--lvmversion)
735 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
738 BASICMODULES="$BASICMODULES $2"
742 echo "geninitrd: version $VERSION"
758 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
761 PREMODS="$PREMODS $2"
765 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
766 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
769 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
774 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
787 if [ -z "$target" ]; then
789 elif [ -z "$kernel" ]; then
800 if [ -z "$target" -o -z "$kernel" ]; then
804 pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
805 pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
807 if [ "x" = "x$INITRDFS" ] ; then
808 if [ "x" = "x$FS" ] ; then
810 # XXX: initramfs blocked for now
811 if [ "1" = " 0" -a "$pack_version" -ge "002005" ] ; then
817 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
822 if [ "$pack_version" -lt "002006" ] ; then
826 [ -z "$USE_UDEV" ] && UDEV_TMPFS=
828 if [ "$pack_version" -ge "002005" ] ; then
833 if is_yes "$USEINSMODSTATIC" ; then
834 insmod="insmod.static"
835 INSMOD="/sbin/insmod.static"
836 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
837 INSMOD="/sbin/insmod.static.modutils"
839 if [ ! -f "$INSMOD" ] ; then
840 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
847 if [ ! -x /sbin/mke2fs ]; then
848 echo "/sbin/mke2fs is missing" 1>&2
853 if [ ! -x /sbin/genromfs ]; then
854 echo "/sbin/genromfs is missing" 1>&2
859 if [ ! -x /sbin/mkcramfs ]; then
860 echo "/sbin/mkcramfs is missing" 1>&2
865 if [ ! -x /bin/cpio ]; then
866 echo "/bin/cpio is missing" 1>&2
869 if [ ! -x /usr/bin/find ]; then
870 echo "/usr/bin/find is missing" 1>&2
875 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
880 if [ -n "$img_vers" ]; then
881 target="$target-$kernel"
884 if [ -z "$force" -a -f "$target" ]; then
885 echo "$target already exists." 1>&2
889 if [ ! -d "/lib/modules/$kernel" ]; then
890 echo "/lib/modules/$kernel is not a directory." 1>&2
894 if is_yes "$USE_SUSPEND"; then
895 if is_yes "$USE_SUSPEND2"; then
896 echo "Suspend2 shouldn't be used in parallel with mainline suspend!." 1>&2
901 if [ ! -f /proc/mounts ]; then
902 echo "WARNING: /proc filesystem not mounted, may cause wrong results or failure." 1>&2
905 if [ "$pack_version" -lt "002005" ]; then
906 modulefile=/etc/modules.conf
907 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
908 modulefile=/etc/conf.modules
911 modulefile=/etc/modprobe.conf
914 for n in $PREMODS; do
918 # allow forcing loading SCSI and/or IDE modules
919 if is_yes "$ADDSCSI" ; then
923 if is_yes "$ADDIDE" ; then
929 org_rootdev="$rootdev1"
931 find_modules_for "$rootdev1"
933 findmodule "-$rootFs"
935 for n in $BASICMODULES; do
939 if is_yes "$USE_SUSPEND2"; then
943 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
944 if [ -n "$verbose" ]; then
945 echo "No modules are needed -- not building initrd image."
950 if [ -n "$verbose" ]; then
951 echo "Using modules: $MODULES"
954 MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
955 IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
956 MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
957 RCFILE="$MNTIMAGE/linuxrc"
959 if [ -f "$MNTIMAGE" ]; then
960 echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
964 if [ -f "$IMAGE" ]; then
965 echo "$IMAGE already exists. Remove it and try again" 1>&2
969 if [ "$INITRDFS" = "ext2" ] ; then
970 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
972 # We have to "echo y |" so that it doesn't complain about $IMAGE not
973 # being a block device
974 echo y | mke2fs -F "$IMAGE" "$IMAGESIZE" >/dev/null 2>/dev/null
977 mount -o loop -t ext2 "$IMAGE" "$MNTPOINT"
983 mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs,var}
986 # We don't need this directory, so let's save space
987 rm -rf "$MNTPOINT"/lost+found
989 modules_install "$MODULES"
991 # mknod'ing the devices instead of copying them works both with and
993 mknod "$MNTIMAGE/dev/console" c 5 1
994 mknod "$MNTIMAGE/dev/null" c 1 3
995 mknod "$MNTIMAGE/dev/zero" c 1 5
998 ln -s /linuxrc $MNTIMAGE/init
1000 inst /bin/initrd-busybox "$MNTIMAGE/bin/sh"
1001 ln -s sh "$MNTIMAGE/bin/busybox"
1003 if is_yes "$USEINSMODSTATIC" ; then
1004 inst "$INSMOD" $MNTIMAGE/bin/insmod.static
1014 modules_add_linuxrc "$MODULES" "$s"
1016 # TODO: rewrite for busybox
1017 #if [ -n "$loopDev" ]; then
1018 # if [ ! -d /initrd ]; then
1022 # cp -a "$loopDev" "$MNTIMAGE/dev"
1023 # cp -a "$rootdev1" "$MNTIMAGE/dev"
1024 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1025 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1026 # echo "echo Setting up loopback device $rootdev1" >> $RCFILE
1027 # echo "losetup $rootdev1 /loopfs$loopFile" >> "$RCFILE"
1030 initrd_gen_suspend() {
1031 if [ ! -x /usr/sbin/resume ]; then
1032 echo "/usr/sbin/resume is missing !"
1035 mkdir -p $MNTIMAGE/etc
1036 mkdir -p $MNTIMAGE/dev
1037 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
1038 cp -HR /dev/snapshot $resume_dev $MNTIMAGE/dev
1039 inst /etc/suspend.conf $MNTIMAGE/etc/suspend.conf
1040 inst /usr/sbin/resume "$MNTIMAGE/bin/resume"
1041 echo "resume" >> "$s"
1044 initrd_gen_suspend2() {
1045 mkdir -p $MNTIMAGE/sys
1046 mkdir -p $MNTIMAGE/proc
1048 mount -t proc none /proc
1049 if [ "\$(awk ' /resume2=/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
1052 echo > /proc/suspend2/do_resume
1059 [ -n "$verbose" ] && echo "Setting up udev..."
1060 mkdir -p $MNTIMAGE/sbin
1061 mkdir -p $MNTIMAGE/proc
1062 mkdir -p $MNTIMAGE/etc/udev
1064 inst /sbin/initrd-udev $MNTIMAGE/sbin/udev
1065 ln -s udev $MNTIMAGE/sbin/udevstart
1066 inst /etc/udev/udev.conf $MNTIMAGE/etc/udev/udev.conf
1068 ln -s udev $MNTIMAGE/sbin/hotplug
1070 if is_yes "$USE_UDEV"; then
1071 if is_yes "$UDEV_TMPFS"; then
1074 mount -o mode=0755 -t tmpfs none /dev
1075 mknod /dev/console c 5 1
1076 mknod /dev/null c 1 3
1077 mknod /dev/zero c 1 5
1083 mount -t proc none /proc
1086 echo -n "/sbin/hotplug" > /proc/sys/kernel/hotplug
1092 initrd_gen_dmraid() {
1093 if [ ! -x /sbin/dmraid-initrd ] ; then
1094 echo "/sbin/dmraid-initrd is missing missing !"
1098 if [ ! -x $MNTIMAGE/sbin/udev ]; then
1099 echo "udev is needed on target initrd for dmraid to work!"
1103 mkdir -p "$MNTIMAGE/sbin"
1104 inst /sbin/dmraid-initrd $MNTIMAGE/sbin/dmraid
1106 mount -t proc none /proc
1107 mount -t sysfs none /sys
1108 # 2 secs was enough for my system to initialize. but really this is udev issue?
1117 initrd_gen_softraid() {
1118 [ -n "$verbose" ] && echo "Setting up mdadm..."
1120 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ] ; then
1121 echo "/sbin/mdadm or /sbin/initrd-mdassemble is missing !"
1125 inst /sbin/initrd-mdassemble "$MNTIMAGE/bin/mdassemble"
1128 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf)
1129 for ex_dev in $dev_list_extra; do
1130 echo "DEVICE $ex_dev" >> "$MNTIMAGE/etc/mdadm.conf"
1133 for nr in `seq 1 $rootdev_nr`; do
1134 eval cr_rootdev="\$rootdev${nr}"
1135 eval cr_dev_list="\$dev_list${nr}"
1136 [ -n "$verbose" ] && echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1138 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1140 echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf"
1141 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1142 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev)
1143 if [ -n "$cr_md_conf" ]; then
1144 echo "$cr_md_conf" >> "$MNTIMAGE/etc/mdadm.conf"
1146 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf"
1149 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1150 # mkdir in case of devfs name
1151 mkdir -p $MNTIMAGE/`my_dirname $f`
1152 [ -e "$MNTIMAGE/$f" ] && continue
1153 [ -n "$verbose" ] && echo "copying $f"
1154 # this works fine with and without devfs
1155 cp -HR $f $MNTIMAGE/$f
1159 echo "mdassemble" >> "$s"
1161 # needed to determine md-version
1162 if [ "$do_md0" -eq 1 ] ; then
1163 mknod $MNTIMAGE/dev/md0 b 9 0
1168 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1169 # have problems like init(XX) being child process of swapper(1).
1170 [ -n "$verbose" ] && echo "Adding rootfs on NFS support to initrd (dhcp)"
1171 mknod "$MNTIMAGE/dev/urandom" c 1 8
1172 mkdir "$MNTIMAGE/newroot"
1173 echo "ifconfig lo 127.0.0.1 up" >> "$s"
1174 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
1175 echo "ifconfig eth0 0.0.0.0 up" >> "$s"
1176 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s"
1177 cat << EOF > "$MNTIMAGE/bin/setdhcp"
1179 [ "\$1" != "bound" ] && exit
1180 [ -n "\$broadcast" ] && BROADCAST="broadcast \$broadcast"
1181 [ -n "\$subnet" ] && NETMASK="netmask \$subnet"
1183 ifconfig \$interface \$ip \$BROADCAST \$NETMASK up
1185 if [ -n "\$router" ]; then
1186 for r in \$router; do
1188 route add default gw \$r dev \$interface
1192 if [ -n "\$rootpath" ]; then
1194 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 \$rootpath /newroot
1198 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1199 echo "All seen variables are listed below:"
1204 chmod 755 "$MNTIMAGE/bin/setdhcp"
1205 echo "cd /newroot" >> "$s"
1206 echo "pivot_root . initrd" >> "$s"
1207 echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1208 echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1212 [ -n "$verbose" ] && echo "Adding LVM support to initrd"
1213 inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
1214 mkdir -p $MNTIMAGE/etc
1215 mkdir -p $MNTIMAGE/tmp
1216 mkdir -p $MNTIMAGE/proc
1217 mkdir -p $MNTIMAGE/newroot
1218 if ! is_yes "$USE_UDEV"; then
1219 mkdir -p $MNTIMAGE/dev/mapper
1220 mknod $MNTIMAGE/dev/mapper/control c 10 63
1221 for device in $PVDEVICES; do
1222 # if LVM on RAID then device might be copied already in gen_softraid
1223 [ -e "$MNTIMAGE/dev/$(basename $device)" ] && continue
1224 cp -HR $device $MNTIMAGE/dev/
1227 echo "mount -t proc none /proc" >> "$s"
1228 echo "mount -t tmpfs none /tmp" >> "$s"
1229 if [ "$LVMTOOLSVERSION" = "1" ] ; then
1230 echo "lvm vgscan -T" >> "$s"
1231 echo "lvm vgchange -T -a y $VGVOLUME" >> "$s"
1232 echo "umount /tmp" >> "$s"
1234 echo "umount /dev" >> "$s"
1235 echo "umount /proc" >> "$s"
1237 echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
1238 echo "global {" > "$MNTIMAGE/etc/lvm.conf"
1239 echo " locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
1240 echo " locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf"
1241 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1242 echo "devices {" >> "$MNTIMAGE/etc/lvm.conf"
1243 echo " sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf"
1244 if is_yes "$raidfound"; then
1245 echo " md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf"
1247 lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf"
1248 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1249 echo "LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure" >> "$s"
1250 echo "LVM_SYSTEM_DIR=/tmp lvm vgchange --ignorelockingfailure -a y $VGVOLUME" >> "$s"
1251 echo "LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure --mknodes" >> "$s"
1252 # Find out major/minor
1253 echo "majmin=\"\`LVM_SYSTEM_DIR=/tmp lvm lvdisplay --ignorelockingfailure -c $org_rootdev\`\"" >> "$s"
1254 echo "majmin=\"\${majmin#*/}\"" >> "$s"
1255 echo "majmin=\"\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}\"" >> "$s"
1256 echo "major=\"\${majmin%:*}\"" >> "$s"
1257 echo "minor=\"\${majmin#*:}\"" >> "$s"
1259 echo "val=\$((256 * \$major + \$minor))" >> "$s"
1260 echo "echo \$val > /proc/sys/kernel/real-root-dev" >> "$s"
1261 echo "umount /tmp" >> "$s"
1262 echo "umount /proc" >> "$s"
1266 initrd_gen_procdata() {
1267 [ -n "$verbose" ] && echo "Adding rootfs finding based on root= option support."
1268 mkdir -p $MNTIMAGE/proc
1271 mount -t proc none /proc
1272 root="\$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,\$0); gsub(/ .*/,NIL,\$0); print \$0; } ' /proc/cmdline)"
1273 if [ -n "\$root" ]; then
1274 rootnr="\$(busybox awk -v root="\$root" ' { if (\$4 == root) { print 256*\$1+\$2; } } ' /proc/partitions)"
1275 if [ -n "\$rootnr" ]; then
1276 echo "\$rootnr" > /proc/sys/kernel/real-root-dev
1286 if is_yes "$USE_UDEV"; then
1290 if is_yes "$USE_SUSPEND"; then
1294 if is_yes "$USE_SUSPEND2"; then
1298 if is_yes "$USE_DMRAID"; then
1302 if is_yes "$usenfs" ; then
1304 elif is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
1306 if is_yes "$uselvm" ; then
1311 elif is_yes "$uselvm" ; then
1317 if [ "$INITRDFS" = "initramfs" ]; then
1318 mkdir -p $MNTIMAGE/newroot
1319 cp -HR $org_rootdev $MNTIMAGE/dev
1320 echo "mount -t $rootFs $org_rootdev /newroot" >> "$s"
1321 echo "switch_root /newroot /sbin/init" >> "$s"
1322 # we need real file, not symlink
1323 rm -f $MNTIMAGE/init
1324 cp -a $MNTIMAGE/linuxrc $MNTIMAGE/init
1329 (cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
1336 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
1339 mkcramfs "$MNTPOINT" "$IMAGE"
1342 (cd $MNTPOINT ; find . | cpio -H newc -o > "$IMAGE")
1345 echo "Filesystem $INITRDFS not supported by $0";
1348 if is_yes "$COMPRESS" ; then
1349 gzip -9 < "$IMAGE" > "$target"
1351 cp -a "$IMAGE" "$target"
1354 if is_yes "$BOOT_SPLASH"; then
1355 if [ ! -x /bin/splash.bin ]; then
1356 echo "Failed to execute /bin/splash.bin. Is bootsplash package installed?" 1>&2
1357 elif [ -z "$THEME" ]; then
1358 echo "Please configure your /etc/sysconfig/bootsplash first." 1>&2
1359 echo "Generating bootsplashes skipped." 1>&2
1361 if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
1362 for res in $BOOT_SPLASH_RESOLUTIONS; do
1363 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1364 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1365 [ -n "$verbose" ] && echo "Added $res $THEME theme to initrd."
1367 echo "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" 1>&2
1371 echo "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." 1>&2
1372 echo "Not adding bootsplash to initrd." 1>&2
1377 rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"