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 . /lib/geninitrd/functions
20 . /etc/sysconfig/system
25 # it should be safe to remove scsi_mod from here, but I'm not sure...
26 PRESCSIMODS="-scsi_mod unknown -sd_mod"
36 # device node for rootfs from fstab
38 # requires bootsplash package to operate
40 # requires splashutils package to operate
42 # requires splashutils package to operate
52 # is /tmp mounted on tmpfs
55 # are /dev nodes already created from /proc/devices info?
58 # whether v86d should be installed
64 # if we should init NFS at boot
69 echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
70 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
71 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
72 echo " [--with-raidstart] [--without-raidstart]"
73 echo " [--with-bootsplash] [--without-bootsplash]"
74 echo " [--with-fbsplash] [--without-fbsplash]"
75 echo " [--with-fbcondecor] [--without-fbcondecor]"
76 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
77 echo " [--with-suspend] [--without-suspend]"
78 echo " [--with-tuxonice] [--without-tuxonice]"
79 echo " [--without-dmraid] [--without-multipath]"
80 echo " [--without-blkid] [--without-luks]"
81 echo " <initrd-image> <kernel-version>"
84 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
97 [ -n "$verbose" ] && msg "$*" >&2
100 # aborts program abnormally
107 # append text to /linuxrc
108 # takes STDIN as input
113 # generate code to mount /dev on tmpfs and create initial nodes
114 # can be called multiple times. /dev is cleaned up (umounted) automatically at
117 if [ "$INITRDFS" = "initramfs" ]; then
118 # initramfs is read-write filesystem, no need for tmpfs
122 # we already generated tmpfs code; return
123 if is_yes "$dev_mounted"; then
129 busybox_applet mount mknod mkdir
132 mount -o mode=0755 -t tmpfs none /dev
133 mknod /dev/console c 5 1
134 mknod /dev/null c 1 3
135 mknod /dev/zero c 1 5
141 # generate code to mount /proc on initrd
142 # can be called multiple times
144 if is_yes "$proc_mounted"; then
149 if [ "$INITRDFS" = "initramfs" ]; then
150 # /proc is mounted with initramfs 2.6.22.14 kernel
151 # XXX: remove when it is clear why proc was already mounted
152 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
154 echo "mount -t proc none /proc" | add_linuxrc
158 # generate code to mount /sys on initrd
159 # can be called multiple times
161 if is_yes "$sys_mounted"; then
166 echo "mount -t sysfs none /sys" | add_linuxrc
169 # generate code to mount /tmp on initrd
170 # can be called multiple times
172 if [ "$INITRDFS" = "initramfs" ]; then
173 # initramfs is read-write filesystem, no need for tmpfs
177 if is_yes "$tmp_mounted"; then
182 echo "mount -t tmpfs none /tmp" | add_linuxrc
185 # unmount all mountpoints mounted by geninitrd
189 : Last shell before umounting all and giving control over to real init.
193 if is_yes "$dev_mounted"; then
194 echo 'umount /dev' | add_linuxrc
197 if is_yes "$proc_mounted"; then
198 echo 'umount /proc' | add_linuxrc
201 if is_yes "$sys_mounted"; then
202 echo 'umount /sys' | add_linuxrc
205 if is_yes "$tmp_mounted"; then
206 echo 'umount /tmp' | add_linuxrc
212 # Checks if busybox has support for APPLET(s)
213 # Exits from geninitrd if the support is not present.
215 # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
219 if [ -z "$busybox_functions" ]; then
220 local tmp=$(/bin/initrd-busybox 2>&1)
222 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
223 if [[ "$tmp" = *applet\ not\ found* ]]; then
225 ln -s /bin/initrd-busybox $t/busybox
226 local tmp=$($t/busybox 2>&1)
230 busybox_functions=$(echo "$tmp" | \
231 sed -ne '/Currently defined functions:/,$p' | \
232 xargs | sed -e 's,.*Currently defined functions: ,,'
238 eval have='$'busybox_have_$applet
239 if [ -z "$have" ]; then
240 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
241 if [ "$have" = 0 ]; then
242 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
245 eval busybox_have_$applet=$have
248 if [ $err = 1 ]; then
253 # Finds module dependencies
257 # Outputs full path to module and it's dependencies
262 # if module is prefixed with dash, we should ignore errors if the module
264 if [ ${module#-} != $module ]; then
269 # This works when user has module-init-tools installed even on 2.4 kernels
271 modprobe=$(modprobe --set-version $kernel --show-depends $module --ignore-install 2>&1)
274 if [ $skiperrors = 1 ]; then
279 if ! is_no "$EXIT_IF_MISSING"; then
280 die "$module: module not found for $kernel kernel"
283 warn "$module: module not found for $kernel kernel"
284 warn "If $module isn't compiled in kernel then this initrd may not start your system."
288 while read insmod modpath options; do
289 [ "$insmod" = "insmod" ] && echo $modpath
296 # no firmware support in 2.4 kernels
297 if [ "$kernel_version_long" -lt "002005048" ]; then
300 echo -n $(NEW_MODINFO=1 modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
305 local mod depmod module=$1
307 depmod=$(find_depmod $module) || exit 1
308 for mod in $depmod; do
309 mod=${mod#/lib/modules/$kernel/}
311 # add each module only once
313 for m in $MODULES; do
314 [ $m = $mod ] && have=1
316 if [ $have = 0 ]; then
317 MODULES="$MODULES $mod"
319 # if we are adding uvesafb, we need v86d as well
320 if [ "$module" = "uvesafb" ]; then
327 # install a file to temporary mount image.
328 # it will operate recursively (copying directories)
329 # and will symlink destinations if source is symlink.
331 if [ $# -lt 2 ]; then
332 die 'Usage: inst <file> [<file>] <destination>'
335 local src i=0 c=$(($# - 1))
336 while [ $i -lt $c ]; do
343 parentDir=$(dirname $DESTDIR$dest)
344 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
345 debug "+ cp $* $DESTDIR$dest"
346 cp -HR "$@" "$DESTDIR$dest"
351 die 'Usage: inst_d <destination> <destination>'
354 install -d "$DESTDIR$dir"
358 # install executable and it's shared libraries
360 if [ $# -lt 2 ]; then
361 die 'Usage: inst_exec <file>[, <file>] <destination>'
363 local src i=0 c=$(($# - 1))
364 while [ $i -lt $c ]; do
374 local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
376 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
378 inst_exec $lib /$_lib
382 # hack for uclibc linked binaries requiring this fixed path
383 # XXX: shouldn't rpath be used here instead so th
384 if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
385 local lib=$DESTDIR/$_lib/libc.so.0
386 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
387 local libdir=$(cd $(dirname "$lib"); pwd)
388 if [ ! -e $DESTDIR$libdir ]; then
389 libdir=$(dirname "$libdir")
391 debug "+ ln -s /$_lib $DESTDIR$libdir"
392 ln -s /$_lib $DESTDIR$libdir
397 # output modules.conf / modprobe.conf
399 echo "$modprobe_conf_cache"
403 # defaults to modprobe -c if not told otherwise, this means include statements
405 cache_modprobe_conf() {
406 if [ "$kernel_version" -lt "002005" ]; then
407 modulefile=/etc/modules.conf
408 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
409 modulefile=/etc/conf.modules
413 if [ -n "$modulefile" ]; then
414 debug "Using $modulefile for modules config"
415 modprobe_conf_cache=$(cat $modulefile)
417 debug "Using modprobe -c to get modules config"
418 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
422 find_modules_scsi() {
424 for n in $PRESCSIMODS; do
425 if [ "X$n" = "Xunknown" ]; then
426 debug "Finding SCSI modules using scsi_hostadapter"
427 local mod scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
428 for mod in $scsimodules; do
429 # for now allow scsi modules to come from anywhere. There are some
430 # RAID controllers with drivers in block
437 find_module "-scsi_wait_scan"
440 # find modules for $devpath
441 find_modules_for_devpath() {
443 if [ -z "$devpath" ]; then
444 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
447 if [[ "$devpath" = /dev/dm-* ]]; then
448 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
449 devpath=$(dm_longname "$devpath")
452 if [ -L "$devpath" ] && ! is_lvm "$devpath"; then
453 # sanitize things like:
454 # /dev/block/104:2 -> /dev/cciss/c0d0p2
455 devpath=$(readlink -f "$devpath")
458 debug "Finding modules for device path $devpath"
460 if is_luks "$devpath"; then
461 find_modules_luks "$devpath"
465 if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
466 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
467 die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
469 if [ ! -f /proc/bus/pci/devices ]; then
470 warn "Remember to add network card modules in /etc/sysconfig/geninitrd, example:"
471 warn "BASICMODULES=\"e1000 ne2k-pci mii 8139too 3c59x\""
474 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
475 warn "NOTE: Network card(s) module(s) $NFS_ETH_MODULES is for this machine"
476 for m in $NFS_ETH_MODULES; do
483 warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
484 warn "or you will have problems like init(xx) being child process of swapper(1)."
488 if is_md "$devpath"; then
489 find_modules_md "$devpath"
493 if is_multipath "$devpath"; then
494 if find_modules_multipath "$devpath"; then
500 if is_dmraid "$devpath"; then
501 if find_modules_dmraid "$devpath"; then
507 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
512 if is_ide "$devpath"; then
513 find_modules_ide "$devpath"
517 if [[ "$devpath" == /dev/rd/* ]]; then
523 if [[ "$devpath" == /dev/ida/* ]]; then
524 find_module "cpqarray"
525 rootdev_add=/dev/ida/
529 if [[ "$devpath" == /dev/cciss/* ]]; then
531 rootdev_add=/dev/cciss/
535 if [[ "$devpath" == /dev/ataraid/* ]]; then
537 find_module "ataraid"
538 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
539 if [ -n "$ataraidmodules" ]; then
540 # FIXME: think about modules compiled in kernel
541 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
543 for n in $ataraidmodules; do
546 rootdev_add=/dev/ataraid/
550 # check to see if we need to set up a loopback filesystem
551 if [[ "$devpath" == /dev/loop* ]]; then
552 die "Sorry, root on loop device isn't supported."
553 # TODO: rewrite for bsp and make nfs ready
554 if [ ! -x /sbin/losetup ]; then
555 die "losetup is missing"
557 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
558 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
559 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"
562 line="`awk '/'$key'/ { print $0; }' $fstab`"
563 loopDev="$(echo $line | awk '{print $3}')"
564 loopFs="$(echo $line | awk '{print $4}')"
565 loopFile="$(echo $line | awk '{print $5}')"
567 BASICMODULES="$BASICMODULES -loop"
568 find_module "-$loopFs"
569 BASICMODULES="$BASICMODULES -${loopFs}"
573 if is_lvm "$devpath"; then
574 find_modules_lvm "$devpath"
579 firmware_install_module() {
581 local firmware_files="$2"
583 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
584 # firmware not yet installed
585 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
587 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
589 echo 1 > /sys$DEVPATH/loading
590 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
591 echo 0 > /sys$DEVPATH/loading
594 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
597 for firmware in $firmware_files; do
598 if [ ! -f "/lib/firmware/$firmware" ]; then
599 die "firmware file /lib/firmware/$firmware doesn't exist."
601 FIRMWAREDIR=${firmware%/*}
602 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
603 inst /lib/firmware/$firmware /lib/firmware/$firmware
608 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
615 for mod in $modules; do
617 inst_d "/lib/modules/$kernel/$MODULEDIR"
618 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
619 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
623 modules_add_linuxrc() {
627 # module path without optional compression
631 module=${modpath##*/}
632 module=${module%$modext}
634 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
636 generic_module=$(echo $module | tr - _)
637 sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
638 firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
640 if [ -n "$verbose" ]; then
642 if [ "$options" ]; then
643 s="$s with options [$options]"
645 if [ "$sleep_var" ]; then
646 s="$s and $sleep_var usleep"
648 debug "Loading module [$module]$s"
651 if [ -n "$firmware_var" ]; then
652 firmware_install_module "$module" "$firmware_var"
654 firmware_files=$(find_firmware "$module")
655 if [ -n "$firmware_files" ]; then
656 for file in $firmware_files; do
657 firmware_install_module "$module" "$file"
662 echo "insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
663 if [ -n "$sleep_var" ]; then
664 echo "usleep $sleep_var" | add_linuxrc
669 find_modules_suspend() {
670 if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then
671 die "/usr/${_lib}/suspend/resume is missing!"
673 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
675 local vgvolumes=$VGVOLUMES
676 find_modules_for_devpath $resume_dev
678 if [ "$VGVOLUMES" != "$vgvolumes" ]; then
679 # save our VG to be able to differenciate between rootfs VG
682 debug "suspend device is on LVM"
686 initrd_gen_suspend() {
687 mknod $DESTDIR/dev/snapshot c 10 231
688 mkdir -p $DESTDIR${resume_dev%/*}
689 inst $resume_dev $resume_dev
691 inst /etc/suspend.conf /etc/suspend.conf
692 if [ -x /usr/${_lib}/suspend/resume ]; then
693 inst_exec /usr/${_lib}/suspend/resume /bin/resume
695 inst_exec /usr/sbin/resume /bin/resume
700 for arg in $CMDLINE; do
701 if [ "${arg##resume=}" != "${arg}" ]; then
705 if [ "$resume" = "yes" ]; then
711 initrd_gen_tuxonice() {
715 for arg in $CMDLINE; do
716 if [ "${arg##resume=}" != "${arg}" -o "${arg##resume2=}" != "${arg}" ]; then
720 if [ "$resume" = "yes" ]; then
721 [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
722 [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
723 [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
729 debug "initrd_gen_v86d"
730 mknod $DESTDIR/dev/mem c 1 1
731 mknod $DESTDIR/dev/tty1 c 4 1
733 inst_exec /sbin/v86d /sbin
737 debug "Setting up udev..."
738 inst_d /sbin /etc/udev
740 if [ ! -x /sbin/initrd-udevd ]; then
741 die "/sbin/initrd-udevd not present"
744 inst_exec /sbin/initrd-udevd /sbin/udevd
745 inst /etc/udev/udev.conf /etc/udev/udev.conf
754 inst_exec /sbin/initrd-udevadm /sbin/udevadm
756 /sbin/udevadm trigger
762 initrd_gen_stop_udevd() {
763 busybox_applet killall
771 initrd_gen_bootsplash() {
774 debug "Generating bootsplash"
776 if [ ! -x /bin/splash.bin ]; then
777 warn "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
781 if [ -r /etc/sysconfig/bootsplash ]; then
782 . /etc/sysconfig/bootsplash
785 if [ -z "$THEME" ]; then
786 warn "Please configure your /etc/sysconfig/bootsplash first."
787 warn "Generating bootsplashes skipped."
791 if [ -z "$BOOT_SPLASH_RESOLUTIONS" ]; then
792 warn "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
793 warn "Not adding bootsplash to initrd."
796 for res in $BOOT_SPLASH_RESOLUTIONS; do
797 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
798 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
799 debug "Added $res $THEME theme to initrd."
801 warn "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
806 initrd_gen_fbsplash() {
807 debug "Generating fbsplash"
809 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
810 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
813 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
814 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
816 if [ -r /etc/sysconfig/fbsplash ]; then
817 . /etc/sysconfig/fbsplash
820 if [ -z "$SPLASH_THEME" ]; then
821 warn "Please configure your /etc/sysconfig/fbsplash first."
822 warn "Generating fbsplashes skipped."
826 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
827 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
828 warn "Not adding fbsplash to initramfs."
832 for res in $FB_SPLASH_RESOLUTIONS; do
833 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
834 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
835 debug "Added $res $SPLASH_THEME theme to initramfs."
837 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
842 initrd_gen_fbcondecor() {
843 debug "Generating fbcondecor"
845 if [ ! -x /usr/bin/splash_geninitramfs -a ! -x /usr/sbin/splash_geninitramfs ]; then
846 warn "Failed to find splash_geninitramfs. Is splashutils package installed?"
849 splash_geninitramfs_bin=/usr/sbin/splash_geninitramfs
850 [ -f /usr/bin/splash_geninitramfs ] && splash_geninitramfs_bin=/usr/bin/splash_geninitramfs
852 if [ -r /etc/sysconfig/splash ]; then
853 . /etc/sysconfig/splash
856 if [ -z "$SPLASH_THEME" ]; then
857 warn "Please configure your /etc/sysconfig/splash first."
858 warn "Generating of splashes skipped."
862 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
863 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/splash."
864 warn "Not adding fbcondecor to initramfs."
868 for res in $FB_SPLASH_RESOLUTIONS; do
869 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
870 $splash_geninitramfs_bin -c $DESTDIR -r $res $SPLASH_THEME && \
871 debug "Added $res $SPLASH_THEME theme to initramfs."
873 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
878 # Generates /dev nodes based on /proc/partitions information.
879 # Needs /proc mounted.
880 # Can be called multiple times.
881 initrd_gen_devices() {
882 if is_yes "$proc_partitions"; then
889 : 'Making device nodes'
890 cat /proc/partitions | (
891 # ignore first two lines: header, empty line
894 while read major minor blocks dev rest; do
897 [ -e $node ] || mknod $node b $major $minor
904 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
905 # have problems like init(XX) being child process of swapper(1).
906 debug "Adding rootfs on NFS support to initrd (dhcp)"
907 mknod "$DESTDIR/dev/urandom" c 1 9
908 mkdir "$DESTDIR/newroot"
910 ifconfig lo 127.0.0.1 up
911 route add -net 127.0.0.0 mask 255.0.0.0 lo
913 udhcpc -i eth0 -f -q -s /bin/setdhcp
917 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
918 exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
921 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
923 [ "$1" != "bound" ] && exit
924 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
925 [ -n "$subnet" ] && NETMASK="netmask $subnet"
926 ifconfig $interface $ip $BROADCAST $NETMASK up
927 if [ -n "$router" ]; then
929 route add default gw $r dev $interface
933 for o in $CMDLINE; do
936 rootpath=${o#nfsroot=}
941 if [ -n "$rootpath" ]; then
942 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
944 echo "Missing rootpath in what DHCP server sent to us. Failing..."
945 echo "All seen variables are listed below:"
950 chmod 755 "$DESTDIR/bin/setdhcp"
955 debug "Adding BLKID support to initrd"
956 inst_exec /sbin/initrd-blkid /bin/blkid
959 # if built with blkid change ROOT=LABEL=something into ROOT=/dev/somethingelse -
961 if [ "${ROOT##LABEL=}" != "${ROOT}" -o "${ROOT##UUID=}" != "${ROOT}" ]; then
962 ROOT="$(/bin/blkid -t $ROOT -o device -l)"
967 initrd_gen_setrootdev() {
968 debug "Adding rootfs finding based on kernel cmdline root= option support."
970 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
971 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
972 if [ -n "$rootnr" ]; then
973 echo "$rootnr" > /proc/sys/kernel/real-root-dev
979 initrd_gen_initramfs_switchroot() {
981 if [ "$rootdev" = "/dev/nfs" ]; then
982 echo "rootfs on NFS root=/dev/nfs"
984 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
987 # parse 'root=xxx' kernel commandline
988 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
990 device=/dev/no_partition_found
991 eval "$(busybox awk -v c="$ROOT" '
993 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
994 num_pattern = "[0-9a-f]" num_pattern_short;
995 dev_pattern = "[hms][a-z][a-z]([0-9])+";
996 partition = "no_partition_found";
1000 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
1001 if (c ~ "^" num_pattern "$") {
1002 maj = sprintf("%s",substr(c,1,2));
1003 min = sprintf("%s",substr(c,3));
1005 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
1006 if (c ~ "^" dev_pattern "$") partition = c;
1009 $4 ~ partition { maj = $1; min = $2; }
1010 $1 ~ maj && $2 ~ min { partition = $4; }
1013 if (maj >= 0 && min >= 0) {
1014 printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
1017 ' /proc/partitions)"
1018 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
1019 mknod $device b $maj $min
1028 add_linuxrc <<-'EOF'
1029 if [ "$device" = '/dev/no_partition_found' ]; then
1033 mount -t $rootfs -r $device /newroot
1034 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
1035 if [ -z "$init" -o ! -x "/newroot$init" ]; then
1041 busybox_applet switch_root
1042 add_linuxrc <<-'EOF'
1043 exec switch_root /newroot $init
1045 echo "Error! initramfs should not reach this place."
1046 echo "It probably means you've got old version of busybox, with broken"
1047 echo "initramfs support. Trying to boot anyway, but won't promise anything."
1049 exec chroot /newroot $init
1051 echo "Failed to chroot!"
1053 # we need /init being real file, not symlink, otherwise the initramfs will
1054 # not be ran by pid 1 which is required for switch_root
1055 mv $DESTDIR/linuxrc $DESTDIR/init
1056 ln -s init $DESTDIR/linuxrc
1060 if [ "$(id -u)" != 0 ]; then
1061 die "You need to be root to generate initrd"
1064 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
1066 . /etc/udev/udev.conf
1070 . /lib/geninitrd/mod-ide.sh
1071 # cryptsetup luks addon
1072 . /lib/geninitrd/mod-luks.sh
1073 # dm-multipath addon
1074 . /lib/geninitrd/mod-multipath.sh
1076 . /lib/geninitrd/mod-dmraid.sh
1078 . /lib/geninitrd/mod-lvm.sh
1080 . /lib/geninitrd/mod-md.sh
1082 if [ -x /sbin/initrd-blkid ]; then
1086 if [ -r /etc/sysconfig/geninitrd ]; then
1087 . /etc/sysconfig/geninitrd
1090 if [ ! -x /bin/initrd-busybox ]; then
1091 die "/bin/initrd-busybox is missing!"
1094 # backwards compatible
1095 if [ "$USE_SUSPEND2" ]; then
1096 USE_TUXONICE=$USE_SUSPEND2
1097 warn "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
1100 while [ $# -gt 0 ]; do
1110 modulefile=${1#--modules-conf=}
1116 --use-raidstart|--with-raidstart)
1119 --without-raidstart)
1125 --without-bootsplash)
1137 --without-fbcondecor)
1146 --with-suspend2 | --with-tuxonice)
1149 --without-suspend2 | --without-tuxonice)
1153 LVMTOOLSVERSION=${1#--lvmversion=}
1155 --lvmtoolsversion=*)
1156 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
1158 --lvmtoolsversion|--lvmversion)
1171 --without-multipath)
1181 BASICMODULES="$BASICMODULES ${1#--with=}"
1184 BASICMODULES="$BASICMODULES $2"
1188 echo "$PROGRAM: version $VERSION"
1204 PREMODS="$PREMODS ${1#--preload=}"
1207 PREMODS="$PREMODS $2"
1211 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1215 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
1220 INITRDFS=${1#--initrdfs=}
1233 if [ -z "$target" ]; then
1235 elif [ -z "$kernel" ]; then
1247 if [ -z "$target" -o -z "$kernel" ]; then
1252 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1253 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1256 kernel_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1257 kernel_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
1259 if [ -z "$INITRDFS" ]; then
1260 if [ -z "$FS" ]; then
1262 if [ "$kernel_version" -ge "002005" ]; then
1263 INITRDFS="initramfs"
1268 warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
1273 if [ "$kernel_version" -lt "002006" ]; then
1278 if [ "$kernel_version" -ge "002005" ]; then
1284 if [ ! -x /sbin/mke2fs ]; then
1285 die "/sbin/mke2fs is missing"
1289 if [ ! -x /sbin/genromfs ]; then
1290 die "/sbin/genromfs is missing"
1294 if [ ! -x /sbin/mkcramfs ]; then
1295 die "/sbin/mkcramfs is missing"
1299 if [ ! -x /bin/cpio ]; then
1300 die "/bin/cpio is missing"
1302 if [ ! -x /usr/bin/find ]; then
1303 die "/usr/bin/find is missing"
1307 die "Filesystem $INITRDFS on initrd is not supported"
1311 if [ -L "$target" ]; then
1312 target=$(readlink -f "$target")
1315 if [ -n "$img_vers" ]; then
1316 target="$target-$kernel"
1319 if [ -z "$force" -a -f "$target" ]; then
1320 die "$target already exists."
1323 if [ ! -d "/lib/modules/$kernel" ]; then
1324 die "/lib/modules/$kernel is not a directory."
1327 if [ "$INITRDFS" != "initramfs" ]; then
1328 if is_yes "$FB_SPLASH"; then
1329 warn "Using fbsplash requires INITRDFS=initramfs; skipping fbsplash generation"
1332 if is_yes "$FB_CON_DECOR"; then
1333 warn "Using fbcondecor requires INITRDFS=initramfs; skipping fbcondecor generation"
1338 if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
1339 warn "Tuxonice and mainline suspend are exclusive!"
1342 if is_yes "$FB_SPLASH" && is_yes "$BOOT_SPLASH"; then
1343 warn "bootsplash and fbsplash are exclusive!"
1346 if [ ! -f /proc/mounts ]; then
1347 warn "/proc filesystem not mounted, may cause wrong results or failure."
1350 if [ -d /usr/lib64 ]; then
1356 debug "Using libdir: $_lib"
1360 for n in $PREMODS; do
1364 if [ "$FBMODULE" ]; then
1365 find_module "$FBMODULE"
1368 # allow forcing loading SCSI and/or IDE modules
1369 if is_yes "$ADDSCSI"; then
1373 if is_yes "$ADDIDE"; then
1377 if is_yes "$USE_SUSPEND"; then
1378 find_modules_suspend
1381 find_root "$fstab" || exit
1382 debug "Using $rootdev as device for rootfs"
1384 find_modules_for_devpath "$rootdev"
1386 find_module "-$rootFs"
1388 for n in $BASICMODULES; do
1392 if is_yes "$USE_TUXONICE"; then
1396 if is_yes "$FB_SPLASH"; then
1397 find_module "-evdev"
1400 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1401 debug "No modules are needed -- not building initrd image."
1405 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
1406 RCFILE="$DESTDIR/linuxrc"
1408 chmod a+rx "$RCFILE"
1409 ln -s linuxrc $DESTDIR/init
1411 # create dirs that we really need
1412 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
1414 modules_install "$MODULES"
1416 # mknod'ing the devices instead of copying them works both with and
1418 mknod "$DESTDIR/dev/console" c 5 1
1419 mknod "$DESTDIR/dev/null" c 1 3
1420 mknod "$DESTDIR/dev/zero" c 1 5
1422 inst_exec /bin/initrd-busybox /bin/initrd-busybox
1423 ln -s initrd-busybox $DESTDIR/bin/sh
1424 ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
1428 # initrd generated by:
1433 add_linuxrc <<-'EOF'
1434 read CMDLINE < /proc/cmdline; export CMDLINE
1436 for arg in $CMDLINE; do
1437 if [ "${arg}" = "debuginitrd" ]; then
1440 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1441 DEBUGINITRD=${arg##debuginitrd=}
1443 if [ "${arg##root=}" != "${arg}" ]; then
1448 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1449 if [ "$DEBUGINITRD" = "sh" ]; then
1452 if is_yes "$RUN_SULOGIN_ON_ERR"; then
1453 add_linuxrc <<-'EOF'
1454 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1457 add_linuxrc <<-'EOF'
1461 add_linuxrc <<-'EOF'
1469 if [ "$DEBUGINITRD" ]; then
1474 modules_add_linuxrc $MODULES
1476 # TODO: rewrite for busybox
1477 #if [ -n "$loopDev" ]; then
1478 # if [ ! -d /initrd ]; then
1482 # cp -a "$loopDev" "$DESTDIR/dev"
1483 # cp -a "$rootdev" "$DESTDIR/dev"
1484 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1485 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1486 # echo "echo Setting up loopback device $rootdev" >> $RCFILE
1487 # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1490 if is_yes "$USE_UDEV"; then
1494 if is_yes "$USE_TUXONICE"; then
1498 if is_yes "$need_v86d"; then
1502 if is_yes "$have_luks"; then
1506 if is_yes "$have_dmraid"; then
1510 if is_yes "$have_multipath"; then
1511 initrd_gen_multipath
1514 if is_yes "$USE_BLKID"; then
1518 if is_yes "$have_nfs"; then
1520 elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
1522 if is_yes "$have_lvm"; then
1525 initrd_gen_setrootdev
1527 elif is_yes "$have_lvm"; then
1530 initrd_gen_setrootdev
1533 if is_yes "$USE_SUSPEND"; then
1537 # additional devs always needed
1538 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
1540 if is_yes "$USE_UDEV"; then
1541 initrd_gen_stop_udevd
1544 if [ "$INITRDFS" = "initramfs" ]; then
1545 initrd_gen_initramfs_switchroot
1550 if is_yes "$FB_SPLASH"; then
1554 if is_yes "$FB_CON_DECOR"; then
1555 initrd_gen_fbcondecor
1558 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
1560 debug "Creating $INITRDFS image $IMAGE"
1563 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
1564 debug "ext2 image size: $IMAGESIZE ($DESTDIR)"
1565 if [ "$IMAGESIZE" -gt 4096 ]; then
1566 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1569 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1570 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1571 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1573 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
1574 debug "Mounting ext2 image $IMAGE to $tmpmnt"
1575 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1576 # We don't need this directory, so let's save space
1577 rm -rf "$tmpmnt"/lost+found
1579 debug "Copy recursively $DESTDIR -> $tmpmnt"
1580 cp -a $DESTDIR/* $tmpmnt
1586 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
1587 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
1588 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
1589 if [ "$IMAGESIZE" -gt 4096 ]; then
1590 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1594 mkcramfs "$DESTDIR" "$IMAGE"
1597 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
1600 echo "Filesystem $INITRDFS not supported by $PROGRAM";
1603 if is_yes "$COMPRESS"; then
1604 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
1605 debug "Compressing $target"
1606 gzip -9 < "$IMAGE" > "$tmp"
1607 mv -f "$tmp" "$target"
1609 cp -a "$IMAGE" "$target"
1612 size=$(stat -c %s $target | awk '{print int((($1/1024)+1023)/1024)*1024}')
1613 debug "Minimum RAM size that could be used for $target is: ramdisk_size=$size"
1615 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
1616 if is_yes "$BOOT_SPLASH"; then
1617 initrd_gen_bootsplash "$target"
1620 rm -rf "$DESTDIR" "$IMAGE"
1622 # vim:ts=4:sw=4:noet:fdm=marker