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 # is /dev on tmpfs. internal variable
48 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udev ]; then
53 if [ -x /sbin/dmraid-initrd ]; then
58 echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
59 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
60 echo " [--initrdfs=rom|ext2|cram] [--modules-conf=<modules.conf>]"
61 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
62 echo " [--without-bootsplash] [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
63 echo " [--without-suspend] [--without-suspend2] [--without-dmraid]"
64 echo " <initrd-image> <kernel-version>"
65 echo " (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)"
71 typeset mods module f level depfile first
73 depfile=/lib/modules/$kernel/modules.dep
75 if [ -f $depfile ] ; then
78 echo "Error: no $depfile ! Run depmod and rerun geninitrd." 1>&2
82 # prepend / if no path given, append $modext.gz if not given,
85 module=$(echo "$2" | \
86 awk '/\// {print;next} {print "/" $0}' | \
87 awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
88 awk '{gsub("/","\\/");print}')
91 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
93 /(.*)/ { gsub(/\\/," "); if (here) print }
97 if [ "$mods" = "" ] ; then
98 module=$(echo "$module" | \
99 awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
103 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
105 /(.*)/ { gsub(/\\/," "); if (here) print }
108 if [ "$mods" = "" ] ; then
109 if [ "$1" != silent ] ; then
110 echo "$origmodule: module not found in $depfile" 1>&2
112 if ! is_no "$EXIT_IF_MISSING" ; then
115 echo "If $origmodule isn't compiled in kernel then this initrd may not start your system". 1>&2
120 if [ "$level" = "" ] ; then
123 level=$(awk "BEGIN{print $level + 1}")
124 if [ $level -gt 20 ] ; then
125 echo "$origmodule: cycle in $depfile" 1>&2
131 if [ "$first" = "" ] ; then
134 find_depmod $1 $f $level
145 if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
146 if [ -n "$skiperrors" ]; then
150 echo "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" 1>&2
154 # only need to add each module once
156 tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
157 if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
158 MODULES="$MODULES $fmPath"
166 if [ "$(echo $modName | awk '{print(substr($0,1,1));}')" = "-" ]; then
168 modName="$(echo $modName | awk '{print(substr($0,2));}')"
172 if [ "$modName" = "pluto" ]; then
176 if [ "$modName" = "fcal" ]; then
181 if [ -n "$skiperrors" ]; then
182 allModulesToFind=`find_depmod silent $modName`
184 allModulesToFind=`find_depmod normal $modName`
185 if [ $? != 0 ] ; then
190 for mod in $allModulesToFind ; do
191 mod=$(echo $mod | 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_admin -u "$1" 2>/dev/null | awk -F= '{print $2}' | xargs
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_admin ] ; then
294 echo "/usr/sbin/xfs_admin is missing" 1>&2
297 get_uuid="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 | awk -v rootdev="$1" '
337 rootdev_devfs = rootdev;
338 if (rootdev ~ /\/dev\/md\/[0-9]/) {
339 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
344 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
346 gsub(/level=/,NUL,raidlevel);
347 if (raidlevel ~ /^raid([0-6]|10)/) {
348 gsub(/raid/,NUL,raidlevel);
352 if (x ~ /devices=/) {
354 gsub(".*devices=", NUL, dev_list);
355 gsub(",", " ", dev_list);
361 print "raidfound=" found;
362 print "raidlevel=" raidlevel;
363 print "dev_list=\"" dev_list "\"";
367 if [ "$raidfound" != "yes" -a -f /etc/raidtab ]; then
368 echo "ERROR: raidtools are not longer supported. Please migrate to mdadm setup!" 1>&2
372 if is_yes "$raidfound" ; then
375 findmodule "raid$raidlevel"
381 echo "raid level $number (in mdadm config) not recognized" 1>&2
385 echo "ERROR: RAID devices not found for \"$1\", check your configuration!" 1>&2
389 rootdev_nr=$(( $rootdev_nr + 1 ))
390 eval "rootdev${rootdev_nr}=\"$1\""
391 eval "dev_list${rootdev_nr}=\"${dev_list}\""
393 for device in $dev_list; do
394 find_modules_for $device
398 find_modules_scsi() {
399 for n in $PRESCSIMODS; do
400 if [ "X$n" = "Xunknown" ] ; then
401 if [ -f "$modulefile" ]; then
402 scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
403 for n in $scsimodules; do
404 # for now allow scsi modules to come from anywhere. There are some
405 # RAID controllers with drivers in block
418 rootdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')"
419 if [ "$pack_version_long" -lt "002004021" ]; then
420 [ -n "$verbose" ] && echo "Finding IDE modules for kernels <= 2.4.20"
421 for n in $PREIDEMODSOLD; do
426 for n in $PREIDEMODS; do
427 if [ "X$n" = "Xunknown" ] ; then
428 if [ -f "$modulefile" ]; then
429 [ -n "$verbose" ] && echo "Finding IDE modules using ide_hostadapter"
430 idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
431 for na in $idemodules; do
437 if [ "$tryauto" -eq 1 ]; then
439 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
440 [ -n "$verbose" ] && echo "Finding IDE modules using PCI ID database"
441 # Finding IDE modules using PCI ID database {{{
442 if is_yes "${ide_only_root}"; then
443 if [ -f /sys/block/${rootdev}/device/../../vendor -a -f /sys/block/${rootdev}/device/../../device ]; then
444 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../vendor)"
445 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../device)"
446 searchpciid="${vendorid}${deviceid}"
447 elif [ -f /proc/ide/${rootdev}/../config ]; then
448 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootdev}/../config)"
452 if [ -z "${searchpciid}" ]; then
453 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
458 for nb in $searchpciid; do
459 eval `awk -v pciid="$nb" '{
465 compmod = $1 ""; # make sure comparison type will be string
466 # cause pci IDs are hexadecimal numeric
467 if (compmod == pciid) {
469 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
476 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
477 }' /usr/share/pci-database/ide.pci`
478 [ -n "$module" ] && idemodules="$idemodules $module"
480 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
482 for nc in idemodules; do
483 new_idemodules="$nc $new_idemodules"
485 idemodules="${new_idemodules}"
488 if [ -z "$idemodules" ]; then
489 echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic."
490 idemodules="ide-generic"
494 for nd in $idemodules; do
500 [ -r /usr/share/pci-database/ide.pci ] || echo "WARNING: /usr/share/pci-database/ide.pci missing."
501 [ -r /proc/bus/pci/devices ] || echo "WARNING: /proc/bus/pci/devices missing."
502 echo "Automatic IDE modules finding not available."
513 # resolve /dev/dm-0 to lvm2 node
514 # which they got from /proc/partitions when rootfs is UUID=
515 _lvm2_node_resolve() {
518 # redirect output to tmpfile so we won't get subshell
520 tmp=$(mktemp) || exit 1
522 lvdisplay -c 2>/dev/null|awk -F: '{print $1}' > $tmp
524 count=$(ls -Ll $dev $node | awk '{print $5, $6}' | sort -u | wc -l)
525 if [ "$count" = 1 ]; then
532 if [ -z "$ret" ]; then
538 # return true if node is lvm node
541 if [ ! -e "$node" ]; then
542 echo "WARNING: check_lvm(): node $node doesn't exists!" 1>&2
546 # block-major-58 is lvm1
547 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
551 [ -n "$verbose" ] && echo "$node is LVM1 node"
556 node=$(_lvm2_node_resolve $node)
557 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
559 if [ $rc -gt 127 ]; then
560 # lvdisplay terminated by signal! most likely it segfaulted.
561 echo >&2 "ERROR: Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
566 [ -n "$verbose" ] && echo "$node is lvm2 node"
568 [ -n "$verbose" ] && echo "$node is not any lvm node"
575 echo "ERROR: no argument passed to find_modules_for() - is your /etc/fstab correct?" >&2
579 if is_yes "`echo "$1" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
580 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then
581 echo "ERROR: root on NFS but /usr/bin/pcidev not found." >&2
582 echo "Please install correct pci-database package and rerun $0." >&2
585 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
586 for m in $NFS_ETH_MODULES; do
592 echo "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel" >&2
593 echo "or you will have problems like init(xx) being child process of swapper(1)." >&2
594 elif is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
595 find_modules_softraid "$1"
596 elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
598 elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
599 find_modules_ide "$1"
600 elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
602 elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
603 findmodule "cpqarray"
604 elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
606 elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
609 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
610 if -n "$ataraidmodules" ; then
611 # FIXME: think about modules compiled in kernel
612 echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
613 echo "Please set it and run $0 again."
616 for n in $ataraidmodules; do
619 # check to see if we need to set up a loopback filesystem
620 elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
621 echo "Sorry, root on loop device isn't supported." 1>&2
623 # TODO: rewrite for bsp and make nfs ready
624 if [ ! -x /sbin/losetup ]; then
625 echo "losetup is missing"
628 key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
629 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
630 echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
631 echo "for this device. Consult the geninitrd man page for more information" 1>&2
635 line="`awk '/'$key'/ { print $0; }' $fstab`"
636 loopDev="$(echo $line | awk '{print $3}')"
637 loopFs="$(echo $line | awk '{print $4}')"
638 loopFile="$(echo $line | awk '{print $5}')"
640 BASICMODULES="$BASICMODULES -loop"
641 findmodule "-$loopFs"
642 BASICMODULES="$BASICMODULES -${loopFs}"
643 elif _check_lvm "$1"; then
644 node=$(_lvm2_node_resolve "$1")
646 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then
647 echo "ERROR: root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found." >&2
648 echo "Please install lvm(2) and lvm(2)-initrd package and rerun $0." >&2
651 if [ -z "$LVMTOOLSVERSION" ] ; then
652 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}')
653 if [ -z "$LVMTOOLSVERSION" ] ; then
654 echo "ERROR: Can't determine LVM tools version. Please set LVMTOOLSVERSION" >&2
655 echo "and rerun $0." >&2
659 if [ -z "$PVDEVICES" ] ; then
660 VGVOLUME=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
661 PVDEVICES=$(/sbin/pvdisplay -c | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
663 if [ -n "$PVDEVICES" ] ; then
664 for device in $PVDEVICES; do
665 find_modules_for $device
668 echo "ERROR: I wasn't able to find PV (via lvdisplay and pvdisplay)." >&2
669 echo "You can try to set PVDEVICES in /etc/sysconfig/geninitrd." >&2
672 if [ "$LVMTOOLSVERSION" = "2" ]; then
674 elif [ "$LVMTOOLSVERSION" = "1" ]; then
676 findmodule "-lvm-mod"
678 echo "ERROR: LVM version $LVMTOOLSVERSION is not supported yet." >&2
681 [ -n "$verbose" ] && echo "LVM $LVMTOOLSVERSION enabled"
686 firmware_install_module_pre() {
691 [ -n "$verbose" ] && echo "Adding Firmwares ($firmware_files) to initrd for module $module"
692 mkdir -p $MNTIMAGE/proc
693 mkdir -p $MNTIMAGE/sys
694 # firmware not yet installed
695 if [ ! -f "$MNTIMAGE/lib/firmware/firmware.sh" ]; then
696 mkdir -p $MNTIMAGE/lib/firmware
697 cat << 'EOF' >> "$MNTIMAGE/lib/firmware/firmware.sh"
699 echo 1 > /sys$DEVPATH/loading
700 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
701 echo 0 > /sys$DEVPATH/loading
704 chmod 755 "$MNTIMAGE/lib/firmware/firmware.sh"
707 for firmware in $firmware_files; do
708 inst "/lib/firmware/$firmware" "$MNTIMAGE/lib/firmware/$firmware"
711 echo "mount -t proc none /proc" >> "$linuxrc"
712 echo "mount -t sysfs none /sys" >> "$linuxrc"
713 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" >> "$linuxrc"
716 firmware_install_module_post() {
720 echo "umount /sys" >> "$linuxrc"
721 echo "umount /proc" >> "$linuxrc"
727 for mod in $modules; do
728 MODULEDIR="`dirname "$mod"`"
729 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
730 cp -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
731 gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
735 modules_add_linuxrc() {
739 for mod in $modules; do
740 MODULE2="`dirname "$mod"`"
741 NAME2=`basename "$mod" .gz`
742 MODULE2=$MODULE2/$NAME2
743 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
744 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
746 generic_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ')
747 sleep_var="$(eval echo \$MODULE_${generic_module}_USLEEP)"
748 firmware_var="$(eval echo \$MODULE_${generic_module}_FIRMWARE)"
750 if [ -n "$verbose" ]; then
751 echo -n "Loading module [$module] "
752 if [ -n "$options" ] ; then
753 echo -n "with options [$options]"
755 echo -n "without options"
757 if [ -n "$sleep_var" ]; then
758 echo " and $sleep_var usleep."
764 if [ -n "$firmware_var" ]; then
765 firmware_install_module_pre "$module" "$linuxrc" "$firmware_var"
767 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
768 if [ -n "${sleep_var}" ]; then
769 echo "usleep $sleep_var" >> "$linuxrc"
771 if [ -n "$firmware_var" ]; then
772 firmware_install_module_post "$module" "$linuxrc" "$firmware_var"
777 if [ -r /etc/sysconfig/geninitrd ] ; then
778 . /etc/sysconfig/geninitrd
781 if [ -r /etc/sysconfig/bootsplash ] ; then
782 . /etc/sysconfig/bootsplash
785 if [ ! -x /bin/initrd-busybox ] ; then
786 echo "/bin/initrd-busybox is missing !"
790 while [ $# -gt 0 ]; do
793 fstab="`echo $1 | awk -F= '{print $2;}'`"
800 modulefile="`echo $1 | awk -F= '{print $2;}'`"
806 --use-raidstart|--with-raidstart)
812 --use-insmod-static|--with-insmod-static)
813 USEINSMODSTATIC="yes"
815 --without-insmod-static)
818 --without-bootsplash)
827 --lvmtoolsversion=|--lvmversion=)
828 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
830 --lvmtoolsversion|--lvmversion)
844 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
847 BASICMODULES="$BASICMODULES $2"
851 echo "geninitrd: version $VERSION"
867 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
870 PREMODS="$PREMODS $2"
874 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
875 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
878 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
883 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
896 if [ -z "$target" ]; then
898 elif [ -z "$kernel" ]; then
909 if [ -z "$target" -o -z "$kernel" ]; then
913 pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
914 pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
916 if [ "x" = "x$INITRDFS" ] ; then
917 if [ "x" = "x$FS" ] ; then
919 # XXX: initramfs blocked for now
920 if [ "1" = " 0" -a "$pack_version" -ge "002005" ] ; then
926 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
931 if [ "$pack_version" -lt "002006" ] ; then
936 if [ "$pack_version" -ge "002005" ] ; then
941 if is_yes "$USEINSMODSTATIC" ; then
942 insmod="insmod.static"
943 INSMOD="/sbin/insmod.static"
944 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
945 INSMOD="/sbin/insmod.static.modutils"
947 if [ ! -f "$INSMOD" ] ; then
948 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
955 if [ ! -x /sbin/mke2fs ]; then
956 echo "/sbin/mke2fs is missing" 1>&2
961 if [ ! -x /sbin/genromfs ]; then
962 echo "/sbin/genromfs is missing" 1>&2
967 if [ ! -x /sbin/mkcramfs ]; then
968 echo "/sbin/mkcramfs is missing" 1>&2
973 if [ ! -x /bin/cpio ]; then
974 echo "/bin/cpio is missing" 1>&2
977 if [ ! -x /usr/bin/find ]; then
978 echo "/usr/bin/find is missing" 1>&2
983 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
988 if [ -n "$img_vers" ]; then
989 target="$target-$kernel"
992 if [ -z "$force" -a -f "$target" ]; then
993 echo "$target already exists." 1>&2
997 if [ ! -d "/lib/modules/$kernel" ]; then
998 echo "/lib/modules/$kernel is not a directory." 1>&2
1002 if is_yes "$USE_SUSPEND"; then
1003 if is_yes "$USE_SUSPEND2"; then
1004 echo "Suspend2 shouldn't be used in parallel with mainline suspend!." 1>&2
1009 if [ ! -f /proc/mounts ]; then
1010 echo "WARNING: /proc filesystem not mounted, may cause wrong results or failure." 1>&2
1013 if [ "$pack_version" -lt "002005" ]; then
1014 modulefile=/etc/modules.conf
1015 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
1016 modulefile=/etc/conf.modules
1019 modulefile=/etc/modprobe.conf
1022 for n in $PREMODS; do
1026 # allow forcing loading SCSI and/or IDE modules
1027 if is_yes "$ADDSCSI" ; then
1031 if is_yes "$ADDIDE" ; then
1037 org_rootdev="$rootdev1"
1039 find_modules_for "$rootdev1"
1041 findmodule "-$rootFs"
1043 for n in $BASICMODULES; do
1047 if is_yes "$USE_SUSPEND2"; then
1051 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1052 if [ -n "$verbose" ]; then
1053 echo "No modules are needed -- not building initrd image."
1058 if [ -n "$verbose" ]; then
1059 echo "Using modules: $MODULES"
1062 MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
1063 IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
1064 MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
1065 RCFILE="$MNTIMAGE/linuxrc"
1067 if [ -f "$MNTIMAGE" ]; then
1068 echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
1072 if [ -f "$IMAGE" ]; then
1073 echo "$IMAGE already exists. Remove it and try again" 1>&2
1077 mkdir -p "$MNTPOINT"
1080 mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs,var}
1083 # We don't need this directory, so let's save space
1084 rm -rf "$MNTPOINT"/lost+found
1086 modules_install "$MODULES"
1088 # mknod'ing the devices instead of copying them works both with and
1090 mknod "$MNTIMAGE/dev/console" c 5 1
1091 mknod "$MNTIMAGE/dev/null" c 1 3
1092 mknod "$MNTIMAGE/dev/zero" c 1 5
1095 ln -s /linuxrc $MNTIMAGE/init
1097 inst /bin/initrd-busybox "$MNTIMAGE/bin/initrd-busybox"
1098 ln -s initrd-busybox "$MNTIMAGE/bin/sh"
1099 ln -s initrd-busybox "$MNTIMAGE/bin/busybox" # for older busyboxes who had /bin/busybox as EXEPATH
1101 if is_yes "$USEINSMODSTATIC" ; then
1102 inst "$INSMOD" $MNTIMAGE/bin/insmod.static
1112 modules_add_linuxrc "$MODULES" "$s"
1114 # TODO: rewrite for busybox
1115 #if [ -n "$loopDev" ]; then
1116 # if [ ! -d /initrd ]; then
1120 # cp -a "$loopDev" "$MNTIMAGE/dev"
1121 # cp -a "$rootdev1" "$MNTIMAGE/dev"
1122 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1123 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1124 # echo "echo Setting up loopback device $rootdev1" >> $RCFILE
1125 # echo "losetup $rootdev1 /loopfs$loopFile" >> "$RCFILE"
1128 initrd_gen_suspend() {
1129 if [ ! -x /usr/sbin/resume ]; then
1130 echo "/usr/sbin/resume is missing !"
1133 mkdir -p $MNTIMAGE/etc
1134 mkdir -p $MNTIMAGE/dev
1135 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
1136 cp -HR /dev/snapshot $resume_dev $MNTIMAGE/dev
1137 inst /etc/suspend.conf $MNTIMAGE/etc/suspend.conf
1138 inst /usr/sbin/resume "$MNTIMAGE/bin/resume"
1139 echo "resume" >> "$s"
1142 initrd_gen_suspend2() {
1143 mkdir -p $MNTIMAGE/sys
1144 mkdir -p $MNTIMAGE/proc
1145 cat << 'EOF' >> "$s"
1146 mount -t proc none /proc
1147 if [ "$(awk ' /resume2=/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
1150 echo > /proc/suspend2/do_resume
1156 initrd_gen_tmpfs_dev() {
1160 mount -o mode=0755 -t tmpfs none /dev
1161 mknod /dev/console c 5 1
1162 mknod /dev/null c 1 3
1163 mknod /dev/zero c 1 5
1170 [ -n "$verbose" ] && echo "Setting up udev..."
1171 mkdir -p $MNTIMAGE/sbin
1172 mkdir -p $MNTIMAGE/proc
1173 mkdir -p $MNTIMAGE/etc/udev
1174 mkdir -p $MNTIMAGE/sys
1176 inst /sbin/initrd-udev $MNTIMAGE/sbin/udev
1177 ln -s udev $MNTIMAGE/sbin/udevstart
1178 inst /etc/udev/udev.conf $MNTIMAGE/etc/udev/udev.conf
1180 ln -s udev $MNTIMAGE/sbin/hotplug
1182 if is_yes "$USE_UDEV"; then
1183 initrd_gen_tmpfs_dev >> "$s"
1185 mount -t proc none /proc
1186 mount -t sysfs none /sys
1189 echo -n /sbin/hotplug > /proc/sys/kernel/hotplug
1196 initrd_gen_dmraid() {
1197 if [ ! -x /sbin/dmraid-initrd ] ; then
1198 echo "/sbin/dmraid-initrd is missing missing !"
1202 # AFAIR it just needs tmpfs on /dev.
1203 if [ ! -x $MNTIMAGE/sbin/udev ]; then
1204 echo "udev is needed on target initrd for dmraid to work!"
1208 mkdir -p "$MNTIMAGE/sbin"
1209 inst /sbin/dmraid-initrd $MNTIMAGE/sbin/dmraid
1211 mount -t proc none /proc
1212 mount -t sysfs none /sys
1213 # 2 secs was enough for my system to initialize. but really this is udev issue?
1215 : 'Activating Device-Mapper RAID(s)'
1223 initrd_gen_softraid() {
1224 [ -n "$verbose" ] && echo "Setting up mdadm..."
1226 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ] ; then
1227 echo "/sbin/mdadm or /sbin/initrd-mdassemble is missing !"
1231 inst /sbin/initrd-mdassemble "$MNTIMAGE/bin/mdassemble"
1234 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf)
1235 for ex_dev in $dev_list_extra; do
1236 echo "DEVICE $ex_dev" >> "$MNTIMAGE/etc/mdadm.conf"
1239 for nr in `seq 1 $rootdev_nr`; do
1240 eval cr_rootdev="\$rootdev${nr}"
1241 eval cr_dev_list="\$dev_list${nr}"
1242 [ -n "$verbose" ] && echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1244 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1246 echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf"
1247 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1248 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev)
1249 if [ -n "$cr_md_conf" ]; then
1250 echo "$cr_md_conf" >> "$MNTIMAGE/etc/mdadm.conf"
1252 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf"
1255 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1256 # mkdir in case of devfs name
1257 mkdir -p $MNTIMAGE/`dirname $f`
1258 [ -e "$MNTIMAGE/$f" ] && continue
1259 [ -n "$verbose" ] && echo "copying $f"
1260 # this works fine with and without devfs
1261 cp -HR $f $MNTIMAGE/$f
1265 echo "mdassemble" >> "$s"
1267 # needed to determine md-version
1268 if [ "$do_md0" -eq 1 ] ; then
1269 mknod $MNTIMAGE/dev/md0 b 9 0
1274 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1275 # have problems like init(XX) being child process of swapper(1).
1276 [ -n "$verbose" ] && echo "Adding rootfs on NFS support to initrd (dhcp)"
1277 mknod "$MNTIMAGE/dev/urandom" c 1 8
1278 mkdir "$MNTIMAGE/newroot"
1279 mkdir "$MNTIMAGE/proc"
1280 echo "ifconfig lo 127.0.0.1 up" >> "$s"
1281 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
1282 echo "ifconfig eth0 0.0.0.0 up" >> "$s"
1283 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s"
1284 cat << 'EOF' > "$MNTIMAGE/bin/setdhcp"
1286 [ "$1" != "bound" ] && exit
1287 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1288 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1290 ifconfig $interface $ip $BROADCAST $NETMASK up
1292 if [ -n "$router" ]; then
1293 for r in $router; do
1295 route add default gw $r dev $interface
1300 mount -t proc none /proc
1301 for o in $(cat /proc/cmdline); do
1304 rootpath=${o#nfsroot=}
1310 if [ -n "$rootpath" ]; then
1312 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1316 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1317 echo "All seen variables are listed below:"
1322 chmod 755 "$MNTIMAGE/bin/setdhcp"
1323 echo "cd /newroot" >> "$s"
1324 echo "pivot_root . initrd" >> "$s"
1325 echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1326 echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1330 [ -n "$verbose" ] && echo "Adding LVM support to initrd"
1331 inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
1332 mkdir -p $MNTIMAGE/etc
1333 mkdir -p $MNTIMAGE/tmp
1334 mkdir -p $MNTIMAGE/proc
1335 mkdir -p $MNTIMAGE/newroot
1337 # always make /dev on tmpfs for LVM2
1338 if [ "$LVMTOOLSVERSION" = "2" ] && ! is_yes "$tmpfs_dev"; then
1339 initrd_gen_tmpfs_dev >> "$s"
1342 if ! is_yes "$tmpfs_dev"; then
1343 mkdir -p $MNTIMAGE/dev/mapper
1344 mknod $MNTIMAGE/dev/mapper/control c 10 63
1345 for device in $PVDEVICES; do
1346 # if LVM on RAID then device might be copied already in gen_softraid
1347 [ -e "$MNTIMAGE/dev/$(basename $device)" ] && continue
1348 cp -HR $device $MNTIMAGE/dev/
1351 echo "mount -t proc none /proc" >> "$s"
1352 echo "mount -t tmpfs none /tmp" >> "$s"
1353 if [ "$LVMTOOLSVERSION" = "1" ] ; then
1354 echo "lvm vgscan -T" >> "$s"
1355 echo "lvm vgchange -T -a y $VGVOLUME" >> "$s"
1356 echo "umount /tmp" >> "$s"
1358 echo "umount /dev" >> "$s"
1359 echo "umount /proc" >> "$s"
1361 org_rootdev=$(_lvm2_node_resolve "$org_rootdev")
1362 echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
1363 echo "global {" > "$MNTIMAGE/etc/lvm.conf"
1364 echo " locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
1365 echo " locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf"
1366 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1367 echo "devices {" >> "$MNTIMAGE/etc/lvm.conf"
1368 echo " sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf"
1369 if is_yes "$raidfound"; then
1370 echo " md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf"
1372 lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf"
1373 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1376 : 'Making device nodes'
1379 # ignore first two lines, header and empty line
1382 while read major minor blocks dev; do
1383 mknod /dev/\$dev b \$major \$minor
1385 ) < /proc/partitions
1387 # disable noise from lvm accessing devices that aren't ready.
1388 printk=\$(cat /proc/sys/kernel/printk)
1389 echo 0 > /proc/sys/kernel/printk
1392 : 'Scanning for Volume Groups'
1393 LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure 2>/dev/null
1395 : 'Activating Volume Groups'
1396 LVM_SYSTEM_DIR=/tmp lvm vgchange --ignorelockingfailure -a y $VGVOLUME 2>/dev/null
1398 echo "\$printk" > /proc/sys/kernel/printk
1400 # Find out major/minor
1401 majmin="\$(LVM_SYSTEM_DIR=/tmp lvm lvdisplay --ignorelockingfailure -c $org_rootdev 2>/dev/null)"
1402 majmin="\${majmin#*/}"
1403 majmin="\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}"
1404 major="\${majmin%:*}"
1405 minor="\${majmin#*:}"
1407 val=\$((256 * \$major + \$minor))
1408 echo \$val > /proc/sys/kernel/real-root-dev
1415 initrd_gen_procdata() {
1416 [ -n "$verbose" ] && echo "Adding rootfs finding based on root= option support."
1417 mkdir -p $MNTIMAGE/proc
1418 cat << 'EOF' >> "$s"
1420 mount -t proc none /proc
1421 root="$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ' /proc/cmdline)"
1422 if [ -n "$root" ]; then
1423 rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)"
1424 if [ -n "$rootnr" ]; then
1425 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1435 if is_yes "$USE_UDEV"; then
1439 if is_yes "$USE_SUSPEND"; then
1443 if is_yes "$USE_SUSPEND2"; then
1447 if is_yes "$USE_DMRAID"; then
1451 if is_yes "$usenfs" ; then
1453 elif is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
1455 if is_yes "$uselvm" ; then
1460 elif is_yes "$uselvm" ; then
1466 if [ "$INITRDFS" = "initramfs" ]; then
1467 mkdir -p $MNTIMAGE/newroot
1468 cp -HR $org_rootdev $MNTIMAGE/dev
1469 echo "mount -t $rootFs $org_rootdev /newroot" >> "$s"
1470 echo "switch_root /newroot /sbin/init" >> "$s"
1471 # we need real file, not symlink
1472 rm -f $MNTIMAGE/init
1473 cp -a $MNTIMAGE/linuxrc $MNTIMAGE/init
1478 (cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
1482 IMAGESIZE=$(du -ks $MNTPOINT | awk '{print int(($1+1023)/1024)*1024}')
1483 [ "$verbose" ] && echo "ext2 image size: $IMAGESIZE ($MNTPOINT)"
1484 if [ "$IMAGESIZE" -gt 4096 ]; then
1485 echo >&2 "$0: Your image size is larger than 4096, You should add ramdisk_size=$IMAGESIZE to your kernel commandline!"
1488 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1489 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1490 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1492 tmpmnt="`mktemp -d /tmp/initrd.mnte2-XXXXXX`"
1493 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1495 (cd "$MNTPOINT"; tar cf - .) | (cd "$tmpmnt"; tar xf -)
1500 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
1503 mkcramfs "$MNTPOINT" "$IMAGE"
1506 (cd $MNTPOINT ; find . | cpio -H newc -o > "$IMAGE")
1509 echo "Filesystem $INITRDFS not supported by $0";
1512 if is_yes "$COMPRESS" ; then
1513 gzip -9 < "$IMAGE" > "$target"
1515 cp -a "$IMAGE" "$target"
1518 if is_yes "$BOOT_SPLASH"; then
1519 if [ ! -x /bin/splash.bin ]; then
1520 echo "Failed to execute /bin/splash.bin. Is bootsplash package installed?" 1>&2
1521 elif [ -z "$THEME" ]; then
1522 echo "Please configure your /etc/sysconfig/bootsplash first." 1>&2
1523 echo "Generating bootsplashes skipped." 1>&2
1525 if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
1526 for res in $BOOT_SPLASH_RESOLUTIONS; do
1527 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1528 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1529 [ -n "$verbose" ] && echo "Added $res $THEME theme to initrd."
1531 echo "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" 1>&2
1535 echo "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." 1>&2
1536 echo "Not adding bootsplash to initrd." 1>&2
1541 rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"
1543 # vim:ts=4:sw=4:noet:fdm=marker