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)
26 # it should be safe to remove scsi_mod from here, but I'm not sure...
27 PRESCSIMODS="-scsi_mod unknown -sd_mod"
28 PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
29 PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
30 SUSPENDMODS="-suspend2_core -suspend2_lzf -suspend2_block_io -suspend2_swap -suspend_core -suspend_text -suspend_lzf -suspend_block_io -suspend_swap"
38 raidtab="/etc/raidtab"
43 # default bootsplash is off, if it have to be on, install bootsplash package
47 echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
48 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
49 echo " [--initrdfs=rom|ext2|cram] [--modules-conf=<modules.conf>]"
50 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
51 echo " [--without-bootsplash] [--lvmtoolsversion=1|2]"
52 echo " <initrd-image> <kernel-version>"
53 echo " (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)"
59 echo $1|awk -F/ '{print substr($0, 0, length($0) - length($NF));}'
63 typeset mods module f level depfile first
65 depfile=/lib/modules/$kernel/modules.dep
67 if [ -f $depfile ] ; then
70 echo "Error: no $depfile ! Run depmod and rerun geninitrd." 1>&2
74 # prepend / if no path given, append $modext.gz if not given,
77 module=$(echo "$2" | \
78 awk '/\// {print;next} {print "/" $0}' | \
79 awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
80 awk '{gsub("/","\\/");print}')
83 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
85 /(.*)/ { gsub(/\\/," "); if (here) print }
89 if [ "$mods" = "" ] ; then
90 module=$(echo "$module" | \
91 awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
95 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
97 /(.*)/ { gsub(/\\/," "); if (here) print }
100 if [ "$mods" = "" ] ; then
101 if [ "$1" != silent ] ; then
102 echo "$origmodule: module not found in $depfile" 1>&2
104 if ! is_no "$EXIT_IF_MISSING" ; then
107 echo "If $origmodule isn't compiled in kernel then this initrd may not start your system". 1>&2
112 if [ "$level" = "" ] ; then
115 level=$(awk "BEGIN{print $level + 1}")
116 if [ $level -gt 20 ] ; then
117 echo "$origmodule: cycle in $depfile" 1>&2
123 if [ "$first" = "" ] ; then
126 find_depmod $1 $f $level
137 if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
138 if [ -n "$skiperrors" ]; then
142 echo "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" 1>&2
146 # only need to add each module once
148 tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
149 if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
150 MODULES="$MODULES $fmPath"
158 if [ "$(echo $modName | awk '{print(substr($0,1,1));}')" = "-" ]; then
160 modName="$(echo $modName | awk '{print(substr($0,2));}')"
164 if [ "$modName" = "pluto" ]; then
168 if [ "$modName" = "fcal" ]; then
173 if [ -n "$skiperrors" ]; then
174 allModulesToFind=`find_depmod silent $modName`
176 allModulesToFind=`find_depmod normal $modName`
177 if [ $? != 0 ] ; then
182 for mod in $allModulesToFind ; do
184 awk '{sub(/^\/lib\/modules\/[^\/]*\//,"");print}')
185 addmodule $mod "$skiperrors"
190 if [ "$#" != "2" ];then
191 echo "usage: inst <file> <destination>"
194 [ -n "$verbose" ] && echo "$1 -> $2"
199 /sbin/e2label $1 2> /dev/null
203 /sbin/tune2fs -l $1 2> /dev/null | awk -F: '/UUID:/ {gsub(" ",""); print $2}'
207 /usr/sbin/xfs_db -x -p xfs_admin -c label -r "$1"|awk -F= '{sub("^\"","", $2); sub("\"$", "", $2); print $2}'
212 /usr/sbin/xfs_db -x -p xfs_admin -c uuid -r "$1"|awk -F= '{print $2}'
216 eval `awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab`
219 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
220 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
221 if [ -n "$rootdev2" ] ; then
226 if [ "$rootdev_found." != "1." ] ; then
229 if [ ! -x /sbin/e2label ] ; then
230 echo "/sbin/e2label is missing" 1>&2
233 get_label="get_label_ext2"
236 if [ ! -x /usr/sbin/xfs_db ] ; then
237 echo "/usr/sbin/xfs_db is missing" 1>&2
240 get_label="get_label_xfs"
243 echo "LABEL on $rootFs in not supported by geninitrd" 1>&2
247 if [ ! -r /proc/partitions ] ; then
248 echo '/proc/partitions is not readable'; 1>&2
251 label=${rootdev#"LABEL="}
252 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
253 if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
254 if [ -n "$verbose" ] ; then
255 echo "Using $dev as device for rootfs"
262 if [ "$rootdev_found." != "1." ] ; then
263 echo "geninitrd can't find real device for LABEL=$label" 1>&2
269 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
270 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
271 if [ -n "$rootdev2" ] ; then
276 if [ "$rootdev_found." != "1." ] ; then
279 if [ ! -x /sbin/tune2fs ] ; then
280 echo "/sbin/tune2fs is missing" 1>&2
283 get_uuid="get_uuid_ext2"
286 if [ ! -x /usr/sbin/xfs_db ] ; then
287 echo "/usr/sbin/xfs_db is missing" 1>&2
290 get_label="get_uuid_xfs"
293 echo "UUID on $rootFs in not supported by geninitrd" 1>&2
297 if [ ! -r /proc/partitions ] ; then
298 echo '/proc/partitions is not readable'; 1>&2
301 uuid=${rootdev#"UUID="}
302 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
303 if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
304 if [ -n "$verbose" ] ; then
305 echo "Using $dev as device for rootfs"
312 if [ "$rootdev_found" != 1 ] ; then
313 echo "geninitrd can't find real device for UUID=$uuid" 1>&2
322 find_modules_softraid() {
323 if [ -f /etc/mdadm.conf ] ; then
324 [ -n "$verbose" ] && echo "Finding RAID details using mdadm for rootdev=$1"
325 eval `/sbin/mdadm --examine --scan --config=/etc/mdadm.conf | \
326 awk -v rootdev="$1" '
331 rootdev_devfs = rootdev;
332 if (rootdev ~ /\/dev\/md\/[0-9]/) {
333 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
338 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
340 gsub(/level=/,NUL,raidlevel);
341 if (raidlevel ~ /^raid[0-5]/) {
342 gsub(/raid/,NUL,raidlevel);
346 if (x ~ /devices=/) {
348 gsub("devices=", NUL, dev_list);
349 gsub(",", " ", dev_list);
355 print "raidfound=" found;
356 print "raidlevel=" raidlevel;
357 print "dev_list=\"" dev_list "\"";
360 if [ "$raidfound" != "yes" ]; then
361 [ -n "$verbose" ] && echo "Finding RAID details using raidtab for rootdev=$1"
362 eval `awk -v rootdev="$1" 'BEGIN {
365 rootdev_devfs = rootdev;
366 if (rootdev ~ /\/dev\/md\/[0-9]/) {
367 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
378 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
381 if (found == "yes") {
386 if (found == "yes") {
387 if ($1 == "device") {
388 dev_list = dev_list " " $2;
390 if ($1 == "raid-level") {
397 print "raidfound=" found "\nraidlevel=" raidlevel "\ndev_list=\"" dev_list "\"\n";
401 if is_yes "$raidfound" ; then
404 findmodule "raid$raidlevel"
410 echo "raid level $number (in $raidtab) not recognized" 1>&2
414 echo "ERROR: RAID devices not found for \"$1\", check your configuration!" 1>&2
418 rootdev_nr=$(( $rootdev_nr + 1 ))
419 eval "rootdev${rootdev_nr}=\"$1\""
420 eval "dev_list${rootdev_nr}=\"${dev_list}\""
422 for device in $dev_list; do
423 find_modules_for $device
427 find_modules_scsi() {
428 for n in $PRESCSIMODS; do
429 if [ "X$n" = "Xunknown" ] ; then
430 if [ -f "$modulefile" ]; then
431 scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
432 for n in $scsimodules; do
433 # for now allow scsi modules to come from anywhere. There are some
434 # RAID controllers with drivers in block
447 rootdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')"
448 if [ "$pack_version_long" -lt "002004021" ]; then
449 [ -n "$verbose" ] && echo "Finding IDE modules for kernels <= 2.4.20"
450 for n in $PREIDEMODSOLD; do
455 for n in $PREIDEMODS; do
456 if [ "X$n" = "Xunknown" ] ; then
457 if [ -f "$modulefile" ]; then
458 [ -n "$verbose" ] && echo "Finding IDE modules using ide_hostadapter"
459 idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
460 for na in $idemodules; do
466 if [ "$tryauto" -eq 1 ]; then
467 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
468 [ -n "$verbose" ] && echo "Finding IDE modules using PCI ID database"
469 if is_yes "${ide_only_root}"; then
470 if [ -f /sys/block/${rootdev}/device/../../vendor -a -f /sys/block/${rootdev}/device/../../device ] ; then
471 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../vendor)"
472 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../device)"
473 searchpciid="${vendorid}${deviceid}"
474 elif [ -f /proc/ide/${rootdev}/../config ]; then
475 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootdev}/../config)"
478 if [ -z "${searchpciid}" ]; then
479 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
482 for nb in $searchpciid; do
483 eval `awk -v pciid="$nb" 'BEGIN {
492 compmod = $1 ""; # make sure comparison type will be string
493 # cause pci IDs are hexadecimal numeric
494 if (compmod == pciid) {
496 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
503 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
504 }' /usr/share/pci-database/ide.pci`
505 [ -n "$module" ] && idemodules="$idemodules $module"
507 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
509 for nc in idemodules; do
510 new_idemodules="$nc $new_idemodules"
512 idemodules="${new_idemodules}"
514 if [ -z "$idemodules" ]; then
515 echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic."
516 idemodules="ide-generic"
518 for nd in $idemodules; do
523 [ -r /usr/share/pci-database/ide.pci ] || echo -n "/usr/share/pci-database/ide.pci missing."
524 [ -r /proc/bus/pci/devices ] || echo -n "/proc/bus/pci/devices missing."
525 echo "Automatic IDE modules finding not available."
537 echo "ERROR: no argument passed to find_modules_for() - is your /etc/fstab correct?" >&2
539 elif is_yes "`echo "$1" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
540 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then
541 echo "ERROR: root on NFS but /usr/bin/pcidev not found." >&2
542 echo "Please install correct pci-database package and rerun $0." >&2
545 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
546 for m in $NFS_ETH_MODULES; do
552 echo "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel" >&2
553 echo "or you will have problems like init(xx) being child process of swapper(1)." >&2
554 elif is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
555 find_modules_softraid "$1"
556 elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
558 elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
559 find_modules_ide "$1"
560 elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
562 elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
563 findmodule "cpqarray"
564 elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
566 elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
569 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
570 if -n "$ataraidmodules" ; then
571 # FIXME: think about modules compiled in kernel
572 echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
573 echo "Please set it and run $0 again."
576 for n in $ataraidmodules; do
579 # check to see if we need to set up a loopback filesystem
580 elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
581 echo "Sorry, root on loop device isn't supported." 1>&2
583 # TODO: rewrite for bsp and make nfs ready
584 if [ ! -x /sbin/losetup ]; then
585 echo "losetup is missing"
588 key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
589 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
590 echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
591 echo "for this device. Consult the geninitrd man page for more information" 1>&2
595 line="`awk '/'$key'/ { print $0; }' $fstab`"
596 loopDev="$(echo $line | awk '{print $3}')"
597 loopFs="$(echo $line | awk '{print $4}')"
598 loopFile="$(echo $line | awk '{print $5}')"
600 BASICMODULES="$BASICMODULES -loop"
601 findmodule "-$loopFs"
602 BASICMODULES="$BASICMODULES -${loopFs}"
603 # don't have any clue, how is this supposed to work
604 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
605 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then
606 echo "ERROR: root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found." >&2
607 echo "Please install lvm(2) and lvm(2)-initrd package and rerun $0." >&2
610 if [ -z "$LVMTOOLSVERSION" ] ; then
611 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}')
612 if [ -z "$LVMTOOLSVERSION" ] ; then
613 echo "ERROR: Can't determine LVM tools version. Please set LVMTOOLSVERSION" >&2
614 echo "and rerun $0." >&2
618 if [ -z "$PVDEVICES" ] ; then
619 VGVOLUME=$(/sbin/lvdisplay -c "$1" 2> /dev/null | awk -F":" ' { print $2 } ')
620 PVDEVICES=$(/sbin/pvdisplay -c | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
622 if [ -n "$PVDEVICES" ] ; then
623 for device in $PVDEVICES; do
624 find_modules_for $device
627 echo "ERROR: I wasn't able to find PV (via lvdisplay and pvdisplay)." >&2
628 echo "You can try to set PVDEVICES in /etc/sysconfig/geninitrd." >&2
631 if [ "$LVMTOOLSVERSION" = "2" ]; then
633 elif [ "$LVMTOOLSVERSION" = "1" ]; then
635 findmodule "-lvm-mod"
637 echo "ERROR: LVM version $LVMTOOLSVERSION is not supported yet." >&2
647 for mod in $modules; do
648 MODULEDIR="`my_dirname "$mod"`"
649 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
650 cp $verbose -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
651 gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
655 modules_add_linuxrc() {
659 for mod in $modules; do
660 MODULE2="`my_dirname "$mod"`"
661 NAME2=`basename "$mod" .gz`
662 MODULE2=$MODULE2/$NAME2
663 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
664 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
666 if [ -n "$verbose" ]; then
667 /bin/echo -n "Loading module [$module] "
668 if [ -n "$options" ] ; then
669 echo "with options [$options]."
671 echo "without options."
674 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
678 if [ -r /etc/sysconfig/geninitrd ] ; then
679 . /etc/sysconfig/geninitrd
682 if [ -r /etc/sysconfig/bootsplash ] ; then
683 . /etc/sysconfig/bootsplash
686 if [ ! -x /bin/initrd-busybox ] ; then
687 echo "/bin/initrd-busybox is missing !"
690 if [ "`uname -m`" = "ia64" ]; then
695 while [ $# -gt 0 ]; do
698 fstab="`echo $1 | awk -F= '{print $2;}'`"
705 modulefile="`echo $1 | awk -F= '{print $2;}'`"
712 raidtab="`echo $1 | awk -F= '{print $2;}'`"
718 --use-raidstart|--with-raidstart)
724 --use-insmod-static|--with-insmod-static)
725 USEINSMODSTATIC="yes"
727 --without-insmod-static)
730 --without-bootsplash)
736 --lvmtoolsversion=|--lvmversion=)
737 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
739 --lvmtoolsversion|--lvmversion)
744 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
747 BASICMODULES="$BASICMODULES $2"
751 echo "geninitrd: version $VERSION"
767 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
770 PREMODS="$PREMODS $2"
774 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
775 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
778 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
783 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
796 if [ -z "$target" ]; then
798 elif [ -z "$kernel" ]; then
809 if [ -z "$target" -o -z "$kernel" ]; then
813 pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
814 pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
816 if [ "x" = "x$INITRDFS" ] ; then
817 if [ "x" = "x$FS" ] ; then
819 # if [ "$pack_version" -ge "002005" ] ; then
820 # INITRDFS="initramfs"
825 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
830 if [ "$pack_version" -ge "002005" ] ; then
835 if is_yes "$USEINSMODSTATIC" ; then
836 insmod="insmod.static"
837 INSMOD="/sbin/insmod.static"
838 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
839 INSMOD="/sbin/insmod.static.modutils"
841 if [ ! -f "$INSMOD" ] ; then
842 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
849 if [ ! -x /sbin/mke2fs ]; then
850 echo "/sbin/mke2fs is missing" 1>&2
855 if [ ! -x /sbin/genromfs ]; then
856 echo "/sbin/genromfs is missing" 1>&2
861 if [ ! -x /sbin/mkcramfs ]; then
862 echo "/sbin/mkcramfs is missing" 1>&2
867 if [ ! -x /bin/cpio ]; then
868 echo "/bin/cpio is missing" 1>&2
871 if [ ! -x /usr/bin/find ]; then
872 echo "/usr/bin/find is missing" 1>&2
877 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
882 if [ -n "$img_vers" ]; then
883 target="$target-$kernel"
886 if [ -z "$force" -a -f "$target" ]; then
887 echo "$target already exists." 1>&2
891 if [ ! -d "/lib/modules/$kernel" ]; then
892 echo "/lib/modules/$kernel is not a directory." 1>&2
896 if [ ! -f /proc/mounts ]; then
897 echo "/proc filesystem not mounted, may cause wrong results or failure." 1>&2
900 if [ "$pack_version" -lt "002005" ]; then
901 modulefile=/etc/modules.conf
902 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
903 modulefile=/etc/conf.modules
906 modulefile=/etc/modprobe.conf
909 for n in $PREMODS; do
913 # allow forcing loading SCSI and/or IDE modules
914 if is_yes "$ADDSCSI" ; then
918 if is_yes "$ADDIDE" ; then
924 org_rootdev="$rootdev1"
926 find_modules_for "$rootdev1"
928 findmodule "-$rootFs"
930 for n in $BASICMODULES; do
934 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
935 if [ -n "$verbose" ]; then
936 echo "No modules are needed -- not building initrd image."
941 if [ -n "$verbose" ]; then
942 echo "Using modules: $MODULES"
945 MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
946 IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
947 MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
948 RCFILE="$MNTIMAGE/linuxrc"
950 if [ -f "$MNTIMAGE" ]; then
951 echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
955 if [ -f "$IMAGE" ]; then
956 echo "$IMAGE already exists. Remove it and try again" 1>&2
960 if [ "$INITRDFS" = "ext2" ] ; then
961 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
963 # We have to "echo y |" so that it doesn't complain about $IMAGE not
964 # being a block device
965 echo y | mke2fs -F "$IMAGE" "$IMAGESIZE" >/dev/null 2>/dev/null
968 mount -o loop -t ext2 "$IMAGE" "$MNTPOINT"
974 mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs,var}
977 # We don't need this directory, so let's save space
978 rm -rf "$MNTPOINT"/lost+found
980 modules_install "$MODULES"
982 # mknod'ing the devices instead of copying them works both with and
984 mknod "$MNTIMAGE/dev/console" c 5 1
985 mknod "$MNTIMAGE/dev/null" c 1 3
986 mknod "$MNTIMAGE/dev/zero" c 1 5
989 ln -s /linuxrc $MNTIMAGE/init
991 inst /bin/initrd-busybox "$MNTIMAGE/bin/sh"
992 ln -s sh "$MNTIMAGE/bin/busybox"
994 if is_yes "$USEINSMODSTATIC" ; then
995 inst "$INSMOD" $MNTIMAGE/bin/insmod.static
1005 modules_add_linuxrc "$MODULES" "$s"
1007 # TODO: rewrite for busybox
1008 #if [ -n "$loopDev" ]; then
1009 # if [ ! -d /initrd ]; then
1013 # cp -a "$loopDev" "$MNTIMAGE/dev"
1014 # cp -a "$rootdev1" "$MNTIMAGE/dev"
1015 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1016 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1017 # echo "echo Setting up loopback device $rootdev1" >> $RCFILE
1018 # echo "losetup $rootdev1 /loopfs$loopFile" >> "$RCFILE"
1021 if is_yes "$USESUSPEND"; then
1023 for mod in $SUSPENDMODS; do
1024 is_yes "$BOOT_SPLASH" && [ "$mod" = "-suspend-text" ] && mod="-suspend_bootsplash"
1027 modules_install "$MODULES"
1028 mkdir -p $MNTIMAGE/sys
1029 mkdir -p $MNTIMAGE/proc
1030 echo "mount -t proc none /proc" >> "$s"
1031 echo "cmdline=\`cat /proc/cmdline\`" >> "$s"
1032 echo "if [ \"\$cmdline\" != \"\${cmdline#* resume2=}\" ]; then" >> "$s"
1033 modules_add_linuxrc "$MODULES" "$s"
1034 echo " echo > /proc/software_suspend/activate" >> "$s"
1035 echo " umount /proc" >> "$s"
1036 echo " exit 0" >> "$s"
1038 echo "umount /proc" >> "$s"
1041 if is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
1042 [ -n "$verbose" ] && echo "Setting up mdadm..."
1044 if [ ! -x /sbin/initrd-mdadm -a ! -x /sbin/initrd-mdassemble ] ; then
1045 echo "/sbin/initrd-mdadm and /sbin/initrd-mdassemble are missing !"
1049 if [ -x /sbin/initrd-mdassemble ] ; then
1051 inst /sbin/initrd-mdassemble "$MNTIMAGE/bin/mdassemble"
1054 inst /sbin/initrd-mdadm "$MNTIMAGE/bin/mdadm"
1059 for nr in `seq 1 $rootdev_nr`; do
1060 eval cr_rootdev="\$rootdev${nr}"
1061 eval cr_dev_list="\$dev_list${nr}"
1062 [ -n "$verbose" ] && echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1064 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1066 if [ "$do_mdassemble" -eq 1 ] ; then
1067 echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf"
1068 $cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1069 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf"
1071 echo "mdadm --assemble $cr_rootdev $cr_dev_list" >> "$s"
1074 for f in $cr_dev_list $cr_rootdev ; do
1075 # mkdir in case of devfs name
1076 mkdir -p $MNTIMAGE/`my_dirname $f`
1077 [ -n "$verbose" ] && echo "copying $f"
1078 # this works fine with and without devfs
1079 cp -HR $f $MNTIMAGE/$f
1083 if [ "$do_mdassemble" -eq 1 ] ; then
1084 echo "mdassemble" >> "$s"
1087 # needed to determine md-version
1088 if [ "$do_md0" -eq 1 ] ; then
1089 mknod $MNTIMAGE/dev/md0 b 9 0
1093 if is_yes "$usenfs" ; then
1094 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1095 # have problems like init(XX) being child process of swapper(1).
1096 [ -n "$verbose" ] && echo "Adding rootfs on NFS support to initrd (dhcp)"
1097 mknod "$MNTIMAGE/dev/urandom" c 1 8
1098 mkdir "$MNTIMAGE/newroot"
1099 echo "ifconfig lo 127.0.0.1 up" >> "$s"
1100 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
1101 echo "ifconfig eth0 0.0.0.0 up" >> "$s"
1102 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s"
1103 cat << EOF > "$MNTIMAGE/bin/setdhcp"
1105 [ "\$1" != "bound" ] && exit
1106 [ -n "\$broadcast" ] && BROADCAST="broadcast \$broadcast"
1107 [ -n "\$subnet" ] && NETMASK="netmask \$subnet"
1109 ifconfig \$interface \$ip \$BROADCAST \$NETMASK up
1111 if [ -n "\$router" ]; then
1112 for r in \$router; do
1114 route add default gw \$r dev \$interface
1118 if [ -n "\$rootpath" ]; then
1120 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 \$rootpath /newroot
1124 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1125 echo "All seen variables are listed below:"
1130 chmod 755 "$MNTIMAGE/bin/setdhcp"
1131 echo "cd /newroot" >> "$s"
1132 echo "pivot_root . initrd" >> "$s"
1133 echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1134 echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1137 if is_yes "$uselvm" ; then
1138 [ -n "$verbose" ] && echo "Adding LVM support to initrd"
1139 inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
1140 mkdir -p $MNTIMAGE/etc
1141 mkdir -p $MNTIMAGE/tmp
1142 mkdir -p $MNTIMAGE/proc
1143 mkdir -p $MNTIMAGE/newroot
1144 echo "mount -t proc none /proc" >> "$s"
1145 echo "mount -t devfs none /dev" >> "$s"
1146 echo "mount -t tmpfs none /tmp" >> "$s"
1147 if [ "$LVMTOOLSVERSION" = "1" ] ; then
1148 echo "lvm vgscan -T" >> "$s"
1149 echo "lvm vgchange -T -a y $VGVOLUME" >> "$s"
1150 echo "umount /tmp" >> "$s"
1152 echo "umount /dev" >> "$s"
1153 echo "umount /proc" >> "$s"
1155 echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
1156 echo "global {" > "$MNTIMAGE/etc/lvm.conf"
1157 echo " locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
1158 echo " locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf"
1159 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1160 echo "devices {" >> "$MNTIMAGE/etc/lvm.conf"
1161 echo " sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf"
1162 if is_yes "$raidfound"; then
1163 echo " md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf"
1165 lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf"
1166 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1167 echo "LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure" >> "$s"
1168 echo "LVM_SYSTEM_DIR=/tmp lvm vgchange --ignorelockingfailure -a y $VGVOLUME" >> "$s"
1169 # Find out major/minor
1170 echo "majmin=\"\`LVM_SYSTEM_DIR=/tmp lvm lvdisplay --ignorelockingfailure -c $org_rootdev\`\"" >> "$s"
1171 echo "majmin=\"\${majmin#*/}\"" >> "$s"
1172 echo "majmin=\"\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}\"" >> "$s"
1173 echo "major=\"\${majmin%:*}\"" >> "$s"
1174 echo "minor=\"\${majmin#*:}\"" >> "$s"
1176 echo "val=\$((256 * \$major + \$minor))" >> "$s"
1177 echo "echo \$val > /proc/sys/kernel/real-root-dev" >> "$s"
1178 echo "umount /tmp" >> "$s"
1179 echo "umount /dev" >> "$s"
1180 echo "umount /proc" >> "$s"
1181 # echo "mount -n -o ro $org_rootdev /newroot" >> "$s"
1182 # echo "cd /newroot" >> "$s"
1183 # echo "pivot_root . initrd" >> "$s"
1184 # echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1185 # echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1191 (cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
1198 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
1201 mkcramfs "$MNTPOINT" "$IMAGE"
1204 (cd $MNTPOINT ; find . | cpio -H newc -o > "$IMAGE")
1207 echo "Filesystem $INITRDFS not supported by $0";
1210 if is_yes "$COMPRESS" ; then
1211 gzip -9 < "$IMAGE" > "$target"
1213 cp -a "$IMAGE" "$target"
1216 if is_yes "$BOOT_SPLASH"; then
1217 if [ ! -x /bin/splash.bin ]; then
1218 echo "Failed to execute /bin/splash.bin. Is bootsplash package installed?" 1>&2
1219 elif [ -z "$THEME" ]; then
1220 echo "Please configure your /etc/sysconfig/bootsplash first." 1>&2
1221 echo "Generating bootsplashes skipped." 1>&2
1223 if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
1224 for res in $BOOT_SPLASH_RESOLUTIONS; do
1225 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1226 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1227 [ -n "$verbose" ] && echo "Added $res $THEME theme to initrd."
1229 echo "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" 1>&2
1233 echo "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." 1>&2
1234 echo "Not adding bootsplash to initrd." 1>&2
1239 rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"