7 # based on mkinitrd from RedHat Linux
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-raidstart] [--without-raidstart]"
53 echo " [--with-bootsplash] [--without-bootsplash]"
54 echo " [--with-fbsplash] [--without-fbsplash]"
55 echo " [--with-fbcondecor] [--without-fbcondecor]"
56 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
57 echo " [--with-suspend] [--without-suspend]"
58 echo " [--with-tuxonice] [--without-tuxonice]"
59 echo " [--without-dmraid] [--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
160 # generate code to mount /proc on initrd
161 # can be called multiple times
163 if is_yes "$proc_mounted"; then
168 if [ "$INITRDFS" = "initramfs" ]; then
169 # /proc is mounted with initramfs 2.6.22.14 kernel
170 # XXX: remove when it is clear why proc was already mounted
171 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
173 echo "mount -t proc none /proc" | add_linuxrc
177 # generate code to mount /sys on initrd
178 # can be called multiple times
180 if is_yes "$sys_mounted"; then
185 echo "mount -t sysfs none /sys" | add_linuxrc
188 # generate code to mount /tmp on initrd
189 # can be called multiple times
191 if [ "$INITRDFS" = "initramfs" ]; then
192 # initramfs is read-write filesystem, no need for tmpfs
196 if is_yes "$tmp_mounted"; then
201 echo "mount -t tmpfs none /tmp" | add_linuxrc
204 # unmount all mountpoints mounted by geninitrd
208 : Last shell before umounting all and giving control over to real init.
212 if is_yes "$dev_mounted"; then
213 echo 'umount /dev' | add_linuxrc
216 if is_yes "$proc_mounted"; then
217 echo 'umount /proc' | add_linuxrc
220 if is_yes "$sys_mounted"; then
221 echo 'umount /sys' | add_linuxrc
224 if is_yes "$tmp_mounted"; then
225 echo 'umount /tmp' | add_linuxrc
231 # Checks if busybox has support for APPLET(s)
232 # Exits from geninitrd if the support is not present.
234 # NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
238 if [ -z "$busybox_functions" ]; then
239 local tmp=$($busybox 2>&1)
241 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
242 if [[ "$tmp" = *applet\ not\ found* ]]; then
244 ln -s $busybox $t/busybox
245 local tmp=$($t/busybox 2>&1)
249 busybox_functions=$(echo "$tmp" | \
250 sed -ne '/Currently defined functions:/,$p' | \
251 xargs | sed -e 's,.*Currently defined functions: ,,'
257 eval have='$'busybox_have_$applet
258 if [ -z "$have" ]; then
259 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
260 if [ "$have" = 0 ]; then
261 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
264 eval busybox_have_$applet=$have
267 if [ $err = 1 ]; then
272 # Finds module dependencies
276 # Outputs full path to module and it's dependencies
281 # if module is prefixed with dash, we should ignore errors if the module
283 if [ ${module#-} != $module ]; then
288 # This works when user has module-init-tools installed even on 2.4 kernels
290 modprobe=$(modprobe --set-version $kernel --show-depends $module --ignore-install 2>&1)
293 if [ $skiperrors = 1 ]; then
298 if ! is_no "$EXIT_IF_MISSING"; then
299 die "$module: module not found for $kernel kernel"
302 warn "$module: module not found for $kernel kernel"
303 warn "If $module isn't compiled in kernel then this initrd may not start your system."
307 while read insmod modpath options; do
308 [ "$insmod" = "insmod" ] && echo $modpath
315 # no firmware support in 2.4 kernels
316 if [ "$kernel_version_long" -lt "002005048" ]; then
319 echo -n $(NEW_MODINFO=1 modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
324 local mod depmod module=$1
326 depmod=$(find_depmod $module) || exit 1
327 for mod in $depmod; do
328 mod=${mod#/lib/modules/$kernel/}
330 # add each module only once
332 for m in $MODULES; do
333 [ $m = $mod ] && have=1
335 if [ $have = 0 ]; then
336 MODULES="$MODULES $mod"
341 # install a file to temporary mount image.
342 # it will operate recursively (copying directories)
343 # and will symlink destinations if source is symlink.
345 if [ $# -lt 2 ]; then
346 die 'Usage: inst <file> [<file>] <destination>'
349 local src i=0 c=$(($# - 1))
350 while [ $i -lt $c ]; do
357 parentDir=$(dirname $DESTDIR$dest)
358 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
359 debug "+ cp $* $DESTDIR$dest"
360 cp -HR "$@" "$DESTDIR$dest"
365 die 'Usage: inst_d <destination> <destination>'
368 install -d "$DESTDIR$dir"
372 # install executable and it's shared libraries
374 if [ $# -lt 2 ]; then
375 die "Invalid params ($@), Usage: inst_exec <file>[, <file>] <destination>"
377 local src i=0 c=$(($# - 1))
378 while [ $i -lt $c ]; do
388 local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
390 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
392 inst_exec $lib /$_lib
396 # hack for uclibc linked binaries requiring this fixed path
397 # XXX: shouldn't rpath be used here instead so th
398 if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
399 local lib=$DESTDIR/$_lib/libc.so.0
400 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
401 local libdir=$(cd $(dirname "$lib"); pwd)
402 if [ ! -e $DESTDIR$libdir ]; then
403 libdir=$(dirname "$libdir")
405 debug "+ ln -s /$_lib $DESTDIR$libdir"
406 ln -s /$_lib $DESTDIR$libdir
411 # output modules.conf / modprobe.conf
413 echo "$modprobe_conf_cache"
417 # defaults to modprobe -c if not told otherwise, this means include statements
419 cache_modprobe_conf() {
420 if [ "$kernel_version" -lt "002005" ]; then
421 modulefile=/etc/modules.conf
422 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
423 modulefile=/etc/conf.modules
427 if [ -n "$modulefile" ]; then
428 debug "Using $modulefile for modules config"
429 modprobe_conf_cache=$(cat $modulefile)
431 debug "Using modprobe -c to get modules config"
432 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
436 # find modules for $devpath
437 find_modules_for_devpath() {
439 if [ -z "$devpath" ]; then
440 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
443 if [[ "$devpath" = /dev/dm-* ]]; then
444 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
445 devpath=$(dm_longname "$devpath")
448 if [ -L "$devpath" ] && ! is_lvm "$devpath"; then
449 # sanitize things like:
450 # /dev/block/104:2 -> /dev/cciss/c0d0p2
451 devpath=$(readlink -f "$devpath")
454 debug "Finding modules for device path $devpath"
456 if is_luks "$devpath"; then
457 find_modules_luks "$devpath"
461 if is_nfs "$devpath"; then
462 find_modules_nfs "$devpath"
466 if is_md "$devpath"; then
467 find_modules_md "$devpath"
471 if is_multipath "$devpath"; then
472 if find_modules_multipath "$devpath"; then
478 if is_dmraid "$devpath"; then
479 if find_modules_dmraid "$devpath"; then
485 if is_scsi "$devpath"; then
486 find_modules_scsi "$devpath"
490 if is_ide "$devpath"; then
491 find_modules_ide "$devpath"
495 if [[ "$devpath" == /dev/rd/* ]]; then
501 if [[ "$devpath" == /dev/ida/* ]]; then
502 find_module "cpqarray"
503 rootdev_add=/dev/ida/
507 if [[ "$devpath" == /dev/cciss/* ]]; then
509 rootdev_add=/dev/cciss/
513 if [[ "$devpath" == /dev/ataraid/* ]]; then
515 find_module "ataraid"
516 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
517 if [ -n "$ataraidmodules" ]; then
518 # FIXME: think about modules compiled in kernel
519 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
521 for n in $ataraidmodules; do
524 rootdev_add=/dev/ataraid/
528 # check to see if we need to set up a loopback filesystem
529 if [[ "$devpath" == /dev/loop* ]]; then
530 die "Sorry, root on loop device isn't supported."
531 # TODO: rewrite for bsp and make nfs ready
532 if [ ! -x /sbin/losetup ]; then
533 die "losetup is missing"
535 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
536 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
537 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"
540 line="`awk '/'$key'/ { print $0; }' $fstab`"
541 loopDev="$(echo $line | awk '{print $3}')"
542 loopFs="$(echo $line | awk '{print $4}')"
543 loopFile="$(echo $line | awk '{print $5}')"
545 BASICMODULES="$BASICMODULES -loop"
546 find_module "-$loopFs"
547 BASICMODULES="$BASICMODULES -${loopFs}"
551 if is_lvm "$devpath"; then
552 find_modules_lvm "$devpath"
557 firmware_install_module() {
559 local firmware_files="$2"
561 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
562 # firmware not yet installed
563 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
565 cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
567 echo 1 > /sys$DEVPATH/loading
568 cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
569 echo 0 > /sys$DEVPATH/loading
572 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
575 for firmware in $firmware_files; do
576 if [ ! -f "/lib/firmware/$firmware" ]; then
577 die "firmware file /lib/firmware/$firmware doesn't exist."
579 FIRMWAREDIR=${firmware%/*}
580 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
581 inst /lib/firmware/$firmware /lib/firmware/$firmware
586 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
593 for mod in $modules; do
595 inst_d "/lib/modules/$kernel/$MODULEDIR"
596 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
597 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
601 modules_add_linuxrc() {
605 # module path without optional compression
609 module=${modpath##*/}
610 module=${module%$modext}
612 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
614 generic_module=$(echo $module | tr - _)
615 sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
616 firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
618 if [ -n "$verbose" ]; then
620 if [ "$options" ]; then
621 s="$s with options [$options]"
623 if [ "$sleep_var" ]; then
624 s="$s and $sleep_var usleep"
626 debug "Loading module [$module]$s"
629 if [ -n "$firmware_var" ]; then
630 firmware_install_module "$module" "$firmware_var"
632 firmware_files=$(find_firmware "$module")
633 if [ -n "$firmware_files" ]; then
634 for file in $firmware_files; do
635 firmware_install_module "$module" "$file"
640 echo "insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
641 if [ -n "$sleep_var" ]; then
642 echo "usleep $sleep_var" | add_linuxrc
647 # Generates /dev nodes based on /proc/partitions information.
648 # Needs /proc mounted.
649 # Can be called multiple times.
650 initrd_gen_devices() {
651 if is_yes "$proc_partitions"; then
658 : 'Making device nodes'
659 cat /proc/partitions | (
660 # ignore first two lines: header, empty line
663 while read major minor blocks dev rest; do
666 [ -e $node ] || mknod $node b $major $minor
673 initrd_gen_setrootdev() {
674 debug "Adding rootfs finding based on kernel cmdline root= option support."
676 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
677 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
678 if [ -n "$rootnr" ]; then
679 echo "$rootnr" > /proc/sys/kernel/real-root-dev
685 initrd_gen_initramfs_switchroot() {
687 if [ "$rootdev" = "/dev/nfs" ]; then
688 echo "rootfs on NFS root=/dev/nfs"
690 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
693 # parse 'root=xxx' kernel commandline
694 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
696 device=/dev/no_partition_found
697 eval "$(busybox awk -v c="$ROOT" '
699 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
700 num_pattern = "[0-9a-f]" num_pattern_short;
701 dev_pattern = "[hms][a-z][a-z]([0-9])+";
702 partition = "no_partition_found";
706 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
707 if (c ~ "^" num_pattern "$") {
708 maj = sprintf("%s",substr(c,1,2));
709 min = sprintf("%s",substr(c,3));
711 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
712 if (c ~ "^" dev_pattern "$") partition = c;
715 $4 ~ partition { maj = $1; min = $2; }
716 $1 ~ maj && $2 ~ min { partition = $4; }
719 if (maj >= 0 && min >= 0) {
720 printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
724 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
725 mknod $device b $maj $min
735 if [ "$device" = '/dev/no_partition_found' ]; then
739 mount -t $rootfs -r $device /newroot
740 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
741 if [ -z "$init" -o ! -x "/newroot$init" ]; then
747 busybox_applet switch_root
749 exec switch_root /newroot $init
751 echo "Error! initramfs should not reach this place."
752 echo "It probably means you've got old version of busybox, with broken"
753 echo "initramfs support. Trying to boot anyway, but won't promise anything."
755 exec chroot /newroot $init
757 echo "Failed to chroot!"
759 # we need /init being real file, not symlink, otherwise the initramfs will
760 # not be ran by pid 1 which is required for switch_root
761 mv $DESTDIR/linuxrc $DESTDIR/init
762 ln -s init $DESTDIR/linuxrc
765 # find if $symbol exists in System.map $mapfile
769 if [ ! -f $mapfile ]; then
770 # missing mapfile (not a pld kernel?)
774 awk -vc=1 -vsymbol="$symbol" '$2 == "T" && $3 == symbol {c = 0} END {exit c}' $mapfile
777 # find best compressor (or forced one) for initrd
780 # the best compressor list
781 local compressors='lzma bzip2 gzip'
783 # a specified one, take it
784 if ! is_yes "$mode"; then
788 debug "finding compressor: $compressors (via $mode)"
789 # check for compressor validity
790 local c prog map=/boot/System.map-$kernel
791 for c in $compressors; do
806 die "Unknown compressor $c"
809 if sym_exists $map $sum && [ -x $prog ]; then
815 debug "using gzip for compressor (fallback)"
819 if [ -r /etc/sysconfig/geninitrd ]; then
820 . /etc/sysconfig/geninitrd
823 geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs scsi
825 while [ $# -gt 0 ]; do
835 modulefile=${1#--modules-conf=}
841 --use-raidstart|--with-raidstart)
850 --without-bootsplash)
862 --without-fbcondecor)
871 --with-suspend2 | --with-tuxonice)
874 --without-suspend2 | --without-tuxonice)
878 LVMTOOLSVERSION=${1#--lvmversion=}
881 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
883 --lvmtoolsversion|--lvmversion)
906 BASICMODULES="$BASICMODULES ${1#--with=}"
909 BASICMODULES="$BASICMODULES $2"
913 echo "$PROGRAM: version $VERSION"
923 COMPRESS="${1#--compress=}"
935 PREMODS="$PREMODS ${1#--preload=}"
938 PREMODS="$PREMODS $2"
942 die "--fs option is obsoleted. Use --initrdfs instead"
945 INITRDFS=${1#--initrdfs=}
958 if [ -z "$target" ]; then
960 elif [ -z "$kernel" ]; then
972 if [ -z "$target" -o -z "$kernel" ]; then
978 if [ "$(id -u)" != 0 ]; then
979 die "You need to be root to generate initrd"
982 if [ -d /usr/lib64 ]; then
988 initrd_dir=/usr/$_lib/initrd
989 kernel_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
990 kernel_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
993 debug "Using _lib: $_lib"
994 debug "Using initrd_dir: $initrd_dir"
996 busybox=$(find_tool $initrd_dir/initrd-busybox /bin/initrd-busybox) || die "Couldn't find busybox suitable for initrd"
998 # we setup mods after parsing command line args
1001 if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1002 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1005 if [ -z "$INITRDFS" ]; then
1006 if [ -n "$FS" ]; then
1007 # FS= can came only via /etc/sysconfig/geninitrd likely?
1008 die "FS configuration option is obsoleted. Use INITRDFS instead"
1012 if [ "$kernel_version" -ge "002005" ]; then
1013 INITRDFS="initramfs"
1021 [ -x /sbin/mke2fs ] || die "/sbin/mke2fs is missing"
1024 [ -x /sbin/genromfs ] || die "/sbin/genromfs is missing"
1027 [ -x /sbin/mkcramfs ] || die "/sbin/mkcramfs is missing"
1030 [ -x /bin/cpio ] || die "/bin/cpio is missing"
1031 [ -x /usr/bin/find ] || die "/usr/bin/find is missing"
1034 die "Filesystem $INITRDFS on initrd is not supported"
1038 if [ -L "$target" ]; then
1039 target=$(readlink -f "$target")
1042 if [ -n "$img_vers" ]; then
1043 target="$target-$kernel"
1046 if [ -z "$force" -a -f "$target" ]; then
1047 die "$target already exists."
1050 if [ ! -d "/lib/modules/$kernel" ]; then
1051 die "/lib/modules/$kernel is not a directory."
1054 if [ ! -f /proc/mounts ]; then
1055 warn "/proc filesystem not mounted, may cause wrong results or failure."
1058 if [ "$kernel_version" -ge "002005" ]; then
1064 for n in $PREMODS; do
1068 if [ "$FBMODULE" ]; then
1069 find_module "$FBMODULE"
1072 # allow forcing loading SCSI and/or IDE modules
1073 # XXX: where ADDSCSI cames from? drop?
1074 if is_yes "$ADDSCSI"; then
1078 # XXX: where ADDIDE cames from? drop?
1079 if is_yes "$ADDIDE"; then
1083 if is_yes "$USE_SUSPEND"; then
1084 find_modules_suspend
1087 find_root "$fstab" || exit
1088 debug "Using $rootdev as device for rootfs"
1090 find_modules_for_devpath "$rootdev"
1092 find_module "-$rootFs"
1094 for n in $BASICMODULES; do
1098 if is_yes "$USE_TUXONICE"; then
1102 find_modules_fbsplash
1104 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1105 debug "No modules are needed -- not building initrd image."
1109 debug "Building initrd..."
1110 DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
1111 RCFILE="$DESTDIR/linuxrc"
1113 chmod a+rx "$RCFILE"
1114 ln -s linuxrc $DESTDIR/init
1116 # create dirs that we really need
1117 inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
1119 modules_install "$MODULES"
1121 # mknod'ing the devices instead of copying them works both with and
1123 mknod "$DESTDIR/dev/console" c 5 1
1124 mknod "$DESTDIR/dev/null" c 1 3
1125 mknod "$DESTDIR/dev/zero" c 1 5
1127 inst_exec $busybox /bin/initrd-busybox
1128 ln -s initrd-busybox $DESTDIR/bin/sh
1129 # for older busyboxes who had /bin/busybox as EXEPATH
1130 ln -s initrd-busybox $DESTDIR/bin/busybox
1134 # initrd generated by:
1139 add_linuxrc <<-'EOF'
1140 read CMDLINE < /proc/cmdline; export CMDLINE
1142 for arg in $CMDLINE; do
1143 if [ "${arg}" = "debuginitrd" ]; then
1146 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1147 DEBUGINITRD=${arg##debuginitrd=}
1149 if [ "${arg##root=}" != "${arg}" ]; then
1154 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1155 if [ "$DEBUGINITRD" = "sh" ]; then
1158 if is_yes "$RUN_SULOGIN_ON_ERR"; then
1159 add_linuxrc <<-'EOF'
1160 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1163 add_linuxrc <<-'EOF'
1167 add_linuxrc <<-'EOF'
1175 if [ "$DEBUGINITRD" ]; then
1180 modules_add_linuxrc $MODULES
1182 # TODO: rewrite for busybox
1183 #if [ -n "$loopDev" ]; then
1184 # if [ ! -d /initrd ]; then
1188 # cp -a "$loopDev" "$DESTDIR/dev"
1189 # cp -a "$rootdev" "$DESTDIR/dev"
1190 # echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1191 # echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1192 # echo "echo Setting up loopback device $rootdev" >> $RCFILE
1193 # echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1196 if is_yes "$USE_UDEV"; then
1200 if is_yes "$USE_TUXONICE"; then
1204 find_modules_uvesafb
1207 if is_yes "$have_luks"; then
1211 if is_yes "$have_dmraid"; then
1215 if is_yes "$have_multipath"; then
1216 initrd_gen_multipath
1219 if is_yes "$USE_BLKID"; then
1223 if is_yes "$have_nfs"; then
1225 elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
1227 if is_yes "$have_lvm"; then
1230 initrd_gen_setrootdev
1232 elif is_yes "$have_lvm"; then
1235 initrd_gen_setrootdev
1238 if is_yes "$USE_SUSPEND"; then
1242 # additional devs always needed
1243 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
1245 if is_yes "$USE_UDEV"; then
1246 initrd_gen_stop_udevd
1249 if [ "$INITRDFS" = "initramfs" ]; then
1250 initrd_gen_initramfs_switchroot
1255 if is_yes "$FB_SPLASH"; then
1259 if is_yes "$FB_CON_DECOR"; then
1260 initrd_gen_fbcondecor
1263 IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
1265 debug "Creating $INITRDFS image $IMAGE"
1268 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
1269 debug "ext2 image size: $IMAGESIZE ($DESTDIR)"
1270 if [ "$IMAGESIZE" -gt 4096 ]; then
1271 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1274 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1275 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1276 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1278 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
1279 debug "Mounting ext2 image $IMAGE to $tmpmnt"
1280 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1281 # We don't need this directory, so let's save space
1282 rm -rf "$tmpmnt"/lost+found
1284 debug "Copy recursively $DESTDIR -> $tmpmnt"
1285 cp -a $DESTDIR/* $tmpmnt
1291 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
1292 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
1293 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
1294 if [ "$IMAGESIZE" -gt 4096 ]; then
1295 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1299 mkcramfs "$DESTDIR" "$IMAGE"
1302 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
1305 die "Filesystem $INITRDFS not supported by $PROGRAM"
1308 if ! is_no "$COMPRESS"; then
1309 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
1310 compressor=$(find_compressor "$COMPRESS")
1311 debug "Compressing $target with $compressor"
1313 # TODO: the image name (specified from kernel.spec) already contains
1314 # extension, which is .gz most of the time.
1315 case "$compressor" in
1317 lzma -9 < "$IMAGE" > "$tmp"
1320 bzip2 -9 < "$IMAGE" > "$tmp"
1323 gzip -9 < "$IMAGE" > "$tmp"
1326 mv -f "$tmp" "$target"
1328 cp -a "$IMAGE" "$target"
1331 size=$(stat -c %s $target | awk '{print int((($1/1024)+1023)/1024)*1024}')
1332 debug "Minimum RAM size that could be used for $target is: ramdisk_size=$size"
1334 # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
1335 if is_yes "$BOOT_SPLASH"; then
1336 initrd_gen_bootsplash "$target"
1339 rm -rf "$DESTDIR" "$IMAGE"
1341 # vim:ts=4:sw=4:noet:fdm=marker