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
46 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udev ]; then
53 echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
54 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
55 echo " [--initrdfs=rom|ext2|cram] [--modules-conf=<modules.conf>]"
56 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
57 echo " [--without-bootsplash] [--lvmtoolsversion=1|2] [--without-udev]"
58 echo " [--without-suspend]"
59 echo " <initrd-image> <kernel-version>"
60 echo " (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)"
66 echo $1|awk -F/ '{print substr($0, 0, length($0) - length($NF));}'
70 typeset mods module f level depfile first
72 depfile=/lib/modules/$kernel/modules.dep
74 if [ -f $depfile ] ; then
77 echo "Error: no $depfile ! Run depmod and rerun geninitrd." 1>&2
81 # prepend / if no path given, append $modext.gz if not given,
84 module=$(echo "$2" | \
85 awk '/\// {print;next} {print "/" $0}' | \
86 awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
87 awk '{gsub("/","\\/");print}')
90 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
92 /(.*)/ { gsub(/\\/," "); if (here) print }
96 if [ "$mods" = "" ] ; then
97 module=$(echo "$module" | \
98 awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
102 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
104 /(.*)/ { gsub(/\\/," "); if (here) print }
107 if [ "$mods" = "" ] ; then
108 if [ "$1" != silent ] ; then
109 echo "$origmodule: module not found in $depfile" 1>&2
111 if ! is_no "$EXIT_IF_MISSING" ; then
114 echo "If $origmodule isn't compiled in kernel then this initrd may not start your system". 1>&2
119 if [ "$level" = "" ] ; then
122 level=$(awk "BEGIN{print $level + 1}")
123 if [ $level -gt 20 ] ; then
124 echo "$origmodule: cycle in $depfile" 1>&2
130 if [ "$first" = "" ] ; then
133 find_depmod $1 $f $level
144 if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
145 if [ -n "$skiperrors" ]; then
149 echo "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" 1>&2
153 # only need to add each module once
155 tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
156 if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
157 MODULES="$MODULES $fmPath"
165 if [ "$(echo $modName | awk '{print(substr($0,1,1));}')" = "-" ]; then
167 modName="$(echo $modName | awk '{print(substr($0,2));}')"
171 if [ "$modName" = "pluto" ]; then
175 if [ "$modName" = "fcal" ]; then
180 if [ -n "$skiperrors" ]; then
181 allModulesToFind=`find_depmod silent $modName`
183 allModulesToFind=`find_depmod normal $modName`
184 if [ $? != 0 ] ; then
189 for mod in $allModulesToFind ; do
191 awk '{sub(/^\/lib\/modules\/[^\/]*\//,"");print}')
192 addmodule $mod "$skiperrors"
197 if [ "$#" != "2" ];then
198 echo "usage: inst <file> <destination>"
201 [ -n "$verbose" ] && echo "$1 -> $2"
206 /sbin/e2label $1 2> /dev/null
210 /sbin/tune2fs -l $1 2> /dev/null | awk -F: '/UUID:/ {gsub(" ",""); print $2}'
214 /usr/sbin/xfs_db -x -p xfs_admin -c label -r "$1"|awk -F= '{sub("^\"","", $2); sub("\"$", "", $2); print $2}'
219 /usr/sbin/xfs_db -x -p xfs_admin -c uuid -r "$1"|awk -F= '{print $2}'
223 eval `awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab`
226 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
227 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
228 if [ -n "$rootdev2" ] ; then
233 if [ "$rootdev_found." != "1." ] ; then
236 if [ ! -x /sbin/e2label ] ; then
237 echo "/sbin/e2label is missing" 1>&2
240 get_label="get_label_ext2"
243 if [ ! -x /usr/sbin/xfs_db ] ; then
244 echo "/usr/sbin/xfs_db is missing" 1>&2
247 get_label="get_label_xfs"
250 echo "LABEL on $rootFs in not supported by geninitrd" 1>&2
254 if [ ! -r /proc/partitions ] ; then
255 echo '/proc/partitions is not readable'; 1>&2
258 label=${rootdev#"LABEL="}
259 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
260 if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
261 if [ -n "$verbose" ] ; then
262 echo "Using $dev as device for rootfs"
269 if [ "$rootdev_found." != "1." ] ; then
270 echo "geninitrd can't find real device for LABEL=$label" 1>&2
276 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
277 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
278 if [ -n "$rootdev2" ] ; then
283 if [ "$rootdev_found." != "1." ] ; then
286 if [ ! -x /sbin/tune2fs ] ; then
287 echo "/sbin/tune2fs is missing" 1>&2
290 get_uuid="get_uuid_ext2"
293 if [ ! -x /usr/sbin/xfs_db ] ; then
294 echo "/usr/sbin/xfs_db is missing" 1>&2
297 get_label="get_uuid_xfs"
300 echo "UUID on $rootFs in not supported by geninitrd" 1>&2
304 if [ ! -r /proc/partitions ] ; then
305 echo '/proc/partitions is not readable'; 1>&2
308 uuid=${rootdev#"UUID="}
309 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
310 if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
311 if [ -n "$verbose" ] ; then
312 echo "Using $dev as device for rootfs"
319 if [ "$rootdev_found" != 1 ] ; then
320 echo "geninitrd can't find real device for UUID=$uuid" 1>&2
329 find_modules_softraid() {
330 if [ -f /etc/mdadm.conf ] ; then
331 [ -n "$verbose" ] && echo "Finding RAID details using mdadm for rootdev=$1"
332 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | \
333 awk -v rootdev="$1" '
338 rootdev_devfs = rootdev;
339 if (rootdev ~ /\/dev\/md\/[0-9]/) {
340 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
345 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
347 gsub(/level=/,NUL,raidlevel);
348 if (raidlevel ~ /^raid[0-5]/) {
349 gsub(/raid/,NUL,raidlevel);
353 if (x ~ /devices=/) {
355 gsub("devices=", NUL, dev_list);
356 gsub(",", " ", dev_list);
362 print "raidfound=" found;
363 print "raidlevel=" raidlevel;
364 print "dev_list=\"" dev_list "\"";
367 if [ "$raidfound" != "yes" ]; then
368 [ -n "$verbose" ] && echo "Finding RAID details using raidtab for rootdev=$1"
369 eval `awk -v rootdev="$1" 'BEGIN {
372 rootdev_devfs = rootdev;
373 if (rootdev ~ /\/dev\/md\/[0-9]/) {
374 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
385 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
388 if (found == "yes") {
393 if (found == "yes") {
394 if ($1 == "device") {
395 dev_list = dev_list " " $2;
397 if ($1 == "raid-level") {
404 print "raidfound=" found "\nraidlevel=" raidlevel "\ndev_list=\"" dev_list "\"\n";
408 if is_yes "$raidfound" ; then
411 findmodule "raid$raidlevel"
417 echo "raid level $number (in $raidtab) not recognized" 1>&2
421 echo "ERROR: RAID devices not found for \"$1\", check your configuration!" 1>&2
425 rootdev_nr=$(( $rootdev_nr + 1 ))
426 eval "rootdev${rootdev_nr}=\"$1\""
427 eval "dev_list${rootdev_nr}=\"${dev_list}\""
429 for device in $dev_list; do
430 find_modules_for $device
434 find_modules_scsi() {
435 for n in $PRESCSIMODS; do
436 if [ "X$n" = "Xunknown" ] ; then
437 if [ -f "$modulefile" ]; then
438 scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
439 for n in $scsimodules; do
440 # for now allow scsi modules to come from anywhere. There are some
441 # RAID controllers with drivers in block
454 rootdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')"
455 if [ "$pack_version_long" -lt "002004021" ]; then
456 [ -n "$verbose" ] && echo "Finding IDE modules for kernels <= 2.4.20"
457 for n in $PREIDEMODSOLD; do
462 for n in $PREIDEMODS; do
463 if [ "X$n" = "Xunknown" ] ; then
464 if [ -f "$modulefile" ]; then
465 [ -n "$verbose" ] && echo "Finding IDE modules using ide_hostadapter"
466 idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
467 for na in $idemodules; do
473 if [ "$tryauto" -eq 1 ]; then
474 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
475 [ -n "$verbose" ] && echo "Finding IDE modules using PCI ID database"
476 if is_yes "${ide_only_root}"; then
477 if [ -f /sys/block/${rootdev}/device/../../vendor -a -f /sys/block/${rootdev}/device/../../device ] ; then
478 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../vendor)"
479 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../device)"
480 searchpciid="${vendorid}${deviceid}"
481 elif [ -f /proc/ide/${rootdev}/../config ]; then
482 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootdev}/../config)"
485 if [ -z "${searchpciid}" ]; then
486 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
489 for nb in $searchpciid; do
490 eval `awk -v pciid="$nb" 'BEGIN {
499 compmod = $1 ""; # make sure comparison type will be string
500 # cause pci IDs are hexadecimal numeric
501 if (compmod == pciid) {
503 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
510 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
511 }' /usr/share/pci-database/ide.pci`
512 [ -n "$module" ] && idemodules="$idemodules $module"
514 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
516 for nc in idemodules; do
517 new_idemodules="$nc $new_idemodules"
519 idemodules="${new_idemodules}"
521 if [ -z "$idemodules" ]; then
522 echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic."
523 idemodules="ide-generic"
525 for nd in $idemodules; do
529 [ -r /usr/share/pci-database/ide.pci ] || echo "WARNING: /usr/share/pci-database/ide.pci missing."
530 [ -r /proc/bus/pci/devices ] || echo "WARNING: /proc/bus/pci/devices missing."
531 echo "Automatic IDE modules finding not available."
543 echo "ERROR: no argument passed to find_modules_for() - is your /etc/fstab correct?" >&2
545 elif is_yes "`echo "$1" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
546 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then
547 echo "ERROR: root on NFS but /usr/bin/pcidev not found." >&2
548 echo "Please install correct pci-database package and rerun $0." >&2
551 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
552 for m in $NFS_ETH_MODULES; do
558 echo "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel" >&2
559 echo "or you will have problems like init(xx) being child process of swapper(1)." >&2
560 elif is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
561 find_modules_softraid "$1"
562 elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
564 elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
565 find_modules_ide "$1"
566 elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
568 elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
569 findmodule "cpqarray"
570 elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
572 elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
575 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
576 if -n "$ataraidmodules" ; then
577 # FIXME: think about modules compiled in kernel
578 echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
579 echo "Please set it and run $0 again."
582 for n in $ataraidmodules; do
585 # check to see if we need to set up a loopback filesystem
586 elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
587 echo "Sorry, root on loop device isn't supported." 1>&2
589 # TODO: rewrite for bsp and make nfs ready
590 if [ ! -x /sbin/losetup ]; then
591 echo "losetup is missing"
594 key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
595 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
596 echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
597 echo "for this device. Consult the geninitrd man page for more information" 1>&2
601 line="`awk '/'$key'/ { print $0; }' $fstab`"
602 loopDev="$(echo $line | awk '{print $3}')"
603 loopFs="$(echo $line | awk '{print $4}')"
604 loopFile="$(echo $line | awk '{print $5}')"
606 BASICMODULES="$BASICMODULES -loop"
607 findmodule "-$loopFs"
608 BASICMODULES="$BASICMODULES -${loopFs}"
609 # don't have any clue, how is this supposed to work
610 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
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
653 for mod in $modules; do
654 MODULEDIR="`my_dirname "$mod"`"
655 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
656 cp $verbose -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
657 gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
661 modules_add_linuxrc() {
665 for mod in $modules; do
666 MODULE2="`my_dirname "$mod"`"
667 NAME2=`basename "$mod" .gz`
668 MODULE2=$MODULE2/$NAME2
669 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
670 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
671 eval sleep_var="MODULE_${module}_SLEEP"
673 if [ -n "$verbose" ]; then
674 echo -n "Loading module [$module] "
675 if [ -n "$options" ] ; then
676 echo -n "with options [$options]"
678 echo -n "without options"
680 if [ -n "$sleep_var" ]; then
681 echo " and $sleep_var sleep."
686 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
687 if [ -n "${sleep_var}" ]; then
688 echo "usleep $sleep_var" >> "$linuxrc"
693 if [ -r /etc/sysconfig/geninitrd ] ; then
694 . /etc/sysconfig/geninitrd
697 if [ -r /etc/sysconfig/bootsplash ] ; then
698 . /etc/sysconfig/bootsplash
701 if [ ! -x /bin/initrd-busybox ] ; then
702 echo "/bin/initrd-busybox is missing !"
705 case "$(uname -m)" in
706 ia64|amd64|x86_64|sparc64)
714 while [ $# -gt 0 ]; do
717 fstab="`echo $1 | awk -F= '{print $2;}'`"
724 modulefile="`echo $1 | awk -F= '{print $2;}'`"
731 raidtab="`echo $1 | awk -F= '{print $2;}'`"
737 --use-raidstart|--with-raidstart)
743 --use-insmod-static|--with-insmod-static)
744 USEINSMODSTATIC="yes"
746 --without-insmod-static)
749 --without-bootsplash)
755 --lvmtoolsversion=|--lvmversion=)
756 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
758 --lvmtoolsversion|--lvmversion)
766 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
769 BASICMODULES="$BASICMODULES $2"
773 echo "geninitrd: version $VERSION"
789 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
792 PREMODS="$PREMODS $2"
796 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
797 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
800 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
805 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
818 if [ -z "$target" ]; then
820 elif [ -z "$kernel" ]; then
831 if [ -z "$target" -o -z "$kernel" ]; then
835 pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
836 pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
838 if [ "x" = "x$INITRDFS" ] ; then
839 if [ "x" = "x$FS" ] ; then
841 # if [ "$pack_version" -ge "002005" ] ; then
842 # INITRDFS="initramfs"
847 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
852 if [ "$pack_version" -lt "002006" ] ; then
855 [ -z "$USE_UDEV" ] && UDEV_TMPFS=
857 if [ "$pack_version" -ge "002005" ] ; then
862 if is_yes "$USEINSMODSTATIC" ; then
863 insmod="insmod.static"
864 INSMOD="/sbin/insmod.static"
865 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
866 INSMOD="/sbin/insmod.static.modutils"
868 if [ ! -f "$INSMOD" ] ; then
869 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
876 if [ ! -x /sbin/mke2fs ]; then
877 echo "/sbin/mke2fs is missing" 1>&2
882 if [ ! -x /sbin/genromfs ]; then
883 echo "/sbin/genromfs is missing" 1>&2
888 if [ ! -x /sbin/mkcramfs ]; then
889 echo "/sbin/mkcramfs is missing" 1>&2
894 if [ ! -x /bin/cpio ]; then
895 echo "/bin/cpio is missing" 1>&2
898 if [ ! -x /usr/bin/find ]; then
899 echo "/usr/bin/find is missing" 1>&2
904 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
909 if [ -n "$img_vers" ]; then
910 target="$target-$kernel"
913 if [ -z "$force" -a -f "$target" ]; then
914 echo "$target already exists." 1>&2
918 if [ ! -d "/lib/modules/$kernel" ]; then
919 echo "/lib/modules/$kernel is not a directory." 1>&2
923 if [ ! -f /proc/mounts ]; then
924 echo "WARNING: /proc filesystem not mounted, may cause wrong results or failure." 1>&2
927 if [ "$pack_version" -lt "002005" ]; then
928 modulefile=/etc/modules.conf
929 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
930 modulefile=/etc/conf.modules
933 modulefile=/etc/modprobe.conf
936 for n in $PREMODS; do
940 # allow forcing loading SCSI and/or IDE modules
941 if is_yes "$ADDSCSI" ; then
945 if is_yes "$ADDIDE" ; then
951 org_rootdev="$rootdev1"
953 find_modules_for "$rootdev1"
955 findmodule "-$rootFs"
957 for n in $BASICMODULES; do
961 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
962 if [ -n "$verbose" ]; then
963 echo "No modules are needed -- not building initrd image."
968 if [ -n "$verbose" ]; then
969 echo "Using modules: $MODULES"
972 MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
973 IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
974 MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
975 RCFILE="$MNTIMAGE/linuxrc"
977 if [ -f "$MNTIMAGE" ]; then
978 echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
982 if [ -f "$IMAGE" ]; then
983 echo "$IMAGE already exists. Remove it and try again" 1>&2
987 if [ "$INITRDFS" = "ext2" ] ; then
988 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
990 # We have to "echo y |" so that it doesn't complain about $IMAGE not
991 # being a block device
992 echo y | mke2fs -F "$IMAGE" "$IMAGESIZE" >/dev/null 2>/dev/null
995 mount -o loop -t ext2 "$IMAGE" "$MNTPOINT"
1001 mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs,var}
1004 # We don't need this directory, so let's save space
1005 rm -rf "$MNTPOINT"/lost+found
1007 modules_install "$MODULES"
1009 # mknod'ing the devices instead of copying them works both with and
1011 mknod "$MNTIMAGE/dev/console" c 5 1
1012 mknod "$MNTIMAGE/dev/null" c 1 3
1013 mknod "$MNTIMAGE/dev/zero" c 1 5
1016 ln -s /linuxrc $MNTIMAGE/init
1018 inst /bin/initrd-busybox "$MNTIMAGE/bin/sh"
1019 ln -s sh "$MNTIMAGE/bin/busybox"
1021 if is_yes "$USEINSMODSTATIC" ; then
1022 inst "$INSMOD" $MNTIMAGE/bin/insmod.static
1032 modules_add_linuxrc "$MODULES" "$s"
1034 # TODO: rewrite for busybox
1035 #if [ -n "$loopDev" ]; then
1036 # if [ ! -d /initrd ]; then
1040 # cp -a "$loopDev" "$MNTIMAGE/dev"
1041 # cp -a "$rootdev1" "$MNTIMAGE/dev"
1042 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1043 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1044 # echo "echo Setting up loopback device $rootdev1" >> $RCFILE
1045 # echo "losetup $rootdev1 /loopfs$loopFile" >> "$RCFILE"
1048 initrd_gen_suspend() {
1050 for mod in $SUSPENDMODS; do
1051 is_yes "$BOOT_SPLASH" && [ "$mod" = "-suspend-text" ] && mod="-suspend_bootsplash"
1054 modules_install "$MODULES"
1055 mkdir -p $MNTIMAGE/sys
1056 mkdir -p $MNTIMAGE/proc
1058 mount -t proc none /proc
1059 if [ "\$(awk ' /resume2=/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
1061 modules_add_linuxrc "$MODULES" "$s"
1063 echo > /proc/software_suspend/activate
1070 [ -n "$verbose" ] && echo "Setting up udev..."
1071 mkdir -p $MNTIMAGE/sbin
1072 mkdir -p $MNTIMAGE/proc
1073 mkdir -p $MNTIMAGE/etc/udev
1075 inst /sbin/initrd-udev $MNTIMAGE/sbin/udev
1076 ln -s udev $MNTIMAGE/sbin/udevstart
1077 inst /etc/udev/udev.conf $MNTIMAGE/etc/udev/udev.conf
1079 ln -s udev $MNTIMAGE/sbin/hotplug
1081 if is_yes "$USE_UDEV"; then
1082 if is_yes "$UDEV_TMPFS"; then
1085 mount -o mode=0755 -t tmpfs none /dev
1086 mknod /dev/console c 5 1
1087 mknod /dev/null c 1 3
1088 mknod /dev/zero c 1 5
1094 mount -t proc none /proc
1097 echo -n "/sbin/hotplug" > /proc/sys/kernel/hotplug
1103 initrd_gen_softraid() {
1104 [ -n "$verbose" ] && echo "Setting up mdadm..."
1106 if [ ! -x /sbin/initrd-mdadm -a ! -x /sbin/initrd-mdassemble ] ; then
1107 echo "/sbin/initrd-mdadm and /sbin/initrd-mdassemble are missing !"
1111 if [ -x /sbin/initrd-mdassemble ] ; then
1113 inst /sbin/initrd-mdassemble "$MNTIMAGE/bin/mdassemble"
1116 inst /sbin/initrd-mdadm "$MNTIMAGE/bin/mdadm"
1121 for nr in `seq 1 $rootdev_nr`; do
1122 eval cr_rootdev="\$rootdev${nr}"
1123 eval cr_dev_list="\$dev_list${nr}"
1124 [ -n "$verbose" ] && echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1126 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1128 if [ "$do_mdassemble" -eq 1 ] ; then
1129 echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf"
1130 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1131 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf"
1133 echo "mdadm --assemble $cr_rootdev $cr_dev_list" >> "$s"
1136 for f in $cr_dev_list $cr_rootdev ; do
1137 # mkdir in case of devfs name
1138 mkdir -p $MNTIMAGE/`my_dirname $f`
1139 [ -n "$verbose" ] && echo "copying $f"
1140 # this works fine with and without devfs
1141 cp -HR $f $MNTIMAGE/$f
1145 if [ "$do_mdassemble" -eq 1 ] ; then
1146 echo "mdassemble" >> "$s"
1149 # needed to determine md-version
1150 if [ "$do_md0" -eq 1 ] ; then
1151 mknod $MNTIMAGE/dev/md0 b 9 0
1156 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1157 # have problems like init(XX) being child process of swapper(1).
1158 [ -n "$verbose" ] && echo "Adding rootfs on NFS support to initrd (dhcp)"
1159 mknod "$MNTIMAGE/dev/urandom" c 1 8
1160 mkdir "$MNTIMAGE/newroot"
1161 echo "ifconfig lo 127.0.0.1 up" >> "$s"
1162 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
1163 echo "ifconfig eth0 0.0.0.0 up" >> "$s"
1164 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s"
1165 cat << EOF > "$MNTIMAGE/bin/setdhcp"
1167 [ "\$1" != "bound" ] && exit
1168 [ -n "\$broadcast" ] && BROADCAST="broadcast \$broadcast"
1169 [ -n "\$subnet" ] && NETMASK="netmask \$subnet"
1171 ifconfig \$interface \$ip \$BROADCAST \$NETMASK up
1173 if [ -n "\$router" ]; then
1174 for r in \$router; do
1176 route add default gw \$r dev \$interface
1180 if [ -n "\$rootpath" ]; then
1182 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 \$rootpath /newroot
1186 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1187 echo "All seen variables are listed below:"
1192 chmod 755 "$MNTIMAGE/bin/setdhcp"
1193 echo "cd /newroot" >> "$s"
1194 echo "pivot_root . initrd" >> "$s"
1195 echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1196 echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1200 [ -n "$verbose" ] && echo "Adding LVM support to initrd"
1201 inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
1202 mkdir -p $MNTIMAGE/etc
1203 mkdir -p $MNTIMAGE/tmp
1204 mkdir -p $MNTIMAGE/proc
1205 mkdir -p $MNTIMAGE/newroot
1206 if ! is_yes "$USE_UDEV"; then
1207 mkdir -p $MNTIMAGE/dev/mapper
1208 mknod $MNTIMAGE/dev/mapper/control c 10 63
1209 for device in $PVDEVICES; do
1210 cp -HR $device $MNTIMAGE
1213 echo "mount -t proc none /proc" >> "$s"
1214 echo "mount -t tmpfs none /tmp" >> "$s"
1215 if [ "$LVMTOOLSVERSION" = "1" ] ; then
1216 echo "lvm vgscan -T" >> "$s"
1217 echo "lvm vgchange -T -a y $VGVOLUME" >> "$s"
1218 echo "umount /tmp" >> "$s"
1220 echo "umount /dev" >> "$s"
1221 echo "umount /proc" >> "$s"
1223 echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
1224 echo "global {" > "$MNTIMAGE/etc/lvm.conf"
1225 echo " locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
1226 echo " locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf"
1227 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1228 echo "devices {" >> "$MNTIMAGE/etc/lvm.conf"
1229 echo " sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf"
1230 if is_yes "$raidfound"; then
1231 echo " md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf"
1233 lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf"
1234 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1235 echo "LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure" >> "$s"
1236 echo "LVM_SYSTEM_DIR=/tmp lvm vgchange --ignorelockingfailure -a y $VGVOLUME" >> "$s"
1237 echo "LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure --mknodes" >> "$s"
1238 # Find out major/minor
1239 echo "majmin=\"\`LVM_SYSTEM_DIR=/tmp lvm lvdisplay --ignorelockingfailure -c $org_rootdev\`\"" >> "$s"
1240 echo "majmin=\"\${majmin#*/}\"" >> "$s"
1241 echo "majmin=\"\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}\"" >> "$s"
1242 echo "major=\"\${majmin%:*}\"" >> "$s"
1243 echo "minor=\"\${majmin#*:}\"" >> "$s"
1245 echo "val=\$((256 * \$major + \$minor))" >> "$s"
1246 echo "echo \$val > /proc/sys/kernel/real-root-dev" >> "$s"
1247 echo "umount /tmp" >> "$s"
1248 echo "umount /proc" >> "$s"
1252 initrd_gen_procdata() {
1253 [ -n "$verbose" ] && echo "Adding rootfs finding based on root= option support."
1254 mkdir -p $MNTIMAGE/proc
1257 mount -t proc none /proc
1258 root="\$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,\$0); gsub(/ .*/,NIL,\$0); print \$0; } ' /proc/cmdline)"
1259 if [ -n "\$root" ]; then
1260 rootnr="\$(busybox awk -v root="\$root" ' { if (\$4 == root) { print 256*\$1+\$2; } } ' /proc/partitions)"
1261 if [ -n "\$rootnr" ]; then
1262 echo "\$rootnr" > /proc/sys/kernel/real-root-dev
1272 if is_yes "$USE_UDEV"; then
1276 if is_yes "$USESUSPEND"; then
1280 if is_yes "$usenfs" ; then
1282 elif is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
1284 if is_yes "$uselvm" ; then
1287 elif is_yes "$uselvm" ; then
1295 (cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
1302 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
1305 mkcramfs "$MNTPOINT" "$IMAGE"
1308 (cd $MNTPOINT ; find . | cpio -H newc -o > "$IMAGE")
1311 echo "Filesystem $INITRDFS not supported by $0";
1314 if is_yes "$COMPRESS" ; then
1315 gzip -9 < "$IMAGE" > "$target"
1317 cp -a "$IMAGE" "$target"
1320 if is_yes "$BOOT_SPLASH"; then
1321 if [ ! -x /bin/splash.bin ]; then
1322 echo "Failed to execute /bin/splash.bin. Is bootsplash package installed?" 1>&2
1323 elif [ -z "$THEME" ]; then
1324 echo "Please configure your /etc/sysconfig/bootsplash first." 1>&2
1325 echo "Generating bootsplashes skipped." 1>&2
1327 if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
1328 for res in $BOOT_SPLASH_RESOLUTIONS; do
1329 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1330 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1331 [ -n "$verbose" ] && echo "Added $res $THEME theme to initrd."
1333 echo "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" 1>&2
1337 echo "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." 1>&2
1338 echo "Not adding bootsplash to initrd." 1>&2
1343 rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"