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
27 # it should be safe to remove scsi_mod from here, but I'm not sure...
28 PRESCSIMODS="-scsi_mod unknown -sd_mod"
29 PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
30 PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
41 # device node for rootfs from fstab
43 # default bootsplash is off, if it have to be on, install bootsplash package
45 # default same as bootsplash, if on install splashutils and some splashutils theme
47 # defualt we don't use udev to make nodes for static modules, as per default
48 # PLD loads the modules needed to mount and boot
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
66 # LVM volume that is used for rootfs
69 # if we should init NFS at boot
71 # if we should init LVM at boot
73 # if we should init md (softraid) at boot
75 # if we should init dmraid at boot
77 # if we should init dm-multipath at boot
79 # dm-multipath wwid which is used for rootfs
84 echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
85 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
86 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
87 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
88 echo " [--with-bootsplash] [--without-bootsplash]"
89 echo " [ --with-fbsplash] [--without-fbsplash]"
90 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
91 echo " [--with-suspend] [--without-suspend]"
92 echo " [--with-tuxonice] [--without-tuxonice]"
93 echo " [--without-dmraid] [--without-multipath]"
94 echo " <initrd-image> <kernel-version>"
97 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
110 [ -n "$verbose" ] && warn "$*"
113 # aborts program abnormally
120 # append text to /linuxrc
121 # takes STDIN as input
126 # generate code to mount /dev on tmpfs and create initial nodes
127 # can be called multiple times. /dev is cleaned up (umounted) automatically at
130 if [ "$INITRDFS" = "initramfs" ]; then
131 # initramfs is read-write filesystem, no need for tmpfs
135 # we already generated tmpfs code; return
136 if is_yes "$dev_mounted"; then
142 busybox_applet mount mknod mkdir
145 mount -o mode=0755 -t tmpfs none /dev
146 mknod /dev/console c 5 1
147 mknod /dev/null c 1 3
148 mknod /dev/zero c 1 5
154 # generate code to mount /proc on initrd
155 # can be called multiple times
157 if is_yes "$proc_mounted"; then
162 if [ "$INITRDFS" = "initramfs" ]; then
163 # /proc is mounted with initramfs 2.6.22.14 kernel
164 # XXX: remove when it is clear why proc was already mounted
165 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
167 echo "mount -t proc none /proc" | add_linuxrc
171 # generate code to mount /sys on initrd
172 # can be called multiple times
174 if is_yes "$sys_mounted"; then
179 echo "mount -t sysfs none /sys" | add_linuxrc
182 # generate code to mount /tmp on initrd
183 # can be called multiple times
185 if [ "$INITRDFS" = "initramfs" ]; then
186 # initramfs is read-write filesystem, no need for tmpfs
190 if is_yes "$tmp_mounted"; then
195 echo "mount -t tmpfs none /tmp" | add_linuxrc
198 # unmount all mountpoints mounted by geninitrd
202 : Last shell before umounting all and giving control over to real init.
206 if is_yes "$dev_mounted"; then
207 echo 'umount /dev' | add_linuxrc
210 if is_yes "$proc_mounted"; then
211 echo 'umount /proc' | add_linuxrc
214 if is_yes "$sys_mounted"; then
215 echo 'umount /sys' | add_linuxrc
218 if is_yes "$tmp_mounted"; then
219 echo 'umount /tmp' | add_linuxrc
225 # Checks if busybox has support for APPLET(s)
226 # Exits from geninitrd if the support is not present.
228 # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
232 if [ -z "$busybox_functions" ]; then
233 local tmp=$(/bin/initrd-busybox 2>&1)
235 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
236 if [[ "$tmp" = *applet\ not\ found* ]]; then
238 ln -s /bin/initrd-busybox $t/busybox
239 local tmp=$($t/busybox 2>&1)
243 busybox_functions=$(echo "$tmp" | \
244 sed -ne '/Currently defined functions:/,$p' | \
245 xargs | sed -e 's,.*Currently defined functions: ,,'
251 eval have='$'busybox_have_$applet
252 if [ -z "$have" ]; then
253 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
254 if [ "$have" = 0 ]; then
255 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
258 eval busybox_have_$applet=$have
261 if [ $err = 1 ]; then
266 # Finds module dependencies
268 # @param $mode silent | normal
271 # Outputs each dependant module full path including the module itself.
276 # backwards compatible, process $mode
278 if [ "$mode" = silent ]; then
279 modfile=$(modinfo -n $module 2>/dev/null)
281 modfile=$(modinfo -n $module)
283 if [ ! -f "$modfile" ]; then
284 if [ "$mode" != silent ]; then
285 warn "$module: module not found for $kernel kernel"
287 if ! is_no "$EXIT_IF_MISSING"; then
290 warn "If $module isn't compiled in kernel then this initrd may not start your system."
294 # This works when user has module-init-tools installed even on 2.4 kernels
295 modprobe --set-version $kernel --show-depends $module | \
296 while read insmod modpath; do
302 typeset mods module f level depfile first
304 depfile=/lib/modules/$kernel/modules.dep
306 if [ ! -f $depfile ]; then
307 die "No $depfile! Run depmod and rerun $PROGRAM."
310 # prepend / if no path given, append $modext.gz if not given,
313 module=$(echo "$2" | \
314 awk '/\// {print;next} {print "/" $0}' | \
315 awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
316 awk '{gsub("/","\\/");print}')
319 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
321 /(.*)/ { gsub(/\\/," "); if (here) print }
324 # fallback to $modext
325 if [ "$mods" = "" ]; then
326 module=$(echo "$module" | awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
332 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
334 /(.*)/ { gsub(/\\/," "); if (here) print }
337 if [ "$mods" = "" ]; then
338 if [ "$1" != silent ]; then
339 warn "$origmodule: module not found in $depfile"
341 if ! is_no "$EXIT_IF_MISSING"; then
344 warn "If $origmodule isn't compiled in kernel then this initrd may not start your system."
349 if [ "$level" = "" ]; then
353 if [ $level -gt 20 ]; then
354 die "$origmodule: cycle in $depfile"
359 if [ "$first" = "" ]; then
362 find_depmod $1 $f $level
373 if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
374 if [ -n "$skiperrors" ]; then
375 # XXX should not ignore here errors
379 die "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)"
382 # only need to add each module once
384 for m in $MODULES; do
385 [ $m = $fmPath ] && have=1
387 if [ $have = 0 ]; then
388 MODULES="$MODULES $fmPath"
396 if [ ${modName#-} != ${modName} ]; then
402 if [ "$modName" = "pluto" ]; then
406 if [ "$modName" = "fcal" ]; then
411 local mod allModulesToFind
412 if [ "$skiperrors" = 1 ]; then
413 allModulesToFind=$(find_depmod silent $modName)
415 allModulesToFind=$(find_depmod normal $modName)
421 for mod in $allModulesToFind; do
422 mod=${mod#/lib/modules/$kernel/}
423 addmodule $mod "$skiperrors"
427 # install a file to temporary mount image.
428 # it will operate recursively (copying directories)
429 # and will symlink destinations if source is symlink.
431 if [ $# -lt 2 ]; then
432 die 'Usage: inst <file> [<file>] <destination>'
435 local src i=0 c=$(($# - 1))
436 while [ $i -lt $c ]; do
444 debug "+ cp $* $DESTDIR$dest"
445 cp -HR "$@" "$DESTDIR$dest"
450 die 'Usage: inst_d <destination> <destination>'
453 install -d "$DESTDIR$dir"
457 # install executable and it's shared libraries
459 if [ $# -lt 2 ]; then
460 die 'Usage: inst_exec <file> [, <file>] <destination>'
462 local src i=0 c=$(($# - 1))
463 while [ $i -lt $c ]; do
473 local lib libs=$(ldd "$@" | awk '/statically|linux-gate\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
475 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
477 inst_exec $lib /$_lib
482 # output modules.conf / modprobe.conf
484 echo "$modprobe_conf_cache"
488 # defaults to modprobe -c if not told otherwise, this means include statements
490 cache_modprobe_conf() {
491 if [ "$pack_version" -lt "002005" ]; then
492 modulefile=/etc/modules.conf
493 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
494 modulefile=/etc/conf.modules
498 if [ -n "$modulefile" ]; then
499 debug "Using $modulefile for modules config"
500 modprobe_conf_cache=$(cat $modulefile)
502 debug "Using modprobe -c to get modules config"
503 modprobe_conf_cache=$(modprobe -c)
508 local found raidlevel
510 if [ -f /etc/mdadm.conf ]; then
511 debug "Finding RAID details using mdadm for rootdev=$1"
512 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
517 rootdev_devfs = rootdev;
518 if (rootdev ~ /\/dev\/md\/[0-9]/) {
519 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
524 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
526 gsub(/level=/,NUL,raidlevel);
527 if (raidlevel ~ /^raid([0-6]|10)/) {
528 gsub(/raid/,NUL,raidlevel);
532 if (x ~ /devices=/) {
534 gsub(".*devices=", NUL, dev_list);
535 gsub(",", " ", dev_list);
541 print "have_md=" found;
542 print "raidlevel=" raidlevel;
543 print "dev_list=\"" dev_list "\"";
547 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
548 die "raidtools are not longer supported. Please migrate to mdadm setup!"
551 if is_yes "$have_md"; then
554 findmodule "raid$raidlevel"
557 findmodule "-raid$raidlevel"
558 findmodule "-raid456"
564 warn "raid level $number (in mdadm config) not recognized"
568 die "RAID devices not found for \"$1\", check your configuration!"
571 rootdev_nr=$(( $rootdev_nr + 1 ))
572 eval "rootdev${rootdev_nr}=\"$1\""
573 eval "dev_list${rootdev_nr}=\"${dev_list}\""
575 for device in $dev_list; do
576 find_modules_for_devpath $device
580 find_modules_scsi() {
582 for n in $PRESCSIMODS; do
583 if [ "X$n" = "Xunknown" ]; then
584 debug "Finding SCSI modules using scsi_hostadapter"
585 local mod scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
586 for mod in $scsimodules; do
587 # for now allow scsi modules to come from anywhere. There are some
588 # RAID controllers with drivers in block
595 findmodule "-scsi_wait_scan"
600 # remove partition, if any
601 local disk=${devpath%[0-9]*}
602 # set blockdev for rootfs (hda, sdc, ...)
603 local rootblkdev=${disk#/dev/}
606 if [ "$pack_version_long" -lt "002004021" ]; then
607 debug "Finding IDE modules for kernels <= 2.4.20"
608 for n in $PREIDEMODSOLD; do
613 for n in $PREIDEMODS; do
614 if [ "X$n" = "Xunknown" ]; then
615 debug "Finding IDE modules using ide_hostadapter"
616 local mod idemodules=$(modprobe_conf | awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
617 for mod in $idemodules; do
622 if [ "$tryauto" -eq 1 ]; then
624 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
625 debug "Finding IDE modules using PCI ID database"
626 # Finding IDE modules using PCI ID database {{{
627 if is_yes "${ide_only_root}"; then
628 if [ -f /sys/block/${rootblkdev}/device/../../vendor -a -f /sys/block/${rootblkdev}/device/../../device ]; then
629 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../vendor)"
630 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../device)"
631 searchpciid="${vendorid}${deviceid}"
632 elif [ -f /proc/ide/${rootblkdev}/../config ]; then
633 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootblkdev}/../config)"
637 if [ -z "${searchpciid}" ]; then
638 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
643 for nb in $searchpciid; do
644 eval `awk -v pciid="$nb" '{
650 compmod = $1 ""; # make sure comparison type will be string
651 # cause pci IDs are hexadecimal numeric
652 if (compmod == pciid) {
654 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
661 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
662 }' /usr/share/pci-database/ide.pci`
663 [ -n "$module" ] && idemodules="$idemodules $module"
665 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
667 for nc in idemodules; do
668 new_idemodules="$nc $new_idemodules"
670 idemodules="${new_idemodules}"
673 if [ -z "$idemodules" ]; then
674 echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic."
675 idemodules="ide-generic"
679 for nd in $idemodules; do
685 [ -r /usr/share/pci-database/ide.pci ] || echo "WARNING: /usr/share/pci-database/ide.pci missing."
686 [ -r /proc/bus/pci/devices ] || echo "WARNING: /proc/bus/pci/devices missing."
687 echo "Automatic IDE modules finding not available."
698 # return true if node is lvm node
701 if [ ! -e "$node" ]; then
702 warn "WARNING: check_lvm(): node $node doesn't exist!"
706 # block-major-58 is lvm1
707 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
711 debug "LVM check: $node is LVM v1 node"
716 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
718 if [ $rc -gt 127 ]; then
719 # lvdisplay terminated by signal! most likely it segfaulted.
720 die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
724 debug "LVM check: $node is LVM v2 node"
726 debug "LVM check: $node is not any LVM node"
731 # return dependencies MAJOR:MINOR [MAJOR:MINOR] for DM_NAME
732 # TODO: patch `dmsetup export`
735 dmsetup deps $dm_name | sed -e 's/, /:/g;s/^.\+ dependencies[^:]: //;s/[()]//g;'
738 # export info from dmsetup
742 # - /dev/mapper/DM_NAME
748 local maj=${arg%:*} min=${arg#*:}
749 dmsetup -j $maj -m $min export
752 local min=${arg#*dm-}
753 local maj=$(awk '$2 == "device-mapper" {print $1}' /proc/devices)
757 local dm_name=${arg#/dev/mapper/}
758 dmsetup export $dm_name
761 die "dm_export: unexpected $arg"
766 # find dm-multipath modules for $devpath
767 # returns false if $devpath is not dm-multipath
768 find_modules_multipath() {
772 eval $(dm_export "$devpath")
773 if [ -z "$DM_NAME" ]; then
774 die "dm_export failed unexpectedly"
779 # DM_UUID=part1-mpath-36006016002c11800a0aa05fbfae0db11
782 # DM_UUID=mpath-36006016002c11800a0aa05fbfae0db11
783 MPATH_WWID=${DM_UUID##*-}
785 local info=$(multipath -l $MPATH_WWID)
786 if [ -z "$info" ]; then
790 debug "Finding modules for dm-multipath (WWID=$MPATH_WWID)"
792 local dev phydevs=$(echo "$info" | awk '$2 ~ /^[0-9]+:[0-9]+:[0-9]+:[0-9]+$/{printf("/dev/%s\n", $3)}')
793 for dev in $phydevs; do
794 find_modules_for_devpath $dev
795 lvm_ignore_devices="$lvm_ignore_devices $dev"
798 local hw hwhandlers=$(echo "$info" | awk '/hwhandler=1/{sub(/.*hwhandler=1 /, ""); sub(/\]$/, ""); print}')
799 for hw in $hwhandlers; do
803 local target targets=$(echo "$info" | awk '/prio=/{print $2}' | sort -u)
804 for target in $targets; do
805 findmodule "dm-$target"
812 # find dmraid modules for $devpath
813 # returns false if $devpath is not on dmraid
814 find_modules_dmraid() {
817 # get blockdev itself (without partition)
818 # /dev/mapper/sil_ahbgadcbchfc3 -> /dev/mapper/sil_ahbgadcbchfc
819 local blockdev=${devpath%%[0-9]*}
820 local raidname=${blockdev#/dev/mapper/}
823 local dev phydevs=$(dmraid -r -cdevpath,raidname | awk -F, -vv="$raidname" '{if ($2 == v) print $1}')
824 for dev in $phydevs; do
825 find_modules_for_devpath $dev
826 lvm_ignore_devices="$lvm_ignore_devices $dev"
830 if [ $found = 0 ]; then
834 findmodule "dm-mirror"
839 # find modules for $devpath
840 find_modules_for_devpath() {
842 if [ -z "$devpath" ]; then
843 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
846 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
849 devpath=$(dm_longname "$devpath")
852 debug "Finding modules for device path $devpath"
854 if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
855 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
856 die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
859 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
860 for m in $NFS_ETH_MODULES; do
866 warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
867 warn "or you will have problems like init(xx) being child process of swapper(1)."
871 if [[ "$devpath" == /dev/md* ]]; then
872 find_modules_md "$devpath"
876 if is_yes "$USE_MULTIPATH" && [[ "$devpath" == /dev/mapper/* ]]; then
877 if find_modules_multipath "$devpath"; then
883 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
884 if find_modules_dmraid "$devpath"; then
890 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
895 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }')"; then
896 find_modules_ide "$devpath"
900 if [[ "$devpath" == /dev/rd/* ]]; then
905 if [[ "$devpath" == /dev/ida/* ]]; then
906 findmodule "cpqarray"
910 if [[ "$devpath" == /dev/ccis/* ]]; then
915 if [[ "$devpath" == /dev/ataraid/* ]]; then
918 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
919 if [ -n "$ataraidmodules" ]; then
920 # FIXME: think about modules compiled in kernel
921 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
923 for n in $ataraidmodules; do
929 # check to see if we need to set up a loopback filesystem
930 if [[ "$devpath" == /dev/loop* ]]; then
931 die "Sorry, root on loop device isn't supported."
932 # TODO: rewrite for bsp and make nfs ready
933 if [ ! -x /sbin/losetup ]; then
934 die "losetup is missing"
936 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
937 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
938 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"
941 line="`awk '/'$key'/ { print $0; }' $fstab`"
942 loopDev="$(echo $line | awk '{print $3}')"
943 loopFs="$(echo $line | awk '{print $4}')"
944 loopFile="$(echo $line | awk '{print $5}')"
946 BASICMODULES="$BASICMODULES -loop"
947 findmodule "-$loopFs"
948 BASICMODULES="$BASICMODULES -${loopFs}"
952 if _check_lvm "$devpath"; then
955 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then
956 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."
958 if [ -z "$LVMTOOLSVERSION" ]; then
959 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}')
960 if [ -z "$LVMTOOLSVERSION" ]; then
961 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
964 if [ -z "$PVDEVICES" ]; then
965 VGVOLUME=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
966 PVDEVICES=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
968 if [ -n "$PVDEVICES" ]; then
969 for device in $PVDEVICES; do
970 find_modules_for_devpath $device
973 die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
975 if [ "$LVMTOOLSVERSION" = "2" ]; then
977 elif [ "$LVMTOOLSVERSION" = "1" ]; then
979 findmodule "-lvm-mod"
981 die "LVM version $LVMTOOLSVERSION is not supported yet."
983 debug "LVM v$LVMTOOLSVERSION enabled"
989 firmware_install_module() {
991 local firmware_files="$2"
993 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
994 # firmware not yet installed
995 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
997 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
999 echo 1 > /sys$DEVPATH/loading
1000 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
1001 echo 0 > /sys$DEVPATH/loading
1004 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
1007 for firmware in $firmware_files; do
1008 inst /lib/firmware/$firmware /lib/firmware/$firmware
1012 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
1019 for mod in $modules; do
1020 MODULEDIR=$(dirname "$mod")
1021 inst_d "/lib/modules/$kernel/$MODULEDIR"
1022 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
1023 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
1027 modules_add_linuxrc() {
1031 for mod in $modules; do
1032 MODULE2="`dirname "$mod"`"
1033 NAME2=`basename "$mod" .gz`
1034 MODULE2=$MODULE2/$NAME2
1035 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
1036 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}')
1038 generic_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ')
1039 sleep_var="$(eval echo \$MODULE_${generic_module}_USLEEP)"
1040 firmware_var="$(eval echo \$MODULE_${generic_module}_FIRMWARE)"
1042 if [ -n "$verbose" ]; then
1043 warn "Loading module [$module]${options:+ with options [$options]}${options:- without options}${sleep_var:+ and $sleep_var usleep}."
1046 if [ -n "$firmware_var" ]; then
1047 firmware_install_module "$module" "$firmware_var"
1049 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" | add_linuxrc
1050 if [ -n "${sleep_var}" ]; then
1051 echo "usleep $sleep_var" | add_linuxrc
1056 initrd_gen_suspend() {
1057 if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then
1058 die "/usr/${_lib}/suspend/resume is missing!"
1060 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
1061 mknod $DESTDIR/dev/snapshot c 10 231
1062 inst $resume_dev /dev
1063 inst /etc/suspend.conf /etc/suspend.conf
1064 if [ -x /usr/${_lib}/suspend/resume ]; then
1065 inst /usr/${_lib}/suspend/resume /bin/resume
1067 inst /usr/sbin/resume /bin/resume
1070 add_linuxrc <<-'EOF'
1075 initrd_gen_tuxonice() {
1077 add_linuxrc <<-'EOF'
1079 for arg in $CMDLINE; do
1080 if [ "${arg##resume2=}" != "${arg}" ]; then
1084 if [ "$resume2" = "yes" ]; then
1085 [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
1086 [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
1087 [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
1093 debug "Setting up udev..."
1094 inst_d /sbin /etc/udev
1096 if [ ! -x /sbin/initrd-udevd ]; then
1097 die "/sbin/initrd-udevd not present"
1100 inst /sbin/initrd-udevd /sbin/udevd
1101 inst /etc/udev/udev.conf /etc/udev/udev.conf
1105 add_linuxrc <<-'EOF'
1107 /sbin/udevd --daemon
1109 if is_yes "$PROBESTATICMODS"; then
1110 inst /sbin/initrd-udevtrigger /sbin/udevtrigger
1111 inst /sbin/initrd-udevsettle /sbin/udevsettle
1112 add_linuxrc <<-'EOF'
1118 busybox_applet killall
1119 add_linuxrc <<-'EOF'
1124 initrd_gen_multipath() {
1125 inst_d /sbin /lib/udev /etc/multipath
1126 inst_exec /sbin/kpartx /sbin
1127 inst_exec /sbin/multipath /sbin
1129 inst_exec /sbin/scsi_id /lib/udev
1130 inst_exec /sbin/mpath* /sbin
1131 egrep -v '^([ ]*$|#)' /etc/multipath.conf > $DESTDIR/etc/multipath.conf
1133 if [ -f /etc/multipath/bindings ]; then
1134 egrep -v '^([ ]*$|#)' /etc/multipath/bindings > $DESTDIR/etc/multipath/bindings
1136 touch $DESTDIR/etc/multipath/bindings
1143 echo "export MPATH_WWID=$MPATH_WWID" | add_linuxrc
1144 add_linuxrc <<-'EOF'
1145 # parse mpath_wwid= from kernel commandline
1146 for arg in $CMDLINE; do
1147 if [ "${arg##mpath_wwid=}" != "${arg}" ]; then
1148 MPATH_WWID=${arg##mpath_wwid=}
1149 if [ "$MPATH_WWID" = "*" ]; then
1150 # '*' would mean activate all WWID-s
1152 echo "multipath: Activating all WWID-s"
1154 echo "multipath: Activating WWID=$WWID"
1160 /sbin/multipath -v 0 $MPATH_WWID
1162 for a in /dev/mapper/*; do
1163 [ $a = /dev/mapper/control ] && continue
1164 /sbin/kpartx -a -p p $a
1170 initrd_gen_dmraid() {
1171 if [ ! -x /sbin/dmraid-initrd ]; then
1172 die "/sbin/dmraid-initrd is missing!"
1176 inst /sbin/dmraid-initrd /sbin/dmraid
1182 # 2 secs was enough for my system to initialize. but really this is udev issue?
1184 : 'Activating Device-Mapper RAID(s)'
1191 initrd_gen_bootsplash() {
1194 debug "Generating bootsplash"
1196 if [ "$INITRDFS" != "initramfs" ]; then
1197 warn "Using bootsplash requires INITRDFS=initramfs; skipping bootsplash generation"
1201 if [ ! -x /bin/splash.bin ]; then
1202 warn "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
1206 if [ -r /etc/sysconfig/bootsplash ]; then
1207 . /etc/sysconfig/bootsplash
1210 if [ -z "$THEME" ]; then
1211 warn "Please configure your /etc/sysconfig/bootsplash first."
1212 warn "Generating bootsplashes skipped."
1216 if [ -z "$BOOT_SPLASH_RESOLUTIONS" ]; then
1217 warn "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
1218 warn "Not adding bootsplash to initrd."
1221 for res in $BOOT_SPLASH_RESOLUTIONS; do
1222 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1223 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1224 debug "Added $res $THEME theme to initrd."
1226 warn "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
1231 initrd_gen_fbsplash() {
1232 debug "Generating fbsplash"
1234 if [ "$INITRDFS" != "initramfs" ]; then
1235 warn "Using fbsplash requires INITRDFS=initramfs; skipping fbsplash generation"
1239 if [ ! -x /usr/bin/splash_geninitramfs ]; then
1240 warn "Failed to execute /usr/bin/splash_geninitramfs. Is splashutils package installed?"
1244 if [ -r /etc/sysconfig/fbsplash ]; then
1245 . /etc/sysconfig/fbsplash
1248 if [ -z "$SPLASH_THEME" ]; then
1249 warn "Please configure your /etc/sysconfig/fbsplash first."
1250 warn "Generating fbsplashes skipped."
1254 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1255 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
1256 warn "Not adding fbsplash to initramfs."
1260 for res in $FB_SPLASH_RESOLUTIONS; do
1261 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1262 /usr/bin/splash_geninitramfs -c $DESTDIR -r $res $SPLASH_THEME && \
1263 debug "Added $res $SPLASH_THEME theme to initramfs."
1265 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1270 # Generates /dev nodes based on /proc/partitions information.
1271 # Needs /proc mounted.
1272 # Can be called multiple times.
1273 initrd_gen_devices() {
1274 if is_yes "$proc_partitions"; then
1280 add_linuxrc <<-'EOF'
1281 : 'Making device nodes'
1282 cat /proc/partitions | (
1283 # ignore first two lines, header, empty line and process rest
1286 while read major minor blocks dev rest; do
1289 mknod $node b $major $minor
1296 debug "Setting up mdadm..."
1298 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1299 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
1302 inst /sbin/initrd-mdassemble /bin/mdassemble
1305 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf)
1306 for ex_dev in $dev_list_extra; do
1307 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
1310 for nr in `seq 1 $rootdev_nr`; do
1311 eval cr_rootdev="\$rootdev${nr}"
1312 eval cr_dev_list="\$dev_list${nr}"
1313 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1315 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1317 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
1318 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1319 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
1320 if [ -n "$cr_md_conf" ]; then
1321 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
1323 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
1326 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1327 # mkdir in case of devfs name
1328 inst_d $(dirname $f)
1329 [ -e "$DESTDIR/$f" ] && continue
1330 # this works fine with and without devfs
1335 echo "mdassemble" | add_linuxrc
1337 # needed to determine md-version
1338 if [ "$do_md0" -eq 1 ]; then
1339 mknod $DESTDIR/dev/md0 b 9 0
1344 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1345 # have problems like init(XX) being child process of swapper(1).
1346 debug "Adding rootfs on NFS support to initrd (dhcp)"
1347 mknod "$DESTDIR/dev/urandom" c 1 9
1348 mkdir "$DESTDIR/newroot"
1349 mkdir "$DESTDIR/proc"
1350 echo "ifconfig lo 127.0.0.1 up" | add_linuxrc
1351 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" | add_linuxrc
1352 echo "ifconfig eth0 0.0.0.0 up" | add_linuxrc
1353 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" | add_linuxrc
1355 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
1357 [ "$1" != "bound" ] && exit
1358 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1359 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1360 ifconfig $interface $ip $BROADCAST $NETMASK up
1361 if [ -n "$router" ]; then
1362 for r in $router; do
1363 route add default gw $r dev $interface
1368 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
1369 for o in $CMDLINE; do
1372 rootpath=${o#nfsroot=}
1377 if [ -n "$rootpath" ]; then
1378 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1380 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1381 echo "All seen variables are listed below:"
1386 chmod 755 "$DESTDIR/bin/setdhcp"
1387 add_linuxrc <<-'EOF'
1390 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1391 exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1396 debug "Adding LVM support to initrd"
1397 inst_d /tmp /newroot
1398 inst /sbin/initrd-lvm /bin/lvm.static
1400 # always make /dev on tmpfs for LVM2
1401 if [ "$LVMTOOLSVERSION" = "2" ]; then
1405 if ! is_yes "$dev_mounted"; then
1407 mknod $DESTDIR/dev/mapper/control c 10 63
1408 for device in $PVDEVICES; do
1409 # if LVM on RAID then device might be copied already in gen_md
1410 [ -e "$DESTDIR/dev/$(basename $device)" ] && continue
1416 if [ "$LVMTOOLSVERSION" = "1" ]; then
1419 lvm vgchange -T -a y $VGVOLUME
1422 echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
1423 echo "global {" > "$DESTDIR/etc/lvm.conf"
1424 echo " locking_type = 0" >> "$DESTDIR/etc/lvm.conf"
1425 echo " locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf"
1426 echo "}" >> "$DESTDIR/etc/lvm.conf"
1427 echo "devices {" >> "$DESTDIR/etc/lvm.conf"
1428 echo " sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf"
1429 if is_yes "$have_md"; then
1430 echo " md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf"
1432 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
1433 echo ' types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf"
1435 if [ "$lvm_ignore_devices" ]; then
1436 # TODO: think of merging with lvm dumpconfig output
1437 echo ' filter = [' >> "$DESTDIR/etc/lvm.conf"
1439 for dev in $lvm_ignore_devices; do
1440 debug "LVM v2: ignore device $dev"
1441 printf ' "r|^%s.*|",\n' $dev
1442 done >> "$DESTDIR/etc/lvm.conf"
1443 echo ']' >> "$DESTDIR/etc/lvm.conf"
1445 # XXX filter= must be on one line!
1446 lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf"
1447 echo "}" >> "$DESTDIR/etc/lvm.conf"
1452 export ROOTDEV=$rootdev
1453 export VGVOLUME=$VGVOLUME
1455 add_linuxrc <<-'EOF'
1456 # parse rootdev from kernel commandline
1457 for arg in $CMDLINE; do
1458 if [ "${arg##root=}" != "${arg}" ]; then
1459 local rdev=${arg##root=}
1460 if [ "$rdev" != "$ROOTDEV" ]; then
1462 echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
1463 local tmp=${ROOTDEV#/dev/}
1464 if [ "$tmp" != "$ROOTDEV" ]; then
1466 echo "LVM: Using Volume Group '$VGVOLUME'"
1472 # disable noise from LVM accessing devices that aren't ready.
1473 read printk < /proc/sys/kernel/printk
1474 echo 0 > /proc/sys/kernel/printk
1476 export LVM_SYSTEM_DIR=/tmp
1477 : 'Scanning for Volume Groups'
1478 lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null
1480 : 'Activating Volume Groups'
1481 lvm.static vgchange --ignorelockingfailure -a y $VGVOLUME 2>/dev/null
1483 echo "$printk" > /proc/sys/kernel/printk
1485 # Find out major/minor
1486 attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $ROOTDEV 2>/dev/null)"
1487 if [ "$attrs" ]; then
1488 majmin="${attrs#*$ROOTDEV*:*:*:*:*:*:*:*:*:*:*:*}"
1489 if [ "$majmin" != "$attrs" ]; then
1490 major="${majmin%:*}"
1491 minor="${majmin#*:}"
1495 if [ "$major" -a "$minor" ]; then
1497 echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev
1499 echo 2>&1 "Error figuring out real root device for $ROOTDEV!"
1500 echo 2>&1 "System will not most likely boot up! So dropping you to a shell!"
1508 initrd_gen_procdata() {
1509 debug "Adding rootfs finding based on kernel cmdline root= option support."
1510 add_linuxrc <<-'EOF'
1511 root="$(echo "$CMDLINE" | busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ')"
1512 if [ -n "$root" ]; then
1513 rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)"
1514 if [ -n "$rootnr" ]; then
1515 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1522 if [ "$(id -u)" != 0 ]; then
1523 die "You need to be root to generate initrd"
1526 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
1528 . /etc/udev/udev.conf
1531 if [ -x /sbin/dmraid-initrd ]; then
1535 if [ -x /sbin/multipath ]; then
1539 if [ -r /etc/sysconfig/geninitrd ]; then
1540 . /etc/sysconfig/geninitrd
1543 if [ ! -x /bin/initrd-busybox ]; then
1544 die "/bin/initrd-busybox is missing!"
1547 # backwards compatible
1548 if [ "$USE_SUSPEND2" ]; then
1549 USE_TUXONICE=$USE_SUSPEND2
1550 warn "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
1553 while [ $# -gt 0 ]; do
1563 modulefile=${1#--modules-conf=}
1569 --use-raidstart|--with-raidstart)
1572 --without-raidstart)
1575 --use-insmod-static|--with-insmod-static)
1578 --without-insmod-static)
1584 --without-bootsplash)
1599 --with-suspend2 | --with-tuxonice)
1602 --without-suspend2 | --without-tuxonice)
1605 --lvmtoolsversion=|--lvmversion=)
1606 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
1608 --lvmtoolsversion|--lvmversion)
1621 --without-multipath)
1625 BASICMODULES="$BASICMODULES ${1#--with=}"
1628 BASICMODULES="$BASICMODULES $2"
1632 echo "$PROGRAM: version $VERSION"
1648 PREMODS="$PREMODS ${1#--preload=}"
1651 PREMODS="$PREMODS $2"
1655 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1659 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1664 INITRDFS=${1#--initrdfs=}
1677 if [ -z "$target" ]; then
1679 elif [ -z "$kernel" ]; then
1690 if [ -z "$target" -o -z "$kernel" ]; then
1694 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1695 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1698 pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
1699 pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
1701 if [ -z "$INITRDFS" ]; then
1702 if [ -z "$FS" ]; then
1704 if [ "$pack_version" -ge "002005" ]; then
1705 INITRDFS="initramfs"
1710 warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
1715 if [ "$pack_version" -lt "002006" ]; then
1720 if [ "$pack_version" -ge "002005" ]; then
1725 if is_yes "$USEINSMODSTATIC"; then
1726 insmod="insmod.static"
1727 INSMOD="/sbin/insmod.static"
1728 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
1729 INSMOD="/sbin/insmod.static.modutils"
1731 if [ ! -f "$INSMOD" ]; then
1732 die "insmod.static requested but /sbin/insmod.static not found!"
1738 if [ ! -x /sbin/mke2fs ]; then
1739 die "/sbin/mke2fs is missing"
1743 if [ ! -x /sbin/genromfs ]; then
1744 die "/sbin/genromfs is missing"
1748 if [ ! -x /sbin/mkcramfs ]; then
1749 die "/sbin/mkcramfs is missing"
1753 if [ ! -x /bin/cpio ]; then
1754 die "/bin/cpio is missing"
1756 if [ ! -x /usr/bin/find ]; then
1757 die "/usr/bin/find is missing"
1761 die "Filesystem $INITRDFS on initrd is not supported"
1765 if [ -n "$img_vers" ]; then
1766 target="$target-$kernel"
1769 if [ -z "$force" -a -f "$target" ]; then
1770 die "$target already exists."
1773 if [ ! -d "/lib/modules/$kernel" ]; then
1774 die "/lib/modules/$kernel is not a directory."
1777 if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
1778 warn "Tuxonice can't be used in parallel with mainline suspend! Disabling both inclustion to initrd"
1783 if is_yes "$FB_SPLASH" && is_yes "$BOOT_SPLASH"; then
1784 warn "You can't use bootsplash and fbsplash together! Disabling both inclusion to initrd"
1789 if [ ! -f /proc/mounts ]; then
1790 warn "WARNING: /proc filesystem not mounted, may cause wrong results or failure."
1793 if [ -d /usr/lib64 ]; then
1798 debug "Using libdir: $_lib"
1802 for n in $PREMODS; do
1806 # allow forcing loading SCSI and/or IDE modules
1807 if is_yes "$ADDSCSI"; then
1811 if is_yes "$ADDIDE"; then
1815 find_root "$fstab" || exit
1816 debug "Using $rootdev as device for rootfs"
1818 find_modules_for_devpath "$rootdev"
1819 [ -n "$rootdev_add" ] && find_modules_for_devpath "$rootdev_add"
1821 findmodule "-$rootFs"
1823 for n in $BASICMODULES; do
1827 if is_yes "$USE_TUXONICE"; then
1831 if is_yes "$FB_SPLASH"; then
1835 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1836 debug "No modules are needed -- not building initrd image."
1840 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
1841 RCFILE="$DESTDIR/linuxrc"
1843 chmod a+rx "$RCFILE"
1844 ln -s linuxrc $DESTDIR/init
1846 # create dirs that we really need
1847 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
1849 modules_install "$MODULES"
1851 # mknod'ing the devices instead of copying them works both with and
1853 mknod "$DESTDIR/dev/console" c 5 1
1854 mknod "$DESTDIR/dev/null" c 1 3
1855 mknod "$DESTDIR/dev/zero" c 1 5
1857 inst /bin/initrd-busybox /bin/initrd-busybox
1858 ln -s initrd-busybox $DESTDIR/bin/sh
1859 ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
1861 if is_yes "$USEINSMODSTATIC"; then
1862 inst "$INSMOD" /bin/insmod.static
1867 # initrd generated by:
1872 add_linuxrc <<-'EOF'
1873 read CMDLINE < /proc/cmdline; export CMDLINE
1875 for arg in $CMDLINE; do
1876 if [ "${arg}" = "debuginitrd" ]; then
1879 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1880 DEBUGINITRD=${arg##debuginitrd=}
1884 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1885 if [ "$DEBUGINITRD" = "sh" ]; then
1895 if [ "$DEBUGINITRD" ]; then
1900 modules_add_linuxrc "$MODULES"
1902 # TODO: rewrite for busybox
1903 #if [ -n "$loopDev" ]; then
1904 # if [ ! -d /initrd ]; then
1908 # cp -a "$loopDev" "$DESTDIR/dev"
1909 # cp -a "$rootdev" "$DESTDIR/dev"
1910 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1911 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1912 # echo "echo Setting up loopback device $rootdev" >> $RCFILE
1913 # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1916 if is_yes "$USE_UDEV"; then
1920 if is_yes "$USE_SUSPEND"; then
1924 if is_yes "$USE_TUXONICE"; then
1928 if is_yes "$have_dmraid" ]; then
1932 if is_yes "$have_multipath"; then
1933 initrd_gen_multipath
1936 if is_yes "$have_nfs"; then
1938 elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
1940 if is_yes "$have_lvm"; then
1945 elif is_yes "$have_lvm"; then
1951 # additional devs always needed
1952 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
1954 if [ "$INITRDFS" = "initramfs" ]; then
1956 if [ "$rootdev" = "/dev/nfs" ]; then
1957 echo "rootfs on NFS root=/dev/nfs"
1959 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev /dev
1961 # Parsing root parameter
1962 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
1963 add_linuxrc <<-'EOF'
1964 eval "$(busybox awk -v c="$CMDLINE" '
1966 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
1967 num_pattern = "[0-9a-f]" num_pattern_short;
1968 dev_pattern = "[hms][a-z][a-z]([0-9])+";
1969 partition = "no_partition_found";
1972 gsub(/.*root=/,NIL,c);
1976 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
1977 if (c ~ "^" num_pattern "$") {
1978 maj = sprintf("%s",substr(c,1,2));
1979 min = sprintf("%s",substr(c,3));
1981 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
1982 if (c ~ "^" dev_pattern "$") partition = c;
1985 $4 ~ partition { maj = $1; min = $2; }
1986 $1 ~ maj && $2 ~ min { partition = $4; }
1989 print sprintf("device=/dev/%s\nmaj=%s\nmin=%s",
1990 partition, maj, min);
1992 ' /proc/partitions)"
1993 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
1994 mknod $device b $maj $min
2003 add_linuxrc <<-'EOF'
2004 if [ "$device" = '/dev/no_partition_found' ]; then
2008 mount -t $rootfs -r $device /newroot
2009 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
2010 if [ -z "$init" -o ! -x "/newroot$init" ]; then
2016 busybox_applet switch_root
2017 add_linuxrc <<-'EOF'
2018 exec switch_root /newroot $init
2020 echo "Error! initramfs should not reach this place."
2021 echo "It probably means you've got old version of busybox, with broken"
2022 echo "initramfs support. Trying to boot anyway, but won't promise anything."
2024 exec chroot /newroot $init
2026 echo "Failed to chroot!"
2028 # we need /init being real file, not symlink, otherwise the initramfs will
2029 # not be ran by pid 1 which is required for switch_root
2030 mv $DESTDIR/linuxrc $DESTDIR/init
2031 ln -s init $DESTDIR/linuxrc
2033 # other than initramfs
2037 if is_yes "$FB_SPLASH"; then
2041 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
2044 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
2045 debug "ext2 image size: $IMAGESIZE ($DESTDIR)"
2046 if [ "$IMAGESIZE" -gt 4096 ]; then
2047 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
2050 debug "Creating ext2 image $IMAGE"
2051 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
2052 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
2053 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
2055 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
2056 debug "Mounting ext2 image $IMAGE to $tmpmnt"
2057 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
2058 # We don't need this directory, so let's save space
2059 rm -rf "$tmpmnt"/lost+found
2061 debug "Copy recursively $DESTDIR -> $tmpmnt"
2062 cp -a $DESTDIR/* $tmpmnt
2068 debug "Generating romfs image: $IMAGE"
2069 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
2070 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
2071 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
2072 if [ "$IMAGESIZE" -gt 4096 ]; then
2073 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
2077 mkcramfs "$DESTDIR" "$IMAGE"
2080 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
2083 echo "Filesystem $INITRDFS not supported by $PROGRAM";
2086 if is_yes "$COMPRESS"; then
2087 local tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
2088 debug "Compressing $target"
2089 gzip -9 < "$IMAGE" > "$tmp"
2090 mv -f "$tmp" "$target"
2092 cp -a "$IMAGE" "$target"
2095 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
2096 if is_yes "$BOOT_SPLASH"; then
2097 initrd_gen_bootsplash "$target"
2100 rm -rf "$DESTDIR" "$IMAGE"
2102 # vim:ts=4:sw=4:noet:fdm=marker