# list of geninitrd modules which need setup routine after commandline args parsing
GENINITRD_MODS=""
COMPRESS=yes
+STRIP=/usr/bin/strip
target=""
kernel=""
force=""
echo "Usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
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 ""
echo "Example:"
- local kdir kver
+ local kdir kver dir=${target:-/boot}
for kdir in /lib/modules/*; do
[ -d $kdir ] || continue
kver=${kdir##*/}
- echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$kver.gz $kver"
- done
- exit 0
+ 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
}
# 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/random c 1 8
- mknod /dev/snapshot c 10 231
- 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
local kofile=$(modinfo -k $kernel -n configs 2> /dev/null)
if [ -n "$kofile" ]; then
/lib/geninitrd/extract-ikconfig $kofile
- else
- # try vmlinuz itself
- /lib/geninitrd/extract-ikconfig /boot/vmlinuz-$kernel
+ 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
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() {
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
}
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
}
# name of the module
local module=${modpath##*/}; module=${module%$modext}
- local options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
+ local options=$(modprobe_options "$module")
local genericname=$(echo $module | tr - _)
local usleep=$(eval echo \$MODULE_${genericname}_USLEEP)
local firmware=$(eval echo \$MODULE_${genericname}_FIRMWARE)
# 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
[ -n "$ROOTFSFLAGS" ] && ROOTFSFLAGS="-o $ROOTFSFLAGS"
- mount -t $rootfs -r $device $ROOTFSFLAGS /newroot || echo "Mount of rootfs failed."
- init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
+ 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."
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 sata 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
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
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"
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##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'
[ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
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
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 Linux/$kernel initrd"
+ genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD Linux/$kernel (geninitrd/$VERSION)"
;;
cram|cramfs)
mkcramfs "$DESTDIR" "$IMAGE"
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