# based on mkinitrd from RedHat Linux
#
-RCSID='$Revision$ $Date$'
-R=${RCSID#* *}; VERSION=${R%% *}
+GENINITRD_RCSID='$Revision$ $Date:: $'
+R=${GENINITRD_RCSID#* *}; VERSION=${R%% *}
PROGRAM=${0##*/}
. /etc/rc.d/init.d/functions
# list of geninitrd modules which need setup routine after commandline args parsing
GENINITRD_MODS=""
COMPRESS=yes
+STRIP=/usr/bin/strip
target=""
kernel=""
force=""
proc_partitions=no
usage() {
- uname_r=$(uname -r)
- echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
+ echo "Usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
- echo " [--compress=yes|lzma|bzip2|gzip]"
+ echo " [--compress=yes|xz|lzma|bzip2|gzip|lzo]"
+ echo " [--nostrip ] [--strip PATH/strip] [--strip=PATH/strip]"
echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
echo " [--with-bootsplash] [--without-bootsplash]"
echo " [--with-fbsplash] [--without-fbsplash]"
echo " [--without-blkid] [--without-luks]"
echo " <initrd-image> <kernel-version>"
echo ""
- echo "example:"
- echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
- exit 0
+ echo "Example:"
+
+ local kdir kver dir=${target:-/boot}
+ for kdir in /lib/modules/*; do
+ [ -d $kdir ] || continue
+ kver=${kdir##*/}
+ echo " $0 -f --initrdfs=initramfs $dir/initrd-$kver.gz $kver $verbose"
+ done | sort -V
}
msg() {
return 0
fi
done
- debug "find_tool: did not found any of: $@"
+ debug "find_tool: did not find any of: $@"
return 1
}
fi
. /lib/geninitrd/mod-$mod.sh
- if type setup_mod_$mod > /dev/null; then
- # add to list which need init
- GENINITRD_MODS="$GENINITRD_MODS $mod"
- fi
+ GENINITRD_MODS="$GENINITRD_MODS $mod"
done
}
# setup geninitrd modules
geninitrd_setup_mods() {
- local mod
+ local mod rcsid
for mod in $GENINITRD_MODS; do
- eval setup_mod_$mod
+ eval rcsid=$(echo \$$mod | LC_ALL=C tr '[a-z]' '[A-Z]')_RCSID
+ debug "# $rcsid (mod-$mod)"
+
+ # some mods want init
+ if type setup_mod_$mod > /dev/null; then
+ eval setup_mod_$mod
+ fi
done
}
# can be called multiple times. /dev is cleaned up (umounted) automatically at
# the end of script.
mount_dev() {
- if [ "$INITRDFS" = "initramfs" ]; then
- # initramfs is read-write filesystem, no need for tmpfs
- return
- fi
-
# we already generated tmpfs code; return
if is_yes "$dev_mounted"; then
return
busybox_applet mount mknod mkdir
add_linuxrc <<-EOF
: 'Creating /dev'
- mount -o mode=0755 -t tmpfs none /dev
- mknod /dev/console c 5 1
- mknod /dev/null c 1 3
- mknod /dev/zero c 1 5
- mknod /dev/urandom c 1 9
+ if ! mount -t devtmpfs -o mode=0755,nosuid devtmpfs /dev > /dev/null 2>&1; then
+ mount -o mode=0755,nosuid -t tmpfs tmpfs /dev
+ mknod /dev/console c 5 1
+ mknod /dev/null c 1 3
+ mknod /dev/zero c 1 5
+ mknod /dev/random c 1 8
+ mknod /dev/snapshot c 10 231
+ mknod /dev/urandom c 1 9
+ mknod /dev/ptmx c 5 2
+ mknod /dev/kmsg c 1 11
+ fi
mkdir /dev/pts
mkdir /dev/shm
EOF
echo "mount -t tmpfs none /tmp" | add_linuxrc
}
+# generate code to mount /run on initrd
+# can be called multiple times
+mount_run() {
+ if is_yes "$run_mounted"; then
+ return
+ fi
+
+ run_mounted=yes
+ echo "mount -t tmpfs run /run" | add_linuxrc
+}
+
# unmount all mountpoints mounted by geninitrd
umount_all() {
debugshell
EOF
+ if is_yes "$run_mounted"; then
+ echo 'mount --bind /run /newroot/run' | add_linuxrc
+ echo 'umount /run' | add_linuxrc
+ run_mounted=no
+ fi
if is_yes "$dev_mounted"; then
echo 'umount /dev' | add_linuxrc
dev_mounted=no
fi
- if is_yes "$proc_mounted"; then
- echo 'umount /proc' | add_linuxrc
- proc_mounted=no
- fi
if is_yes "$sys_mounted"; then
echo 'umount /sys' | add_linuxrc
sys_mounted=no
echo 'umount /tmp' | add_linuxrc
tmp_mounted=no
fi
+ if is_yes "$proc_mounted"; then
+ echo 'umount /proc' | add_linuxrc
+ proc_mounted=no
+ fi
}
#
# NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
busybox_applet() {
- local err=0
+ local err=0 applet
if [ -z "$busybox_functions" ]; then
local tmp=$($busybox 2>&1)
fi
}
+# Extract the .config file from a kernel image
+# uses extract-ikconfig from kernel sources (scripts/extract-ikconfig)
+ikconfig() {
+ local kofile=$(modinfo -k $kernel -n configs 2> /dev/null)
+ if [ -n "$kofile" ]; then
+ /lib/geninitrd/extract-ikconfig $kofile
+ return
+ fi
+
+ # see if config available as separate file
+ if [ -f /boot/config-$kernel ]; then
+ cat /boot/config-$kernel
+ return
+ fi
+
+ # finally try vmlinuz itself
+ /lib/geninitrd/extract-ikconfig /boot/vmlinuz-$kernel
+}
+
# Finds module dependencies
#
# @param $module
if [ $? != 0 ]; then
if [ $skiperrors = 1 ]; then
- return
+ return 0
fi
echo >&2 "$modprobe"
while read insmod modpath options; do
[ "$insmod" = "insmod" ] && echo $modpath
done
+ return 0
}
find_firmware() {
done
local dest=$1
set -- $src
- parentDir=$(dirname $DESTDIR$dest)
+ local parentDir=$(dirname $DESTDIR$dest)
[ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
debug "+ cp $* $DESTDIR$dest"
cp -HR "$@" "$DESTDIR$dest"
inst "$@" $dest
- local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
- for lib in $libs; do
- if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
- inst_d /$_lib
- inst_exec $lib /$_lib
- fi
+ local obj lib libs
+ for obj in "$@"; do
+ case "$obj" in
+ /lib/ld-linux.so.2 | /lib64/ld-linux-x86-64.so.2)
+ continue
+ esac
+
+ libs=$(ldd "$obj" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
+ for lib in $libs; do
+ if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
+ inst_d /$_lib
+ inst_exec $lib /$_lib
+ fi
+ done
done
# hack for uclibc linked binaries requiring this fixed path
echo "$modprobe_conf_cache"
}
+# return options for MODULE
+# @param $1 module name
+modprobe_options() {
+ local module=$1
+ local options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}')
+ echo ${options# }
+}
+
#
# defaults to modprobe -c if not told otherwise, this means include statements
# work from there.
if [ -n "$modulefile" ]; then
debug "Using $modulefile for modules config"
- modprobe_conf_cache=$(cat $modulefile)
+ modprobe_conf_cache=$(cat $modulefile | awk '!/^[\t ]*#/ { print }')
+
else
debug "Using modprobe -c to get modules config"
- modprobe_conf_cache=$(modprobe -c --set-version $kernel)
+ modprobe_conf_cache=$(modprobe -c --set-version $kernel | awk '!/^[\t ]*#/ { print }')
fi
}
if [[ "$devpath" = /dev/dm-* ]]; then
# /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
- devpath=$(dm_longname "$devpath")
+ devpath=$(dm_node "$devpath")
fi
- if [ -L "$devpath" ] && ! is_lvm "$devpath"; then
+ if [ -L "$devpath" ] && ! is_lvm "$devpath" && ! is_luks "$devpath"; then
# sanitize things like:
# /dev/block/104:2 -> /dev/cciss/c0d0p2
devpath=$(readlink -f "$devpath")
fi
if [[ "$devpath" == /dev/cciss/* ]]; then
- find_module "cciss"
rootdev_add=/dev/cciss/
+
+ # load hpsa for future kernels, cciss for backwards compat
+ if [ "$kernel_version_long" -ge "003000000" ]; then
+ find_module "hpsa" "-cciss"
+ find_modules_scsi "$devpath"
+ else
+ find_module "cciss"
+ fi
+
return
fi
if [[ "$devpath" == /dev/ataraid/* ]]; then
find_modules_ide
find_module "ataraid"
- ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
+ ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ { print $3 }')
if [ -n "$ataraidmodules" ]; then
# FIXME: think about modules compiled in kernel
die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
exit 0
EOF
chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
+
+ # setup firmware loader agent
+ echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
fi
for firmware in $firmware_files; do
[ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
inst /lib/firmware/$firmware /lib/firmware/$firmware
else
- die "firmware file /lib/firmware/$firmware nor /lib/firmware/$kernel/$firmware found."
+ warn "Possible missing firmware file /lib/firmware/$firmware or /lib/firmware/$kernel/$firmware for module $module."
fi
done
mount_sys
- echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
}
modules_install() {
inst_d "/lib/modules/$kernel/$MODULEDIR"
cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
+ if [ "$STRIP" ] && [ -x "$STRIP" ]; then
+ $STRIP -g --remove-section=.comment "$DESTDIR/lib/modules/$kernel/${mod%.gz}"
+ fi
done
}
modpath=${mod%.gz}
# name of the module
- module=${modpath##*/}
- module=${module%$modext}
-
- options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
-
- generic_module=$(echo $module | tr - _)
- sleep_var=$(eval echo \$MODULE_${generic_module}_USLEEP)
- firmware_var=$(eval echo \$MODULE_${generic_module}_FIRMWARE)
+ local module=${modpath##*/}; module=${module%$modext}
+ local options=$(modprobe_options "$module")
+ local genericname=$(echo $module | tr - _)
+ local usleep=$(eval echo \$MODULE_${genericname}_USLEEP)
+ local firmware=$(eval echo \$MODULE_${genericname}_FIRMWARE)
+
+ if [ "$module" = "scsi_mod" -a "$kernel_version_long" -ge "002006030" ]; then
+ options="scan=sync $options"
+ fi
if [ -n "$verbose" ]; then
s=""
if [ "$options" ]; then
s="$s with options [$options]"
fi
- if [ "$sleep_var" ]; then
- s="$s and $sleep_var usleep"
+ if [ "$usleep" ]; then
+ s="$s and $usleep usleep"
fi
debug "Loading module [$module]$s"
fi
- if [ -n "$firmware_var" ]; then
- firmware_install_module "$module" "$firmware_var"
+ if [ -n "$firmware" ]; then
+ firmware_install_module "$module" "$firmware"
else
- firmware_files=$(find_firmware "$module")
- if [ -n "$firmware_files" ]; then
- for file in $firmware_files; do
- firmware_install_module "$module" "$file"
- done
- fi
+ for file in $(find_firmware "$module"); do
+ firmware_install_module "$module" "$file"
+ done
fi
echo "insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
- if [ -n "$sleep_var" ]; then
- echo "usleep $sleep_var" | add_linuxrc
+ if [ -n "$usleep" ]; then
+ echo "usleep $usleep" | add_linuxrc
fi
+ if [ "$module" = "scsi_wait_scan" ]; then
+ if [ "$(busybox_applet rmmod 2>/dev/null; echo $?)" = 0 ]; then
+ echo "rmmod scsi_wait_scan" | add_linuxrc
+ fi
+ fi
+
done
}
initrd_gen_setrootdev() {
debug "Adding rootfs finding based on kernel cmdline root= option support."
+ busybox_applet ls
add_linuxrc <<-'EOF'
if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
+ # fallback to ls
+ if [ -z "$rootnr" ]; then
+ rootnr="$(busybox ls -lL ${ROOT} | busybox awk '{if (/^b/) { print 256 * $3 + $4; }}')"
+ fi
if [ -n "$rootnr" ]; then
echo "$rootnr" > /proc/sys/kernel/real-root-dev
fi
# parse 'root=xxx' kernel commandline
# We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
add_linuxrc <<-'EOF'
- device=/dev/no_partition_found
+ device=
eval "$(busybox awk -v c="$ROOT" '
BEGIN {
num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
num_pattern = "[0-9a-f]" num_pattern_short;
dev_pattern = "[hms][a-z][a-z]([0-9])+";
- partition = "no_partition_found";
+ partition = "";
min = -1; maj = -1;
sub("^0x", "", c);
if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
if (c ~ "^" num_pattern "$") {
- maj = sprintf("%s",substr(c,1,2));
- min = sprintf("%s",substr(c,3));
+ maj = sprintf("%d",substr(c,1,2));
+ min = sprintf("%d",substr(c,3));
}
if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
if (c ~ "^" dev_pattern "$") partition = c;
}
- $4 ~ partition { maj = $1; min = $2; }
- $1 ~ maj && $2 ~ min { partition = $4; }
+ partition && $4 == partition { maj = $1; min = $2; }
+ $1 == maj && $2 == min { partition = $4; }
END {
if (maj >= 0 && min >= 0) {
- printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
+ printf("maj=%s; min=%s;\n", maj, min);
+ }
+ if (partition) {
+ printf("device=/dev/%s;\n", partition);
}
}
' /proc/partitions)"
- if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
- mknod $device b $maj $min
- fi
- EOF
- add_linuxrc <<-EOF
- rootdev=$rootdev
- rootfs=$rootFs
- EOF
+ if [ -z "$device" ]; then
+ device=$ROOT
+ fi
- add_linuxrc <<-'EOF'
- if [ "$device" = '/dev/no_partition_found' ]; then
- device=$rootdev
+ if [ "$device" -a ! -b $device ]; then
+ mknod $device b $maj $min
fi
- mount -t $rootfs -r $device /newroot
- init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
+ [ -n "$ROOTFSFLAGS" ] && ROOTFSFLAGS="-o $ROOTFSFLAGS"
+
+ mount -t $ROOTFS -r $device $ROOTFSFLAGS /newroot || echo "Mount of rootfs failed."
+ init=$INIT
if [ -z "$init" -o ! -x "/newroot$init" ]; then
init=/sbin/init
fi
umount_all
busybox_applet switch_root
add_linuxrc <<-'EOF'
+ [ ! -e /newroot/dev/console ] && mknod -m 660 /newroot/dev/console c 5 1
exec switch_root /newroot $init ${1:+"$@"}
echo "Error! initramfs should not reach this place."
exec chroot /newroot $init ${1:+"$@"}
echo "Failed to chroot!"
+ debugshell
EOF
# we need /init being real file, not symlink, otherwise the initramfs will
# not be ran by pid 1 which is required for switch_root
# find best compressor (or forced one) for initrd
find_compressor() {
local mode="$1"
- # the best compressor list
- local compressors='lzma bzip2 gzip'
+ # fastest initrd decompression speed is first
+ local compressors='lzo gzip xz lzma bzip2'
# a specified one, take it
if ! is_yes "$mode"; then
local c prog map=/boot/System.map-$kernel
for c in $compressors; do
case $c in
+ xz)
+ sym=unxz
+ prog=/usr/bin/xz
+ ;;
lzma)
sym=unlzma
- prog=/usr/bin/lzma
+ prog=/usr/bin/xz
;;
bzip2)
sym=bzip2
sym=gunzip
prog=/bin/gzip
;;
+ lzo)
+ sym=unlzo
+ prog=/usr/bin/lzop
+ ;;
+ none|no)
+ # any existing sym will work
+ sym=initrd_load
+ prog=/bin/cat
+ ;;
*)
die "Unknown compressor $c"
;;
echo gzip
}
+# compresses kernel image image
+# in function so we could retry with other compressor on failure
+compress_image() {
+ local compressor="$1" IMAGE="$2" target="$3" tmp
+ tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
+
+ case "$compressor" in
+ xz)
+ # don't use -9 here since kernel won't understand it
+ xz --format=xz --check=crc32 --lzma2=preset=6e,dict=1MiB < "$IMAGE" > "$tmp" || return $?
+ ;;
+ lzma)
+ xz --format=lzma -9 < "$IMAGE" > "$tmp" || return $?
+ ;;
+ bzip2)
+ bzip2 -9 < "$IMAGE" > "$tmp" || return $?
+ ;;
+ gzip)
+ gzip -9 < "$IMAGE" > "$tmp" || return $?
+ ;;
+ lzo)
+ lzop -9 < "$IMAGE" > "$tmp" || return $?
+ ;;
+ none|no)
+ cat < "$IMAGE" > "$tmp" || return $?
+ ;;
+ esac
+
+ mv -f "$tmp" "$target"
+}
+
if [ -r /etc/sysconfig/geninitrd ]; then
. /etc/sysconfig/geninitrd
fi
warn "/proc filesystem not mounted, may cause wrong results or failure."
fi
-geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs scsi
+geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs sata scsi usbkbd
while [ $# -gt 0 ]; do
case $1 in
--nocompress)
COMPRESS=no
;;
+ --nostrip)
+ STRIP=
+ ;;
+ --strip=*)
+ STRIP="${1#--strip=}"
+ ;;
+ --strip)
+ STRIP=$2
+ shift
+ ;;
--ifneeded)
ifneeded=1
;;
elif [ -z "$kernel" ]; then
kernel="$1"
else
- usage >&2
+ usage
exit 1
fi
;;
done
if [ -z "$target" -o -z "$kernel" ]; then
- usage >&2
+ usage
exit 1
fi
die "You need to be root to generate initrd"
fi
-if [ -d /usr/lib64 ]; then
+if [ -d /lib64 -a -d /usr/lib64 ]; then
_lib=lib64
else
_lib=lib
fi
initrd_dir=/usr/$_lib/initrd
-kernel_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
-kernel_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
+kernel_version=$(echo "$kernel" | awk -F. '{gsub(/[_-].*/, "", $0); print sprintf("%03d%03d",$1,$2)}')
+kernel_version_long=$(echo "$kernel" | awk -F. '{gsub(/[_-].*/, "", $0); print sprintf("%03d%03d%03d",$1,$2,$3)}')
-debug "# $RCSID"
+debug "# $GENINITRD_RCSID (geninitrd)"
debug "Using _lib: $_lib"
debug "Using initrd_dir: $initrd_dir"
-busybox=$(find_tool $initrd_dir/initrd-busybox /bin/initrd-busybox) || die "Couldn't find busybox suitable for initrd"
+busybox=$(find_tool $initrd_dir/busybox $initrd_dir/initrd-busybox /bin/initrd-busybox) || die "Couldn't find busybox suitable for initrd"
# we setup mods after parsing command line args
geninitrd_setup_mods
find_module "$FBMODULE"
fi
+# autodetect USB keyboards
+find_modules_usbkbd
+
# allow forcing loading SCSI and/or IDE modules
# XXX: where ADDSCSI cames from? drop?
if is_yes "$ADDSCSI"; then
find_modules_scsi
fi
+# autodetect SATA modules
+find_modules_sata
+
# XXX: where ADDIDE cames from? drop?
if is_yes "$ADDIDE"; then
find_modules_ide
ln -s linuxrc $DESTDIR/init
# create dirs that we really need
-inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
+inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,run,sys}
modules_install "$MODULES"
mknod "$DESTDIR/dev/console" c 5 1
mknod "$DESTDIR/dev/null" c 1 3
mknod "$DESTDIR/dev/zero" c 1 5
+mknod "$DESTDIR/dev/random" c 1 8
+mknod "$DESTDIR/dev/urandom" c 1 9
-inst_exec $busybox /bin/initrd-busybox
-ln -s initrd-busybox $DESTDIR/bin/sh
-# for older busyboxes who had /bin/busybox as EXEPATH
-ln -s initrd-busybox $DESTDIR/bin/busybox
+inst_exec $busybox /bin/busybox
+ln -s busybox $DESTDIR/bin/sh
+# for older busyboxes who had /bin/initrd-busybox as EXEPATH
+ln -s busybox $DESTDIR/bin/initrd-busybox
add_linuxrc <<EOF
#!/bin/sh
# initrd generated by:
-# $RCSID
+# $GENINITRD_RCSID
EOF
mount_proc
+add_linuxrc <<-EOF
+ # builtin defaults from geninitrd
+ ROOT=$rootdev
+ ROOTFS=$rootFs
+EOF
add_linuxrc <<-'EOF'
- read CMDLINE < /proc/cmdline; export CMDLINE
+ read CMDLINE < /proc/cmdline
for arg in $CMDLINE; do
if [ "${arg}" = "debuginitrd" ]; then
if [ "${arg##root=}" != "${arg}" ]; then
ROOT=${arg##root=}
fi
+ if [ "${arg##rootfsflags=}" != "${arg}" ]; then
+ ROOTFSFLAGS=${arg##rootfsflags=}
+ fi
+ if [ "${arg##init=}" != "${arg}" ]; then
+ INIT=${arg##init=}
+ fi
done
# make debugshell() invoke subshell if $DEBUGINITRD=sh
EOF
if is_yes "$RUN_SULOGIN_ON_ERR"; then
add_linuxrc <<-'EOF'
- echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
+ echo "debug shell disabled by /etc/sysconfig/system: RUN_SULOGIN_ON_ERR setting"
EOF
else
add_linuxrc <<-'EOF'
initrd_gen_udev
fi
-if is_yes "$USE_TUXONICE"; then
- initrd_gen_tuxonice
-fi
-
find_modules_uvesafb
initrd_gen_uvesafb
-if is_yes "$have_luks"; then
- initrd_gen_luks
-fi
-
-if is_yes "$have_dmraid"; then
- initrd_gen_dmraid
-fi
-
-if is_yes "$have_multipath"; then
- initrd_gen_multipath
-fi
-
-if is_yes "$USE_BLKID"; then
- initrd_gen_blkid
-fi
+initrd_gen_luks
+initrd_gen_dmraid
+initrd_gen_multipath
+initrd_gen_blkid
if is_yes "$have_nfs"; then
initrd_gen_nfs
-elif is_yes "$have_md"; then
+else
initrd_gen_md
- if is_yes "$have_lvm"; then
- initrd_gen_lvm
- else
- initrd_gen_setrootdev
- fi
-elif is_yes "$have_lvm"; then
initrd_gen_lvm
-else
+ initrd_gen_luks
initrd_gen_setrootdev
fi
-if is_yes "$USE_SUSPEND"; then
- initrd_gen_suspend
-fi
+initrd_gen_tuxonice
+initrd_gen_suspend
# additional devs always needed
[ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
-if is_yes "$USE_UDEV"; then
- initrd_gen_stop_udevd
-fi
+initrd_gen_stop_udevd
+initrd_gen_stop_uvesafb
+
+# clean up env
+add_linuxrc <<-'EOF'
+ ifs=$IFS
+ IFS="
+ "
+ for i in $(export -p); do
+ i=${i#declare -x } # ksh/bash
+ i=${i#export } # busybox
+
+ case "$i" in
+ *=*)
+ : ;;
+ *)
+ continue ;;
+ esac
+
+ i=${i%%=*}
+
+ [ -z "$i" ] && continue
+
+ case "$i" in
+ ROOT|PATH|HOME|TERM)
+ :
+ ;;
+ *)
+ unset $i
+ ;;
+ esac
+ done
+ IFS=$ifs
+EOF
if [ "$INITRDFS" = "initramfs" ]; then
initrd_gen_initramfs_switchroot
umount_all
fi
-if is_yes "$FB_SPLASH"; then
- initrd_gen_fbsplash
-fi
-
-if is_yes "$FB_CON_DECOR"; then
- initrd_gen_fbcondecor
-fi
+initrd_gen_fbsplash
+initrd_gen_fbcondecor
IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
+IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
+debug "image size: $IMAGESIZE KiB ($DESTDIR)"
+
debug "Creating $INITRDFS image $IMAGE"
case "$INITRDFS" in
ext2)
dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
- mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
+ # NOTE: ext2 label is max 16 chars
+ mke2fs -q -F -b 1024 -m 0 -L "PLD/$kernel" "$IMAGE" 2>/dev/null 1>&2
tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
debug "Mounting ext2 image $IMAGE to $tmpmnt"
- mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
+ mount -o loop -t ext2 "$IMAGE" "$tmpmnt" || die "mount failed, check dmesg(1)"
# We don't need this directory, so let's save space
rm -rf "$tmpmnt"/lost+found
;;
rom|romfs)
- genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
+ genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD Linux/$kernel (geninitrd/$VERSION)"
;;
cram|cramfs)
mkcramfs "$DESTDIR" "$IMAGE"
die "Filesystem $INITRDFS not supported by $PROGRAM"
esac
-# TODO: figure out this automatically
-CONFIG_BLK_DEV_RAM_SIZE=4096
+CONFIG_BLK_DEV_RAM_SIZE=$(ikconfig | awk -F= '/^CONFIG_BLK_DEV_RAM_SIZE/{print $2}')
+if [ -z "$CONFIG_BLK_DEV_RAM_SIZE" ]; then
+ CONFIG_BLK_DEV_RAM_SIZE=4096
+ warn "No CONFIG_BLK_DEV_RAM_SIZE detected, fallback to $CONFIG_BLK_DEV_RAM_SIZE"
+fi
-IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
-debug "image size: $IMAGESIZE KiB ($DESTDIR)"
if [ "$IMAGESIZE" -gt $CONFIG_BLK_DEV_RAM_SIZE ]; then
warn "Your image size is larger than $CONFIG_BLK_DEV_RAM_SIZE, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
fi
if ! is_no "$COMPRESS"; then
- tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
compressor=$(find_compressor "$COMPRESS")
debug "Compressing $target with $compressor"
# TODO: the image name (specified from kernel.spec) already contains
# extension, which is .gz most of the time.
- case "$compressor" in
- lzma)
- lzma -9 < "$IMAGE" > "$tmp"
- ;;
- bzip2)
- bzip2 -9 < "$IMAGE" > "$tmp"
- ;;
- gzip)
- gzip -9 < "$IMAGE" > "$tmp"
- ;;
- esac
- mv -f "$tmp" "$target"
+ compress_image "$compressor" "$IMAGE" "$target" || {
+ if [ $compressor != gzip ]; then
+ warn "Could not compress with $compressor, retrying with gzip"
+ compress_image gzip "$IMAGE" "$target" || die "compress failed with gzip" $?
+ else
+ die "Could not compress image with $compressor"
+ fi
+ }
else
cp -a "$IMAGE" "$target"
fi
# XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
-if is_yes "$BOOT_SPLASH"; then
- initrd_gen_bootsplash "$target"
-fi
+initrd_gen_bootsplash "$target"
rm -rf "$DESTDIR" "$IMAGE"