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 # whether v86d should be installed
68 # if we should init NFS at boot
70 # if we should init md (softraid) at boot
75 echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
76 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
77 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
78 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
79 echo " [--with-bootsplash] [--without-bootsplash]"
80 echo " [--with-fbsplash] [--without-fbsplash]"
81 echo " [--with-fbcondecor] [--without-fbcondecor]"
82 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
83 echo " [--with-suspend] [--without-suspend]"
84 echo " [--with-tuxonice] [--without-tuxonice]"
85 echo " [--without-dmraid] [--without-multipath]"
86 echo " [--without-blkid] [--without-luks]"
87 echo " <initrd-image> <kernel-version>"
90 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
103 [ -n "$verbose" ] && msg "$*" >&2
106 # aborts program abnormally
113 # append text to /linuxrc
114 # takes STDIN as input
119 # generate code to mount /dev on tmpfs and create initial nodes
120 # can be called multiple times. /dev is cleaned up (umounted) automatically at
123 if [ "$INITRDFS" = "initramfs" ]; then
124 # initramfs is read-write filesystem, no need for tmpfs
128 # we already generated tmpfs code; return
129 if is_yes "$dev_mounted"; then
135 busybox_applet mount mknod mkdir
138 mount -o mode=0755 -t tmpfs none /dev
139 mknod /dev/console c 5 1
140 mknod /dev/null c 1 3
141 mknod /dev/zero c 1 5
147 # generate code to mount /proc on initrd
148 # can be called multiple times
150 if is_yes "$proc_mounted"; then
155 if [ "$INITRDFS" = "initramfs" ]; then
156 # /proc is mounted with initramfs 2.6.22.14 kernel
157 # XXX: remove when it is clear why proc was already mounted
158 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
160 echo "mount -t proc none /proc" | add_linuxrc
164 # generate code to mount /sys on initrd
165 # can be called multiple times
167 if is_yes "$sys_mounted"; then
172 echo "mount -t sysfs none /sys" | add_linuxrc
175 # generate code to mount /tmp on initrd
176 # can be called multiple times
178 if [ "$INITRDFS" = "initramfs" ]; then
179 # initramfs is read-write filesystem, no need for tmpfs
183 if is_yes "$tmp_mounted"; then
188 echo "mount -t tmpfs none /tmp" | add_linuxrc
191 # unmount all mountpoints mounted by geninitrd
195 : Last shell before umounting all and giving control over to real init.
199 if is_yes "$dev_mounted"; then
200 echo 'umount /dev' | add_linuxrc
203 if is_yes "$proc_mounted"; then
204 echo 'umount /proc' | add_linuxrc
207 if is_yes "$sys_mounted"; then
208 echo 'umount /sys' | add_linuxrc
211 if is_yes "$tmp_mounted"; then
212 echo 'umount /tmp' | add_linuxrc
218 # Checks if busybox has support for APPLET(s)
219 # Exits from geninitrd if the support is not present.
221 # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
225 if [ -z "$busybox_functions" ]; then
226 local tmp=$(/bin/initrd-busybox 2>&1)
228 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
229 if [[ "$tmp" = *applet\ not\ found* ]]; then
231 ln -s /bin/initrd-busybox $t/busybox
232 local tmp=$($t/busybox 2>&1)
236 busybox_functions=$(echo "$tmp" | \
237 sed -ne '/Currently defined functions:/,$p' | \
238 xargs | sed -e 's,.*Currently defined functions: ,,'
244 eval have='$'busybox_have_$applet
245 if [ -z "$have" ]; then
246 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
247 if [ "$have" = 0 ]; then
248 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
251 eval busybox_have_$applet=$have
254 if [ $err = 1 ]; then
259 # Finds module dependencies
262 # @param $mode [silent]
264 # Outputs each dependant module full path including the module itself.
269 # backwards compatible, process $mode
270 local modfile=$(modinfo -k $kernel -n $module 2>/dev/null)
271 if [ ! -f "$modfile" ]; then
272 # module not found. try aliases!
273 local alias aliases=$(modprobe_conf | awk -vm="$module" '$1 == "alias" && $2 == m { print $3 }')
274 if [ "$aliases" ]; then
275 for alias in $aliases; do
276 debug "Try $alias alias for $module"
282 if [ "$mode" != "silent" ]; then
283 warn "$module: module not found for $kernel kernel"
285 if ! is_no "$EXIT_IF_MISSING"; then
288 warn "If $module isn't compiled in kernel then this initrd may not start your system."
292 # This works when user has module-init-tools installed even on 2.4 kernels
293 modprobe --set-version $kernel --show-depends $module --ignore-install | \
294 while read insmod modpath options; do
295 [ "$insmod" = "insmod" ] && echo $modpath
301 echo -n $(modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
308 if [ ${modName#-} != $modName ]; then
314 if [ "$modName" = "pluto" ]; then
318 if [ "$modName" = "fcal" ]; then
324 if [ "$skiperrors" = 1 ]; then
325 depmod=$(find_depmod $modName silent)
327 depmod=$(find_depmod $modName)
333 for mod in $depmod; do
334 mod=${mod#/lib/modules/$kernel/}
336 # add each module only once
338 for m in $MODULES; do
339 [ $m = $mod ] && have=1
341 if [ $have = 0 ]; then
342 MODULES="$MODULES $mod"
344 # if we are adding uvesafb, we need v86d as well
345 if [ "$modName" = "uvesafb" ]; then
352 # install a file to temporary mount image.
353 # it will operate recursively (copying directories)
354 # and will symlink destinations if source is symlink.
356 if [ $# -lt 2 ]; then
357 die 'Usage: inst <file> [<file>] <destination>'
360 local src i=0 c=$(($# - 1))
361 while [ $i -lt $c ]; do
368 parentDir=$(dirname $DESTDIR$dest)
369 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
370 debug "+ cp $* $DESTDIR$dest"
371 cp -HR "$@" "$DESTDIR$dest"
376 die 'Usage: inst_d <destination> <destination>'
379 install -d "$DESTDIR$dir"
383 # install executable and it's shared libraries
385 if [ $# -lt 2 ]; then
386 die 'Usage: inst_exec <file>[, <file>] <destination>'
388 local src i=0 c=$(($# - 1))
389 while [ $i -lt $c ]; do
399 local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
401 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
403 inst_exec $lib /$_lib
407 # hack for uclibc linked binaries requiring this fixed path
408 # XXX: shouldn't rpath be used here instead so th
409 if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
410 local lib=$DESTDIR/$_lib/libc.so.0
411 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
412 local libdir=$(cd $(dirname "$lib"); pwd)
413 if [ ! -e $DESTDIR$libdir ]; then
414 libdir=$(dirname "$libdir")
416 debug "+ ln -s /$_lib $DESTDIR$libdir"
417 ln -s /$_lib $DESTDIR$libdir
422 # output modules.conf / modprobe.conf
424 echo "$modprobe_conf_cache"
428 # defaults to modprobe -c if not told otherwise, this means include statements
430 cache_modprobe_conf() {
431 if [ "$pack_version" -lt "002005" ]; then
432 modulefile=/etc/modules.conf
433 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
434 modulefile=/etc/conf.modules
438 if [ -n "$modulefile" ]; then
439 debug "Using $modulefile for modules config"
440 modprobe_conf_cache=$(cat $modulefile)
442 debug "Using modprobe -c to get modules config"
443 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
448 local found raidlevel
450 if [ -f /etc/mdadm.conf ]; then
451 debug "Finding RAID details using mdadm for rootdev=$1"
452 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
457 rootdev_devfs = rootdev;
458 if (rootdev ~ /\/dev\/md\/[0-9]/) {
459 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
464 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
466 gsub(/level=/,NUL,raidlevel);
467 if (raidlevel ~ /^raid([0-6]|10)/) {
468 gsub(/raid/,NUL,raidlevel);
472 if (x ~ /devices=/) {
474 gsub(".*devices=", NUL, dev_list);
475 gsub(",", " ", dev_list);
481 print "have_md=" found;
482 print "raidlevel=" raidlevel;
483 print "dev_list=\"" dev_list "\"";
487 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
488 die "raidtools are not longer supported. Please migrate to mdadm setup!"
491 if is_yes "$have_md"; then
494 findmodule "raid$raidlevel"
497 findmodule "-raid$raidlevel"
498 findmodule "-raid456"
504 warn "raid level $number (in mdadm config) not recognized"
508 die "RAID devices not found for \"$1\", check your configuration!"
511 rootdev_nr=$(( $rootdev_nr + 1 ))
512 eval "rootdev${rootdev_nr}=\"$1\""
513 eval "dev_list${rootdev_nr}=\"${dev_list}\""
515 for device in $dev_list; do
516 find_modules_for_devpath $device
520 find_modules_scsi() {
522 for n in $PRESCSIMODS; do
523 if [ "X$n" = "Xunknown" ]; then
524 debug "Finding SCSI modules using scsi_hostadapter"
525 local mod scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
526 for mod in $scsimodules; do
527 # for now allow scsi modules to come from anywhere. There are some
528 # RAID controllers with drivers in block
535 findmodule "-scsi_wait_scan"
538 # return dependencies MAJOR:MINOR [MAJOR:MINOR] for DM_NAME
539 # TODO: patch `dmsetup export`
542 dmsetup deps $dm_name | sed -e 's/, /:/g;s/^.\+ dependencies[^:]: //;s/[()]//g;'
545 # export info from dmsetup
549 # - /dev/mapper/DM_NAME
555 local maj=${arg%:*} min=${arg#*:}
556 dmsetup -j $maj -m $min export
559 local min=${arg#*dm-}
560 local maj=$(awk '$2 == "device-mapper" {print $1}' /proc/devices)
564 local dm_name=${arg#/dev/mapper/}
565 dmsetup export $dm_name
568 die "dm_export: unexpected $arg"
573 # find modules for $devpath
574 find_modules_for_devpath() {
576 if [ -z "$devpath" ]; then
577 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
580 if [[ "$devpath" = /dev/dm-* ]]; then
581 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
582 devpath=$(dm_longname "$devpath")
585 if [ -L "$devpath" ] && ! is_lvm "$devpath"; then
586 # sanitize things like:
587 # /dev/block/104:2 -> /dev/cciss/c0d0p2
588 devpath=$(readlink -f "$devpath")
591 debug "Finding modules for device path $devpath"
593 if is_luks "$devpath"; then
594 find_modules_luks "$devpath"
598 if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
599 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
600 die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
602 if [ ! -f /proc/bus/pci/devices ]; then
603 warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:"
604 warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\""
607 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
608 warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
609 for m in $NFS_ETH_MODULES; do
616 warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
617 warn "or you will have problems like init(xx) being child process of swapper(1)."
621 if [[ "$devpath" == /dev/md* ]]; then
622 find_modules_md "$devpath"
626 if is_multipath "$devpath"; then
627 if find_modules_multipath "$devpath"; then
633 if is_dmraid "$devpath"; then
634 if find_modules_dmraid "$devpath"; then
640 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
645 if is_ide "$devpath"; then
646 find_modules_ide "$devpath"
650 if [[ "$devpath" == /dev/rd/* ]]; then
656 if [[ "$devpath" == /dev/ida/* ]]; then
657 findmodule "cpqarray"
658 rootdev_add=/dev/ida/
662 if [[ "$devpath" == /dev/cciss/* ]]; then
664 rootdev_add=/dev/cciss/
668 if [[ "$devpath" == /dev/ataraid/* ]]; then
671 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
672 if [ -n "$ataraidmodules" ]; then
673 # FIXME: think about modules compiled in kernel
674 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
676 for n in $ataraidmodules; do
679 rootdev_add=/dev/ataraid/
683 # check to see if we need to set up a loopback filesystem
684 if [[ "$devpath" == /dev/loop* ]]; then
685 die "Sorry, root on loop device isn't supported."
686 # TODO: rewrite for bsp and make nfs ready
687 if [ ! -x /sbin/losetup ]; then
688 die "losetup is missing"
690 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
691 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
692 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"
695 line="`awk '/'$key'/ { print $0; }' $fstab`"
696 loopDev="$(echo $line | awk '{print $3}')"
697 loopFs="$(echo $line | awk '{print $4}')"
698 loopFile="$(echo $line | awk '{print $5}')"
700 BASICMODULES="$BASICMODULES -loop"
701 findmodule "-$loopFs"
702 BASICMODULES="$BASICMODULES -${loopFs}"
706 if is_lvm "$devpath"; then
707 find_modules_lvm "$devpath"
712 firmware_install_module() {
714 local firmware_files="$2"
716 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
717 # firmware not yet installed
718 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
720 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
722 echo 1 > /sys$DEVPATH/loading
723 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
724 echo 0 > /sys$DEVPATH/loading
727 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
730 for firmware in $firmware_files; do
731 if [ ! -f "/lib/firmware/$firmware" ]; then
732 die "firmware file /lib/firmware/$firmware doesn't exist."
734 FIRMWAREDIR=${firmware%/*}
735 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
736 inst /lib/firmware/$firmware /lib/firmware/$firmware
741 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
748 for mod in $modules; do
750 inst_d "/lib/modules/$kernel/$MODULEDIR"
751 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
752 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
756 modules_add_linuxrc() {
760 # module path without optional compression
764 module=${modpath##*/}
765 module=${module%$modext}
767 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
769 generic_module=$(echo $module | tr - _)
770 sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
771 firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
773 if [ -n "$verbose" ]; then
775 if [ "$options" ]; then
776 s="$s with options [$options]"
778 if [ "$sleep_var" ]; then
779 s="$s and $sleep_var usleep"
781 debug "Loading module [$module]$s"
784 if [ -n "$firmware_var" ]; then
785 firmware_install_module "$module" "$firmware_var"
787 firmware_files=$(find_firmware "$module")
788 if [ -n "$firmware_files" ]; then
789 for file in $firmware_files; do
790 firmware_install_module "$module" "$file"
795 echo "$insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
796 if [ -n "$sleep_var" ]; then
797 echo "usleep $sleep_var" | add_linuxrc
802 find_modules_suspend() {
803 if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then
804 die "/usr/${_lib}/suspend/resume is missing!"
806 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
808 local vgvolumes=$VGVOLUMES
809 find_modules_for_devpath $resume_dev
811 if [ "$VGVOLUMES" != "$vgvolumes" ]; then
812 # save our VG to be able to differenciate between rootfs VG
815 debug "suspend device is on LVM"
819 initrd_gen_suspend() {
820 mknod $DESTDIR/dev/snapshot c 10 231
821 mkdir -p $DESTDIR${resume_dev%/*}
822 inst $resume_dev $resume_dev
824 inst /etc/suspend.conf /etc/suspend.conf
825 if [ -x /usr/${_lib}/suspend/resume ]; then
826 inst_exec /usr/${_lib}/suspend/resume /bin/resume
828 inst_exec /usr/sbin/resume /bin/resume
833 for arg in $CMDLINE; do
834 if [ "${arg##resume=}" != "${arg}" ]; then
838 if [ "$resume" = "yes" ]; then
844 initrd_gen_tuxonice() {
848 for arg in $CMDLINE; do
849 if [ "${arg##resume=}" != "${arg}" -o "${arg##resume2=}" != "${arg}" ]; then
853 if [ "$resume" = "yes" ]; then
854 [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
855 [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
856 [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
862 debug "initrd_gen_v86d"
863 mknod $DESTDIR/dev/mem c 1 1
864 mknod $DESTDIR/dev/tty1 c 4 1
866 inst_exec /sbin/v86d /sbin
870 debug "Setting up udev..."
871 inst_d /sbin /etc/udev
873 if [ ! -x /sbin/initrd-udevd ]; then
874 die "/sbin/initrd-udevd not present"
877 inst_exec /sbin/initrd-udevd /sbin/udevd
878 inst /etc/udev/udev.conf /etc/udev/udev.conf
887 inst_exec /sbin/initrd-udevadm /sbin/udevadm
889 /sbin/udevadm trigger
895 initrd_gen_stop_udevd() {
896 busybox_applet killall
904 initrd_gen_bootsplash() {
907 debug "Generating bootsplash"
909 if [ ! -x /bin/splash.bin ]; then
910 warn "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
914 if [ -r /etc/sysconfig/bootsplash ]; then
915 . /etc/sysconfig/bootsplash
918 if [ -z "$THEME" ]; then
919 warn "Please configure your /etc/sysconfig/bootsplash first."
920 warn "Generating bootsplashes skipped."
924 if [ -z "$BOOT_SPLASH_RESOLUTIONS" ]; then
925 warn "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
926 warn "Not adding bootsplash to initrd."
929 for res in $BOOT_SPLASH_RESOLUTIONS; do
930 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
931 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
932 debug "Added $res $THEME theme to initrd."
934 warn "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
939 initrd_gen_fbsplash() {
940 debug "Generating fbsplash"
942 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
943 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
946 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
947 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
949 if [ -r /etc/sysconfig/fbsplash ]; then
950 . /etc/sysconfig/fbsplash
953 if [ -z "$SPLASH_THEME" ]; then
954 warn "Please configure your /etc/sysconfig/fbsplash first."
955 warn "Generating fbsplashes skipped."
959 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
960 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
961 warn "Not adding fbsplash to initramfs."
965 for res in $FB_SPLASH_RESOLUTIONS; do
966 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
967 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
968 debug "Added $res $SPLASH_THEME theme to initramfs."
970 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
975 initrd_gen_fbcondecor() {
976 debug "Generating fbcondecor"
978 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
979 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
982 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
983 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
985 if [ -r /etc/sysconfig/splash ]; then
986 . /etc/sysconfig/splash
989 if [ -z "$SPLASH_THEME" ]; then
990 warn "Please configure your /etc/sysconfig/splash first."
991 warn "Generating of splashes skipped."
995 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
996 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/splash."
997 warn "Not adding fbcondecor to initramfs."
1001 for res in $FB_SPLASH_RESOLUTIONS; do
1002 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1003 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
1004 debug "Added $res $SPLASH_THEME theme to initramfs."
1006 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1011 # Generates /dev nodes based on /proc/partitions information.
1012 # Needs /proc mounted.
1013 # Can be called multiple times.
1014 initrd_gen_devices() {
1015 if is_yes "$proc_partitions"; then
1021 add_linuxrc <<-'EOF'
1022 : 'Making device nodes'
1023 cat /proc/partitions | (
1024 # ignore first two lines: header, empty line
1027 while read major minor blocks dev rest; do
1030 [ -e $node ] || mknod $node b $major $minor
1037 debug "Setting up mdadm..."
1039 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1040 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
1043 inst_exec /sbin/initrd-mdassemble /bin/mdassemble
1046 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
1047 if [ "$dev_list_extra" = "partitions" ]; then
1048 # FIXME: handle this case (see man mdadm.conf)
1049 echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
1052 for ex_dev in $dev_list_extra; do
1053 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
1057 for nr in `seq 1 $rootdev_nr`; do
1058 eval cr_rootdev="\$rootdev${nr}"
1059 eval cr_dev_list="\$dev_list${nr}"
1060 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1062 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1064 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
1065 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1066 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
1067 if [ -n "$cr_md_conf" ]; then
1068 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
1070 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
1073 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1074 # mkdir in case of devfs name
1075 inst_d $(dirname $f)
1076 [ -e "$DESTDIR/$f" ] && continue
1077 # this works fine with and without devfs
1082 echo "mdassemble" | add_linuxrc
1084 # needed to determine md-version
1085 if [ "$do_md0" -eq 1 ]; then
1086 mknod $DESTDIR/dev/md0 b 9 0
1091 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1092 # have problems like init(XX) being child process of swapper(1).
1093 debug "Adding rootfs on NFS support to initrd (dhcp)"
1094 mknod "$DESTDIR/dev/urandom" c 1 9
1095 mkdir "$DESTDIR/newroot"
1096 add_linuxrc <<-'EOF'
1097 ifconfig lo 127.0.0.1 up
1098 route add -net 127.0.0.0 mask 255.0.0.0 lo
1100 udhcpc -i eth0 -f -q -s /bin/setdhcp
1104 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1105 exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1108 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
1110 [ "$1" != "bound" ] && exit
1111 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1112 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1113 ifconfig $interface $ip $BROADCAST $NETMASK up
1114 if [ -n "$router" ]; then
1115 for r in $router; do
1116 route add default gw $r dev $interface
1120 for o in $CMDLINE; do
1123 rootpath=${o#nfsroot=}
1128 if [ -n "$rootpath" ]; then
1129 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1131 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1132 echo "All seen variables are listed below:"
1137 chmod 755 "$DESTDIR/bin/setdhcp"
1142 debug "Adding BLKID support to initrd"
1143 inst_exec /sbin/initrd-blkid /bin/blkid
1145 add_linuxrc <<-'EOF'
1146 # if built with blkid change ROOT=LABEL=something into ROOT=/dev/somethingelse -
1148 if [ "${ROOT##LABEL=}" != "${ROOT}" -o "${ROOT##UUID=}" != "${ROOT}" ]; then
1149 ROOT="$(/bin/blkid -t $ROOT -o device -l)"
1154 initrd_gen_setrootdev() {
1155 debug "Adding rootfs finding based on kernel cmdline root= option support."
1156 add_linuxrc <<-'EOF'
1157 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
1158 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
1159 if [ -n "$rootnr" ]; then
1160 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1166 initrd_gen_initramfs_switchroot() {
1168 if [ "$rootdev" = "/dev/nfs" ]; then
1169 echo "rootfs on NFS root=/dev/nfs"
1171 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
1174 # parse 'root=xxx' kernel commandline
1175 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
1176 add_linuxrc <<-'EOF'
1177 device=/dev/no_partition_found
1178 eval "$(busybox awk -v c="$ROOT" '
1180 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
1181 num_pattern = "[0-9a-f]" num_pattern_short;
1182 dev_pattern = "[hms][a-z][a-z]([0-9])+";
1183 partition = "no_partition_found";
1187 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
1188 if (c ~ "^" num_pattern "$") {
1189 maj = sprintf("%s",substr(c,1,2));
1190 min = sprintf("%s",substr(c,3));
1192 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
1193 if (c ~ "^" dev_pattern "$") partition = c;
1196 $4 ~ partition { maj = $1; min = $2; }
1197 $1 ~ maj && $2 ~ min { partition = $4; }
1200 if (maj >= 0 && min >= 0) {
1201 printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
1204 ' /proc/partitions)"
1205 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
1206 mknod $device b $maj $min
1215 add_linuxrc <<-'EOF'
1216 if [ "$device" = '/dev/no_partition_found' ]; then
1220 mount -t $rootfs -r $device /newroot
1221 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
1222 if [ -z "$init" -o ! -x "/newroot$init" ]; then
1228 busybox_applet switch_root
1229 add_linuxrc <<-'EOF'
1230 exec switch_root /newroot $init
1232 echo "Error! initramfs should not reach this place."
1233 echo "It probably means you've got old version of busybox, with broken"
1234 echo "initramfs support. Trying to boot anyway, but won't promise anything."
1236 exec chroot /newroot $init
1238 echo "Failed to chroot!"
1240 # we need /init being real file, not symlink, otherwise the initramfs will
1241 # not be ran by pid 1 which is required for switch_root
1242 mv $DESTDIR/linuxrc $DESTDIR/init
1243 ln -s init $DESTDIR/linuxrc
1247 if [ "$(id -u)" != 0 ]; then
1248 die "You need to be root to generate initrd"
1251 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
1253 . /etc/udev/udev.conf
1257 . /etc/geninitrd/mod-ide.sh
1258 # cryptsetup luks addon
1259 . /etc/geninitrd/mod-luks.sh
1260 # dm-multipath addon
1261 . /etc/geninitrd/mod-multipath.sh
1263 . /etc/geninitrd/mod-dmraid.sh
1265 . /etc/geninitrd/mod-lvm.sh
1267 if [ -x /sbin/initrd-blkid ]; then
1271 if [ -r /etc/sysconfig/geninitrd ]; then
1272 . /etc/sysconfig/geninitrd
1275 if [ ! -x /bin/initrd-busybox ]; then
1276 die "/bin/initrd-busybox is missing!"
1279 # backwards compatible
1280 if [ "$USE_SUSPEND2" ]; then
1281 USE_TUXONICE=$USE_SUSPEND2
1282 warn "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
1285 while [ $# -gt 0 ]; do
1295 modulefile=${1#--modules-conf=}
1301 --use-raidstart|--with-raidstart)
1304 --without-raidstart)
1307 --use-insmod-static|--with-insmod-static)
1310 --without-insmod-static)
1316 --without-bootsplash)
1328 --without-fbcondecor)
1337 --with-suspend2 | --with-tuxonice)
1340 --without-suspend2 | --without-tuxonice)
1344 LVMTOOLSVERSION=${1#--lvmversion=}
1346 --lvmtoolsversion=*)
1347 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
1349 --lvmtoolsversion|--lvmversion)
1362 --without-multipath)
1372 BASICMODULES="$BASICMODULES ${1#--with=}"
1375 BASICMODULES="$BASICMODULES $2"
1379 echo "$PROGRAM: version $VERSION"
1395 PREMODS="$PREMODS ${1#--preload=}"
1398 PREMODS="$PREMODS $2"
1402 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1406 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1411 INITRDFS=${1#--initrdfs=}
1424 if [ -z "$target" ]; then
1426 elif [ -z "$kernel" ]; then
1438 if [ -z "$target" -o -z "$kernel" ]; then
1443 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1444 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1447 pack_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1448 pack_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
1450 if [ -z "$INITRDFS" ]; then
1451 if [ -z "$FS" ]; then
1453 if [ "$pack_version" -ge "002005" ]; then
1454 INITRDFS="initramfs"
1459 warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
1464 if [ "$pack_version" -lt "002006" ]; then
1469 if [ "$pack_version" -ge "002005" ]; then
1474 if is_yes "$USEINSMODSTATIC"; then
1475 insmod="insmod.static"
1476 INSMOD="/sbin/insmod.static"
1477 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
1478 INSMOD="/sbin/insmod.static.modutils"
1480 if [ ! -f "$INSMOD" ]; then
1481 die "insmod.static requested but /sbin/insmod.static not found!"
1487 if [ ! -x /sbin/mke2fs ]; then
1488 die "/sbin/mke2fs is missing"
1492 if [ ! -x /sbin/genromfs ]; then
1493 die "/sbin/genromfs is missing"
1497 if [ ! -x /sbin/mkcramfs ]; then
1498 die "/sbin/mkcramfs is missing"
1502 if [ ! -x /bin/cpio ]; then
1503 die "/bin/cpio is missing"
1505 if [ ! -x /usr/bin/find ]; then
1506 die "/usr/bin/find is missing"
1510 die "Filesystem $INITRDFS on initrd is not supported"
1514 if [ -L "$target" ]; then
1515 target=$(readlink -f "$target")
1518 if [ -n "$img_vers" ]; then
1519 target="$target-$kernel"
1522 if [ -z "$force" -a -f "$target" ]; then
1523 die "$target already exists."
1526 if [ ! -d "/lib/modules/$kernel" ]; then
1527 die "/lib/modules/$kernel is not a directory."
1530 if [ "$INITRDFS" != "initramfs" ]; then
1531 if is_yes "$FB_SPLASH"; then
1532 warn "Using fbsplash requires INITRDFS=initramfs; skipping fbsplash generation"
1535 if is_yes "$FB_CON_DECOR"; then
1536 warn "Using fbcondecor requires INITRDFS=initramfs; skipping fbcondecor generation"
1541 if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
1542 warn "Tuxonice and mainline suspend are exclusive!"
1545 if is_yes "$FB_SPLASH" && is_yes "$BOOT_SPLASH"; then
1546 warn "bootsplash and fbsplash are exclusive!"
1549 if [ ! -f /proc/mounts ]; then
1550 warn "/proc filesystem not mounted, may cause wrong results or failure."
1553 if [ -d /usr/lib64 ]; then
1559 debug "Using libdir: $_lib"
1563 for n in $PREMODS; do
1567 if [ "$FBMODULE" ]; then
1568 findmodule "$FBMODULE"
1571 # allow forcing loading SCSI and/or IDE modules
1572 if is_yes "$ADDSCSI"; then
1576 if is_yes "$ADDIDE"; then
1580 if is_yes "$USE_SUSPEND"; then
1581 find_modules_suspend
1584 find_root "$fstab" || exit
1585 debug "Using $rootdev as device for rootfs"
1587 find_modules_for_devpath "$rootdev"
1589 findmodule "-$rootFs"
1591 for n in $BASICMODULES; do
1595 if is_yes "$USE_TUXONICE"; then
1599 if is_yes "$FB_SPLASH"; then
1603 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1604 debug "No modules are needed -- not building initrd image."
1608 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
1609 RCFILE="$DESTDIR/linuxrc"
1611 chmod a+rx "$RCFILE"
1612 ln -s linuxrc $DESTDIR/init
1614 # create dirs that we really need
1615 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
1617 modules_install "$MODULES"
1619 # mknod'ing the devices instead of copying them works both with and
1621 mknod "$DESTDIR/dev/console" c 5 1
1622 mknod "$DESTDIR/dev/null" c 1 3
1623 mknod "$DESTDIR/dev/zero" c 1 5
1625 inst_exec /bin/initrd-busybox /bin/initrd-busybox
1626 ln -s initrd-busybox $DESTDIR/bin/sh
1627 ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
1629 if is_yes "$USEINSMODSTATIC"; then
1630 inst_exec "$INSMOD" /bin/insmod.static
1635 # initrd generated by:
1640 add_linuxrc <<-'EOF'
1641 read CMDLINE < /proc/cmdline; export CMDLINE
1643 for arg in $CMDLINE; do
1644 if [ "${arg}" = "debuginitrd" ]; then
1647 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1648 DEBUGINITRD=${arg##debuginitrd=}
1650 if [ "${arg##root=}" != "${arg}" ]; then
1655 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1656 if [ "$DEBUGINITRD" = "sh" ]; then
1659 if is_yes "$RUN_SULOGIN_ON_ERR"; then
1660 add_linuxrc <<-'EOF'
1661 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1664 add_linuxrc <<-'EOF'
1668 add_linuxrc <<-'EOF'
1676 if [ "$DEBUGINITRD" ]; then
1681 modules_add_linuxrc $MODULES
1683 # TODO: rewrite for busybox
1684 #if [ -n "$loopDev" ]; then
1685 # if [ ! -d /initrd ]; then
1689 # cp -a "$loopDev" "$DESTDIR/dev"
1690 # cp -a "$rootdev" "$DESTDIR/dev"
1691 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1692 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1693 # echo "echo Setting up loopback device $rootdev" >> $RCFILE
1694 # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1697 if is_yes "$USE_UDEV"; then
1701 if is_yes "$USE_TUXONICE"; then
1705 if is_yes "$need_v86d"; then
1709 if is_yes "$have_luks"; then
1713 if is_yes "$have_dmraid"; then
1717 if is_yes "$have_multipath"; then
1718 initrd_gen_multipath
1721 if is_yes "$USE_BLKID"; then
1725 if is_yes "$have_nfs"; then
1727 elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
1729 if is_yes "$have_lvm"; then
1732 initrd_gen_setrootdev
1734 elif is_yes "$have_lvm"; then
1737 initrd_gen_setrootdev
1740 if is_yes "$USE_SUSPEND"; then
1744 # additional devs always needed
1745 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
1747 if is_yes "$USE_UDEV"; then
1748 initrd_gen_stop_udevd
1751 if [ "$INITRDFS" = "initramfs" ]; then
1752 initrd_gen_initramfs_switchroot
1757 if is_yes "$FB_SPLASH"; then
1761 if is_yes "$FB_CON_DECOR"; then
1762 initrd_gen_fbcondecor
1765 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
1767 debug "Creating $INITRDFS image $IMAGE"
1770 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
1771 debug "ext2 image size: $IMAGESIZE ($DESTDIR)"
1772 if [ "$IMAGESIZE" -gt 4096 ]; then
1773 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1776 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1777 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1778 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1780 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
1781 debug "Mounting ext2 image $IMAGE to $tmpmnt"
1782 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1783 # We don't need this directory, so let's save space
1784 rm -rf "$tmpmnt"/lost+found
1786 debug "Copy recursively $DESTDIR -> $tmpmnt"
1787 cp -a $DESTDIR/* $tmpmnt
1793 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
1794 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
1795 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
1796 if [ "$IMAGESIZE" -gt 4096 ]; then
1797 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1801 mkcramfs "$DESTDIR" "$IMAGE"
1804 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
1807 echo "Filesystem $INITRDFS not supported by $PROGRAM";
1810 if is_yes "$COMPRESS"; then
1811 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
1812 debug "Compressing $target"
1813 gzip -9 < "$IMAGE" > "$tmp"
1814 mv -f "$tmp" "$target"
1816 cp -a "$IMAGE" "$target"
1819 size=$(stat -c %s $target | awk '{print int((($1/1024)+1023)/1024)*1024}')
1820 debug "Minimum RAM size that could be used for $target is: ramdisk_size=$size"
1822 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
1823 if is_yes "$BOOT_SPLASH"; then
1824 initrd_gen_bootsplash "$target"
1827 rm -rf "$DESTDIR" "$IMAGE"
1829 # vim:ts=4:sw=4:noet:fdm=marker