7 # based on mkinitrd from RedHat Linux
10 RCSID='$Revision$ $Date$'
11 R=${RCSID#* *}; VERSION=${R%% *}
14 . /etc/rc.d/init.d/functions
15 . /lib/geninitrd/functions
16 . /etc/sysconfig/system
18 # list of geninitrd modules which need setup routine after commandline args parsing
30 # device node for rootfs from fstab
40 # is /tmp mounted on tmpfs
43 # are /dev nodes already created from /proc/devices info?
48 echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
49 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
50 echo " [--compress=yes|lzma|bzip2|gzip]"
51 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
52 echo " [--with-bootsplash] [--without-bootsplash]"
53 echo " [--with-fbsplash] [--without-fbsplash]"
54 echo " [--with-fbcondecor] [--without-fbcondecor]"
55 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
56 echo " [--with-suspend] [--without-suspend]"
57 echo " [--with-tuxonice] [--without-tuxonice]"
58 echo " [--without-dmraid]"
59 echo " [--with-multipath=DEVPATH] [--without-multipath]"
60 echo " [--without-blkid] [--without-luks]"
61 echo " <initrd-image> <kernel-version>"
64 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
77 [ -n "$verbose" ] && msg "$*" >&2
80 # aborts program abnormally
87 # find program from specified paths
93 debug "find_tool: found $x"
97 debug "find_tool: did not found any of: $@"
101 # loads geninitrd modules
102 geninitrd_load_mods() {
105 if [ ! -f /lib/geninitrd/mod-$mod.sh ]; then
106 die "$mod geninitrd module can't be loaded"
108 . /lib/geninitrd/mod-$mod.sh
110 if type setup_mod_$mod > /dev/null; then
111 # add to list which need init
112 GENINITRD_MODS="$GENINITRD_MODS $mod"
117 # setup geninitrd modules
118 geninitrd_setup_mods() {
121 for mod in $GENINITRD_MODS; do
126 # append text to /linuxrc
127 # takes STDIN as input
132 # generate code to mount /dev on tmpfs and create initial nodes
133 # can be called multiple times. /dev is cleaned up (umounted) automatically at
136 if [ "$INITRDFS" = "initramfs" ]; then
137 # initramfs is read-write filesystem, no need for tmpfs
141 # we already generated tmpfs code; return
142 if is_yes "$dev_mounted"; then
148 busybox_applet mount mknod mkdir
151 mount -o mode=0755 -t tmpfs none /dev
152 mknod /dev/console c 5 1
153 mknod /dev/null c 1 3
154 mknod /dev/zero c 1 5
155 mknod /dev/urandom c 1 9
161 # generate code to mount /proc on initrd
162 # can be called multiple times
164 if is_yes "$proc_mounted"; then
169 if [ "$INITRDFS" = "initramfs" ]; then
170 # /proc is mounted with initramfs 2.6.22.14 kernel
171 # XXX: remove when it is clear why proc was already mounted
172 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
174 echo "mount -t proc none /proc" | add_linuxrc
178 # generate code to mount /sys on initrd
179 # can be called multiple times
181 if is_yes "$sys_mounted"; then
186 echo "mount -t sysfs none /sys" | add_linuxrc
189 # generate code to mount /tmp on initrd
190 # can be called multiple times
192 if [ "$INITRDFS" = "initramfs" ]; then
193 # initramfs is read-write filesystem, no need for tmpfs
197 if is_yes "$tmp_mounted"; then
202 echo "mount -t tmpfs none /tmp" | add_linuxrc
205 # unmount all mountpoints mounted by geninitrd
209 : Last shell before umounting all and giving control over to real init.
213 if is_yes "$dev_mounted"; then
214 echo 'umount /dev' | add_linuxrc
217 if is_yes "$proc_mounted"; then
218 echo 'umount /proc' | add_linuxrc
221 if is_yes "$sys_mounted"; then
222 echo 'umount /sys' | add_linuxrc
225 if is_yes "$tmp_mounted"; then
226 echo 'umount /tmp' | add_linuxrc
232 # Checks if busybox has support for APPLET(s)
233 # Exits from geninitrd if the support is not present.
235 # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
239 if [ -z "$busybox_functions" ]; then
240 local tmp=$($busybox 2>&1)
242 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
243 if [[ "$tmp" = *applet\ not\ found* ]]; then
245 ln -s $busybox $t/busybox
246 local tmp=$($t/busybox 2>&1)
250 busybox_functions=$(echo "$tmp" | \
251 sed -ne '/Currently defined functions:/,$p' | \
252 xargs | sed -e 's,.*Currently defined functions: ,,'
258 eval have='$'busybox_have_$applet
259 if [ -z "$have" ]; then
260 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
261 if [ "$have" = 0 ]; then
262 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
265 eval busybox_have_$applet=$have
268 if [ $err = 1 ]; then
273 # Finds module dependencies
277 # Outputs full path to module and it's dependencies
282 # if module is prefixed with dash, we should ignore errors if the module
284 if [ ${module#-} != $module ]; then
289 # This works when user has module-init-tools installed even on 2.4 kernels
291 modprobe=$(modprobe --set-version $kernel --show-depends $module --ignore-install 2>&1)
294 if [ $skiperrors = 1 ]; then
299 if ! is_no "$EXIT_IF_MISSING"; then
300 die "$module: module not found for $kernel kernel"
303 warn "$module: module not found for $kernel kernel"
304 warn "If $module isn't compiled in kernel then this initrd may not start your system."
308 while read insmod modpath options; do
309 [ "$insmod" = "insmod" ] && echo $modpath
316 # no firmware support in 2.4 kernels
317 if [ "$kernel_version_long" -lt "002005048" ]; then
320 echo -n $(NEW_MODINFO=1 modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
325 local mod depmod module=$1
327 depmod=$(find_depmod $module) || exit 1
328 for mod in $depmod; do
329 mod=${mod#/lib/modules/$kernel/}
331 # add each module only once
333 for m in $MODULES; do
334 [ $m = $mod ] && have=1
336 if [ $have = 0 ]; then
337 MODULES="$MODULES $mod"
342 # install a file to temporary mount image.
343 # it will operate recursively (copying directories)
344 # and will symlink destinations if source is symlink.
346 if [ $# -lt 2 ]; then
347 die 'Usage: inst <file> [<file>] <destination>'
350 local src i=0 c=$(($# - 1))
351 while [ $i -lt $c ]; do
358 parentDir=$(dirname $DESTDIR$dest)
359 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
360 debug "+ cp $* $DESTDIR$dest"
361 cp -HR "$@" "$DESTDIR$dest"
366 die 'Usage: inst_d <destination> <destination>'
369 install -d "$DESTDIR$dir"
373 # install executable and it's shared libraries
375 if [ $# -lt 2 ]; then
376 die "Invalid params ($@), Usage: inst_exec <file>[, <file>] <destination>"
378 local src i=0 c=$(($# - 1))
379 while [ $i -lt $c ]; do
389 local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
391 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
393 inst_exec $lib /$_lib
397 # hack for uclibc linked binaries requiring this fixed path
398 # XXX: shouldn't rpath be used here instead so th
399 if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
400 local lib=$DESTDIR/$_lib/libc.so.0
401 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
402 local libdir=$(cd $(dirname "$lib"); pwd)
403 if [ ! -e $DESTDIR$libdir ]; then
404 libdir=$(dirname "$libdir")
406 debug "+ ln -s /$_lib $DESTDIR$libdir"
407 ln -s /$_lib $DESTDIR$libdir
412 # output modules.conf / modprobe.conf
414 echo "$modprobe_conf_cache"
418 # defaults to modprobe -c if not told otherwise, this means include statements
420 cache_modprobe_conf() {
421 if [ "$kernel_version" -lt "002005" ]; then
422 modulefile=/etc/modules.conf
423 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
424 modulefile=/etc/conf.modules
428 if [ -n "$modulefile" ]; then
429 debug "Using $modulefile for modules config"
430 modprobe_conf_cache=$(cat $modulefile)
432 debug "Using modprobe -c to get modules config"
433 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
437 # find modules for $devpath
438 find_modules_for_devpath() {
440 if [ -z "$devpath" ]; then
441 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
444 if [[ "$devpath" = /dev/dm-* ]]; then
445 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
446 devpath=$(dm_longname "$devpath")
449 if [ -L "$devpath" ] && ! is_lvm "$devpath"; then
450 # sanitize things like:
451 # /dev/block/104:2 -> /dev/cciss/c0d0p2
452 devpath=$(readlink -f "$devpath")
455 debug "Finding modules for device path $devpath"
457 if is_luks "$devpath"; then
458 find_modules_luks "$devpath"
462 if is_nfs "$devpath"; then
463 find_modules_nfs "$devpath"
467 if is_md "$devpath"; then
468 find_modules_md "$devpath"
472 if is_multipath "$devpath"; then
473 if find_modules_multipath "$devpath"; then
480 if is_dmraid "$devpath"; then
481 if find_modules_dmraid "$devpath"; then
487 if is_scsi "$devpath"; then
488 find_modules_scsi "$devpath"
492 if is_ide "$devpath"; then
493 find_modules_ide "$devpath"
497 if [[ "$devpath" == /dev/rd/* ]]; then
503 if [[ "$devpath" == /dev/ida/* ]]; then
504 find_module "cpqarray"
505 rootdev_add=/dev/ida/
509 if [[ "$devpath" == /dev/cciss/* ]]; then
511 rootdev_add=/dev/cciss/
515 if [[ "$devpath" == /dev/ataraid/* ]]; then
517 find_module "ataraid"
518 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
519 if [ -n "$ataraidmodules" ]; then
520 # FIXME: think about modules compiled in kernel
521 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
523 for n in $ataraidmodules; do
526 rootdev_add=/dev/ataraid/
530 # check to see if we need to set up a loopback filesystem
531 if [[ "$devpath" == /dev/loop* ]]; then
532 die "Sorry, root on loop device isn't supported."
533 # TODO: rewrite for bsp and make nfs ready
534 if [ ! -x /sbin/losetup ]; then
535 die "losetup is missing"
537 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
538 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
539 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"
542 line="`awk '/'$key'/ { print $0; }' $fstab`"
543 loopDev="$(echo $line | awk '{print $3}')"
544 loopFs="$(echo $line | awk '{print $4}')"
545 loopFile="$(echo $line | awk '{print $5}')"
547 BASICMODULES="$BASICMODULES -loop"
548 find_module "-$loopFs"
549 BASICMODULES="$BASICMODULES -${loopFs}"
553 if is_lvm "$devpath"; then
554 find_modules_lvm "$devpath"
559 firmware_install_module() {
561 local firmware_files="$2"
563 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
564 # firmware not yet installed
565 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
567 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
569 echo 1 > /sys$DEVPATH/loading
570 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
571 echo 0 > /sys$DEVPATH/loading
574 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
577 for firmware in $firmware_files; do
578 if [ -f "/lib/firmware/$kernel/$firmware" ]; then
579 FIRMWAREDIR=${firmware%/*}
580 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
581 inst /lib/firmware/$kernel/$firmware /lib/firmware/$firmware
582 elif [ -f "/lib/firmware/$firmware" ]; then
583 FIRMWAREDIR=${firmware%/*}
584 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
585 inst /lib/firmware/$firmware /lib/firmware/$firmware
587 die "firmware file /lib/firmware/$firmware nor /lib/firmware/$kernel/$firmware found."
592 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
599 for mod in $modules; do
601 inst_d "/lib/modules/$kernel/$MODULEDIR"
602 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
603 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
607 modules_add_linuxrc() {
611 # module path without optional compression
615 module=${modpath##*/}
616 module=${module%$modext}
618 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
620 generic_module=$(echo $module | tr - _)
621 sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
622 firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
624 if [ -n "$verbose" ]; then
626 if [ "$options" ]; then
627 s="$s with options [$options]"
629 if [ "$sleep_var" ]; then
630 s="$s and $sleep_var usleep"
632 debug "Loading module [$module]$s"
635 if [ -n "$firmware_var" ]; then
636 firmware_install_module "$module" "$firmware_var"
638 firmware_files=$(find_firmware "$module")
639 if [ -n "$firmware_files" ]; then
640 for file in $firmware_files; do
641 firmware_install_module "$module" "$file"
646 echo "insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
647 if [ -n "$sleep_var" ]; then
648 echo "usleep $sleep_var" | add_linuxrc
650 if [ "$module" = "scsi_wait_scan" ]; then
651 if [ "$(busybox_applet rmmod 2>/dev/null; echo $?)" = 0 ]; then
652 echo "rmmod scsi_wait_scan" | add_linuxrc
659 # Generates /dev nodes based on /proc/partitions information.
660 # Needs /proc mounted.
661 # Can be called multiple times.
662 initrd_gen_devices() {
663 if is_yes "$proc_partitions"; then
670 : 'Making device nodes'
671 cat /proc/partitions | (
672 # ignore first two lines: header, empty line
675 while read major minor blocks dev rest; do
678 [ -e $node ] || mknod $node b $major $minor
685 initrd_gen_setrootdev() {
686 debug "Adding rootfs finding based on kernel cmdline root= option support."
688 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
689 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
690 if [ -n "$rootnr" ]; then
691 echo "$rootnr" > /proc/sys/kernel/real-root-dev
697 initrd_gen_initramfs_switchroot() {
699 if [ "$rootdev" = "/dev/nfs" ]; then
700 echo "rootfs on NFS root=/dev/nfs"
702 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
705 # parse 'root=xxx' kernel commandline
706 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
708 device=/dev/no_partition_found
709 eval "$(busybox awk -v c="$ROOT" '
711 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
712 num_pattern = "[0-9a-f]" num_pattern_short;
713 dev_pattern = "[hms][a-z][a-z]([0-9])+";
714 partition = "no_partition_found";
718 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
719 if (c ~ "^" num_pattern "$") {
720 maj = sprintf("%s",substr(c,1,2));
721 min = sprintf("%s",substr(c,3));
723 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
724 if (c ~ "^" dev_pattern "$") partition = c;
727 $4 ~ partition { maj = $1; min = $2; }
728 $1 ~ maj && $2 ~ min { partition = $4; }
731 if (maj >= 0 && min >= 0) {
732 printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
736 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
737 mknod $device b $maj $min
747 if [ "$device" = '/dev/no_partition_found' ]; then
751 mount -t $rootfs -r $device /newroot
752 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
753 if [ -z "$init" -o ! -x "/newroot$init" ]; then
759 busybox_applet switch_root
761 exec switch_root /newroot $init ${1:+"$@"}
763 echo "Error! initramfs should not reach this place."
764 echo "It probably means you've got old version of busybox, with broken"
765 echo "initramfs support. Trying to boot anyway, but won't promise anything."
767 exec chroot /newroot $init ${1:+"$@"}
769 echo "Failed to chroot!"
771 # we need /init being real file, not symlink, otherwise the initramfs will
772 # not be ran by pid 1 which is required for switch_root
773 mv $DESTDIR/linuxrc $DESTDIR/init
774 ln -s init $DESTDIR/linuxrc
777 # find if $symbol exists in System.map $mapfile
781 if [ ! -f $mapfile ]; then
782 # missing mapfile (not a pld kernel?)
786 awk -vc=1 -vsymbol="$symbol" '$2 == "T" && $3 == symbol {c = 0} END {exit c}' $mapfile
789 # find best compressor (or forced one) for initrd
792 # the best compressor list
793 local compressors='lzma bzip2 gzip'
795 # a specified one, take it
796 if ! is_yes "$mode"; then
800 debug "finding compressor: $compressors (via $mode)"
801 # check for compressor validity
802 local c prog map=/boot/System.map-$kernel
803 for c in $compressors; do
818 die "Unknown compressor $c"
821 if sym_exists $map $sym && [ -x $prog ]; then
827 debug "using gzip for compressor (fallback)"
831 if [ -r /etc/sysconfig/geninitrd ]; then
832 . /etc/sysconfig/geninitrd
835 if [ ! -f /proc/mounts ]; then
836 warn "/proc filesystem not mounted, may cause wrong results or failure."
839 geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs scsi
841 while [ $# -gt 0 ]; do
851 modulefile=${1#--modules-conf=}
860 --without-bootsplash)
872 --without-fbcondecor)
881 --with-suspend2 | --with-tuxonice)
884 --without-suspend2 | --without-tuxonice)
888 LVMTOOLSVERSION=${1#--lvmversion=}
891 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
893 --lvmtoolsversion|--lvmversion)
910 USE_MULTIPATH=${1#--with-multipath=}
919 BASICMODULES="$BASICMODULES ${1#--with=}"
922 BASICMODULES="$BASICMODULES $2"
926 echo "$PROGRAM: version $VERSION"
936 COMPRESS="${1#--compress=}"
948 PREMODS="$PREMODS ${1#--preload=}"
951 PREMODS="$PREMODS $2"
955 die "--fs option is obsoleted. Use --initrdfs instead"
958 INITRDFS=${1#--initrdfs=}
971 if [ -z "$target" ]; then
973 elif [ -z "$kernel" ]; then
985 if [ -z "$target" -o -z "$kernel" ]; then
991 if [ "$(id -u)" != 0 ]; then
992 die "You need to be root to generate initrd"
995 if [ -d /usr/lib64 ]; then
1001 initrd_dir=/usr/$_lib/initrd
1002 kernel_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1003 kernel_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
1006 debug "Using _lib: $_lib"
1007 debug "Using initrd_dir: $initrd_dir"
1009 busybox=$(find_tool $initrd_dir/initrd-busybox /bin/initrd-busybox) || die "Couldn't find busybox suitable for initrd"
1011 # we setup mods after parsing command line args
1012 geninitrd_setup_mods
1014 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1015 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1018 if [ -z "$INITRDFS" ]; then
1019 if [ -n "$FS" ]; then
1020 # FS= can came only via /etc/sysconfig/geninitrd likely?
1021 die "FS configuration option is obsoleted. Use INITRDFS instead"
1025 if [ "$kernel_version" -ge "002005" ]; then
1026 INITRDFS="initramfs"
1034 [ -x /sbin/mke2fs ] || die "/sbin/mke2fs is missing"
1037 [ -x /sbin/genromfs ] || die "/sbin/genromfs is missing"
1040 [ -x /sbin/mkcramfs ] || die "/sbin/mkcramfs is missing"
1043 [ -x /bin/cpio ] || die "/bin/cpio is missing"
1044 [ -x /usr/bin/find ] || die "/usr/bin/find is missing"
1047 die "Filesystem $INITRDFS on initrd is not supported"
1051 if [ -L "$target" ]; then
1052 target=$(readlink -f "$target")
1055 if [ -n "$img_vers" ]; then
1056 target="$target-$kernel"
1059 if [ -z "$force" -a -f "$target" ]; then
1060 die "$target already exists."
1063 if [ ! -d "/lib/modules/$kernel" ]; then
1064 die "/lib/modules/$kernel is not a directory."
1067 if [ "$kernel_version" -ge "002005" ]; then
1073 for n in $PREMODS; do
1077 if [ "$FBMODULE" ]; then
1078 find_module "$FBMODULE"
1081 # allow forcing loading SCSI and/or IDE modules
1082 # XXX: where ADDSCSI cames from? drop?
1083 if is_yes "$ADDSCSI"; then
1087 # XXX: where ADDIDE cames from? drop?
1088 if is_yes "$ADDIDE"; then
1092 if is_yes "$USE_SUSPEND"; then
1093 find_modules_suspend
1096 find_root "$fstab" || exit
1097 debug "Using $rootdev as device for rootfs"
1099 find_modules_for_devpath "$rootdev"
1101 # if USE_MULTIPATH is path to device, scan that too
1102 # this is to bootstrap multipath setup into initrd.
1103 if ! is_no "$USE_MULTIPATH" && ! is_yes "$USE_MULTIPATH"; then
1104 find_modules_multipath $USE_MULTIPATH
1107 find_module "-$rootFs"
1109 for n in $BASICMODULES; do
1113 if is_yes "$USE_TUXONICE"; then
1117 find_modules_fbsplash
1119 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1120 debug "No modules are needed -- not building initrd image."
1124 debug "Building initrd..."
1125 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
1126 RCFILE="$DESTDIR/linuxrc"
1128 chmod a+rx "$RCFILE"
1129 ln -s linuxrc $DESTDIR/init
1131 # create dirs that we really need
1132 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
1134 modules_install "$MODULES"
1136 # mknod'ing the devices instead of copying them works both with and
1138 mknod "$DESTDIR/dev/console" c 5 1
1139 mknod "$DESTDIR/dev/null" c 1 3
1140 mknod "$DESTDIR/dev/zero" c 1 5
1141 mknod "$DESTDIR/dev/urandom" c 1 9
1143 inst_exec $busybox /bin/initrd-busybox
1144 ln -s initrd-busybox $DESTDIR/bin/sh
1145 # for older busyboxes who had /bin/busybox as EXEPATH
1146 ln -s initrd-busybox $DESTDIR/bin/busybox
1150 # initrd generated by:
1155 add_linuxrc <<-'EOF'
1156 read CMDLINE < /proc/cmdline; export CMDLINE
1158 for arg in $CMDLINE; do
1159 if [ "${arg}" = "debuginitrd" ]; then
1162 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1163 DEBUGINITRD=${arg##debuginitrd=}
1165 if [ "${arg##root=}" != "${arg}" ]; then
1170 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1171 if [ "$DEBUGINITRD" = "sh" ]; then
1174 if is_yes "$RUN_SULOGIN_ON_ERR"; then
1175 add_linuxrc <<-'EOF'
1176 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1179 add_linuxrc <<-'EOF'
1183 add_linuxrc <<-'EOF'
1191 if [ "$DEBUGINITRD" ]; then
1196 modules_add_linuxrc $MODULES
1198 # TODO: rewrite for busybox
1199 #if [ -n "$loopDev" ]; then
1200 # if [ ! -d /initrd ]; then
1204 # cp -a "$loopDev" "$DESTDIR/dev"
1205 # cp -a "$rootdev" "$DESTDIR/dev"
1206 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1207 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1208 # echo "echo Setting up loopback device $rootdev" >> $RCFILE
1209 # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1212 if is_yes "$USE_UDEV"; then
1216 if is_yes "$USE_TUXONICE"; then
1220 find_modules_uvesafb
1223 if is_yes "$have_luks"; then
1227 if is_yes "$have_dmraid"; then
1231 if is_yes "$have_multipath"; then
1232 initrd_gen_multipath
1235 if is_yes "$USE_BLKID"; then
1239 if is_yes "$have_nfs"; then
1241 elif is_yes "$have_md"; then
1243 if is_yes "$have_lvm"; then
1246 initrd_gen_setrootdev
1248 elif is_yes "$have_lvm"; then
1251 initrd_gen_setrootdev
1254 if is_yes "$USE_SUSPEND"; then
1258 # additional devs always needed
1259 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
1261 if is_yes "$USE_UDEV"; then
1262 initrd_gen_stop_udevd
1265 if [ "$INITRDFS" = "initramfs" ]; then
1266 initrd_gen_initramfs_switchroot
1271 if is_yes "$FB_SPLASH"; then
1275 if is_yes "$FB_CON_DECOR"; then
1276 initrd_gen_fbcondecor
1279 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
1281 debug "Creating $INITRDFS image $IMAGE"
1284 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1285 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1286 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1288 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
1289 debug "Mounting ext2 image $IMAGE to $tmpmnt"
1290 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1291 # We don't need this directory, so let's save space
1292 rm -rf "$tmpmnt"/lost+found
1294 debug "Copy recursively $DESTDIR -> $tmpmnt"
1295 cp -a $DESTDIR/* $tmpmnt
1301 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
1304 mkcramfs "$DESTDIR" "$IMAGE"
1307 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
1310 die "Filesystem $INITRDFS not supported by $PROGRAM"
1313 # TODO: figure out this automatically
1314 CONFIG_BLK_DEV_RAM_SIZE=4096
1316 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
1317 debug "image size: $IMAGESIZE KiB ($DESTDIR)"
1318 if [ "$IMAGESIZE" -gt $CONFIG_BLK_DEV_RAM_SIZE ]; then
1319 warn "Your image size is larger than $CONFIG_BLK_DEV_RAM_SIZE, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1322 if ! is_no "$COMPRESS"; then
1323 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
1324 compressor=$(find_compressor "$COMPRESS")
1325 debug "Compressing $target with $compressor"
1327 # TODO: the image name (specified from kernel.spec) already contains
1328 # extension, which is .gz most of the time.
1329 case "$compressor" in
1331 lzma < "$IMAGE" > "$tmp"
1334 bzip2 -9 < "$IMAGE" > "$tmp"
1337 gzip -9 < "$IMAGE" > "$tmp"
1340 mv -f "$tmp" "$target"
1342 cp -a "$IMAGE" "$target"
1345 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
1346 if is_yes "$BOOT_SPLASH"; then
1347 initrd_gen_bootsplash "$target"
1350 rm -rf "$DESTDIR" "$IMAGE"
1352 # vim:ts=4:sw=4:noet:fdm=marker