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] [--without-luks]"
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
289 local modfile=$(modinfo -k $kernel -n $module 2>/dev/null)
290 if [ ! -f "$modfile" ]; then
291 # module not found. try aliases!
292 local alias aliases=$(modprobe_conf | awk -vm="$module" '$1 == "alias" && $2 == m { print $3 }')
293 if [ "$aliases" ]; then
294 for alias in $aliases; do
295 debug "Try $alias alias for $module"
301 if [ "$mode" != "silent" ]; then
302 warn "$module: module not found for $kernel kernel"
304 if ! is_no "$EXIT_IF_MISSING"; then
307 warn "If $module isn't compiled in kernel then this initrd may not start your system."
311 # This works when user has module-init-tools installed even on 2.4 kernels
312 modprobe --set-version $kernel --show-depends $module | \
313 while read insmod modpath options; do
320 echo -n $(modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
327 if [ ${modName#-} != $modName ]; then
333 if [ "$modName" = "pluto" ]; then
337 if [ "$modName" = "fcal" ]; then
343 if [ "$skiperrors" = 1 ]; then
344 depmod=$(find_depmod $modName silent)
346 depmod=$(find_depmod $modName)
352 for mod in $depmod; do
353 mod=${mod#/lib/modules/$kernel/}
355 # add each module only once
357 for m in $MODULES; do
358 [ $m = $mod ] && have=1
360 if [ $have = 0 ]; then
361 MODULES="$MODULES $mod"
363 # if we are adding uvesafb, we need v86d as well
364 if [ "$modName" = "uvesafb" ]; then
371 # install a file to temporary mount image.
372 # it will operate recursively (copying directories)
373 # and will symlink destinations if source is symlink.
375 if [ $# -lt 2 ]; then
376 die 'Usage: inst <file> [<file>] <destination>'
379 local src i=0 c=$(($# - 1))
380 while [ $i -lt $c ]; do
387 parentDir=$(dirname $DESTDIR$dest)
388 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
389 debug "+ cp $* $DESTDIR$dest"
390 cp -HR "$@" "$DESTDIR$dest"
395 die 'Usage: inst_d <destination> <destination>'
398 install -d "$DESTDIR$dir"
402 # install executable and it's shared libraries
404 if [ $# -lt 2 ]; then
405 die 'Usage: inst_exec <file>[, <file>] <destination>'
407 local src i=0 c=$(($# - 1))
408 while [ $i -lt $c ]; do
418 local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
420 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
422 inst_exec $lib /$_lib
426 # hack for uclibc linked binaries requiring this fixed path
427 # XXX: shouldn't rpath be used here instead so th
428 if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
429 local lib=$DESTDIR/$_lib/libc.so.0
430 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
431 local libdir=$(cd $(dirname "$lib"); pwd)
432 if [ ! -e $DESTDIR$libdir ]; then
433 libdir=$(dirname "$libdir")
435 debug "+ ln -s /$_lib $DESTDIR$libdir"
436 ln -s /$_lib $DESTDIR$libdir
441 # output modules.conf / modprobe.conf
443 echo "$modprobe_conf_cache"
447 # defaults to modprobe -c if not told otherwise, this means include statements
449 cache_modprobe_conf() {
450 if [ "$pack_version" -lt "002005" ]; then
451 modulefile=/etc/modules.conf
452 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
453 modulefile=/etc/conf.modules
457 if [ -n "$modulefile" ]; then
458 debug "Using $modulefile for modules config"
459 modprobe_conf_cache=$(cat $modulefile)
461 debug "Using modprobe -c to get modules config"
462 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
467 local found raidlevel
469 if [ -f /etc/mdadm.conf ]; then
470 debug "Finding RAID details using mdadm for rootdev=$1"
471 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
476 rootdev_devfs = rootdev;
477 if (rootdev ~ /\/dev\/md\/[0-9]/) {
478 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
483 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
485 gsub(/level=/,NUL,raidlevel);
486 if (raidlevel ~ /^raid([0-6]|10)/) {
487 gsub(/raid/,NUL,raidlevel);
491 if (x ~ /devices=/) {
493 gsub(".*devices=", NUL, dev_list);
494 gsub(",", " ", dev_list);
500 print "have_md=" found;
501 print "raidlevel=" raidlevel;
502 print "dev_list=\"" dev_list "\"";
506 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
507 die "raidtools are not longer supported. Please migrate to mdadm setup!"
510 if is_yes "$have_md"; then
513 findmodule "raid$raidlevel"
516 findmodule "-raid$raidlevel"
517 findmodule "-raid456"
523 warn "raid level $number (in mdadm config) not recognized"
527 die "RAID devices not found for \"$1\", check your configuration!"
530 rootdev_nr=$(( $rootdev_nr + 1 ))
531 eval "rootdev${rootdev_nr}=\"$1\""
532 eval "dev_list${rootdev_nr}=\"${dev_list}\""
534 for device in $dev_list; do
535 find_modules_for_devpath $device
539 find_modules_scsi() {
541 for n in $PRESCSIMODS; do
542 if [ "X$n" = "Xunknown" ]; then
543 debug "Finding SCSI modules using scsi_hostadapter"
544 local mod scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
545 for mod in $scsimodules; do
546 # for now allow scsi modules to come from anywhere. There are some
547 # RAID controllers with drivers in block
554 findmodule "-scsi_wait_scan"
559 # remove partition, if any
560 local disk=${devpath%[0-9]*}
561 # set blockdev for rootfs (hda, sdc, ...)
562 local rootblkdev=${disk#/dev/}
565 if [ "$pack_version_long" -lt "002004021" ]; then
566 debug "Finding IDE modules for kernels <= 2.4.20"
567 for n in $PREIDEMODSOLD; do
572 for n in $PREIDEMODS; do
573 if [ "X$n" = "Xunknown" ]; then
574 debug "Finding IDE modules using ide_hostadapter"
575 local mod idemodules=$(modprobe_conf | awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
576 for mod in $idemodules; do
581 if [ "$tryauto" -eq 1 ]; then
583 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
584 debug "Finding IDE modules using PCI ID database"
585 # Finding IDE modules using PCI ID database {{{
586 if is_yes "${ide_only_root}"; then
587 if [ -f /sys/block/${rootblkdev}/device/../../vendor -a -f /sys/block/${rootblkdev}/device/../../device ]; then
588 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../vendor)"
589 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../device)"
590 searchpciid="${vendorid}${deviceid}"
591 elif [ -f /proc/ide/${rootblkdev}/../config ]; then
592 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootblkdev}/../config)"
596 if [ -z "${searchpciid}" ]; then
597 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
602 for nb in $searchpciid; do
603 eval `awk -v pciid="$nb" '{
609 compmod = $1 ""; # make sure comparison type will be string
610 # cause pci IDs are hexadecimal numeric
611 if (compmod == pciid) {
613 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
620 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
621 }' /usr/share/pci-database/ide.pci`
622 [ -n "$module" ] && idemodules="$idemodules $module"
624 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
626 for nc in idemodules; do
627 new_idemodules="$nc $new_idemodules"
629 idemodules="${new_idemodules}"
632 if [ -z "$idemodules" ]; then
633 warn "rootfs on IDE device but no related modules found, loading ide-generic."
634 idemodules="ide-generic"
638 for nd in $idemodules; do
644 [ -r /usr/share/pci-database/ide.pci ] || warn "/usr/share/pci-database/ide.pci missing."
645 [ -r /proc/bus/pci/devices ] || warn "/proc/bus/pci/devices missing."
646 warn "Automatic IDE modules finding not available."
657 # return true if node is lvm node
660 if [ ! -e "$node" ]; then
661 warn "check_lvm(): node $node doesn't exist!"
665 # block-major-58 is lvm1
666 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
670 debug "LVM check: $node is LVM v1 node"
675 if [ ! -x /sbin/lvm ]; then
676 debug "LVM check: no lvm2 tools present to check"
680 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
682 if [ $rc -gt 127 ]; then
683 # lvdisplay terminated by signal! most likely it segfaulted.
684 die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
688 debug "LVM check: $node is LVM v2 node"
690 debug "LVM check: $node is not any LVM node"
696 # return dependencies MAJOR:MINOR [MAJOR:MINOR] for DM_NAME
697 # TODO: patch `dmsetup export`
700 dmsetup deps $dm_name | sed -e 's/, /:/g;s/^.\+ dependencies[^:]: //;s/[()]//g;'
703 # export info from dmsetup
707 # - /dev/mapper/DM_NAME
713 local maj=${arg%:*} min=${arg#*:}
714 dmsetup -j $maj -m $min export
717 local min=${arg#*dm-}
718 local maj=$(awk '$2 == "device-mapper" {print $1}' /proc/devices)
722 local dm_name=${arg#/dev/mapper/}
723 dmsetup export $dm_name
726 die "dm_export: unexpected $arg"
731 # find dm-multipath modules for $devpath
732 # returns false if $devpath is not dm-multipath
733 find_modules_multipath() {
737 eval $(dm_export "$devpath")
738 if [ -z "$DM_NAME" ]; then
739 die "dm_export failed unexpectedly"
744 # DM_UUID=part1-mpath-36006016002c11800a0aa05fbfae0db11
747 # DM_UUID=mpath-36006016002c11800a0aa05fbfae0db11
748 MPATH_WWID=${DM_UUID##*-}
750 local info=$(multipath -l $MPATH_WWID)
751 if [ -z "$info" ]; then
755 debug "Finding modules for dm-multipath (WWID=$MPATH_WWID)"
757 local dev phydevs=$(echo "$info" | awk '$2 ~ /^[0-9]+:[0-9]+:[0-9]+:[0-9]+$/{printf("/dev/%s\n", $3)}')
758 for dev in $phydevs; do
759 find_modules_for_devpath $dev
760 lvm_ignore_devices="$lvm_ignore_devices $dev"
763 local hw hwhandlers=$(echo "$info" | awk '/hwhandler=1/{sub(/.*hwhandler=1 /, ""); sub(/\]$/, ""); print}')
764 for hw in $hwhandlers; do
768 local target targets=$(echo "$info" | awk '/prio=/{print $2}' | sort -u)
769 for target in $targets; do
770 findmodule "dm-$target"
777 # find dmraid modules for $devpath
778 # returns false if $devpath is not on dmraid
779 find_modules_dmraid() {
782 # get blockdev itself (without partition)
783 # /dev/mapper/sil_ahbgadcbchfc3 -> /dev/mapper/sil_ahbgadcbchfc
784 local blockdev=${devpath%%[0-9]*}
785 local raidname=${blockdev#/dev/mapper/}
788 local dev phydevs=$(dmraid -r -cdevpath,raidname | awk -F, -vv="$raidname" '{if ($2 == v) print $1}')
789 for dev in $phydevs; do
790 find_modules_for_devpath $dev
791 lvm_ignore_devices="$lvm_ignore_devices $dev"
795 if [ $found = 0 ]; then
799 findmodule "dm-mirror"
804 # find modules for $devpath
805 find_modules_for_devpath() {
807 if [ -z "$devpath" ]; then
808 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
811 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
814 devpath=$(dm_longname "$devpath")
817 debug "Finding modules for device path $devpath"
819 if is_luks "$devpath"; then
820 find_modules_luks "$devpath"
824 if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
825 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
826 die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
828 if [ ! -f /proc/bus/pci/devices ]; then
829 warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:"
830 warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\""
833 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
834 warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
835 for m in $NFS_ETH_MODULES; do
842 warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
843 warn "or you will have problems like init(xx) being child process of swapper(1)."
847 if [[ "$devpath" == /dev/md* ]]; then
848 find_modules_md "$devpath"
852 if is_yes "$USE_MULTIPATH" && [[ "$devpath" == /dev/mapper/* ]]; then
853 if find_modules_multipath "$devpath"; then
859 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
860 if find_modules_dmraid "$devpath"; then
866 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
871 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }')"; then
872 find_modules_ide "$devpath"
876 if [[ "$devpath" == /dev/rd/* ]]; then
878 rootdev_add="/dev/rd/"
882 if [[ "$devpath" == /dev/ida/* ]]; then
883 findmodule "cpqarray"
884 rootdev_add="/dev/ida/"
888 if [[ "$devpath" == /dev/cciss/* ]]; then
890 rootdev_add="/dev/cciss/"
894 if [[ "$devpath" == /dev/ataraid/* ]]; then
897 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
898 if [ -n "$ataraidmodules" ]; then
899 # FIXME: think about modules compiled in kernel
900 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
902 for n in $ataraidmodules; do
905 rootdev_add="/dev/ataraid/"
909 # check to see if we need to set up a loopback filesystem
910 if [[ "$devpath" == /dev/loop* ]]; then
911 die "Sorry, root on loop device isn't supported."
912 # TODO: rewrite for bsp and make nfs ready
913 if [ ! -x /sbin/losetup ]; then
914 die "losetup is missing"
916 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
917 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
918 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"
921 line="`awk '/'$key'/ { print $0; }' $fstab`"
922 loopDev="$(echo $line | awk '{print $3}')"
923 loopFs="$(echo $line | awk '{print $4}')"
924 loopFile="$(echo $line | awk '{print $5}')"
926 BASICMODULES="$BASICMODULES -loop"
927 findmodule "-$loopFs"
928 BASICMODULES="$BASICMODULES -${loopFs}"
932 if is_lvm_node "$devpath"; then
935 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then
936 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."
938 if [ -z "$LVMTOOLSVERSION" ]; then
939 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}')
940 if [ -z "$LVMTOOLSVERSION" ]; then
941 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
945 local vg=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
946 VGVOLUMES=$(echo $VGVOLUMES $vg | tr ' ' '\n' | sort -u)
947 local pv=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$vg" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
948 PVDEVICES=$(echo $PVDEVICES $pv | tr ' ' '\n' | sort -u)
950 if [ -n "$PVDEVICES" ]; then
951 for device in $PVDEVICES; do
952 find_modules_for_devpath $device
955 die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
957 if [ "$LVMTOOLSVERSION" = "2" ]; then
959 elif [ "$LVMTOOLSVERSION" = "1" ]; then
961 findmodule "-lvm-mod"
963 die "LVM version $LVMTOOLSVERSION is not supported yet."
965 debug "LVM v$LVMTOOLSVERSION enabled"
971 firmware_install_module() {
973 local firmware_files="$2"
975 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
976 # firmware not yet installed
977 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
979 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
981 echo 1 > /sys$DEVPATH/loading
982 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
983 echo 0 > /sys$DEVPATH/loading
986 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
989 for firmware in $firmware_files; do
990 if [ ! -f "/lib/firmware/$firmware" ]; then
991 die "firmware file /lib/firmware/$firmware doesn't exist."
993 FIRMWAREDIR=${firmware%/*}
994 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
995 inst /lib/firmware/$firmware /lib/firmware/$firmware
1000 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
1007 for mod in $modules; do
1009 inst_d "/lib/modules/$kernel/$MODULEDIR"
1010 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
1011 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
1015 modules_add_linuxrc() {
1019 # module path without optional compression
1022 # name of the module
1023 module=${modpath##*/}
1024 module=${module%$modext}
1026 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
1028 generic_module=$(echo $module | tr - _)
1029 sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
1030 firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
1032 if [ -n "$verbose" ]; then
1034 if [ "$options" ]; then
1035 s="$s with options [$options]"
1037 if [ "$sleep_var" ]; then
1038 s="$s and $sleep_var usleep"
1040 debug "Loading module [$module]$s"
1043 if [ -n "$firmware_var" ]; then
1044 firmware_install_module "$module" "$firmware_var"
1046 firmware_files=$(find_firmware "$module")
1047 if [ -n "$firmware_files" ]; then
1048 for file in $firmware_files; do
1049 firmware_install_module "$module" "$file"
1054 echo "$insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
1055 if [ -n "$sleep_var" ]; then
1056 echo "usleep $sleep_var" | add_linuxrc
1061 find_modules_suspend() {
1062 if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then
1063 die "/usr/${_lib}/suspend/resume is missing!"
1065 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
1067 local vgvolumes=$VGVOLUMES
1068 find_modules_for_devpath $resume_dev
1070 if [ "$VGVOLUMES" != "$vgvolumes" ]; then
1071 # save our VG to be able to differenciate between rootfs VG
1072 SUSPENDVG=$VGVOLUMES
1073 VGVOLUMES=$vgvolumes
1074 debug "suspend device is on LVM"
1078 initrd_gen_suspend() {
1079 mknod $DESTDIR/dev/snapshot c 10 231
1080 mkdir -p $DESTDIR${resume_dev%/*}
1081 inst $resume_dev $resume_dev
1083 inst /etc/suspend.conf /etc/suspend.conf
1084 if [ -x /usr/${_lib}/suspend/resume ]; then
1085 inst_exec /usr/${_lib}/suspend/resume /bin/resume
1087 inst_exec /usr/sbin/resume /bin/resume
1090 add_linuxrc <<-'EOF'
1092 for arg in $CMDLINE; do
1093 if [ "${arg##resume=}" != "${arg}" ]; then
1097 if [ "$resume" = "yes" ]; then
1103 initrd_gen_tuxonice() {
1105 add_linuxrc <<-'EOF'
1107 for arg in $CMDLINE; do
1108 if [ "${arg##resume=}" != "${arg}" -o "${arg##resume2=}" != "${arg}" ]; then
1112 if [ "$resume" = "yes" ]; then
1113 [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
1114 [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
1115 [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
1121 debug "initrd_gen_v86d"
1122 mknod $DESTDIR/dev/mem c 1 1
1123 mknod $DESTDIR/dev/tty1 c 4 1
1125 inst_exec /sbin/v86d /sbin
1129 debug "Setting up udev..."
1130 inst_d /sbin /etc/udev
1132 if [ ! -x /sbin/initrd-udevd ]; then
1133 die "/sbin/initrd-udevd not present"
1136 inst_exec /sbin/initrd-udevd /sbin/udevd
1137 inst /etc/udev/udev.conf /etc/udev/udev.conf
1141 add_linuxrc <<-'EOF'
1143 /sbin/udevd --daemon
1146 inst_exec /sbin/initrd-udevadm /sbin/udevadm
1147 add_linuxrc <<-'EOF'
1148 /sbin/udevadm trigger
1149 /sbin/udevadm settle
1154 initrd_gen_stop_udevd() {
1155 busybox_applet killall
1156 add_linuxrc <<-'EOF'
1161 initrd_gen_multipath() {
1162 inst_d /sbin /lib/udev /etc/multipath
1163 inst_exec /sbin/kpartx /sbin
1164 inst_exec /sbin/multipath /sbin
1166 inst_exec /sbin/scsi_id /lib/udev
1167 inst_exec /sbin/mpath* /sbin
1168 egrep -v '^([ ]*$|#)' /etc/multipath.conf > $DESTDIR/etc/multipath.conf
1170 if [ -f /etc/multipath/bindings ]; then
1171 egrep -v '^([ ]*$|#)' /etc/multipath/bindings > $DESTDIR/etc/multipath/bindings
1173 touch $DESTDIR/etc/multipath/bindings
1180 echo "export MPATH_WWID=$MPATH_WWID" | add_linuxrc
1181 add_linuxrc <<-'EOF'
1182 # parse mpath_wwid= from kernel commandline
1183 for arg in $CMDLINE; do
1184 if [ "${arg##mpath_wwid=}" != "${arg}" ]; then
1185 MPATH_WWID=${arg##mpath_wwid=}
1186 if [ "$MPATH_WWID" = "*" ]; then
1187 # '*' would mean activate all WWID-s
1189 echo "multipath: Activating all WWID-s"
1191 echo "multipath: Activating WWID=$WWID"
1197 /sbin/multipath -v 0 $MPATH_WWID
1199 for a in /dev/mapper/*; do
1200 [ $a = /dev/mapper/control ] && continue
1201 /sbin/kpartx -a -p p $a
1207 initrd_gen_dmraid() {
1208 if [ ! -x /sbin/dmraid-initrd ]; then
1209 die "/sbin/dmraid-initrd is missing!"
1213 inst_exec /sbin/dmraid-initrd /sbin/dmraid
1219 # 2 secs was enough for my system to initialize. but really this is udev issue?
1221 : 'Activating Device-Mapper RAID(s)'
1228 initrd_gen_bootsplash() {
1231 debug "Generating bootsplash"
1233 if [ ! -x /bin/splash.bin ]; then
1234 warn "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
1238 if [ -r /etc/sysconfig/bootsplash ]; then
1239 . /etc/sysconfig/bootsplash
1242 if [ -z "$THEME" ]; then
1243 warn "Please configure your /etc/sysconfig/bootsplash first."
1244 warn "Generating bootsplashes skipped."
1248 if [ -z "$BOOT_SPLASH_RESOLUTIONS" ]; then
1249 warn "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
1250 warn "Not adding bootsplash to initrd."
1253 for res in $BOOT_SPLASH_RESOLUTIONS; do
1254 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1255 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1256 debug "Added $res $THEME theme to initrd."
1258 warn "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
1263 initrd_gen_fbsplash() {
1264 debug "Generating fbsplash"
1266 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
1267 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
1270 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
1271 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1273 if [ -r /etc/sysconfig/fbsplash ]; then
1274 . /etc/sysconfig/fbsplash
1277 if [ -z "$SPLASH_THEME" ]; then
1278 warn "Please configure your /etc/sysconfig/fbsplash first."
1279 warn "Generating fbsplashes skipped."
1283 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1284 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
1285 warn "Not adding fbsplash to initramfs."
1289 for res in $FB_SPLASH_RESOLUTIONS; do
1290 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1291 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1292 debug "Added $res $SPLASH_THEME theme to initramfs."
1294 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1299 initrd_gen_fbcondecor() {
1300 debug "Generating fbcondecor"
1302 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
1303 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
1306 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
1307 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1309 if [ -r /etc/sysconfig/splash ]; then
1310 . /etc/sysconfig/splash
1313 if [ -z "$SPLASH_THEME" ]; then
1314 warn "Please configure your /etc/sysconfig/splash first."
1315 warn "Generating of splashes skipped."
1319 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1320 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/splash."
1321 warn "Not adding fbcondecor to initramfs."
1325 for res in $FB_SPLASH_RESOLUTIONS; do
1326 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1327 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1328 debug "Added $res $SPLASH_THEME theme to initramfs."
1330 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1335 # Generates /dev nodes based on /proc/partitions information.
1336 # Needs /proc mounted.
1337 # Can be called multiple times.
1338 initrd_gen_devices() {
1339 if is_yes "$proc_partitions"; then
1345 add_linuxrc <<-'EOF'
1346 : 'Making device nodes'
1347 cat /proc/partitions | (
1348 # ignore first two lines: header, empty line
1351 while read major minor blocks dev rest; do
1354 [ -e $node ] || mknod $node b $major $minor
1361 debug "Setting up mdadm..."
1363 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1364 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
1367 inst_exec /sbin/initrd-mdassemble /bin/mdassemble
1370 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
1371 if [ "$dev_list_extra" = "partitions" ]; then
1372 # FIXME: handle this case (see man mdadm.conf)
1373 echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
1376 for ex_dev in $dev_list_extra; do
1377 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
1381 for nr in `seq 1 $rootdev_nr`; do
1382 eval cr_rootdev="\$rootdev${nr}"
1383 eval cr_dev_list="\$dev_list${nr}"
1384 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1386 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1388 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
1389 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1390 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
1391 if [ -n "$cr_md_conf" ]; then
1392 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
1394 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
1397 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1398 # mkdir in case of devfs name
1399 inst_d $(dirname $f)
1400 [ -e "$DESTDIR/$f" ] && continue
1401 # this works fine with and without devfs
1406 echo "mdassemble" | add_linuxrc
1408 # needed to determine md-version
1409 if [ "$do_md0" -eq 1 ]; then
1410 mknod $DESTDIR/dev/md0 b 9 0
1415 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1416 # have problems like init(XX) being child process of swapper(1).
1417 debug "Adding rootfs on NFS support to initrd (dhcp)"
1418 mknod "$DESTDIR/dev/urandom" c 1 9
1419 mkdir "$DESTDIR/newroot"
1420 add_linuxrc <<-'EOF'
1421 ifconfig lo 127.0.0.1 up
1422 route add -net 127.0.0.0 mask 255.0.0.0 lo
1424 udhcpc -i eth0 -f -q -s /bin/setdhcp
1428 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1429 exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1432 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
1434 [ "$1" != "bound" ] && exit
1435 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1436 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1437 ifconfig $interface $ip $BROADCAST $NETMASK up
1438 if [ -n "$router" ]; then
1439 for r in $router; do
1440 route add default gw $r dev $interface
1444 for o in $CMDLINE; do
1447 rootpath=${o#nfsroot=}
1452 if [ -n "$rootpath" ]; then
1453 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1455 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1456 echo "All seen variables are listed below:"
1461 chmod 755 "$DESTDIR/bin/setdhcp"
1465 debug "Adding LVM support to initrd"
1466 inst_d /tmp /newroot
1467 inst_exec /sbin/initrd-lvm /bin/lvm.static
1469 # always make /dev on tmpfs for LVM2
1470 if [ "$LVMTOOLSVERSION" = "2" ]; then
1474 if ! is_yes "$dev_mounted"; then
1476 mknod $DESTDIR/dev/mapper/control c 10 63
1477 for device in $PVDEVICES; do
1478 # if LVM on RAID then device might be copied already in gen_md
1479 [ -e "$DESTDIR/dev/$(basename $device)" ] && continue
1485 if [ "$LVMTOOLSVERSION" = "1" ]; then
1488 for vg in $VGVOLUMES; do
1489 lvm vgchange -T -a y $vg
1493 echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
1494 echo "global {" > "$DESTDIR/etc/lvm.conf"
1495 echo " locking_type = 0" >> "$DESTDIR/etc/lvm.conf"
1496 echo " locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf"
1497 echo "}" >> "$DESTDIR/etc/lvm.conf"
1498 echo "devices {" >> "$DESTDIR/etc/lvm.conf"
1499 echo " sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf"
1500 if is_yes "$have_md"; then
1501 echo " md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf"
1503 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
1504 echo ' types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf"
1506 if [ "$lvm_ignore_devices" ]; then
1507 # TODO: think of merging with lvm dumpconfig output
1508 echo ' filter = [' >> "$DESTDIR/etc/lvm.conf"
1510 for dev in $lvm_ignore_devices; do
1511 debug "LVM v2: ignore device $dev"
1512 printf ' "r|^%s.*|",\n' $dev
1513 done >> "$DESTDIR/etc/lvm.conf"
1514 echo ']' >> "$DESTDIR/etc/lvm.conf"
1516 # XXX filter= must be on one line!
1517 lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf"
1518 echo "}" >> "$DESTDIR/etc/lvm.conf"
1523 export ROOTDEV=$rootdev
1524 export ROOTVG="$VGVOLUMES"
1525 export SUSPENDVG=$SUSPENDVG
1527 add_linuxrc <<-'EOF'
1528 # parse rootdev from kernel commandline if it begins with /
1531 if [ "$ROOT" != "$ROOTDEV" ]; then
1533 echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
1534 local tmp=${ROOTDEV#/dev/}
1535 if [ "$tmp" != "$ROOTDEV" ]; then
1537 echo "LVM: Using Volume Group '$ROOTVG' for rootfs"
1544 if [ "$SUSPENDVG" = "$ROOTVG" ]; then
1545 export VGVOLUMES="$ROOTVG"
1547 export VGVOLUMES="$SUSPENDVG $ROOTVG"
1550 # disable noise from LVM accessing devices that aren't ready.
1551 read printk < /proc/sys/kernel/printk
1552 if [ ! "$DEBUGINITRD" ]; then
1553 echo 0 > /proc/sys/kernel/printk
1556 export LVM_SYSTEM_DIR=/tmp
1557 : 'Scanning for Volume Groups'
1558 lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null
1560 : 'Activating Volume Groups'
1561 for vol in $VGVOLUMES; do
1562 lvm.static vgchange --ignorelockingfailure -a y $vol 2>/dev/null
1565 echo "$printk" > /proc/sys/kernel/printk
1567 # Find out major/minor
1568 attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $ROOTDEV 2>/dev/null)"
1569 if [ "$attrs" ]; then
1570 majmin="${attrs#*$ROOTDEV*:*:*:*:*:*:*:*:*:*:*:*}"
1571 if [ "$majmin" != "$attrs" ]; then
1572 major="${majmin%:*}"
1573 minor="${majmin#*:}"
1577 if [ "$major" -a "$minor" ]; then
1579 echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev
1581 echo 2>&1 "Error figuring out real root device for $ROOTDEV!"
1582 echo 2>&1 "System will not most likely boot up! So dropping you to a shell!"
1592 debug "Adding BLKID support to initrd"
1593 inst_exec /sbin/initrd-blkid /bin/blkid
1595 add_linuxrc <<-'EOF'
1596 # if built with blkid change ROOT=LABEL=something into ROOT=/dev/somethingelse -
1598 if [ "${ROOT##LABEL=}" != "${ROOT}" -o "${ROOT##UUID=}" != "${ROOT}" ]; then
1599 ROOT="$(/bin/blkid -t $ROOT -o device -l)"
1604 initrd_gen_setrootdev() {
1605 debug "Adding rootfs finding based on kernel cmdline root= option support."
1606 add_linuxrc <<-'EOF'
1607 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
1608 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
1609 if [ -n "$rootnr" ]; then
1610 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1616 initrd_gen_initramfs_switchroot() {
1618 if [ "$rootdev" = "/dev/nfs" ]; then
1619 echo "rootfs on NFS root=/dev/nfs"
1621 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
1623 # Parsing root parameter
1624 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
1625 add_linuxrc <<-'EOF'
1626 device=/dev/no_partition_found
1627 eval "$(busybox awk -v c="$ROOT" '
1629 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
1630 num_pattern = "[0-9a-f]" num_pattern_short;
1631 dev_pattern = "[hms][a-z][a-z]([0-9])+";
1632 partition = "no_partition_found";
1636 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
1637 if (c ~ "^" num_pattern "$") {
1638 maj = sprintf("%s",substr(c,1,2));
1639 min = sprintf("%s",substr(c,3));
1641 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
1642 if (c ~ "^" dev_pattern "$") partition = c;
1645 $4 ~ partition { maj = $1; min = $2; }
1646 $1 ~ maj && $2 ~ min { partition = $4; }
1649 print sprintf("device=/dev/%s\nmaj=%s\nmin=%s",
1650 partition, maj, min);
1652 ' /proc/partitions)"
1653 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
1654 mknod $device b $maj $min
1663 add_linuxrc <<-'EOF'
1664 if [ "$device" = '/dev/no_partition_found' ]; then
1668 mount -t $rootfs -r $device /newroot
1669 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
1670 if [ -z "$init" -o ! -x "/newroot$init" ]; then
1676 busybox_applet switch_root
1677 add_linuxrc <<-'EOF'
1678 exec switch_root /newroot $init
1680 echo "Error! initramfs should not reach this place."
1681 echo "It probably means you've got old version of busybox, with broken"
1682 echo "initramfs support. Trying to boot anyway, but won't promise anything."
1684 exec chroot /newroot $init
1686 echo "Failed to chroot!"
1688 # we need /init being real file, not symlink, otherwise the initramfs will
1689 # not be ran by pid 1 which is required for switch_root
1690 mv $DESTDIR/linuxrc $DESTDIR/init
1691 ln -s init $DESTDIR/linuxrc
1695 if [ "$(id -u)" != 0 ]; then
1696 die "You need to be root to generate initrd"
1699 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
1701 . /etc/udev/udev.conf
1704 if [ -x /sbin/dmraid-initrd ]; then
1708 # cryptsetup luks addon
1709 . /etc/geninitrd/mod-luks.sh
1711 if [ -x /sbin/multipath ]; then
1715 if [ -x /sbin/initrd-blkid ]; then
1719 if [ -r /etc/sysconfig/geninitrd ]; then
1720 . /etc/sysconfig/geninitrd
1723 if [ ! -x /bin/initrd-busybox ]; then
1724 die "/bin/initrd-busybox is missing!"
1727 # backwards compatible
1728 if [ "$USE_SUSPEND2" ]; then
1729 USE_TUXONICE=$USE_SUSPEND2
1730 warn "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
1733 while [ $# -gt 0 ]; do
1743 modulefile=${1#--modules-conf=}
1749 --use-raidstart|--with-raidstart)
1752 --without-raidstart)
1755 --use-insmod-static|--with-insmod-static)
1758 --without-insmod-static)
1764 --without-bootsplash)
1776 --without-fbcondecor)
1785 --with-suspend2 | --with-tuxonice)
1788 --without-suspend2 | --without-tuxonice)
1791 --lvmtoolsversion=|--lvmversion=)
1792 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
1793 LVMTOOLSVERSION=${1#--lvmversion=}
1795 --lvmtoolsversion|--lvmversion)
1808 --without-multipath)
1818 BASICMODULES="$BASICMODULES ${1#--with=}"
1821 BASICMODULES="$BASICMODULES $2"
1825 echo "$PROGRAM: version $VERSION"
1841 PREMODS="$PREMODS ${1#--preload=}"
1844 PREMODS="$PREMODS $2"
1848 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1852 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1857 INITRDFS=${1#--initrdfs=}
1870 if [ -z "$target" ]; then
1872 elif [ -z "$kernel" ]; then
1883 if [ -z "$target" -o -z "$kernel" ]; then
1887 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1888 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1891 pack_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1892 pack_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
1894 if [ -z "$INITRDFS" ]; then
1895 if [ -z "$FS" ]; then
1897 if [ "$pack_version" -ge "002005" ]; then
1898 INITRDFS="initramfs"
1903 warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
1908 if [ "$pack_version" -lt "002006" ]; then
1913 if [ "$pack_version" -ge "002005" ]; then
1918 if is_yes "$USEINSMODSTATIC"; then
1919 insmod="insmod.static"
1920 INSMOD="/sbin/insmod.static"
1921 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
1922 INSMOD="/sbin/insmod.static.modutils"
1924 if [ ! -f "$INSMOD" ]; then
1925 die "insmod.static requested but /sbin/insmod.static not found!"
1931 if [ ! -x /sbin/mke2fs ]; then
1932 die "/sbin/mke2fs is missing"
1936 if [ ! -x /sbin/genromfs ]; then
1937 die "/sbin/genromfs is missing"
1941 if [ ! -x /sbin/mkcramfs ]; then
1942 die "/sbin/mkcramfs is missing"
1946 if [ ! -x /bin/cpio ]; then
1947 die "/bin/cpio is missing"
1949 if [ ! -x /usr/bin/find ]; then
1950 die "/usr/bin/find is missing"
1954 die "Filesystem $INITRDFS on initrd is not supported"
1958 if [ -L "$target" ]; then
1959 target=$(readlink -f "$target")
1962 if [ -n "$img_vers" ]; then
1963 target="$target-$kernel"
1966 if [ -z "$force" -a -f "$target" ]; then
1967 die "$target already exists."
1970 if [ ! -d "/lib/modules/$kernel" ]; then
1971 die "/lib/modules/$kernel is not a directory."
1974 if [ "$INITRDFS" != "initramfs" ]; then
1975 if is_yes "$FB_SPLASH"; then
1976 warn "Using fbsplash requires INITRDFS=initramfs; skipping fbsplash generation"
1979 if is_yes "$FB_CON_DECOR"; then
1980 warn "Using fbcondecor requires INITRDFS=initramfs; skipping fbcondecor generation"
1985 if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
1986 warn "Tuxonice and mainline suspend are exclusive!"
1989 if is_yes "$FB_SPLASH" && is_yes "$BOOT_SPLASH"; then
1990 warn "bootsplash and fbsplash are exclusive!"
1993 if [ ! -f /proc/mounts ]; then
1994 warn "/proc filesystem not mounted, may cause wrong results or failure."
1997 if [ -d /usr/lib64 ]; then
2002 debug "Using libdir: $_lib"
2006 for n in $PREMODS; do
2010 if [ "$FBMODULE" ]; then
2011 findmodule "$FBMODULE"
2014 # allow forcing loading SCSI and/or IDE modules
2015 if is_yes "$ADDSCSI"; then
2019 if is_yes "$ADDIDE"; then
2023 if is_yes "$USE_SUSPEND"; then
2024 find_modules_suspend
2027 find_root "$fstab" || exit
2028 debug "Using $rootdev as device for rootfs"
2030 find_modules_for_devpath "$rootdev"
2031 [ -n "$rootdev_add" ] && find_modules_for_devpath "$rootdev_add"
2033 findmodule "-$rootFs"
2035 for n in $BASICMODULES; do
2039 if is_yes "$USE_TUXONICE"; then
2043 if is_yes "$FB_SPLASH"; then
2047 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
2048 debug "No modules are needed -- not building initrd image."
2052 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
2053 RCFILE="$DESTDIR/linuxrc"
2055 chmod a+rx "$RCFILE"
2056 ln -s linuxrc $DESTDIR/init
2058 # create dirs that we really need
2059 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
2061 modules_install "$MODULES"
2063 # mknod'ing the devices instead of copying them works both with and
2065 mknod "$DESTDIR/dev/console" c 5 1
2066 mknod "$DESTDIR/dev/null" c 1 3
2067 mknod "$DESTDIR/dev/zero" c 1 5
2069 inst_exec /bin/initrd-busybox /bin/initrd-busybox
2070 ln -s initrd-busybox $DESTDIR/bin/sh
2071 ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
2073 if is_yes "$USEINSMODSTATIC"; then
2074 inst_exec "$INSMOD" /bin/insmod.static
2079 # initrd generated by:
2084 add_linuxrc <<-'EOF'
2085 read CMDLINE < /proc/cmdline; export CMDLINE
2087 for arg in $CMDLINE; do
2088 if [ "${arg}" = "debuginitrd" ]; then
2091 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
2092 DEBUGINITRD=${arg##debuginitrd=}
2094 if [ "${arg##root=}" != "${arg}" ]; then
2099 # make debugshell() invoke subshell if $DEBUGINITRD=sh
2100 if [ "$DEBUGINITRD" = "sh" ]; then
2103 if is_yes "$RUN_SULOGIN_ON_ERR"; then
2104 add_linuxrc <<-'EOF'
2105 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
2108 add_linuxrc <<-'EOF'
2112 add_linuxrc <<-'EOF'
2120 if [ "$DEBUGINITRD" ]; then
2125 modules_add_linuxrc $MODULES
2127 # TODO: rewrite for busybox
2128 #if [ -n "$loopDev" ]; then
2129 # if [ ! -d /initrd ]; then
2133 # cp -a "$loopDev" "$DESTDIR/dev"
2134 # cp -a "$rootdev" "$DESTDIR/dev"
2135 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
2136 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
2137 # echo "echo Setting up loopback device $rootdev" >> $RCFILE
2138 # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
2141 if is_yes "$USE_UDEV"; then
2145 if is_yes "$USE_TUXONICE"; then
2149 if is_yes "$need_v86d"; then
2153 if is_yes "$have_luks"; then
2157 if is_yes "$have_dmraid"; then
2161 if is_yes "$have_multipath"; then
2162 initrd_gen_multipath
2165 if is_yes "$USE_BLKID"; then
2169 if is_yes "$have_nfs"; then
2171 elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
2173 if is_yes "$have_lvm"; then
2176 initrd_gen_setrootdev
2178 elif is_yes "$have_lvm"; then
2181 initrd_gen_setrootdev
2184 if is_yes "$USE_SUSPEND"; then
2188 # additional devs always needed
2189 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
2191 if is_yes "$USE_UDEV"; then
2192 initrd_gen_stop_udevd
2195 if [ "$INITRDFS" = "initramfs" ]; then
2196 initrd_gen_initramfs_switchroot
2201 if is_yes "$FB_SPLASH"; then
2205 if is_yes "$FB_CON_DECOR"; then
2206 initrd_gen_fbcondecor
2209 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
2211 debug "Creating $INITRDFS image $IMAGE"
2214 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
2215 debug "ext2 image size: $IMAGESIZE ($DESTDIR)"
2216 if [ "$IMAGESIZE" -gt 4096 ]; then
2217 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
2220 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
2221 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
2222 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
2224 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
2225 debug "Mounting ext2 image $IMAGE to $tmpmnt"
2226 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
2227 # We don't need this directory, so let's save space
2228 rm -rf "$tmpmnt"/lost+found
2230 debug "Copy recursively $DESTDIR -> $tmpmnt"
2231 cp -a $DESTDIR/* $tmpmnt
2237 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
2238 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
2239 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
2240 if [ "$IMAGESIZE" -gt 4096 ]; then
2241 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
2245 mkcramfs "$DESTDIR" "$IMAGE"
2248 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
2251 echo "Filesystem $INITRDFS not supported by $PROGRAM";
2254 if is_yes "$COMPRESS"; then
2255 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
2256 debug "Compressing $target"
2257 gzip -9 < "$IMAGE" > "$tmp"
2258 mv -f "$tmp" "$target"
2260 cp -a "$IMAGE" "$target"
2263 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
2264 if is_yes "$BOOT_SPLASH"; then
2265 initrd_gen_bootsplash "$target"
2268 rm -rf "$DESTDIR" "$IMAGE"
2270 # vim:ts=4:sw=4:noet:fdm=marker