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"
40 # device node for rootfs from fstab
42 # requires bootsplash package to operate
44 # requires splashutils package to operate
46 # requires splashutils package to operate
56 # is /tmp mounted on tmpfs
59 # are /dev nodes already created from /proc/devices info?
62 # LVM devices that should not be included in vgscan on initrd
65 # whether v86d should be installed
68 # LVM volumes that are needed to activate
71 # VG for suspend resume dev
77 # if we should init NFS at boot
79 # if we should init LVM at boot
81 # if we should init md (softraid) at boot
86 echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
87 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
88 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
89 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
90 echo " [--with-bootsplash] [--without-bootsplash]"
91 echo " [--with-fbsplash] [--without-fbsplash]"
92 echo " [--with-fbcondecor] [--without-fbcondecor]"
93 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
94 echo " [--with-suspend] [--without-suspend]"
95 echo " [--with-tuxonice] [--without-tuxonice]"
96 echo " [--without-dmraid] [--without-multipath]"
97 echo " [--without-blkid] [--without-luks]"
98 echo " <initrd-image> <kernel-version>"
101 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
110 msg "WARNING: $*" >&2
114 [ -n "$verbose" ] && msg "$*" >&2
117 # aborts program abnormally
124 # append text to /linuxrc
125 # takes STDIN as input
130 # generate code to mount /dev on tmpfs and create initial nodes
131 # can be called multiple times. /dev is cleaned up (umounted) automatically at
134 if [ "$INITRDFS" = "initramfs" ]; then
135 # initramfs is read-write filesystem, no need for tmpfs
139 # we already generated tmpfs code; return
140 if is_yes "$dev_mounted"; then
146 busybox_applet mount mknod mkdir
149 mount -o mode=0755 -t tmpfs none /dev
150 mknod /dev/console c 5 1
151 mknod /dev/null c 1 3
152 mknod /dev/zero c 1 5
158 # generate code to mount /proc on initrd
159 # can be called multiple times
161 if is_yes "$proc_mounted"; then
166 if [ "$INITRDFS" = "initramfs" ]; then
167 # /proc is mounted with initramfs 2.6.22.14 kernel
168 # XXX: remove when it is clear why proc was already mounted
169 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
171 echo "mount -t proc none /proc" | add_linuxrc
175 # generate code to mount /sys on initrd
176 # can be called multiple times
178 if is_yes "$sys_mounted"; then
183 echo "mount -t sysfs none /sys" | add_linuxrc
186 # generate code to mount /tmp on initrd
187 # can be called multiple times
189 if [ "$INITRDFS" = "initramfs" ]; then
190 # initramfs is read-write filesystem, no need for tmpfs
194 if is_yes "$tmp_mounted"; then
199 echo "mount -t tmpfs none /tmp" | add_linuxrc
202 # unmount all mountpoints mounted by geninitrd
206 : Last shell before umounting all and giving control over to real init.
210 if is_yes "$dev_mounted"; then
211 echo 'umount /dev' | add_linuxrc
214 if is_yes "$proc_mounted"; then
215 echo 'umount /proc' | add_linuxrc
218 if is_yes "$sys_mounted"; then
219 echo 'umount /sys' | add_linuxrc
222 if is_yes "$tmp_mounted"; then
223 echo 'umount /tmp' | add_linuxrc
229 # Checks if busybox has support for APPLET(s)
230 # Exits from geninitrd if the support is not present.
232 # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
236 if [ -z "$busybox_functions" ]; then
237 local tmp=$(/bin/initrd-busybox 2>&1)
239 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
240 if [[ "$tmp" = *applet\ not\ found* ]]; then
242 ln -s /bin/initrd-busybox $t/busybox
243 local tmp=$($t/busybox 2>&1)
247 busybox_functions=$(echo "$tmp" | \
248 sed -ne '/Currently defined functions:/,$p' | \
249 xargs | sed -e 's,.*Currently defined functions: ,,'
255 eval have='$'busybox_have_$applet
256 if [ -z "$have" ]; then
257 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
258 if [ "$have" = 0 ]; then
259 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
262 eval busybox_have_$applet=$have
265 if [ $err = 1 ]; then
270 # Finds module dependencies
273 # @param $mode [silent]
275 # Outputs each dependant module full path including the module itself.
280 # backwards compatible, process $mode
281 local modfile=$(modinfo -k $kernel -n $module 2>/dev/null)
282 if [ ! -f "$modfile" ]; then
283 # module not found. try aliases!
284 local alias aliases=$(modprobe_conf | awk -vm="$module" '$1 == "alias" && $2 == m { print $3 }')
285 if [ "$aliases" ]; then
286 for alias in $aliases; do
287 debug "Try $alias alias for $module"
293 if [ "$mode" != "silent" ]; then
294 warn "$module: module not found for $kernel kernel"
296 if ! is_no "$EXIT_IF_MISSING"; then
299 warn "If $module isn't compiled in kernel then this initrd may not start your system."
303 # This works when user has module-init-tools installed even on 2.4 kernels
304 modprobe --set-version $kernel --show-depends $module --ignore-install | \
305 while read insmod modpath options; do
306 [ "$insmod" = "insmod" ] && echo $modpath
312 echo -n $(modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
319 if [ ${modName#-} != $modName ]; then
325 if [ "$modName" = "pluto" ]; then
329 if [ "$modName" = "fcal" ]; then
335 if [ "$skiperrors" = 1 ]; then
336 depmod=$(find_depmod $modName silent)
338 depmod=$(find_depmod $modName)
344 for mod in $depmod; do
345 mod=${mod#/lib/modules/$kernel/}
347 # add each module only once
349 for m in $MODULES; do
350 [ $m = $mod ] && have=1
352 if [ $have = 0 ]; then
353 MODULES="$MODULES $mod"
355 # if we are adding uvesafb, we need v86d as well
356 if [ "$modName" = "uvesafb" ]; then
363 # install a file to temporary mount image.
364 # it will operate recursively (copying directories)
365 # and will symlink destinations if source is symlink.
367 if [ $# -lt 2 ]; then
368 die 'Usage: inst <file> [<file>] <destination>'
371 local src i=0 c=$(($# - 1))
372 while [ $i -lt $c ]; do
379 parentDir=$(dirname $DESTDIR$dest)
380 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
381 debug "+ cp $* $DESTDIR$dest"
382 cp -HR "$@" "$DESTDIR$dest"
387 die 'Usage: inst_d <destination> <destination>'
390 install -d "$DESTDIR$dir"
394 # install executable and it's shared libraries
396 if [ $# -lt 2 ]; then
397 die 'Usage: inst_exec <file>[, <file>] <destination>'
399 local src i=0 c=$(($# - 1))
400 while [ $i -lt $c ]; do
410 local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
412 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
414 inst_exec $lib /$_lib
418 # hack for uclibc linked binaries requiring this fixed path
419 # XXX: shouldn't rpath be used here instead so th
420 if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
421 local lib=$DESTDIR/$_lib/libc.so.0
422 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
423 local libdir=$(cd $(dirname "$lib"); pwd)
424 if [ ! -e $DESTDIR$libdir ]; then
425 libdir=$(dirname "$libdir")
427 debug "+ ln -s /$_lib $DESTDIR$libdir"
428 ln -s /$_lib $DESTDIR$libdir
433 # output modules.conf / modprobe.conf
435 echo "$modprobe_conf_cache"
439 # defaults to modprobe -c if not told otherwise, this means include statements
441 cache_modprobe_conf() {
442 if [ "$pack_version" -lt "002005" ]; then
443 modulefile=/etc/modules.conf
444 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
445 modulefile=/etc/conf.modules
449 if [ -n "$modulefile" ]; then
450 debug "Using $modulefile for modules config"
451 modprobe_conf_cache=$(cat $modulefile)
453 debug "Using modprobe -c to get modules config"
454 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
459 local found raidlevel
461 if [ -f /etc/mdadm.conf ]; then
462 debug "Finding RAID details using mdadm for rootdev=$1"
463 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
468 rootdev_devfs = rootdev;
469 if (rootdev ~ /\/dev\/md\/[0-9]/) {
470 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
475 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
477 gsub(/level=/,NUL,raidlevel);
478 if (raidlevel ~ /^raid([0-6]|10)/) {
479 gsub(/raid/,NUL,raidlevel);
483 if (x ~ /devices=/) {
485 gsub(".*devices=", NUL, dev_list);
486 gsub(",", " ", dev_list);
492 print "have_md=" found;
493 print "raidlevel=" raidlevel;
494 print "dev_list=\"" dev_list "\"";
498 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
499 die "raidtools are not longer supported. Please migrate to mdadm setup!"
502 if is_yes "$have_md"; then
505 findmodule "raid$raidlevel"
508 findmodule "-raid$raidlevel"
509 findmodule "-raid456"
515 warn "raid level $number (in mdadm config) not recognized"
519 die "RAID devices not found for \"$1\", check your configuration!"
522 rootdev_nr=$(( $rootdev_nr + 1 ))
523 eval "rootdev${rootdev_nr}=\"$1\""
524 eval "dev_list${rootdev_nr}=\"${dev_list}\""
526 for device in $dev_list; do
527 find_modules_for_devpath $device
531 find_modules_scsi() {
533 for n in $PRESCSIMODS; do
534 if [ "X$n" = "Xunknown" ]; then
535 debug "Finding SCSI modules using scsi_hostadapter"
536 local mod scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
537 for mod in $scsimodules; do
538 # for now allow scsi modules to come from anywhere. There are some
539 # RAID controllers with drivers in block
546 findmodule "-scsi_wait_scan"
549 # return true if node is lvm node
552 if [ ! -e "$node" ]; then
553 warn "check_lvm(): node $node doesn't exist!"
557 # block-major-58 is lvm1
558 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
562 debug "LVM check: $node is LVM v1 node"
567 if [ ! -x /sbin/lvm ]; then
568 debug "LVM check: no lvm2 tools present to check"
572 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
574 if [ $rc -gt 127 ]; then
575 # lvdisplay terminated by signal! most likely it segfaulted.
576 die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
580 debug "LVM check: $node is LVM v2 node"
582 debug "LVM check: $node is not any LVM node"
588 # return dependencies MAJOR:MINOR [MAJOR:MINOR] for DM_NAME
589 # TODO: patch `dmsetup export`
592 dmsetup deps $dm_name | sed -e 's/, /:/g;s/^.\+ dependencies[^:]: //;s/[()]//g;'
595 # export info from dmsetup
599 # - /dev/mapper/DM_NAME
605 local maj=${arg%:*} min=${arg#*:}
606 dmsetup -j $maj -m $min export
609 local min=${arg#*dm-}
610 local maj=$(awk '$2 == "device-mapper" {print $1}' /proc/devices)
614 local dm_name=${arg#/dev/mapper/}
615 dmsetup export $dm_name
618 die "dm_export: unexpected $arg"
623 # find modules for $devpath
624 find_modules_for_devpath() {
626 if [ -z "$devpath" ]; then
627 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
630 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
633 devpath=$(dm_longname "$devpath")
636 debug "Finding modules for device path $devpath"
638 if is_luks "$devpath"; then
639 find_modules_luks "$devpath"
643 if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
644 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
645 die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
647 if [ ! -f /proc/bus/pci/devices ]; then
648 warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:"
649 warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\""
652 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
653 warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
654 for m in $NFS_ETH_MODULES; do
661 warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
662 warn "or you will have problems like init(xx) being child process of swapper(1)."
666 if [[ "$devpath" == /dev/md* ]]; then
667 find_modules_md "$devpath"
671 if is_multipath "$devpath"; then
672 if find_modules_multipath "$devpath"; then
678 if is_dmraid "$devpath"; then
679 if find_modules_dmraid "$devpath"; then
685 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
690 if is_ide "$devpath"; then
691 find_modules_ide "$devpath"
695 if [[ "$devpath" == /dev/rd/* ]]; then
697 rootdev_add="/dev/rd/"
701 if [[ "$devpath" == /dev/ida/* ]]; then
702 findmodule "cpqarray"
703 rootdev_add="/dev/ida/"
707 if [[ "$devpath" == /dev/cciss/* ]]; then
709 rootdev_add="/dev/cciss/"
713 if [[ "$devpath" == /dev/ataraid/* ]]; then
716 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
717 if [ -n "$ataraidmodules" ]; then
718 # FIXME: think about modules compiled in kernel
719 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
721 for n in $ataraidmodules; do
724 rootdev_add="/dev/ataraid/"
728 # check to see if we need to set up a loopback filesystem
729 if [[ "$devpath" == /dev/loop* ]]; then
730 die "Sorry, root on loop device isn't supported."
731 # TODO: rewrite for bsp and make nfs ready
732 if [ ! -x /sbin/losetup ]; then
733 die "losetup is missing"
735 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
736 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
737 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"
740 line="`awk '/'$key'/ { print $0; }' $fstab`"
741 loopDev="$(echo $line | awk '{print $3}')"
742 loopFs="$(echo $line | awk '{print $4}')"
743 loopFile="$(echo $line | awk '{print $5}')"
745 BASICMODULES="$BASICMODULES -loop"
746 findmodule "-$loopFs"
747 BASICMODULES="$BASICMODULES -${loopFs}"
751 if is_lvm_node "$devpath"; then
754 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then
755 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."
757 if [ -z "$LVMTOOLSVERSION" ]; then
758 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}')
759 if [ -z "$LVMTOOLSVERSION" ]; then
760 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
764 local vg=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
765 VGVOLUMES=$(echo $VGVOLUMES $vg | tr ' ' '\n' | sort -u)
766 local pv=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$vg" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
767 PVDEVICES=$(echo $PVDEVICES $pv | tr ' ' '\n' | sort -u)
769 if [ -n "$PVDEVICES" ]; then
770 for device in $PVDEVICES; do
771 find_modules_for_devpath $device
774 die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
776 if [ "$LVMTOOLSVERSION" = "2" ]; then
778 elif [ "$LVMTOOLSVERSION" = "1" ]; then
780 findmodule "-lvm-mod"
782 die "LVM version $LVMTOOLSVERSION is not supported yet."
784 debug "LVM v$LVMTOOLSVERSION enabled"
790 firmware_install_module() {
792 local firmware_files="$2"
794 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
795 # firmware not yet installed
796 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
798 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
800 echo 1 > /sys$DEVPATH/loading
801 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
802 echo 0 > /sys$DEVPATH/loading
805 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
808 for firmware in $firmware_files; do
809 if [ ! -f "/lib/firmware/$firmware" ]; then
810 die "firmware file /lib/firmware/$firmware doesn't exist."
812 FIRMWAREDIR=${firmware%/*}
813 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
814 inst /lib/firmware/$firmware /lib/firmware/$firmware
819 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
826 for mod in $modules; do
828 inst_d "/lib/modules/$kernel/$MODULEDIR"
829 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
830 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
834 modules_add_linuxrc() {
838 # module path without optional compression
842 module=${modpath##*/}
843 module=${module%$modext}
845 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
847 generic_module=$(echo $module | tr - _)
848 sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
849 firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
851 if [ -n "$verbose" ]; then
853 if [ "$options" ]; then
854 s="$s with options [$options]"
856 if [ "$sleep_var" ]; then
857 s="$s and $sleep_var usleep"
859 debug "Loading module [$module]$s"
862 if [ -n "$firmware_var" ]; then
863 firmware_install_module "$module" "$firmware_var"
865 firmware_files=$(find_firmware "$module")
866 if [ -n "$firmware_files" ]; then
867 for file in $firmware_files; do
868 firmware_install_module "$module" "$file"
873 echo "$insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
874 if [ -n "$sleep_var" ]; then
875 echo "usleep $sleep_var" | add_linuxrc
880 find_modules_suspend() {
881 if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then
882 die "/usr/${_lib}/suspend/resume is missing!"
884 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
886 local vgvolumes=$VGVOLUMES
887 find_modules_for_devpath $resume_dev
889 if [ "$VGVOLUMES" != "$vgvolumes" ]; then
890 # save our VG to be able to differenciate between rootfs VG
893 debug "suspend device is on LVM"
897 initrd_gen_suspend() {
898 mknod $DESTDIR/dev/snapshot c 10 231
899 mkdir -p $DESTDIR${resume_dev%/*}
900 inst $resume_dev $resume_dev
902 inst /etc/suspend.conf /etc/suspend.conf
903 if [ -x /usr/${_lib}/suspend/resume ]; then
904 inst_exec /usr/${_lib}/suspend/resume /bin/resume
906 inst_exec /usr/sbin/resume /bin/resume
911 for arg in $CMDLINE; do
912 if [ "${arg##resume=}" != "${arg}" ]; then
916 if [ "$resume" = "yes" ]; then
922 initrd_gen_tuxonice() {
926 for arg in $CMDLINE; do
927 if [ "${arg##resume=}" != "${arg}" -o "${arg##resume2=}" != "${arg}" ]; then
931 if [ "$resume" = "yes" ]; then
932 [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
933 [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
934 [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
940 debug "initrd_gen_v86d"
941 mknod $DESTDIR/dev/mem c 1 1
942 mknod $DESTDIR/dev/tty1 c 4 1
944 inst_exec /sbin/v86d /sbin
948 debug "Setting up udev..."
949 inst_d /sbin /etc/udev
951 if [ ! -x /sbin/initrd-udevd ]; then
952 die "/sbin/initrd-udevd not present"
955 inst_exec /sbin/initrd-udevd /sbin/udevd
956 inst /etc/udev/udev.conf /etc/udev/udev.conf
965 inst_exec /sbin/initrd-udevadm /sbin/udevadm
967 /sbin/udevadm trigger
973 initrd_gen_stop_udevd() {
974 busybox_applet killall
982 initrd_gen_bootsplash() {
985 debug "Generating bootsplash"
987 if [ ! -x /bin/splash.bin ]; then
988 warn "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
992 if [ -r /etc/sysconfig/bootsplash ]; then
993 . /etc/sysconfig/bootsplash
996 if [ -z "$THEME" ]; then
997 warn "Please configure your /etc/sysconfig/bootsplash first."
998 warn "Generating bootsplashes skipped."
1002 if [ -z "$BOOT_SPLASH_RESOLUTIONS" ]; then
1003 warn "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
1004 warn "Not adding bootsplash to initrd."
1007 for res in $BOOT_SPLASH_RESOLUTIONS; do
1008 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1009 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1010 debug "Added $res $THEME theme to initrd."
1012 warn "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
1017 initrd_gen_fbsplash() {
1018 debug "Generating fbsplash"
1020 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
1021 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
1024 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
1025 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1027 if [ -r /etc/sysconfig/fbsplash ]; then
1028 . /etc/sysconfig/fbsplash
1031 if [ -z "$SPLASH_THEME" ]; then
1032 warn "Please configure your /etc/sysconfig/fbsplash first."
1033 warn "Generating fbsplashes skipped."
1037 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1038 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
1039 warn "Not adding fbsplash to initramfs."
1043 for res in $FB_SPLASH_RESOLUTIONS; do
1044 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1045 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1046 debug "Added $res $SPLASH_THEME theme to initramfs."
1048 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1053 initrd_gen_fbcondecor() {
1054 debug "Generating fbcondecor"
1056 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
1057 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
1060 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
1061 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
1063 if [ -r /etc/sysconfig/splash ]; then
1064 . /etc/sysconfig/splash
1067 if [ -z "$SPLASH_THEME" ]; then
1068 warn "Please configure your /etc/sysconfig/splash first."
1069 warn "Generating of splashes skipped."
1073 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
1074 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/splash."
1075 warn "Not adding fbcondecor to initramfs."
1079 for res in $FB_SPLASH_RESOLUTIONS; do
1080 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1081 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1082 debug "Added $res $SPLASH_THEME theme to initramfs."
1084 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1089 # Generates /dev nodes based on /proc/partitions information.
1090 # Needs /proc mounted.
1091 # Can be called multiple times.
1092 initrd_gen_devices() {
1093 if is_yes "$proc_partitions"; then
1099 add_linuxrc <<-'EOF'
1100 : 'Making device nodes'
1101 cat /proc/partitions | (
1102 # ignore first two lines: header, empty line
1105 while read major minor blocks dev rest; do
1108 [ -e $node ] || mknod $node b $major $minor
1115 debug "Setting up mdadm..."
1117 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1118 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
1121 inst_exec /sbin/initrd-mdassemble /bin/mdassemble
1124 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
1125 if [ "$dev_list_extra" = "partitions" ]; then
1126 # FIXME: handle this case (see man mdadm.conf)
1127 echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
1130 for ex_dev in $dev_list_extra; do
1131 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
1135 for nr in `seq 1 $rootdev_nr`; do
1136 eval cr_rootdev="\$rootdev${nr}"
1137 eval cr_dev_list="\$dev_list${nr}"
1138 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1140 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1142 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
1143 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1144 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
1145 if [ -n "$cr_md_conf" ]; then
1146 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
1148 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
1151 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1152 # mkdir in case of devfs name
1153 inst_d $(dirname $f)
1154 [ -e "$DESTDIR/$f" ] && continue
1155 # this works fine with and without devfs
1160 echo "mdassemble" | add_linuxrc
1162 # needed to determine md-version
1163 if [ "$do_md0" -eq 1 ]; then
1164 mknod $DESTDIR/dev/md0 b 9 0
1169 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1170 # have problems like init(XX) being child process of swapper(1).
1171 debug "Adding rootfs on NFS support to initrd (dhcp)"
1172 mknod "$DESTDIR/dev/urandom" c 1 9
1173 mkdir "$DESTDIR/newroot"
1174 add_linuxrc <<-'EOF'
1175 ifconfig lo 127.0.0.1 up
1176 route add -net 127.0.0.0 mask 255.0.0.0 lo
1178 udhcpc -i eth0 -f -q -s /bin/setdhcp
1182 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1183 exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1186 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
1188 [ "$1" != "bound" ] && exit
1189 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1190 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1191 ifconfig $interface $ip $BROADCAST $NETMASK up
1192 if [ -n "$router" ]; then
1193 for r in $router; do
1194 route add default gw $r dev $interface
1198 for o in $CMDLINE; do
1201 rootpath=${o#nfsroot=}
1206 if [ -n "$rootpath" ]; then
1207 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1209 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1210 echo "All seen variables are listed below:"
1215 chmod 755 "$DESTDIR/bin/setdhcp"
1219 debug "Adding LVM support to initrd"
1220 inst_d /tmp /newroot
1221 inst_exec /sbin/initrd-lvm /bin/lvm.static
1223 # always make /dev on tmpfs for LVM2
1224 if [ "$LVMTOOLSVERSION" = "2" ]; then
1228 if ! is_yes "$dev_mounted"; then
1230 mknod $DESTDIR/dev/mapper/control c 10 63
1231 for device in $PVDEVICES; do
1232 # if LVM on RAID then device might be copied already in gen_md
1233 [ -e "$DESTDIR/dev/$(basename $device)" ] && continue
1239 if [ "$LVMTOOLSVERSION" = "1" ]; then
1242 for vg in $VGVOLUMES; do
1243 lvm vgchange -T -a y $vg
1247 echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
1248 echo "global {" > "$DESTDIR/etc/lvm.conf"
1249 echo " locking_type = 0" >> "$DESTDIR/etc/lvm.conf"
1250 echo " locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf"
1251 echo "}" >> "$DESTDIR/etc/lvm.conf"
1252 echo "devices {" >> "$DESTDIR/etc/lvm.conf"
1253 echo " sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf"
1254 if is_yes "$have_md"; then
1255 echo " md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf"
1257 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
1258 echo ' types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf"
1260 if [ "$lvm_ignore_devices" ]; then
1261 # TODO: think of merging with lvm dumpconfig output
1262 echo ' filter = [' >> "$DESTDIR/etc/lvm.conf"
1264 for dev in $lvm_ignore_devices; do
1265 debug "LVM v2: ignore device $dev"
1266 printf ' "r|^%s.*|",\n' $dev
1267 done >> "$DESTDIR/etc/lvm.conf"
1268 echo ']' >> "$DESTDIR/etc/lvm.conf"
1270 # XXX filter= must be on one line!
1271 lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf"
1272 echo "}" >> "$DESTDIR/etc/lvm.conf"
1277 export ROOTDEV=$rootdev
1278 export ROOTVG="$VGVOLUMES"
1279 export SUSPENDVG=$SUSPENDVG
1281 add_linuxrc <<-'EOF'
1282 # parse rootdev from kernel commandline if it begins with /
1285 if [ "$ROOT" != "$ROOTDEV" ]; then
1287 echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
1288 local tmp=${ROOTDEV#/dev/}
1289 if [ "$tmp" != "$ROOTDEV" ]; then
1291 echo "LVM: Using Volume Group '$ROOTVG' for rootfs"
1298 if [ "$SUSPENDVG" = "$ROOTVG" ]; then
1299 export VGVOLUMES="$ROOTVG"
1301 export VGVOLUMES="$SUSPENDVG $ROOTVG"
1304 # disable noise from LVM accessing devices that aren't ready.
1305 read printk < /proc/sys/kernel/printk
1306 if [ ! "$DEBUGINITRD" ]; then
1307 echo 0 > /proc/sys/kernel/printk
1310 export LVM_SYSTEM_DIR=/tmp
1311 : 'Scanning for Volume Groups'
1312 lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null
1314 : 'Activating Volume Groups'
1315 for vol in $VGVOLUMES; do
1316 lvm.static vgchange --ignorelockingfailure -a y $vol 2>/dev/null
1319 echo "$printk" > /proc/sys/kernel/printk
1321 # Find out major/minor
1322 attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $ROOTDEV 2>/dev/null)"
1323 if [ "$attrs" ]; then
1324 majmin="${attrs#*$ROOTDEV*:*:*:*:*:*:*:*:*:*:*:*}"
1325 if [ "$majmin" != "$attrs" ]; then
1326 major="${majmin%:*}"
1327 minor="${majmin#*:}"
1331 if [ "$major" -a "$minor" ]; then
1333 echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev
1335 echo 2>&1 "Error figuring out real root device for $ROOTDEV!"
1336 echo 2>&1 "System will not most likely boot up! So dropping you to a shell!"
1346 debug "Adding BLKID support to initrd"
1347 inst_exec /sbin/initrd-blkid /bin/blkid
1349 add_linuxrc <<-'EOF'
1350 # if built with blkid change ROOT=LABEL=something into ROOT=/dev/somethingelse -
1352 if [ "${ROOT##LABEL=}" != "${ROOT}" -o "${ROOT##UUID=}" != "${ROOT}" ]; then
1353 ROOT="$(/bin/blkid -t $ROOT -o device -l)"
1358 initrd_gen_setrootdev() {
1359 debug "Adding rootfs finding based on kernel cmdline root= option support."
1360 add_linuxrc <<-'EOF'
1361 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
1362 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
1363 if [ -n "$rootnr" ]; then
1364 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1370 initrd_gen_initramfs_switchroot() {
1372 if [ "$rootdev" = "/dev/nfs" ]; then
1373 echo "rootfs on NFS root=/dev/nfs"
1375 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
1378 # parse 'root=xxx' kernel commandline
1379 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
1380 add_linuxrc <<-'EOF'
1381 device=/dev/no_partition_found
1382 eval "$(busybox awk -v c="$ROOT" '
1384 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
1385 num_pattern = "[0-9a-f]" num_pattern_short;
1386 dev_pattern = "[hms][a-z][a-z]([0-9])+";
1387 partition = "no_partition_found";
1391 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
1392 if (c ~ "^" num_pattern "$") {
1393 maj = sprintf("%s",substr(c,1,2));
1394 min = sprintf("%s",substr(c,3));
1396 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
1397 if (c ~ "^" dev_pattern "$") partition = c;
1400 $4 ~ partition { maj = $1; min = $2; }
1401 $1 ~ maj && $2 ~ min { partition = $4; }
1404 if (maj >= 0 && min >= 0) {
1405 printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
1408 ' /proc/partitions)"
1409 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
1410 mknod $device b $maj $min
1419 add_linuxrc <<-'EOF'
1420 if [ "$device" = '/dev/no_partition_found' ]; then
1424 mount -t $rootfs -r $device /newroot
1425 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
1426 if [ -z "$init" -o ! -x "/newroot$init" ]; then
1432 busybox_applet switch_root
1433 add_linuxrc <<-'EOF'
1434 exec switch_root /newroot $init
1436 echo "Error! initramfs should not reach this place."
1437 echo "It probably means you've got old version of busybox, with broken"
1438 echo "initramfs support. Trying to boot anyway, but won't promise anything."
1440 exec chroot /newroot $init
1442 echo "Failed to chroot!"
1444 # we need /init being real file, not symlink, otherwise the initramfs will
1445 # not be ran by pid 1 which is required for switch_root
1446 mv $DESTDIR/linuxrc $DESTDIR/init
1447 ln -s init $DESTDIR/linuxrc
1451 if [ "$(id -u)" != 0 ]; then
1452 die "You need to be root to generate initrd"
1455 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
1457 . /etc/udev/udev.conf
1461 . /etc/geninitrd/mod-ide.sh
1462 # cryptsetup luks addon
1463 . /etc/geninitrd/mod-luks.sh
1464 # dm-multipath addon
1465 . /etc/geninitrd/mod-multipath.sh
1467 . /etc/geninitrd/mod-dmraid.sh
1469 if [ -x /sbin/initrd-blkid ]; then
1473 if [ -r /etc/sysconfig/geninitrd ]; then
1474 . /etc/sysconfig/geninitrd
1477 if [ ! -x /bin/initrd-busybox ]; then
1478 die "/bin/initrd-busybox is missing!"
1481 # backwards compatible
1482 if [ "$USE_SUSPEND2" ]; then
1483 USE_TUXONICE=$USE_SUSPEND2
1484 warn "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
1487 while [ $# -gt 0 ]; do
1497 modulefile=${1#--modules-conf=}
1503 --use-raidstart|--with-raidstart)
1506 --without-raidstart)
1509 --use-insmod-static|--with-insmod-static)
1512 --without-insmod-static)
1518 --without-bootsplash)
1530 --without-fbcondecor)
1539 --with-suspend2 | --with-tuxonice)
1542 --without-suspend2 | --without-tuxonice)
1546 LVMTOOLSVERSION=${1#--lvmversion=}
1548 --lvmtoolsversion=*)
1549 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
1551 --lvmtoolsversion|--lvmversion)
1564 --without-multipath)
1574 BASICMODULES="$BASICMODULES ${1#--with=}"
1577 BASICMODULES="$BASICMODULES $2"
1581 echo "$PROGRAM: version $VERSION"
1597 PREMODS="$PREMODS ${1#--preload=}"
1600 PREMODS="$PREMODS $2"
1604 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1608 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1613 INITRDFS=${1#--initrdfs=}
1626 if [ -z "$target" ]; then
1628 elif [ -z "$kernel" ]; then
1640 if [ -z "$target" -o -z "$kernel" ]; then
1645 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1646 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1649 pack_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1650 pack_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
1652 if [ -z "$INITRDFS" ]; then
1653 if [ -z "$FS" ]; then
1655 if [ "$pack_version" -ge "002005" ]; then
1656 INITRDFS="initramfs"
1661 warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
1666 if [ "$pack_version" -lt "002006" ]; then
1671 if [ "$pack_version" -ge "002005" ]; then
1676 if is_yes "$USEINSMODSTATIC"; then
1677 insmod="insmod.static"
1678 INSMOD="/sbin/insmod.static"
1679 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
1680 INSMOD="/sbin/insmod.static.modutils"
1682 if [ ! -f "$INSMOD" ]; then
1683 die "insmod.static requested but /sbin/insmod.static not found!"
1689 if [ ! -x /sbin/mke2fs ]; then
1690 die "/sbin/mke2fs is missing"
1694 if [ ! -x /sbin/genromfs ]; then
1695 die "/sbin/genromfs is missing"
1699 if [ ! -x /sbin/mkcramfs ]; then
1700 die "/sbin/mkcramfs is missing"
1704 if [ ! -x /bin/cpio ]; then
1705 die "/bin/cpio is missing"
1707 if [ ! -x /usr/bin/find ]; then
1708 die "/usr/bin/find is missing"
1712 die "Filesystem $INITRDFS on initrd is not supported"
1716 if [ -L "$target" ]; then
1717 target=$(readlink -f "$target")
1720 if [ -n "$img_vers" ]; then
1721 target="$target-$kernel"
1724 if [ -z "$force" -a -f "$target" ]; then
1725 die "$target already exists."
1728 if [ ! -d "/lib/modules/$kernel" ]; then
1729 die "/lib/modules/$kernel is not a directory."
1732 if [ "$INITRDFS" != "initramfs" ]; then
1733 if is_yes "$FB_SPLASH"; then
1734 warn "Using fbsplash requires INITRDFS=initramfs; skipping fbsplash generation"
1737 if is_yes "$FB_CON_DECOR"; then
1738 warn "Using fbcondecor requires INITRDFS=initramfs; skipping fbcondecor generation"
1743 if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
1744 warn "Tuxonice and mainline suspend are exclusive!"
1747 if is_yes "$FB_SPLASH" && is_yes "$BOOT_SPLASH"; then
1748 warn "bootsplash and fbsplash are exclusive!"
1751 if [ ! -f /proc/mounts ]; then
1752 warn "/proc filesystem not mounted, may cause wrong results or failure."
1755 if [ -d /usr/lib64 ]; then
1760 debug "Using libdir: $_lib"
1764 for n in $PREMODS; do
1768 if [ "$FBMODULE" ]; then
1769 findmodule "$FBMODULE"
1772 # allow forcing loading SCSI and/or IDE modules
1773 if is_yes "$ADDSCSI"; then
1777 if is_yes "$ADDIDE"; then
1781 if is_yes "$USE_SUSPEND"; then
1782 find_modules_suspend
1785 find_root "$fstab" || exit
1786 debug "Using $rootdev as device for rootfs"
1788 find_modules_for_devpath "$rootdev"
1789 [ -n "$rootdev_add" ] && find_modules_for_devpath "$rootdev_add"
1791 findmodule "-$rootFs"
1793 for n in $BASICMODULES; do
1797 if is_yes "$USE_TUXONICE"; then
1801 if is_yes "$FB_SPLASH"; then
1805 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1806 debug "No modules are needed -- not building initrd image."
1810 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
1811 RCFILE="$DESTDIR/linuxrc"
1813 chmod a+rx "$RCFILE"
1814 ln -s linuxrc $DESTDIR/init
1816 # create dirs that we really need
1817 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
1819 modules_install "$MODULES"
1821 # mknod'ing the devices instead of copying them works both with and
1823 mknod "$DESTDIR/dev/console" c 5 1
1824 mknod "$DESTDIR/dev/null" c 1 3
1825 mknod "$DESTDIR/dev/zero" c 1 5
1827 inst_exec /bin/initrd-busybox /bin/initrd-busybox
1828 ln -s initrd-busybox $DESTDIR/bin/sh
1829 ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
1831 if is_yes "$USEINSMODSTATIC"; then
1832 inst_exec "$INSMOD" /bin/insmod.static
1837 # initrd generated by:
1842 add_linuxrc <<-'EOF'
1843 read CMDLINE < /proc/cmdline; export CMDLINE
1845 for arg in $CMDLINE; do
1846 if [ "${arg}" = "debuginitrd" ]; then
1849 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1850 DEBUGINITRD=${arg##debuginitrd=}
1852 if [ "${arg##root=}" != "${arg}" ]; then
1857 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1858 if [ "$DEBUGINITRD" = "sh" ]; then
1861 if is_yes "$RUN_SULOGIN_ON_ERR"; then
1862 add_linuxrc <<-'EOF'
1863 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1866 add_linuxrc <<-'EOF'
1870 add_linuxrc <<-'EOF'
1878 if [ "$DEBUGINITRD" ]; then
1883 modules_add_linuxrc $MODULES
1885 # TODO: rewrite for busybox
1886 #if [ -n "$loopDev" ]; then
1887 # if [ ! -d /initrd ]; then
1891 # cp -a "$loopDev" "$DESTDIR/dev"
1892 # cp -a "$rootdev" "$DESTDIR/dev"
1893 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1894 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1895 # echo "echo Setting up loopback device $rootdev" >> $RCFILE
1896 # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1899 if is_yes "$USE_UDEV"; then
1903 if is_yes "$USE_TUXONICE"; then
1907 if is_yes "$need_v86d"; then
1911 if is_yes "$have_luks"; then
1915 if is_yes "$have_dmraid"; then
1919 if is_yes "$have_multipath"; then
1920 initrd_gen_multipath
1923 if is_yes "$USE_BLKID"; then
1927 if is_yes "$have_nfs"; then
1929 elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
1931 if is_yes "$have_lvm"; then
1934 initrd_gen_setrootdev
1936 elif is_yes "$have_lvm"; then
1939 initrd_gen_setrootdev
1942 if is_yes "$USE_SUSPEND"; then
1946 # additional devs always needed
1947 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
1949 if is_yes "$USE_UDEV"; then
1950 initrd_gen_stop_udevd
1953 if [ "$INITRDFS" = "initramfs" ]; then
1954 initrd_gen_initramfs_switchroot
1959 if is_yes "$FB_SPLASH"; then
1963 if is_yes "$FB_CON_DECOR"; then
1964 initrd_gen_fbcondecor
1967 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
1969 debug "Creating $INITRDFS image $IMAGE"
1972 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
1973 debug "ext2 image size: $IMAGESIZE ($DESTDIR)"
1974 if [ "$IMAGESIZE" -gt 4096 ]; then
1975 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1978 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1979 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1980 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1982 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
1983 debug "Mounting ext2 image $IMAGE to $tmpmnt"
1984 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1985 # We don't need this directory, so let's save space
1986 rm -rf "$tmpmnt"/lost+found
1988 debug "Copy recursively $DESTDIR -> $tmpmnt"
1989 cp -a $DESTDIR/* $tmpmnt
1995 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
1996 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
1997 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
1998 if [ "$IMAGESIZE" -gt 4096 ]; then
1999 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
2003 mkcramfs "$DESTDIR" "$IMAGE"
2006 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
2009 echo "Filesystem $INITRDFS not supported by $PROGRAM";
2012 if is_yes "$COMPRESS"; then
2013 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
2014 debug "Compressing $target"
2015 gzip -9 < "$IMAGE" > "$tmp"
2016 mv -f "$tmp" "$target"
2018 cp -a "$IMAGE" "$target"
2021 size=$(stat -c %s $target | awk '{print int((($1/1024)+1023)/1024)*1024}')
2022 debug "Minimum RAM size that could be used for $target is: ramdisk_size=$size"
2024 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
2025 if is_yes "$BOOT_SPLASH"; then
2026 initrd_gen_bootsplash "$target"
2029 rm -rf "$DESTDIR" "$IMAGE"
2031 # vim:ts=4:sw=4:noet:fdm=marker