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
88 echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
89 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
90 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
91 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
92 echo " [--with-bootsplash] [--without-bootsplash]"
93 echo " [--with-fbsplash] [--without-fbsplash]"
94 echo " [--with-fbcondecor] [--without-fbcondecor]"
95 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
96 echo " [--with-suspend] [--without-suspend]"
97 echo " [--with-tuxonice] [--without-tuxonice]"
98 echo " [--without-dmraid] [--without-multipath]"
99 echo " [--without-blkid] [--without-luks]"
100 echo " <initrd-image> <kernel-version>"
103 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
112 msg "WARNING: $*" >&2
116 [ -n "$verbose" ] && msg "$*" >&2
119 # aborts program abnormally
126 # append text to /linuxrc
127 # takes STDIN as input
132 # generate code to mount /dev on tmpfs and create initial nodes
133 # can be called multiple times. /dev is cleaned up (umounted) automatically at
136 if [ "$INITRDFS" = "initramfs" ]; then
137 # initramfs is read-write filesystem, no need for tmpfs
141 # we already generated tmpfs code; return
142 if is_yes "$dev_mounted"; then
148 busybox_applet mount mknod mkdir
151 mount -o mode=0755 -t tmpfs none /dev
152 mknod /dev/console c 5 1
153 mknod /dev/null c 1 3
154 mknod /dev/zero c 1 5
160 # generate code to mount /proc on initrd
161 # can be called multiple times
163 if is_yes "$proc_mounted"; then
168 if [ "$INITRDFS" = "initramfs" ]; then
169 # /proc is mounted with initramfs 2.6.22.14 kernel
170 # XXX: remove when it is clear why proc was already mounted
171 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
173 echo "mount -t proc none /proc" | add_linuxrc
177 # generate code to mount /sys on initrd
178 # can be called multiple times
180 if is_yes "$sys_mounted"; then
185 echo "mount -t sysfs none /sys" | add_linuxrc
188 # generate code to mount /tmp on initrd
189 # can be called multiple times
191 if [ "$INITRDFS" = "initramfs" ]; then
192 # initramfs is read-write filesystem, no need for tmpfs
196 if is_yes "$tmp_mounted"; then
201 echo "mount -t tmpfs none /tmp" | add_linuxrc
204 # unmount all mountpoints mounted by geninitrd
208 : Last shell before umounting all and giving control over to real init.
212 if is_yes "$dev_mounted"; then
213 echo 'umount /dev' | add_linuxrc
216 if is_yes "$proc_mounted"; then
217 echo 'umount /proc' | add_linuxrc
220 if is_yes "$sys_mounted"; then
221 echo 'umount /sys' | add_linuxrc
224 if is_yes "$tmp_mounted"; then
225 echo 'umount /tmp' | add_linuxrc
231 # Checks if busybox has support for APPLET(s)
232 # Exits from geninitrd if the support is not present.
234 # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
238 if [ -z "$busybox_functions" ]; then
239 local tmp=$(/bin/initrd-busybox 2>&1)
241 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
242 if [[ "$tmp" = *applet\ not\ found* ]]; then
244 ln -s /bin/initrd-busybox $t/busybox
245 local tmp=$($t/busybox 2>&1)
249 busybox_functions=$(echo "$tmp" | \
250 sed -ne '/Currently defined functions:/,$p' | \
251 xargs | sed -e 's,.*Currently defined functions: ,,'
257 eval have='$'busybox_have_$applet
258 if [ -z "$have" ]; then
259 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
260 if [ "$have" = 0 ]; then
261 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
264 eval busybox_have_$applet=$have
267 if [ $err = 1 ]; then
272 # Finds module dependencies
275 # @param $mode [silent]
277 # Outputs each dependant module full path including the module itself.
282 # backwards compatible, process $mode
283 local modfile=$(modinfo -k $kernel -n $module 2>/dev/null)
284 if [ ! -f "$modfile" ]; then
285 # module not found. try aliases!
286 local alias aliases=$(modprobe_conf | awk -vm="$module" '$1 == "alias" && $2 == m { print $3 }')
287 if [ "$aliases" ]; then
288 for alias in $aliases; do
289 debug "Try $alias alias for $module"
295 if [ "$mode" != "silent" ]; then
296 warn "$module: module not found for $kernel kernel"
298 if ! is_no "$EXIT_IF_MISSING"; then
301 warn "If $module isn't compiled in kernel then this initrd may not start your system."
305 # This works when user has module-init-tools installed even on 2.4 kernels
306 modprobe --set-version $kernel --show-depends $module | \
307 while read insmod modpath options; do
314 echo -n $(modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
321 if [ ${modName#-} != $modName ]; then
327 if [ "$modName" = "pluto" ]; then
331 if [ "$modName" = "fcal" ]; then
337 if [ "$skiperrors" = 1 ]; then
338 depmod=$(find_depmod $modName silent)
340 depmod=$(find_depmod $modName)
346 for mod in $depmod; do
347 mod=${mod#/lib/modules/$kernel/}
349 # add each module only once
351 for m in $MODULES; do
352 [ $m = $mod ] && have=1
354 if [ $have = 0 ]; then
355 MODULES="$MODULES $mod"
357 # if we are adding uvesafb, we need v86d as well
358 if [ "$modName" = "uvesafb" ]; then
365 # install a file to temporary mount image.
366 # it will operate recursively (copying directories)
367 # and will symlink destinations if source is symlink.
369 if [ $# -lt 2 ]; then
370 die 'Usage: inst <file> [<file>] <destination>'
373 local src i=0 c=$(($# - 1))
374 while [ $i -lt $c ]; do
381 parentDir=$(dirname $DESTDIR$dest)
382 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
383 debug "+ cp $* $DESTDIR$dest"
384 cp -HR "$@" "$DESTDIR$dest"
389 die 'Usage: inst_d <destination> <destination>'
392 install -d "$DESTDIR$dir"
396 # install executable and it's shared libraries
398 if [ $# -lt 2 ]; then
399 die 'Usage: inst_exec <file>[, <file>] <destination>'
401 local src i=0 c=$(($# - 1))
402 while [ $i -lt $c ]; do
412 local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
414 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
416 inst_exec $lib /$_lib
420 # hack for uclibc linked binaries requiring this fixed path
421 # XXX: shouldn't rpath be used here instead so th
422 if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
423 local lib=$DESTDIR/$_lib/libc.so.0
424 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
425 local libdir=$(cd $(dirname "$lib"); pwd)
426 if [ ! -e $DESTDIR$libdir ]; then
427 libdir=$(dirname "$libdir")
429 debug "+ ln -s /$_lib $DESTDIR$libdir"
430 ln -s /$_lib $DESTDIR$libdir
435 # output modules.conf / modprobe.conf
437 echo "$modprobe_conf_cache"
441 # defaults to modprobe -c if not told otherwise, this means include statements
443 cache_modprobe_conf() {
444 if [ "$pack_version" -lt "002005" ]; then
445 modulefile=/etc/modules.conf
446 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
447 modulefile=/etc/conf.modules
451 if [ -n "$modulefile" ]; then
452 debug "Using $modulefile for modules config"
453 modprobe_conf_cache=$(cat $modulefile)
455 debug "Using modprobe -c to get modules config"
456 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
461 local found raidlevel
463 if [ -f /etc/mdadm.conf ]; then
464 debug "Finding RAID details using mdadm for rootdev=$1"
465 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
470 rootdev_devfs = rootdev;
471 if (rootdev ~ /\/dev\/md\/[0-9]/) {
472 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
477 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
479 gsub(/level=/,NUL,raidlevel);
480 if (raidlevel ~ /^raid([0-6]|10)/) {
481 gsub(/raid/,NUL,raidlevel);
485 if (x ~ /devices=/) {
487 gsub(".*devices=", NUL, dev_list);
488 gsub(",", " ", dev_list);
494 print "have_md=" found;
495 print "raidlevel=" raidlevel;
496 print "dev_list=\"" dev_list "\"";
500 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
501 die "raidtools are not longer supported. Please migrate to mdadm setup!"
504 if is_yes "$have_md"; then
507 findmodule "raid$raidlevel"
510 findmodule "-raid$raidlevel"
511 findmodule "-raid456"
517 warn "raid level $number (in mdadm config) not recognized"
521 die "RAID devices not found for \"$1\", check your configuration!"
524 rootdev_nr=$(( $rootdev_nr + 1 ))
525 eval "rootdev${rootdev_nr}=\"$1\""
526 eval "dev_list${rootdev_nr}=\"${dev_list}\""
528 for device in $dev_list; do
529 find_modules_for_devpath $device
533 find_modules_scsi() {
535 for n in $PRESCSIMODS; do
536 if [ "X$n" = "Xunknown" ]; then
537 debug "Finding SCSI modules using scsi_hostadapter"
538 local mod scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
539 for mod in $scsimodules; do
540 # for now allow scsi modules to come from anywhere. There are some
541 # RAID controllers with drivers in block
548 findmodule "-scsi_wait_scan"
553 # remove partition, if any
554 local disk=${devpath%[0-9]*}
555 # set blockdev for rootfs (hda, sdc, ...)
556 local rootblkdev=${disk#/dev/}
559 if [ "$pack_version_long" -lt "002004021" ]; then
560 debug "Finding IDE modules for kernels <= 2.4.20"
561 for n in $PREIDEMODSOLD; do
566 for n in $PREIDEMODS; do
567 if [ "X$n" = "Xunknown" ]; then
568 debug "Finding IDE modules using ide_hostadapter"
569 local mod idemodules=$(modprobe_conf | awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
570 for mod in $idemodules; do
575 if [ "$tryauto" -eq 1 ]; then
577 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
578 debug "Finding IDE modules using PCI ID database"
579 # Finding IDE modules using PCI ID database {{{
580 if is_yes "${ide_only_root}"; then
581 if [ -f /sys/block/${rootblkdev}/device/../../vendor -a -f /sys/block/${rootblkdev}/device/../../device ]; then
582 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../vendor)"
583 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../device)"
584 searchpciid="${vendorid}${deviceid}"
585 elif [ -f /proc/ide/${rootblkdev}/../config ]; then
586 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootblkdev}/../config)"
590 if [ -z "${searchpciid}" ]; then
591 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
596 for nb in $searchpciid; do
597 eval `awk -v pciid="$nb" '{
603 compmod = $1 ""; # make sure comparison type will be string
604 # cause pci IDs are hexadecimal numeric
605 if (compmod == pciid) {
607 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
614 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
615 }' /usr/share/pci-database/ide.pci`
616 [ -n "$module" ] && idemodules="$idemodules $module"
618 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
620 for nc in idemodules; do
621 new_idemodules="$nc $new_idemodules"
623 idemodules="${new_idemodules}"
626 if [ -z "$idemodules" ]; then
627 warn "rootfs on IDE device but no related modules found, loading ide-generic."
628 idemodules="ide-generic"
632 for nd in $idemodules; do
638 [ -r /usr/share/pci-database/ide.pci ] || warn "/usr/share/pci-database/ide.pci missing."
639 [ -r /proc/bus/pci/devices ] || warn "/proc/bus/pci/devices missing."
640 warn "Automatic IDE modules finding not available."
651 # return true if node is lvm node
654 if [ ! -e "$node" ]; then
655 warn "check_lvm(): node $node doesn't exist!"
659 # block-major-58 is lvm1
660 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
664 debug "LVM check: $node is LVM v1 node"
669 if [ ! -x /sbin/lvm ]; then
670 debug "LVM check: no lvm2 tools present to check"
674 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
676 if [ $rc -gt 127 ]; then
677 # lvdisplay terminated by signal! most likely it segfaulted.
678 die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
682 debug "LVM check: $node is LVM v2 node"
684 debug "LVM check: $node is not any LVM node"
690 # return dependencies MAJOR:MINOR [MAJOR:MINOR] for DM_NAME
691 # TODO: patch `dmsetup export`
694 dmsetup deps $dm_name | sed -e 's/, /:/g;s/^.\+ dependencies[^:]: //;s/[()]//g;'
697 # export info from dmsetup
701 # - /dev/mapper/DM_NAME
707 local maj=${arg%:*} min=${arg#*:}
708 dmsetup -j $maj -m $min export
711 local min=${arg#*dm-}
712 local maj=$(awk '$2 == "device-mapper" {print $1}' /proc/devices)
716 local dm_name=${arg#/dev/mapper/}
717 dmsetup export $dm_name
720 die "dm_export: unexpected $arg"
725 # find modules for $devpath
726 find_modules_for_devpath() {
728 if [ -z "$devpath" ]; then
729 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
732 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
735 devpath=$(dm_longname "$devpath")
738 debug "Finding modules for device path $devpath"
740 if is_luks "$devpath"; then
741 find_modules_luks "$devpath"
745 if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
746 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
747 die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
749 if [ ! -f /proc/bus/pci/devices ]; then
750 warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:"
751 warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\""
754 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
755 warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
756 for m in $NFS_ETH_MODULES; do
763 warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
764 warn "or you will have problems like init(xx) being child process of swapper(1)."
768 if [[ "$devpath" == /dev/md* ]]; then
769 find_modules_md "$devpath"
773 if is_multipath "$devpath"; then
774 if find_modules_multipath "$devpath"; then
780 if is_dmraid "$devpath"; then
781 if find_modules_dmraid "$devpath"; then
787 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
792 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(hd[a-l]|ide\/)/ { print "yes"; }')"; then
793 find_modules_ide "$devpath"
797 if [[ "$devpath" == /dev/rd/* ]]; then
799 rootdev_add="/dev/rd/"
803 if [[ "$devpath" == /dev/ida/* ]]; then
804 findmodule "cpqarray"
805 rootdev_add="/dev/ida/"
809 if [[ "$devpath" == /dev/cciss/* ]]; then
811 rootdev_add="/dev/cciss/"
815 if [[ "$devpath" == /dev/ataraid/* ]]; then
818 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
819 if [ -n "$ataraidmodules" ]; then
820 # FIXME: think about modules compiled in kernel
821 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
823 for n in $ataraidmodules; do
826 rootdev_add="/dev/ataraid/"
830 # check to see if we need to set up a loopback filesystem
831 if [[ "$devpath" == /dev/loop* ]]; then
832 die "Sorry, root on loop device isn't supported."
833 # TODO: rewrite for bsp and make nfs ready
834 if [ ! -x /sbin/losetup ]; then
835 die "losetup is missing"
837 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
838 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
839 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"
842 line="`awk '/'$key'/ { print $0; }' $fstab`"
843 loopDev="$(echo $line | awk '{print $3}')"
844 loopFs="$(echo $line | awk '{print $4}')"
845 loopFile="$(echo $line | awk '{print $5}')"
847 BASICMODULES="$BASICMODULES -loop"
848 findmodule "-$loopFs"
849 BASICMODULES="$BASICMODULES -${loopFs}"
853 if is_lvm_node "$devpath"; then
856 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then
857 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."
859 if [ -z "$LVMTOOLSVERSION" ]; then
860 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}')
861 if [ -z "$LVMTOOLSVERSION" ]; then
862 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
866 local vg=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
867 VGVOLUMES=$(echo $VGVOLUMES $vg | tr ' ' '\n' | sort -u)
868 local pv=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$vg" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
869 PVDEVICES=$(echo $PVDEVICES $pv | tr ' ' '\n' | sort -u)
871 if [ -n "$PVDEVICES" ]; then
872 for device in $PVDEVICES; do
873 find_modules_for_devpath $device
876 die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
878 if [ "$LVMTOOLSVERSION" = "2" ]; then
880 elif [ "$LVMTOOLSVERSION" = "1" ]; then
882 findmodule "-lvm-mod"
884 die "LVM version $LVMTOOLSVERSION is not supported yet."
886 debug "LVM v$LVMTOOLSVERSION enabled"
892 firmware_install_module() {
894 local firmware_files="$2"
896 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
897 # firmware not yet installed
898 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
900 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
902 echo 1 > /sys$DEVPATH/loading
903 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
904 echo 0 > /sys$DEVPATH/loading
907 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
910 for firmware in $firmware_files; do
911 if [ ! -f "/lib/firmware/$firmware" ]; then
912 die "firmware file /lib/firmware/$firmware doesn't exist."
914 FIRMWAREDIR=${firmware%/*}
915 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
916 inst /lib/firmware/$firmware /lib/firmware/$firmware
921 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
928 for mod in $modules; do
930 inst_d "/lib/modules/$kernel/$MODULEDIR"
931 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
932 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
936 modules_add_linuxrc() {
940 # module path without optional compression
944 module=${modpath##*/}
945 module=${module%$modext}
947 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
949 generic_module=$(echo $module | tr - _)
950 sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
951 firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
953 if [ -n "$verbose" ]; then
955 if [ "$options" ]; then
956 s="$s with options [$options]"
958 if [ "$sleep_var" ]; then
959 s="$s and $sleep_var usleep"
961 debug "Loading module [$module]$s"
964 if [ -n "$firmware_var" ]; then
965 firmware_install_module "$module" "$firmware_var"
967 firmware_files=$(find_firmware "$module")
968 if [ -n "$firmware_files" ]; then
969 for file in $firmware_files; do
970 firmware_install_module "$module" "$file"
975 echo "$insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
976 if [ -n "$sleep_var" ]; then
977 echo "usleep $sleep_var" | add_linuxrc
982 find_modules_suspend() {
983 if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then
984 die "/usr/${_lib}/suspend/resume is missing!"
986 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
988 local vgvolumes=$VGVOLUMES
989 find_modules_for_devpath $resume_dev
991 if [ "$VGVOLUMES" != "$vgvolumes" ]; then
992 # save our VG to be able to differenciate between rootfs VG
995 debug "suspend device is on LVM"
999 initrd_gen_suspend() {
1000 mknod $DESTDIR/dev/snapshot c 10 231
1001 mkdir -p $DESTDIR${resume_dev%/*}
1002 inst $resume_dev $resume_dev
1004 inst /etc/suspend.conf /etc/suspend.conf
1005 if [ -x /usr/${_lib}/suspend/resume ]; then
1006 inst_exec /usr/${_lib}/suspend/resume /bin/resume
1008 inst_exec /usr/sbin/resume /bin/resume
1011 add_linuxrc <<-'EOF'
1013 for arg in $CMDLINE; do
1014 if [ "${arg##resume=}" != "${arg}" ]; then
1018 if [ "$resume" = "yes" ]; then
1024 initrd_gen_tuxonice() {
1026 add_linuxrc <<-'EOF'
1028 for arg in $CMDLINE; do
1029 if [ "${arg##resume=}" != "${arg}" -o "${arg##resume2=}" != "${arg}" ]; then
1033 if [ "$resume" = "yes" ]; then
1034 [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
1035 [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
1036 [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
1042 debug "initrd_gen_v86d"
1043 mknod $DESTDIR/dev/mem c 1 1
1044 mknod $DESTDIR/dev/tty1 c 4 1
1046 inst_exec /sbin/v86d /sbin
1050 debug "Setting up udev..."
1051 inst_d /sbin /etc/udev
1053 if [ ! -x /sbin/initrd-udevd ]; then
1054 die "/sbin/initrd-udevd not present"
1057 inst_exec /sbin/initrd-udevd /sbin/udevd
1058 inst /etc/udev/udev.conf /etc/udev/udev.conf
1062 add_linuxrc <<-'EOF'
1064 /sbin/udevd --daemon
1067 inst_exec /sbin/initrd-udevadm /sbin/udevadm
1068 add_linuxrc <<-'EOF'
1069 /sbin/udevadm trigger
1070 /sbin/udevadm settle
1075 initrd_gen_stop_udevd() {
1076 busybox_applet killall
1077 add_linuxrc <<-'EOF'
1084 initrd_gen_bootsplash() {
1087 debug "Generating bootsplash"
1089 if [ ! -x /bin/splash.bin ]; then
1090 warn "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
1094 if [ -r /etc/sysconfig/bootsplash ]; then
1095 . /etc/sysconfig/bootsplash
1098 if [ -z "$THEME" ]; then
1099 warn "Please configure your /etc/sysconfig/bootsplash first."
1100 warn "Generating bootsplashes skipped."
1104 if [ -z "$BOOT_SPLASH_RESOLUTIONS" ]; then
1105 warn "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
1106 warn "Not adding bootsplash to initrd."
1109 for res in $BOOT_SPLASH_RESOLUTIONS; do
1110 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1111 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1112 debug "Added $res $THEME theme to initrd."
1114 warn "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
1119 initrd_gen_fbsplash() {
1120 debug "Generating fbsplash"
1122 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
1123 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
1126 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
1127 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1129 if [ -r /etc/sysconfig/fbsplash ]; then
1130 . /etc/sysconfig/fbsplash
1133 if [ -z "$SPLASH_THEME" ]; then
1134 warn "Please configure your /etc/sysconfig/fbsplash first."
1135 warn "Generating fbsplashes skipped."
1139 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1140 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
1141 warn "Not adding fbsplash to initramfs."
1145 for res in $FB_SPLASH_RESOLUTIONS; do
1146 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1147 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1148 debug "Added $res $SPLASH_THEME theme to initramfs."
1150 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1155 initrd_gen_fbcondecor() {
1156 debug "Generating fbcondecor"
1158 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
1159 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
1162 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
1163 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1165 if [ -r /etc/sysconfig/splash ]; then
1166 . /etc/sysconfig/splash
1169 if [ -z "$SPLASH_THEME" ]; then
1170 warn "Please configure your /etc/sysconfig/splash first."
1171 warn "Generating of splashes skipped."
1175 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1176 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/splash."
1177 warn "Not adding fbcondecor to initramfs."
1181 for res in $FB_SPLASH_RESOLUTIONS; do
1182 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1183 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1184 debug "Added $res $SPLASH_THEME theme to initramfs."
1186 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1191 # Generates /dev nodes based on /proc/partitions information.
1192 # Needs /proc mounted.
1193 # Can be called multiple times.
1194 initrd_gen_devices() {
1195 if is_yes "$proc_partitions"; then
1201 add_linuxrc <<-'EOF'
1202 : 'Making device nodes'
1203 cat /proc/partitions | (
1204 # ignore first two lines: header, empty line
1207 while read major minor blocks dev rest; do
1210 [ -e $node ] || mknod $node b $major $minor
1217 debug "Setting up mdadm..."
1219 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1220 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
1223 inst_exec /sbin/initrd-mdassemble /bin/mdassemble
1226 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
1227 if [ "$dev_list_extra" = "partitions" ]; then
1228 # FIXME: handle this case (see man mdadm.conf)
1229 echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
1232 for ex_dev in $dev_list_extra; do
1233 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
1237 for nr in `seq 1 $rootdev_nr`; do
1238 eval cr_rootdev="\$rootdev${nr}"
1239 eval cr_dev_list="\$dev_list${nr}"
1240 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1242 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1244 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
1245 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1246 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
1247 if [ -n "$cr_md_conf" ]; then
1248 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
1250 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
1253 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1254 # mkdir in case of devfs name
1255 inst_d $(dirname $f)
1256 [ -e "$DESTDIR/$f" ] && continue
1257 # this works fine with and without devfs
1262 echo "mdassemble" | add_linuxrc
1264 # needed to determine md-version
1265 if [ "$do_md0" -eq 1 ]; then
1266 mknod $DESTDIR/dev/md0 b 9 0
1271 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1272 # have problems like init(XX) being child process of swapper(1).
1273 debug "Adding rootfs on NFS support to initrd (dhcp)"
1274 mknod "$DESTDIR/dev/urandom" c 1 9
1275 mkdir "$DESTDIR/newroot"
1276 add_linuxrc <<-'EOF'
1277 ifconfig lo 127.0.0.1 up
1278 route add -net 127.0.0.0 mask 255.0.0.0 lo
1280 udhcpc -i eth0 -f -q -s /bin/setdhcp
1284 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1285 exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1288 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
1290 [ "$1" != "bound" ] && exit
1291 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1292 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1293 ifconfig $interface $ip $BROADCAST $NETMASK up
1294 if [ -n "$router" ]; then
1295 for r in $router; do
1296 route add default gw $r dev $interface
1300 for o in $CMDLINE; do
1303 rootpath=${o#nfsroot=}
1308 if [ -n "$rootpath" ]; then
1309 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1311 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1312 echo "All seen variables are listed below:"
1317 chmod 755 "$DESTDIR/bin/setdhcp"
1321 debug "Adding LVM support to initrd"
1322 inst_d /tmp /newroot
1323 inst_exec /sbin/initrd-lvm /bin/lvm.static
1325 # always make /dev on tmpfs for LVM2
1326 if [ "$LVMTOOLSVERSION" = "2" ]; then
1330 if ! is_yes "$dev_mounted"; then
1332 mknod $DESTDIR/dev/mapper/control c 10 63
1333 for device in $PVDEVICES; do
1334 # if LVM on RAID then device might be copied already in gen_md
1335 [ -e "$DESTDIR/dev/$(basename $device)" ] && continue
1341 if [ "$LVMTOOLSVERSION" = "1" ]; then
1344 for vg in $VGVOLUMES; do
1345 lvm vgchange -T -a y $vg
1349 echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
1350 echo "global {" > "$DESTDIR/etc/lvm.conf"
1351 echo " locking_type = 0" >> "$DESTDIR/etc/lvm.conf"
1352 echo " locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf"
1353 echo "}" >> "$DESTDIR/etc/lvm.conf"
1354 echo "devices {" >> "$DESTDIR/etc/lvm.conf"
1355 echo " sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf"
1356 if is_yes "$have_md"; then
1357 echo " md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf"
1359 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
1360 echo ' types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf"
1362 if [ "$lvm_ignore_devices" ]; then
1363 # TODO: think of merging with lvm dumpconfig output
1364 echo ' filter = [' >> "$DESTDIR/etc/lvm.conf"
1366 for dev in $lvm_ignore_devices; do
1367 debug "LVM v2: ignore device $dev"
1368 printf ' "r|^%s.*|",\n' $dev
1369 done >> "$DESTDIR/etc/lvm.conf"
1370 echo ']' >> "$DESTDIR/etc/lvm.conf"
1372 # XXX filter= must be on one line!
1373 lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf"
1374 echo "}" >> "$DESTDIR/etc/lvm.conf"
1379 export ROOTDEV=$rootdev
1380 export ROOTVG="$VGVOLUMES"
1381 export SUSPENDVG=$SUSPENDVG
1383 add_linuxrc <<-'EOF'
1384 # parse rootdev from kernel commandline if it begins with /
1387 if [ "$ROOT" != "$ROOTDEV" ]; then
1389 echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
1390 local tmp=${ROOTDEV#/dev/}
1391 if [ "$tmp" != "$ROOTDEV" ]; then
1393 echo "LVM: Using Volume Group '$ROOTVG' for rootfs"
1400 if [ "$SUSPENDVG" = "$ROOTVG" ]; then
1401 export VGVOLUMES="$ROOTVG"
1403 export VGVOLUMES="$SUSPENDVG $ROOTVG"
1406 # disable noise from LVM accessing devices that aren't ready.
1407 read printk < /proc/sys/kernel/printk
1408 if [ ! "$DEBUGINITRD" ]; then
1409 echo 0 > /proc/sys/kernel/printk
1412 export LVM_SYSTEM_DIR=/tmp
1413 : 'Scanning for Volume Groups'
1414 lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null
1416 : 'Activating Volume Groups'
1417 for vol in $VGVOLUMES; do
1418 lvm.static vgchange --ignorelockingfailure -a y $vol 2>/dev/null
1421 echo "$printk" > /proc/sys/kernel/printk
1423 # Find out major/minor
1424 attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $ROOTDEV 2>/dev/null)"
1425 if [ "$attrs" ]; then
1426 majmin="${attrs#*$ROOTDEV*:*:*:*:*:*:*:*:*:*:*:*}"
1427 if [ "$majmin" != "$attrs" ]; then
1428 major="${majmin%:*}"
1429 minor="${majmin#*:}"
1433 if [ "$major" -a "$minor" ]; then
1435 echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev
1437 echo 2>&1 "Error figuring out real root device for $ROOTDEV!"
1438 echo 2>&1 "System will not most likely boot up! So dropping you to a shell!"
1448 debug "Adding BLKID support to initrd"
1449 inst_exec /sbin/initrd-blkid /bin/blkid
1451 add_linuxrc <<-'EOF'
1452 # if built with blkid change ROOT=LABEL=something into ROOT=/dev/somethingelse -
1454 if [ "${ROOT##LABEL=}" != "${ROOT}" -o "${ROOT##UUID=}" != "${ROOT}" ]; then
1455 ROOT="$(/bin/blkid -t $ROOT -o device -l)"
1460 initrd_gen_setrootdev() {
1461 debug "Adding rootfs finding based on kernel cmdline root= option support."
1462 add_linuxrc <<-'EOF'
1463 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
1464 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
1465 if [ -n "$rootnr" ]; then
1466 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1472 initrd_gen_initramfs_switchroot() {
1474 if [ "$rootdev" = "/dev/nfs" ]; then
1475 echo "rootfs on NFS root=/dev/nfs"
1477 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
1480 # parse 'root=xxx' kernel commandline
1481 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
1482 add_linuxrc <<-'EOF'
1483 device=/dev/no_partition_found
1484 eval "$(busybox awk -v c="$ROOT" '
1486 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
1487 num_pattern = "[0-9a-f]" num_pattern_short;
1488 dev_pattern = "[hms][a-z][a-z]([0-9])+";
1489 partition = "no_partition_found";
1493 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
1494 if (c ~ "^" num_pattern "$") {
1495 maj = sprintf("%s",substr(c,1,2));
1496 min = sprintf("%s",substr(c,3));
1498 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
1499 if (c ~ "^" dev_pattern "$") partition = c;
1502 $4 ~ partition { maj = $1; min = $2; }
1503 $1 ~ maj && $2 ~ min { partition = $4; }
1506 printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
1508 ' /proc/partitions)"
1509 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
1510 mknod $device b $maj $min
1519 add_linuxrc <<-'EOF'
1520 if [ "$device" = '/dev/no_partition_found' ]; then
1524 mount -t $rootfs -r $device /newroot
1525 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
1526 if [ -z "$init" -o ! -x "/newroot$init" ]; then
1532 busybox_applet switch_root
1533 add_linuxrc <<-'EOF'
1534 exec switch_root /newroot $init
1536 echo "Error! initramfs should not reach this place."
1537 echo "It probably means you've got old version of busybox, with broken"
1538 echo "initramfs support. Trying to boot anyway, but won't promise anything."
1540 exec chroot /newroot $init
1542 echo "Failed to chroot!"
1544 # we need /init being real file, not symlink, otherwise the initramfs will
1545 # not be ran by pid 1 which is required for switch_root
1546 mv $DESTDIR/linuxrc $DESTDIR/init
1547 ln -s init $DESTDIR/linuxrc
1551 if [ "$(id -u)" != 0 ]; then
1552 die "You need to be root to generate initrd"
1555 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
1557 . /etc/udev/udev.conf
1560 # cryptsetup luks addon
1561 . /etc/geninitrd/mod-luks.sh
1562 # dm-multipath addon
1563 . /etc/geninitrd/mod-multipath.sh
1565 . /etc/geninitrd/mod-dmraid.sh
1567 if [ -x /sbin/initrd-blkid ]; then
1571 if [ -r /etc/sysconfig/geninitrd ]; then
1572 . /etc/sysconfig/geninitrd
1575 if [ ! -x /bin/initrd-busybox ]; then
1576 die "/bin/initrd-busybox is missing!"
1579 # backwards compatible
1580 if [ "$USE_SUSPEND2" ]; then
1581 USE_TUXONICE=$USE_SUSPEND2
1582 warn "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
1585 while [ $# -gt 0 ]; do
1595 modulefile=${1#--modules-conf=}
1601 --use-raidstart|--with-raidstart)
1604 --without-raidstart)
1607 --use-insmod-static|--with-insmod-static)
1610 --without-insmod-static)
1616 --without-bootsplash)
1628 --without-fbcondecor)
1637 --with-suspend2 | --with-tuxonice)
1640 --without-suspend2 | --without-tuxonice)
1644 LVMTOOLSVERSION=${1#--lvmversion=}
1646 --lvmtoolsversion=*)
1647 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
1649 --lvmtoolsversion|--lvmversion)
1662 --without-multipath)
1672 BASICMODULES="$BASICMODULES ${1#--with=}"
1675 BASICMODULES="$BASICMODULES $2"
1679 echo "$PROGRAM: version $VERSION"
1695 PREMODS="$PREMODS ${1#--preload=}"
1698 PREMODS="$PREMODS $2"
1702 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1706 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1711 INITRDFS=${1#--initrdfs=}
1724 if [ -z "$target" ]; then
1726 elif [ -z "$kernel" ]; then
1738 if [ -z "$target" -o -z "$kernel" ]; then
1743 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1744 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1747 pack_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1748 pack_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
1750 if [ -z "$INITRDFS" ]; then
1751 if [ -z "$FS" ]; then
1753 if [ "$pack_version" -ge "002005" ]; then
1754 INITRDFS="initramfs"
1759 warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
1764 if [ "$pack_version" -lt "002006" ]; then
1769 if [ "$pack_version" -ge "002005" ]; then
1774 if is_yes "$USEINSMODSTATIC"; then
1775 insmod="insmod.static"
1776 INSMOD="/sbin/insmod.static"
1777 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
1778 INSMOD="/sbin/insmod.static.modutils"
1780 if [ ! -f "$INSMOD" ]; then
1781 die "insmod.static requested but /sbin/insmod.static not found!"
1787 if [ ! -x /sbin/mke2fs ]; then
1788 die "/sbin/mke2fs is missing"
1792 if [ ! -x /sbin/genromfs ]; then
1793 die "/sbin/genromfs is missing"
1797 if [ ! -x /sbin/mkcramfs ]; then
1798 die "/sbin/mkcramfs is missing"
1802 if [ ! -x /bin/cpio ]; then
1803 die "/bin/cpio is missing"
1805 if [ ! -x /usr/bin/find ]; then
1806 die "/usr/bin/find is missing"
1810 die "Filesystem $INITRDFS on initrd is not supported"
1814 if [ -L "$target" ]; then
1815 target=$(readlink -f "$target")
1818 if [ -n "$img_vers" ]; then
1819 target="$target-$kernel"
1822 if [ -z "$force" -a -f "$target" ]; then
1823 die "$target already exists."
1826 if [ ! -d "/lib/modules/$kernel" ]; then
1827 die "/lib/modules/$kernel is not a directory."
1830 if [ "$INITRDFS" != "initramfs" ]; then
1831 if is_yes "$FB_SPLASH"; then
1832 warn "Using fbsplash requires INITRDFS=initramfs; skipping fbsplash generation"
1835 if is_yes "$FB_CON_DECOR"; then
1836 warn "Using fbcondecor requires INITRDFS=initramfs; skipping fbcondecor generation"
1841 if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
1842 warn "Tuxonice and mainline suspend are exclusive!"
1845 if is_yes "$FB_SPLASH" && is_yes "$BOOT_SPLASH"; then
1846 warn "bootsplash and fbsplash are exclusive!"
1849 if [ ! -f /proc/mounts ]; then
1850 warn "/proc filesystem not mounted, may cause wrong results or failure."
1853 if [ -d /usr/lib64 ]; then
1858 debug "Using libdir: $_lib"
1862 for n in $PREMODS; do
1866 if [ "$FBMODULE" ]; then
1867 findmodule "$FBMODULE"
1870 # allow forcing loading SCSI and/or IDE modules
1871 if is_yes "$ADDSCSI"; then
1875 if is_yes "$ADDIDE"; then
1879 if is_yes "$USE_SUSPEND"; then
1880 find_modules_suspend
1883 find_root "$fstab" || exit
1884 debug "Using $rootdev as device for rootfs"
1886 find_modules_for_devpath "$rootdev"
1887 [ -n "$rootdev_add" ] && find_modules_for_devpath "$rootdev_add"
1889 findmodule "-$rootFs"
1891 for n in $BASICMODULES; do
1895 if is_yes "$USE_TUXONICE"; then
1899 if is_yes "$FB_SPLASH"; then
1903 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1904 debug "No modules are needed -- not building initrd image."
1908 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
1909 RCFILE="$DESTDIR/linuxrc"
1911 chmod a+rx "$RCFILE"
1912 ln -s linuxrc $DESTDIR/init
1914 # create dirs that we really need
1915 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
1917 modules_install "$MODULES"
1919 # mknod'ing the devices instead of copying them works both with and
1921 mknod "$DESTDIR/dev/console" c 5 1
1922 mknod "$DESTDIR/dev/null" c 1 3
1923 mknod "$DESTDIR/dev/zero" c 1 5
1925 inst_exec /bin/initrd-busybox /bin/initrd-busybox
1926 ln -s initrd-busybox $DESTDIR/bin/sh
1927 ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
1929 if is_yes "$USEINSMODSTATIC"; then
1930 inst_exec "$INSMOD" /bin/insmod.static
1935 # initrd generated by:
1940 add_linuxrc <<-'EOF'
1941 read CMDLINE < /proc/cmdline; export CMDLINE
1943 for arg in $CMDLINE; do
1944 if [ "${arg}" = "debuginitrd" ]; then
1947 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1948 DEBUGINITRD=${arg##debuginitrd=}
1950 if [ "${arg##root=}" != "${arg}" ]; then
1955 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1956 if [ "$DEBUGINITRD" = "sh" ]; then
1959 if is_yes "$RUN_SULOGIN_ON_ERR"; then
1960 add_linuxrc <<-'EOF'
1961 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1964 add_linuxrc <<-'EOF'
1968 add_linuxrc <<-'EOF'
1976 if [ "$DEBUGINITRD" ]; then
1981 modules_add_linuxrc $MODULES
1983 # TODO: rewrite for busybox
1984 #if [ -n "$loopDev" ]; then
1985 # if [ ! -d /initrd ]; then
1989 # cp -a "$loopDev" "$DESTDIR/dev"
1990 # cp -a "$rootdev" "$DESTDIR/dev"
1991 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1992 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1993 # echo "echo Setting up loopback device $rootdev" >> $RCFILE
1994 # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1997 if is_yes "$USE_UDEV"; then
2001 if is_yes "$USE_TUXONICE"; then
2005 if is_yes "$need_v86d"; then
2009 if is_yes "$have_luks"; then
2013 if is_yes "$have_dmraid"; then
2017 if is_yes "$have_multipath"; then
2018 initrd_gen_multipath
2021 if is_yes "$USE_BLKID"; then
2025 if is_yes "$have_nfs"; then
2027 elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
2029 if is_yes "$have_lvm"; then
2032 initrd_gen_setrootdev
2034 elif is_yes "$have_lvm"; then
2037 initrd_gen_setrootdev
2040 if is_yes "$USE_SUSPEND"; then
2044 # additional devs always needed
2045 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
2047 if is_yes "$USE_UDEV"; then
2048 initrd_gen_stop_udevd
2051 if [ "$INITRDFS" = "initramfs" ]; then
2052 initrd_gen_initramfs_switchroot
2057 if is_yes "$FB_SPLASH"; then
2061 if is_yes "$FB_CON_DECOR"; then
2062 initrd_gen_fbcondecor
2065 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
2067 debug "Creating $INITRDFS image $IMAGE"
2070 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
2071 debug "ext2 image size: $IMAGESIZE ($DESTDIR)"
2072 if [ "$IMAGESIZE" -gt 4096 ]; then
2073 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
2076 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
2077 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
2078 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
2080 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
2081 debug "Mounting ext2 image $IMAGE to $tmpmnt"
2082 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
2083 # We don't need this directory, so let's save space
2084 rm -rf "$tmpmnt"/lost+found
2086 debug "Copy recursively $DESTDIR -> $tmpmnt"
2087 cp -a $DESTDIR/* $tmpmnt
2093 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
2094 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
2095 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
2096 if [ "$IMAGESIZE" -gt 4096 ]; then
2097 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
2101 mkcramfs "$DESTDIR" "$IMAGE"
2104 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
2107 echo "Filesystem $INITRDFS not supported by $PROGRAM";
2110 if is_yes "$COMPRESS"; then
2111 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
2112 debug "Compressing $target"
2113 gzip -9 < "$IMAGE" > "$tmp"
2114 mv -f "$tmp" "$target"
2116 cp -a "$IMAGE" "$target"
2119 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
2120 if is_yes "$BOOT_SPLASH"; then
2121 initrd_gen_bootsplash "$target"
2124 rm -rf "$DESTDIR" "$IMAGE"
2126 # vim:ts=4:sw=4:noet:fdm=marker