7 # based on mkinitrd from RedHat Linux
10 # - make udev start before insmods
11 # - make proper use of USE_UDEV - don't copy rules if USE_UDEV is off no!
15 R=${RCSID#* * }; VERSION=${R%% *}
18 . /etc/rc.d/init.d/functions
19 . /etc/geninitrd/functions
20 . /etc/sysconfig/system
28 # it should be safe to remove scsi_mod from here, but I'm not sure...
29 PRESCSIMODS="-scsi_mod unknown -sd_mod"
30 PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
31 PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
42 # device node for rootfs from fstab
44 # requires bootsplash package to operate
46 # requires splashutils package to operate
48 # requires splashutils package to operate
58 # is /tmp mounted on tmpfs
61 # are /dev nodes already created from /proc/devices info?
64 # LVM devices that should not be included in vgscan on initrd
67 # whether v86d should be installed
70 # LVM volumes that are needed to activate
73 # VG for suspend resume dev
79 # if we should init NFS at boot
81 # if we should init LVM at boot
83 # if we should init md (softraid) at boot
85 # if we should init dmraid at boot
87 # if we should init dm-multipath at boot
89 # dm-multipath wwid which is used for rootfs
94 echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
95 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
96 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
97 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
98 echo " [--with-bootsplash] [--without-bootsplash]"
99 echo " [--with-fbsplash] [--without-fbsplash]"
100 echo " [--with-fbcondecor] [--without-fbcondecor]"
101 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
102 echo " [--with-suspend] [--without-suspend]"
103 echo " [--with-tuxonice] [--without-tuxonice]"
104 echo " [--without-dmraid] [--without-multipath]"
105 echo " [--without-blkid]"
106 echo " <initrd-image> <kernel-version>"
109 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
118 msg "WARNING: $*" >&2
122 [ -n "$verbose" ] && msg "$*" >&2
125 # aborts program abnormally
132 # append text to /linuxrc
133 # takes STDIN as input
138 # generate code to mount /dev on tmpfs and create initial nodes
139 # can be called multiple times. /dev is cleaned up (umounted) automatically at
142 if [ "$INITRDFS" = "initramfs" ]; then
143 # initramfs is read-write filesystem, no need for tmpfs
147 # we already generated tmpfs code; return
148 if is_yes "$dev_mounted"; then
154 busybox_applet mount mknod mkdir
157 mount -o mode=0755 -t tmpfs none /dev
158 mknod /dev/console c 5 1
159 mknod /dev/null c 1 3
160 mknod /dev/zero c 1 5
166 # generate code to mount /proc on initrd
167 # can be called multiple times
169 if is_yes "$proc_mounted"; then
174 if [ "$INITRDFS" = "initramfs" ]; then
175 # /proc is mounted with initramfs 2.6.22.14 kernel
176 # XXX: remove when it is clear why proc was already mounted
177 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
179 echo "mount -t proc none /proc" | add_linuxrc
183 # generate code to mount /sys on initrd
184 # can be called multiple times
186 if is_yes "$sys_mounted"; then
191 echo "mount -t sysfs none /sys" | add_linuxrc
194 # generate code to mount /tmp on initrd
195 # can be called multiple times
197 if [ "$INITRDFS" = "initramfs" ]; then
198 # initramfs is read-write filesystem, no need for tmpfs
202 if is_yes "$tmp_mounted"; then
207 echo "mount -t tmpfs none /tmp" | add_linuxrc
210 # unmount all mountpoints mounted by geninitrd
214 : Last shell before umounting all and giving control over to real init.
218 if is_yes "$dev_mounted"; then
219 echo 'umount /dev' | add_linuxrc
222 if is_yes "$proc_mounted"; then
223 echo 'umount /proc' | add_linuxrc
226 if is_yes "$sys_mounted"; then
227 echo 'umount /sys' | add_linuxrc
230 if is_yes "$tmp_mounted"; then
231 echo 'umount /tmp' | add_linuxrc
237 # Checks if busybox has support for APPLET(s)
238 # Exits from geninitrd if the support is not present.
240 # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
244 if [ -z "$busybox_functions" ]; then
245 local tmp=$(/bin/initrd-busybox 2>&1)
247 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
248 if [[ "$tmp" = *applet\ not\ found* ]]; then
250 ln -s /bin/initrd-busybox $t/busybox
251 local tmp=$($t/busybox 2>&1)
255 busybox_functions=$(echo "$tmp" | \
256 sed -ne '/Currently defined functions:/,$p' | \
257 xargs | sed -e 's,.*Currently defined functions: ,,'
263 eval have='$'busybox_have_$applet
264 if [ -z "$have" ]; then
265 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
266 if [ "$have" = 0 ]; then
267 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
270 eval busybox_have_$applet=$have
273 if [ $err = 1 ]; then
278 # Finds module dependencies
281 # @param $mode [silent]
283 # Outputs each dependant module full path including the module itself.
288 # backwards compatible, process $mode
290 if [ "$mode" = "silent" ]; then
291 modfile=$(modinfo -k $kernel -n $module 2>/dev/null)
293 modfile=$(modinfo -k $kernel -n $module)
295 if [ ! -f "$modfile" ]; then
296 if [ "$mode" != "silent" ]; then
297 warn "$module: module not found for $kernel kernel"
299 if ! is_no "$EXIT_IF_MISSING"; then
302 warn "If $module isn't compiled in kernel then this initrd may not start your system."
306 # This works when user has module-init-tools installed even on 2.4 kernels
307 modprobe --set-version $kernel --show-depends $module | \
308 while read insmod modpath options; do
315 echo -n $(modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
322 if [ ${modName#-} != $modName ]; then
328 if [ "$modName" = "pluto" ]; then
332 if [ "$modName" = "fcal" ]; then
338 if [ "$skiperrors" = 1 ]; then
339 depmod=$(find_depmod $modName silent)
341 depmod=$(find_depmod $modName)
347 for mod in $depmod; do
348 mod=${mod#/lib/modules/$kernel/}
350 # add each module only once
352 for m in $MODULES; do
353 [ $m = $mod ] && have=1
355 if [ $have = 0 ]; then
356 MODULES="$MODULES $mod"
358 # if we are adding uvesafb, we need v86d as well
359 if [ "$modName" = "uvesafb" ]; then
366 # install a file to temporary mount image.
367 # it will operate recursively (copying directories)
368 # and will symlink destinations if source is symlink.
370 if [ $# -lt 2 ]; then
371 die 'Usage: inst <file> [<file>] <destination>'
374 local src i=0 c=$(($# - 1))
375 while [ $i -lt $c ]; do
382 parentDir=$(dirname $DESTDIR$dest)
383 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
384 debug "+ cp $* $DESTDIR$dest"
385 cp -HR "$@" "$DESTDIR$dest"
390 die 'Usage: inst_d <destination> <destination>'
393 install -d "$DESTDIR$dir"
397 # install executable and it's shared libraries
399 if [ $# -lt 2 ]; then
400 die 'Usage: inst_exec <file>[, <file>] <destination>'
402 local src i=0 c=$(($# - 1))
403 while [ $i -lt $c ]; do
413 local lib libs=$(ldd "$@" | awk '/statically|linux-gate\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
415 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
417 inst_exec $lib /$_lib
422 # output modules.conf / modprobe.conf
424 echo "$modprobe_conf_cache"
428 # defaults to modprobe -c if not told otherwise, this means include statements
430 cache_modprobe_conf() {
431 if [ "$pack_version" -lt "002005" ]; then
432 modulefile=/etc/modules.conf
433 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
434 modulefile=/etc/conf.modules
438 if [ -n "$modulefile" ]; then
439 debug "Using $modulefile for modules config"
440 modprobe_conf_cache=$(cat $modulefile)
442 debug "Using modprobe -c to get modules config"
443 modprobe_conf_cache=$(modprobe -c)
448 local found raidlevel
450 if [ -f /etc/mdadm.conf ]; then
451 debug "Finding RAID details using mdadm for rootdev=$1"
452 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
457 rootdev_devfs = rootdev;
458 if (rootdev ~ /\/dev\/md\/[0-9]/) {
459 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
464 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
466 gsub(/level=/,NUL,raidlevel);
467 if (raidlevel ~ /^raid([0-6]|10)/) {
468 gsub(/raid/,NUL,raidlevel);
472 if (x ~ /devices=/) {
474 gsub(".*devices=", NUL, dev_list);
475 gsub(",", " ", dev_list);
481 print "have_md=" found;
482 print "raidlevel=" raidlevel;
483 print "dev_list=\"" dev_list "\"";
487 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
488 die "raidtools are not longer supported. Please migrate to mdadm setup!"
491 if is_yes "$have_md"; then
494 findmodule "raid$raidlevel"
497 findmodule "-raid$raidlevel"
498 findmodule "-raid456"
504 warn "raid level $number (in mdadm config) not recognized"
508 die "RAID devices not found for \"$1\", check your configuration!"
511 rootdev_nr=$(( $rootdev_nr + 1 ))
512 eval "rootdev${rootdev_nr}=\"$1\""
513 eval "dev_list${rootdev_nr}=\"${dev_list}\""
515 for device in $dev_list; do
516 find_modules_for_devpath $device
520 find_modules_scsi() {
522 for n in $PRESCSIMODS; do
523 if [ "X$n" = "Xunknown" ]; then
524 debug "Finding SCSI modules using scsi_hostadapter"
525 local mod scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
526 for mod in $scsimodules; do
527 # for now allow scsi modules to come from anywhere. There are some
528 # RAID controllers with drivers in block
535 findmodule "-scsi_wait_scan"
540 # remove partition, if any
541 local disk=${devpath%[0-9]*}
542 # set blockdev for rootfs (hda, sdc, ...)
543 local rootblkdev=${disk#/dev/}
546 if [ "$pack_version_long" -lt "002004021" ]; then
547 debug "Finding IDE modules for kernels <= 2.4.20"
548 for n in $PREIDEMODSOLD; do
553 for n in $PREIDEMODS; do
554 if [ "X$n" = "Xunknown" ]; then
555 debug "Finding IDE modules using ide_hostadapter"
556 local mod idemodules=$(modprobe_conf | awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
557 for mod in $idemodules; do
562 if [ "$tryauto" -eq 1 ]; then
564 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
565 debug "Finding IDE modules using PCI ID database"
566 # Finding IDE modules using PCI ID database {{{
567 if is_yes "${ide_only_root}"; then
568 if [ -f /sys/block/${rootblkdev}/device/../../vendor -a -f /sys/block/${rootblkdev}/device/../../device ]; then
569 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../vendor)"
570 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../device)"
571 searchpciid="${vendorid}${deviceid}"
572 elif [ -f /proc/ide/${rootblkdev}/../config ]; then
573 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootblkdev}/../config)"
577 if [ -z "${searchpciid}" ]; then
578 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
583 for nb in $searchpciid; do
584 eval `awk -v pciid="$nb" '{
590 compmod = $1 ""; # make sure comparison type will be string
591 # cause pci IDs are hexadecimal numeric
592 if (compmod == pciid) {
594 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
601 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
602 }' /usr/share/pci-database/ide.pci`
603 [ -n "$module" ] && idemodules="$idemodules $module"
605 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
607 for nc in idemodules; do
608 new_idemodules="$nc $new_idemodules"
610 idemodules="${new_idemodules}"
613 if [ -z "$idemodules" ]; then
614 warn "rootfs on IDE device but no related modules found, loading ide-generic."
615 idemodules="ide-generic"
619 for nd in $idemodules; do
625 [ -r /usr/share/pci-database/ide.pci ] || warn "/usr/share/pci-database/ide.pci missing."
626 [ -r /proc/bus/pci/devices ] || warn "/proc/bus/pci/devices missing."
627 warn "Automatic IDE modules finding not available."
638 # return true if node is lvm node
641 if [ ! -e "$node" ]; then
642 warn "check_lvm(): node $node doesn't exist!"
646 # block-major-58 is lvm1
647 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
651 debug "LVM check: $node is LVM v1 node"
656 if [ ! -x /sbin/lvm ]; then
657 debug "LVM check: no lvm2 tools present to check"
661 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
663 if [ $rc -gt 127 ]; then
664 # lvdisplay terminated by signal! most likely it segfaulted.
665 die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
669 debug "LVM check: $node is LVM v2 node"
671 debug "LVM check: $node is not any LVM node"
676 # return dependencies MAJOR:MINOR [MAJOR:MINOR] for DM_NAME
677 # TODO: patch `dmsetup export`
680 dmsetup deps $dm_name | sed -e 's/, /:/g;s/^.\+ dependencies[^:]: //;s/[()]//g;'
683 # export info from dmsetup
687 # - /dev/mapper/DM_NAME
693 local maj=${arg%:*} min=${arg#*:}
694 dmsetup -j $maj -m $min export
697 local min=${arg#*dm-}
698 local maj=$(awk '$2 == "device-mapper" {print $1}' /proc/devices)
702 local dm_name=${arg#/dev/mapper/}
703 dmsetup export $dm_name
706 die "dm_export: unexpected $arg"
711 # find dm-multipath modules for $devpath
712 # returns false if $devpath is not dm-multipath
713 find_modules_multipath() {
717 eval $(dm_export "$devpath")
718 if [ -z "$DM_NAME" ]; then
719 die "dm_export failed unexpectedly"
724 # DM_UUID=part1-mpath-36006016002c11800a0aa05fbfae0db11
727 # DM_UUID=mpath-36006016002c11800a0aa05fbfae0db11
728 MPATH_WWID=${DM_UUID##*-}
730 local info=$(multipath -l $MPATH_WWID)
731 if [ -z "$info" ]; then
735 debug "Finding modules for dm-multipath (WWID=$MPATH_WWID)"
737 local dev phydevs=$(echo "$info" | awk '$2 ~ /^[0-9]+:[0-9]+:[0-9]+:[0-9]+$/{printf("/dev/%s\n", $3)}')
738 for dev in $phydevs; do
739 find_modules_for_devpath $dev
740 lvm_ignore_devices="$lvm_ignore_devices $dev"
743 local hw hwhandlers=$(echo "$info" | awk '/hwhandler=1/{sub(/.*hwhandler=1 /, ""); sub(/\]$/, ""); print}')
744 for hw in $hwhandlers; do
748 local target targets=$(echo "$info" | awk '/prio=/{print $2}' | sort -u)
749 for target in $targets; do
750 findmodule "dm-$target"
757 # find dmraid modules for $devpath
758 # returns false if $devpath is not on dmraid
759 find_modules_dmraid() {
762 # get blockdev itself (without partition)
763 # /dev/mapper/sil_ahbgadcbchfc3 -> /dev/mapper/sil_ahbgadcbchfc
764 local blockdev=${devpath%%[0-9]*}
765 local raidname=${blockdev#/dev/mapper/}
768 local dev phydevs=$(dmraid -r -cdevpath,raidname | awk -F, -vv="$raidname" '{if ($2 == v) print $1}')
769 for dev in $phydevs; do
770 find_modules_for_devpath $dev
771 lvm_ignore_devices="$lvm_ignore_devices $dev"
775 if [ $found = 0 ]; then
779 findmodule "dm-mirror"
784 # find modules for $devpath
785 find_modules_for_devpath() {
787 if [ -z "$devpath" ]; then
788 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
791 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
794 devpath=$(dm_longname "$devpath")
797 debug "Finding modules for device path $devpath"
799 if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
800 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
801 die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
803 if [ ! -f /proc/bus/pci/devices ]; then
804 warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:"
805 warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\""
808 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
809 warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
810 for m in $NFS_ETH_MODULES; do
817 warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
818 warn "or you will have problems like init(xx) being child process of swapper(1)."
822 if [[ "$devpath" == /dev/md* ]]; then
823 find_modules_md "$devpath"
827 if is_yes "$USE_MULTIPATH" && [[ "$devpath" == /dev/mapper/* ]]; then
828 if find_modules_multipath "$devpath"; then
834 if is_yes "$USE_DMRAID" && is_yes "$(echo "$devpath" | awk '/^\/dev\/mapper\/(sil|hpt37x|hpt45x|isw|lsi|nvidia|pdc|sil|via|dos)_/ { print "yes"; }')"; then
835 if find_modules_dmraid "$devpath"; then
841 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
846 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }')"; then
847 find_modules_ide "$devpath"
851 if [[ "$devpath" == /dev/rd/* ]]; then
853 rootdev_add="/dev/rd/"
857 if [[ "$devpath" == /dev/ida/* ]]; then
858 findmodule "cpqarray"
859 rootdev_add="/dev/ida/"
863 if [[ "$devpath" == /dev/cciss/* ]]; then
865 rootdev_add="/dev/cciss/"
869 if [[ "$devpath" == /dev/ataraid/* ]]; then
872 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
873 if [ -n "$ataraidmodules" ]; then
874 # FIXME: think about modules compiled in kernel
875 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
877 for n in $ataraidmodules; do
880 rootdev_add="/dev/ataraid/"
884 # check to see if we need to set up a loopback filesystem
885 if [[ "$devpath" == /dev/loop* ]]; then
886 die "Sorry, root on loop device isn't supported."
887 # TODO: rewrite for bsp and make nfs ready
888 if [ ! -x /sbin/losetup ]; then
889 die "losetup is missing"
891 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
892 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
893 die "The root filesystem is on a $devpath, but there is no magic entry in $fstab for this device. Consult the $PROGRAM man page for more information"
896 line="`awk '/'$key'/ { print $0; }' $fstab`"
897 loopDev="$(echo $line | awk '{print $3}')"
898 loopFs="$(echo $line | awk '{print $4}')"
899 loopFile="$(echo $line | awk '{print $5}')"
901 BASICMODULES="$BASICMODULES -loop"
902 findmodule "-$loopFs"
903 BASICMODULES="$BASICMODULES -${loopFs}"
907 if is_lvm_node "$devpath"; then
910 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then
911 die "root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found. Please install lvm(2) and lvm(2)-initrd package and rerun $PROGRAM."
913 if [ -z "$LVMTOOLSVERSION" ]; then
914 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}')
915 if [ -z "$LVMTOOLSVERSION" ]; then
916 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
920 local vg=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
921 VGVOLUMES=$(echo $VGVOLUMES $vg | tr ' ' '\n' | sort -u)
922 local pv=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$vg" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
923 PVDEVICES=$(echo $PVDEVICES $pv | tr ' ' '\n' | sort -u)
925 if [ -n "$PVDEVICES" ]; then
926 for device in $PVDEVICES; do
927 find_modules_for_devpath $device
930 die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
932 if [ "$LVMTOOLSVERSION" = "2" ]; then
934 elif [ "$LVMTOOLSVERSION" = "1" ]; then
936 findmodule "-lvm-mod"
938 die "LVM version $LVMTOOLSVERSION is not supported yet."
940 debug "LVM v$LVMTOOLSVERSION enabled"
946 firmware_install_module() {
948 local firmware_files="$2"
950 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
951 # firmware not yet installed
952 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
954 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
956 echo 1 > /sys$DEVPATH/loading
957 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
958 echo 0 > /sys$DEVPATH/loading
961 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
964 for firmware in $firmware_files; do
965 if [ ! -f "/lib/firmware/$firmware" ]; then
966 die "firmware file /lib/firmware/$firmware doesn't exist."
968 FIRMWAREDIR=${firmware%/*}
969 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
970 inst /lib/firmware/$firmware /lib/firmware/$firmware
975 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
982 for mod in $modules; do
984 inst_d "/lib/modules/$kernel/$MODULEDIR"
985 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
986 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
990 modules_add_linuxrc() {
994 # module path without optional compression
998 module=${modpath##*/}
999 module=${module%$modext}
1001 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
1003 generic_module=$(echo $module | tr - _)
1004 sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
1005 firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
1007 if [ -n "$verbose" ]; then
1009 if [ "$options" ]; then
1010 s="$s with options [$options]"
1012 if [ "$sleep_var" ]; then
1013 s="$s and $sleep_var usleep"
1015 debug "Loading module [$module]$s"
1018 if [ -n "$firmware_var" ]; then
1019 firmware_install_module "$module" "$firmware_var"
1021 firmware_files=$(find_firmware "$module")
1022 if [ -n "$firmware_files" ]; then
1023 for file in $firmware_files; do
1024 firmware_install_module "$module" "$file"
1029 echo "$insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
1030 if [ -n "$sleep_var" ]; then
1031 echo "usleep $sleep_var" | add_linuxrc
1036 find_modules_suspend() {
1037 if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then
1038 die "/usr/${_lib}/suspend/resume is missing!"
1040 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
1042 local vgvolumes=$VGVOLUMES
1043 find_modules_for_devpath $resume_dev
1045 if [ "$VGVOLUMES" != "$vgvolumes" ]; then
1046 # save our VG to be able to differenciate between rootfs VG
1047 SUSPENDVG=$VGVOLUMES
1048 VGVOLUMES=$vgvolumes
1049 debug "suspend device is on LVM"
1053 initrd_gen_suspend() {
1054 mknod $DESTDIR/dev/snapshot c 10 231
1055 mkdir -p $DESTDIR${resume_dev%/*}
1056 inst $resume_dev $resume_dev
1058 inst /etc/suspend.conf /etc/suspend.conf
1059 if [ -x /usr/${_lib}/suspend/resume ]; then
1060 inst /usr/${_lib}/suspend/resume /bin/resume
1062 inst /usr/sbin/resume /bin/resume
1065 add_linuxrc <<-'EOF'
1067 for arg in $CMDLINE; do
1068 if [ "${arg##resume=}" != "${arg}" ]; then
1072 if [ "$resume" = "yes" ]; then
1078 initrd_gen_tuxonice() {
1080 add_linuxrc <<-'EOF'
1082 for arg in $CMDLINE; do
1083 if [ "${arg##resume=}" != "${arg}" -o "${arg##resume2=}" != "${arg}" ]; then
1087 if [ "$resume" = "yes" ]; then
1088 [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
1089 [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
1090 [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
1096 debug "initrd_gen_v86d"
1097 mknod $DESTDIR/dev/mem c 1 1
1098 mknod $DESTDIR/dev/tty1 c 4 1
1100 inst_exec /sbin/v86d /sbin
1104 debug "Setting up udev..."
1105 inst_d /sbin /etc/udev
1107 if [ ! -x /sbin/initrd-udevd ]; then
1108 die "/sbin/initrd-udevd not present"
1111 inst /sbin/initrd-udevd /sbin/udevd
1112 inst /etc/udev/udev.conf /etc/udev/udev.conf
1116 add_linuxrc <<-'EOF'
1118 /sbin/udevd --daemon
1121 inst /sbin/initrd-udevadm /sbin/udevadm
1122 ln -s udevadm $DESTDIR/sbin/udevsettle
1123 ln -s udevadm $DESTDIR/sbin/udevtrigger
1124 add_linuxrc <<-'EOF'
1129 busybox_applet killall
1130 add_linuxrc <<-'EOF'
1135 initrd_gen_multipath() {
1136 inst_d /sbin /lib/udev /etc/multipath
1137 inst_exec /sbin/kpartx /sbin
1138 inst_exec /sbin/multipath /sbin
1140 inst_exec /sbin/scsi_id /lib/udev
1141 inst_exec /sbin/mpath* /sbin
1142 egrep -v '^([ ]*$|#)' /etc/multipath.conf > $DESTDIR/etc/multipath.conf
1144 if [ -f /etc/multipath/bindings ]; then
1145 egrep -v '^([ ]*$|#)' /etc/multipath/bindings > $DESTDIR/etc/multipath/bindings
1147 touch $DESTDIR/etc/multipath/bindings
1154 echo "export MPATH_WWID=$MPATH_WWID" | add_linuxrc
1155 add_linuxrc <<-'EOF'
1156 # parse mpath_wwid= from kernel commandline
1157 for arg in $CMDLINE; do
1158 if [ "${arg##mpath_wwid=}" != "${arg}" ]; then
1159 MPATH_WWID=${arg##mpath_wwid=}
1160 if [ "$MPATH_WWID" = "*" ]; then
1161 # '*' would mean activate all WWID-s
1163 echo "multipath: Activating all WWID-s"
1165 echo "multipath: Activating WWID=$WWID"
1171 /sbin/multipath -v 0 $MPATH_WWID
1173 for a in /dev/mapper/*; do
1174 [ $a = /dev/mapper/control ] && continue
1175 /sbin/kpartx -a -p p $a
1181 initrd_gen_dmraid() {
1182 if [ ! -x /sbin/dmraid-initrd ]; then
1183 die "/sbin/dmraid-initrd is missing!"
1187 inst /sbin/dmraid-initrd /sbin/dmraid
1193 # 2 secs was enough for my system to initialize. but really this is udev issue?
1195 : 'Activating Device-Mapper RAID(s)'
1202 initrd_gen_bootsplash() {
1205 debug "Generating bootsplash"
1207 if [ ! -x /bin/splash.bin ]; then
1208 warn "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
1212 if [ -r /etc/sysconfig/bootsplash ]; then
1213 . /etc/sysconfig/bootsplash
1216 if [ -z "$THEME" ]; then
1217 warn "Please configure your /etc/sysconfig/bootsplash first."
1218 warn "Generating bootsplashes skipped."
1222 if [ -z "$BOOT_SPLASH_RESOLUTIONS" ]; then
1223 warn "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
1224 warn "Not adding bootsplash to initrd."
1227 for res in $BOOT_SPLASH_RESOLUTIONS; do
1228 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1229 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1230 debug "Added $res $THEME theme to initrd."
1232 warn "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
1237 initrd_gen_fbsplash() {
1238 debug "Generating fbsplash"
1240 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
1241 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
1244 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
1245 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1247 if [ -r /etc/sysconfig/fbsplash ]; then
1248 . /etc/sysconfig/fbsplash
1251 if [ -z "$SPLASH_THEME" ]; then
1252 warn "Please configure your /etc/sysconfig/fbsplash first."
1253 warn "Generating fbsplashes skipped."
1257 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1258 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
1259 warn "Not adding fbsplash to initramfs."
1263 for res in $FB_SPLASH_RESOLUTIONS; do
1264 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1265 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1266 debug "Added $res $SPLASH_THEME theme to initramfs."
1268 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1273 initrd_gen_fbcondecor() {
1274 debug "Generating fbcondecor"
1276 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
1277 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
1280 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
1281 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1283 if [ -r /etc/sysconfig/splash ]; then
1284 . /etc/sysconfig/splash
1287 if [ -z "$SPLASH_THEME" ]; then
1288 warn "Please configure your /etc/sysconfig/splash first."
1289 warn "Generating of splashes skipped."
1293 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1294 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/splash."
1295 warn "Not adding fbcondecor to initramfs."
1299 for res in $FB_SPLASH_RESOLUTIONS; do
1300 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1301 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1302 debug "Added $res $SPLASH_THEME theme to initramfs."
1304 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1309 # Generates /dev nodes based on /proc/partitions information.
1310 # Needs /proc mounted.
1311 # Can be called multiple times.
1312 initrd_gen_devices() {
1313 if is_yes "$proc_partitions"; then
1319 add_linuxrc <<-'EOF'
1320 : 'Making device nodes'
1321 cat /proc/partitions | (
1322 # ignore first two lines: header, empty line
1325 while read major minor blocks dev rest; do
1328 [ -e $node ] || mknod $node b $major $minor
1335 debug "Setting up mdadm..."
1337 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1338 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
1341 inst /sbin/initrd-mdassemble /bin/mdassemble
1344 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
1345 if [ "$dev_list_extra" = "partitions" ]; then
1346 # FIXME: handle this case (see man mdadm.conf)
1347 echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
1350 for ex_dev in $dev_list_extra; do
1351 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
1355 for nr in `seq 1 $rootdev_nr`; do
1356 eval cr_rootdev="\$rootdev${nr}"
1357 eval cr_dev_list="\$dev_list${nr}"
1358 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1360 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1362 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
1363 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1364 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
1365 if [ -n "$cr_md_conf" ]; then
1366 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
1368 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
1371 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1372 # mkdir in case of devfs name
1373 inst_d $(dirname $f)
1374 [ -e "$DESTDIR/$f" ] && continue
1375 # this works fine with and without devfs
1380 echo "mdassemble" | add_linuxrc
1382 # needed to determine md-version
1383 if [ "$do_md0" -eq 1 ]; then
1384 mknod $DESTDIR/dev/md0 b 9 0
1389 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1390 # have problems like init(XX) being child process of swapper(1).
1391 debug "Adding rootfs on NFS support to initrd (dhcp)"
1392 mknod "$DESTDIR/dev/urandom" c 1 9
1393 mkdir "$DESTDIR/newroot"
1394 add_linuxrc <<-'EOF'
1395 ifconfig lo 127.0.0.1 up
1396 route add -net 127.0.0.0 mask 255.0.0.0 lo
1398 udhcpc -i eth0 -f -q -s /bin/setdhcp
1402 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1403 exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1406 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
1408 [ "$1" != "bound" ] && exit
1409 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1410 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1411 ifconfig $interface $ip $BROADCAST $NETMASK up
1412 if [ -n "$router" ]; then
1413 for r in $router; do
1414 route add default gw $r dev $interface
1418 for o in $CMDLINE; do
1421 rootpath=${o#nfsroot=}
1426 if [ -n "$rootpath" ]; then
1427 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1429 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1430 echo "All seen variables are listed below:"
1435 chmod 755 "$DESTDIR/bin/setdhcp"
1439 debug "Adding LVM support to initrd"
1440 inst_d /tmp /newroot
1441 inst /sbin/initrd-lvm /bin/lvm.static
1443 # always make /dev on tmpfs for LVM2
1444 if [ "$LVMTOOLSVERSION" = "2" ]; then
1448 if ! is_yes "$dev_mounted"; then
1450 mknod $DESTDIR/dev/mapper/control c 10 63
1451 for device in $PVDEVICES; do
1452 # if LVM on RAID then device might be copied already in gen_md
1453 [ -e "$DESTDIR/dev/$(basename $device)" ] && continue
1459 if [ "$LVMTOOLSVERSION" = "1" ]; then
1462 for vg in $VGVOLUMES; do
1463 lvm vgchange -T -a y $vg
1467 echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
1468 echo "global {" > "$DESTDIR/etc/lvm.conf"
1469 echo " locking_type = 0" >> "$DESTDIR/etc/lvm.conf"
1470 echo " locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf"
1471 echo "}" >> "$DESTDIR/etc/lvm.conf"
1472 echo "devices {" >> "$DESTDIR/etc/lvm.conf"
1473 echo " sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf"
1474 if is_yes "$have_md"; then
1475 echo " md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf"
1477 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
1478 echo ' types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf"
1480 if [ "$lvm_ignore_devices" ]; then
1481 # TODO: think of merging with lvm dumpconfig output
1482 echo ' filter = [' >> "$DESTDIR/etc/lvm.conf"
1484 for dev in $lvm_ignore_devices; do
1485 debug "LVM v2: ignore device $dev"
1486 printf ' "r|^%s.*|",\n' $dev
1487 done >> "$DESTDIR/etc/lvm.conf"
1488 echo ']' >> "$DESTDIR/etc/lvm.conf"
1490 # XXX filter= must be on one line!
1491 lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf"
1492 echo "}" >> "$DESTDIR/etc/lvm.conf"
1497 export ROOTDEV=$rootdev
1498 export ROOTVG="$VGVOLUMES"
1499 export SUSPENDVG=$SUSPENDVG
1501 add_linuxrc <<-'EOF'
1502 # parse rootdev from kernel commandline if it begins with /
1505 if [ "$ROOT" != "$ROOTDEV" ]; then
1507 echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
1508 local tmp=${ROOTDEV#/dev/}
1509 if [ "$tmp" != "$ROOTDEV" ]; then
1511 echo "LVM: Using Volume Group '$ROOTVG' for rootfs"
1518 if [ "$SUSPENDVG" = "$ROOTVG" ]; then
1519 export VGVOLUMES="$ROOTVG"
1521 export VGVOLUMES="$SUSPENDVG $ROOTVG"
1524 # disable noise from LVM accessing devices that aren't ready.
1525 read printk < /proc/sys/kernel/printk
1526 if [ ! "$DEBUGINITRD" ]; then
1527 echo 0 > /proc/sys/kernel/printk
1530 export LVM_SYSTEM_DIR=/tmp
1531 : 'Scanning for Volume Groups'
1532 lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null
1534 : 'Activating Volume Groups'
1535 for vol in $VGVOLUMES; do
1536 lvm.static vgchange --ignorelockingfailure -a y $vol 2>/dev/null
1539 echo "$printk" > /proc/sys/kernel/printk
1541 # Find out major/minor
1542 attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $ROOTDEV 2>/dev/null)"
1543 if [ "$attrs" ]; then
1544 majmin="${attrs#*$ROOTDEV*:*:*:*:*:*:*:*:*:*:*:*}"
1545 if [ "$majmin" != "$attrs" ]; then
1546 major="${majmin%:*}"
1547 minor="${majmin#*:}"
1551 if [ "$major" -a "$minor" ]; then
1553 echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev
1555 echo 2>&1 "Error figuring out real root device for $ROOTDEV!"
1556 echo 2>&1 "System will not most likely boot up! So dropping you to a shell!"
1566 debug "Adding BLKID support to initrd"
1567 inst /sbin/initrd-blkid /bin/blkid
1569 add_linuxrc <<-'EOF'
1570 # if built with blkid change ROOT=LABEL=something into ROOT=/dev/somethingelse -
1572 if [ "${ROOT##LABEL=}" != "${ROOT}" -o "${ROOT##UUID=}" != "${ROOT}" ]; then
1573 ROOT="$(/bin/blkid -t $ROOT -o device -l)"
1578 initrd_gen_setrootdev() {
1579 debug "Adding rootfs finding based on kernel cmdline root= option support."
1580 add_linuxrc <<-'EOF'
1581 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
1582 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
1583 if [ -n "$rootnr" ]; then
1584 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1591 if [ "$(id -u)" != 0 ]; then
1592 die "You need to be root to generate initrd"
1595 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
1597 . /etc/udev/udev.conf
1600 if [ -x /sbin/dmraid-initrd ]; then
1604 if [ -x /sbin/multipath ]; then
1608 if [ -x /sbin/initrd-blkid ]; then
1612 if [ -r /etc/sysconfig/geninitrd ]; then
1613 . /etc/sysconfig/geninitrd
1616 if [ ! -x /bin/initrd-busybox ]; then
1617 die "/bin/initrd-busybox is missing!"
1620 # backwards compatible
1621 if [ "$USE_SUSPEND2" ]; then
1622 USE_TUXONICE=$USE_SUSPEND2
1623 warn "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
1626 while [ $# -gt 0 ]; do
1636 modulefile=${1#--modules-conf=}
1642 --use-raidstart|--with-raidstart)
1645 --without-raidstart)
1648 --use-insmod-static|--with-insmod-static)
1651 --without-insmod-static)
1657 --without-bootsplash)
1669 --without-fbcondecor)
1678 --with-suspend2 | --with-tuxonice)
1681 --without-suspend2 | --without-tuxonice)
1684 --lvmtoolsversion=|--lvmversion=)
1685 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
1686 LVMTOOLSVERSION=${1#--lvmversion=}
1688 --lvmtoolsversion|--lvmversion)
1701 --without-multipath)
1708 BASICMODULES="$BASICMODULES ${1#--with=}"
1711 BASICMODULES="$BASICMODULES $2"
1715 echo "$PROGRAM: version $VERSION"
1731 PREMODS="$PREMODS ${1#--preload=}"
1734 PREMODS="$PREMODS $2"
1738 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1742 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1747 INITRDFS=${1#--initrdfs=}
1760 if [ -z "$target" ]; then
1762 elif [ -z "$kernel" ]; then
1773 if [ -z "$target" -o -z "$kernel" ]; then
1777 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1778 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1781 pack_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1782 pack_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
1784 if [ -z "$INITRDFS" ]; then
1785 if [ -z "$FS" ]; then
1787 if [ "$pack_version" -ge "002005" ]; then
1788 INITRDFS="initramfs"
1793 warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
1798 if [ "$pack_version" -lt "002006" ]; then
1803 if [ "$pack_version" -ge "002005" ]; then
1808 if is_yes "$USEINSMODSTATIC"; then
1809 insmod="insmod.static"
1810 INSMOD="/sbin/insmod.static"
1811 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
1812 INSMOD="/sbin/insmod.static.modutils"
1814 if [ ! -f "$INSMOD" ]; then
1815 die "insmod.static requested but /sbin/insmod.static not found!"
1821 if [ ! -x /sbin/mke2fs ]; then
1822 die "/sbin/mke2fs is missing"
1826 if [ ! -x /sbin/genromfs ]; then
1827 die "/sbin/genromfs is missing"
1831 if [ ! -x /sbin/mkcramfs ]; then
1832 die "/sbin/mkcramfs is missing"
1836 if [ ! -x /bin/cpio ]; then
1837 die "/bin/cpio is missing"
1839 if [ ! -x /usr/bin/find ]; then
1840 die "/usr/bin/find is missing"
1844 die "Filesystem $INITRDFS on initrd is not supported"
1848 if [ -L "$target" ]; then
1849 target=$(readlink -f "$target")
1852 if [ -n "$img_vers" ]; then
1853 target="$target-$kernel"
1856 if [ -z "$force" -a -f "$target" ]; then
1857 die "$target already exists."
1860 if [ ! -d "/lib/modules/$kernel" ]; then
1861 die "/lib/modules/$kernel is not a directory."
1864 if [ "$INITRDFS" != "initramfs" ]; then
1865 if is_yes "$FB_SPLASH"; then
1866 warn "Using fbsplash requires INITRDFS=initramfs; skipping fbsplash generation"
1869 if is_yes "$FB_CON_DECOR"; then
1870 warn "Using fbcondecor requires INITRDFS=initramfs; skipping fbcondecor generation"
1875 if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
1876 warn "Tuxonice and mainline suspend are exclusive!"
1879 if is_yes "$FB_SPLASH" && is_yes "$BOOT_SPLASH"; then
1880 warn "bootsplash and fbsplash are exclusive!"
1883 if [ ! -f /proc/mounts ]; then
1884 warn "/proc filesystem not mounted, may cause wrong results or failure."
1887 if [ -d /usr/lib64 ]; then
1892 debug "Using libdir: $_lib"
1896 for n in $PREMODS; do
1900 if [ "$FBMODULE" ]; then
1901 findmodule "$FBMODULE"
1904 # allow forcing loading SCSI and/or IDE modules
1905 if is_yes "$ADDSCSI"; then
1909 if is_yes "$ADDIDE"; then
1913 if is_yes "$USE_SUSPEND"; then
1914 find_modules_suspend
1917 find_root "$fstab" || exit
1918 debug "Using $rootdev as device for rootfs"
1920 find_modules_for_devpath "$rootdev"
1921 [ -n "$rootdev_add" ] && find_modules_for_devpath "$rootdev_add"
1923 findmodule "-$rootFs"
1925 for n in $BASICMODULES; do
1929 if is_yes "$USE_TUXONICE"; then
1933 if is_yes "$FB_SPLASH"; then
1937 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1938 debug "No modules are needed -- not building initrd image."
1942 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
1943 RCFILE="$DESTDIR/linuxrc"
1945 chmod a+rx "$RCFILE"
1946 ln -s linuxrc $DESTDIR/init
1948 # create dirs that we really need
1949 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
1951 modules_install "$MODULES"
1953 # mknod'ing the devices instead of copying them works both with and
1955 mknod "$DESTDIR/dev/console" c 5 1
1956 mknod "$DESTDIR/dev/null" c 1 3
1957 mknod "$DESTDIR/dev/zero" c 1 5
1959 inst /bin/initrd-busybox /bin/initrd-busybox
1960 ln -s initrd-busybox $DESTDIR/bin/sh
1961 ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
1963 if is_yes "$USEINSMODSTATIC"; then
1964 inst "$INSMOD" /bin/insmod.static
1969 # initrd generated by:
1974 add_linuxrc <<-'EOF'
1975 read CMDLINE < /proc/cmdline; export CMDLINE
1977 for arg in $CMDLINE; do
1978 if [ "${arg}" = "debuginitrd" ]; then
1981 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1982 DEBUGINITRD=${arg##debuginitrd=}
1984 if [ "${arg##root=}" != "${arg}" ]; then
1989 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1990 if [ "$DEBUGINITRD" = "sh" ]; then
1993 if is_yes "$RUN_SULOGIN_ON_ERR"; then
1994 add_linuxrc <<-'EOF'
1995 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1998 add_linuxrc <<-'EOF'
2002 add_linuxrc <<-'EOF'
2010 if [ "$DEBUGINITRD" ]; then
2015 modules_add_linuxrc $MODULES
2017 # TODO: rewrite for busybox
2018 #if [ -n "$loopDev" ]; then
2019 # if [ ! -d /initrd ]; then
2023 # cp -a "$loopDev" "$DESTDIR/dev"
2024 # cp -a "$rootdev" "$DESTDIR/dev"
2025 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
2026 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
2027 # echo "echo Setting up loopback device $rootdev" >> $RCFILE
2028 # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
2031 if is_yes "$USE_UDEV"; then
2035 if is_yes "$USE_TUXONICE"; then
2039 if is_yes "$need_v86d"; then
2043 if is_yes "$have_dmraid"; then
2047 if is_yes "$have_multipath"; then
2048 initrd_gen_multipath
2051 if is_yes "$USE_BLKID"; then
2055 if is_yes "$have_nfs"; then
2057 elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
2059 if is_yes "$have_lvm"; then
2062 initrd_gen_setrootdev
2064 elif is_yes "$have_lvm"; then
2067 initrd_gen_setrootdev
2070 if is_yes "$USE_SUSPEND"; then
2074 # additional devs always needed
2075 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
2077 if [ "$INITRDFS" = "initramfs" ]; then
2079 if [ "$rootdev" = "/dev/nfs" ]; then
2080 echo "rootfs on NFS root=/dev/nfs"
2082 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
2084 # Parsing root parameter
2085 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
2086 add_linuxrc <<-'EOF'
2087 device=/dev/no_partition_found
2088 eval "$(busybox awk -v c="$ROOT" '
2090 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
2091 num_pattern = "[0-9a-f]" num_pattern_short;
2092 dev_pattern = "[hms][a-z][a-z]([0-9])+";
2093 partition = "no_partition_found";
2097 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
2098 if (c ~ "^" num_pattern "$") {
2099 maj = sprintf("%s",substr(c,1,2));
2100 min = sprintf("%s",substr(c,3));
2102 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
2103 if (c ~ "^" dev_pattern "$") partition = c;
2106 $4 ~ partition { maj = $1; min = $2; }
2107 $1 ~ maj && $2 ~ min { partition = $4; }
2110 print sprintf("device=/dev/%s\nmaj=%s\nmin=%s",
2111 partition, maj, min);
2113 ' /proc/partitions)"
2114 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
2115 mknod $device b $maj $min
2124 add_linuxrc <<-'EOF'
2125 if [ "$device" = '/dev/no_partition_found' ]; then
2129 mount -t $rootfs -r $device /newroot
2130 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
2131 if [ -z "$init" -o ! -x "/newroot$init" ]; then
2137 busybox_applet switch_root
2138 add_linuxrc <<-'EOF'
2139 exec switch_root /newroot $init
2141 echo "Error! initramfs should not reach this place."
2142 echo "It probably means you've got old version of busybox, with broken"
2143 echo "initramfs support. Trying to boot anyway, but won't promise anything."
2145 exec chroot /newroot $init
2147 echo "Failed to chroot!"
2149 # we need /init being real file, not symlink, otherwise the initramfs will
2150 # not be ran by pid 1 which is required for switch_root
2151 mv $DESTDIR/linuxrc $DESTDIR/init
2152 ln -s init $DESTDIR/linuxrc
2154 # other than initramfs
2158 if is_yes "$FB_SPLASH"; then
2162 if is_yes "$FB_CON_DECOR"; then
2163 initrd_gen_fbcondecor
2166 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
2168 debug "Creating $INITRDFS image $IMAGE"
2171 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
2172 debug "ext2 image size: $IMAGESIZE ($DESTDIR)"
2173 if [ "$IMAGESIZE" -gt 4096 ]; then
2174 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
2177 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
2178 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
2179 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
2181 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
2182 debug "Mounting ext2 image $IMAGE to $tmpmnt"
2183 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
2184 # We don't need this directory, so let's save space
2185 rm -rf "$tmpmnt"/lost+found
2187 debug "Copy recursively $DESTDIR -> $tmpmnt"
2188 cp -a $DESTDIR/* $tmpmnt
2194 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
2195 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
2196 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
2197 if [ "$IMAGESIZE" -gt 4096 ]; then
2198 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
2202 mkcramfs "$DESTDIR" "$IMAGE"
2205 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
2208 echo "Filesystem $INITRDFS not supported by $PROGRAM";
2211 if is_yes "$COMPRESS"; then
2212 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
2213 debug "Compressing $target"
2214 gzip -9 < "$IMAGE" > "$tmp"
2215 mv -f "$tmp" "$target"
2217 cp -a "$IMAGE" "$target"
2220 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
2221 if is_yes "$BOOT_SPLASH"; then
2222 initrd_gen_bootsplash "$target"
2225 rm -rf "$DESTDIR" "$IMAGE"
2227 # vim:ts=4:sw=4:noet:fdm=marker