summaryrefslogtreecommitdiffstats
path: root/source/a/mkinitrd/mkinitrd
diff options
context:
space:
mode:
author Patrick J Volkerding <volkerdi@slackware.com>2009-08-26 10:00:38 -0500
committer Eric Hameleers <alien@slackware.com>2018-05-31 22:41:17 +0200
commit5a12e7c134274dba706667107d10d231517d3e05 (patch)
tree55718d5acb710fde798d9f38d0bbaf594ed4b296 /source/a/mkinitrd/mkinitrd
downloadcurrent-5a12e7c134274dba706667107d10d231517d3e05.tar.gz
current-5a12e7c134274dba706667107d10d231517d3e05.tar.xz
Slackware 13.0slackware-13.0
Wed Aug 26 10:00:38 CDT 2009 Slackware 13.0 x86_64 is released as stable! Thanks to everyone who helped make this release possible -- see the RELEASE_NOTES for the credits. The ISOs are off to the replicator. This time it will be a 6 CD-ROM 32-bit set and a dual-sided 32-bit/64-bit x86/x86_64 DVD. We're taking pre-orders now at store.slackware.com. Please consider picking up a copy to help support the project. Once again, thanks to the entire Slackware community for all the help testing and fixing things and offering suggestions during this development cycle. As always, have fun and enjoy! -P.
Diffstat (limited to '')
-rw-r--r--source/a/mkinitrd/mkinitrd494
-rw-r--r--source/a/mkinitrd/mkinitrd.8194
-rwxr-xr-xsource/a/mkinitrd/mkinitrd.SlackBuild119
-rw-r--r--source/a/mkinitrd/mkinitrd.conf.5174
-rw-r--r--source/a/mkinitrd/mkinitrd.conf.sample16
-rw-r--r--source/a/mkinitrd/mkinitrd_command_generator.sh842
-rw-r--r--source/a/mkinitrd/mkinitrd_kernelcheck.diff15
7 files changed, 1854 insertions, 0 deletions
diff --git a/source/a/mkinitrd/mkinitrd b/source/a/mkinitrd/mkinitrd
new file mode 100644
index 000000000..8f77725fe
--- /dev/null
+++ b/source/a/mkinitrd/mkinitrd
@@ -0,0 +1,494 @@
+#!/bin/sh
+# Copyright 2004 Slackware Linux, Inc., Concord, CA, USA
+# Copyright 2004 Patrick J. Volkerding, Concord, CA, USA
+# Copyright 2007, 2008, 2009 Patrick J. Volkerding, Sebeka, MN, USA
+# All rights reserved.
+#
+# Redistribution and use of this script, with or without modification, is
+# permitted provided that the following conditions are met:
+#
+# 1. Redistributions of this script must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
+# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Modified by Robby Workman <rworkman@slackware.com> 26 November 2007
+# to add support for mkinitrd.conf - No additional license terms added
+# Modified by Alan Hicks <alan@slackware.com> 27 November 2007 to enable
+# passing arguments to kernel modules - No additional license terms added
+# volkerdi - feel free to remove these :)
+# Modified by Eric Hameleers <alien@slackware.com> 3 April 2008
+# to add support custom keymaps - No additional license terms added
+# Modified by Patrick Volkerding <volkerdi@slackware.com> 17 Dec 2008
+# Added support to bail out if kernel modules are requested for a kernel
+# version that is not installed (thanks to Eric Hameleers), be more
+# verbose about showing modules added to the initrd (thanks to
+# Ellington Santos), and if "mount" returns /dev/root as the root device,
+# use readlink to resolve the device pointed to by the /dev/root
+# symlink, changed modprobe to use --ignore-install to avoid catching
+# custom "install" lines and causing /sbin/modprobe to be copied to the
+# initrd (thanks to Ken Milmore).
+# Of course, license terms remain unchanged.
+
+MKINITRD_VERSION=1.3.4
+
+print_usage() {
+ cat << EOF
+Usage: mkinitrd [OPTION]
+
+mkinitrd creates an initial ramdisk (actually an initramfs cpio+gzip
+archive) used to load kernel modules that are needed to mount the
+root filesystem, or other modules that might be needed before the
+root filesystem is available. Other binaries may be added to the
+initrd, and the script is easy to modify. Be creative. :-)
+
+ -F Use the contents of /etc/mkinitrd.conf (optional)
+ If this is used in conjunction with any other options passed
+ on the command line, the command-line options will override
+ the config file options. See mkinitrd.conf(5) for details.
+ -c Clear the existing initrd tree first
+ -f Filesystem to use for root partition (must be used with -r)
+ --help Display this message
+ -h Device to resume from hibernation. Needs to be the name of
+ the swap partition holding the hibernation image.
+ -k Kernel version to use
+ -l Custom keymap to load. Like, 'nl' or 'de-latin1-nodeadkeys'
+ -m A colon (:) delimited list of kernel modules to load.
+ Additional options may be added to use when loading the
+ kernel modules (but in this case the entire list must be
+ wrapped with double quotes). Any dependencies of requested
+ modules will also be added to the initrd.
+ -o Output image (default /boot/initrd.gz)
+ -r Root partition device (must be used with -f)
+ -s Initrd source tree (default /boot/initrd-tree/)
+ -w Time to wait until all disks are detected
+ -C Use cryptsetup to unlock the underlying device of an
+ encrypted root filesystem (must be used with '-r' parameter).
+ Two scenarios are possible. (1) root filesystem was created on the
+ encrypted disk/LVM partition, example:
+ -C /dev/sda2 -r cryptroot
+ where /dev/sda2 is the encrypted partition and
+ the actual root device name in /etc/fstab is:
+ /dev/mapper/cryptroot
+ (2) the encrypted partition contains a LVM volume which holds the
+ root filesystem, example:
+ -C /dev/sda2 -r /dev/vg/root
+ where /dev/sda2 is the encrypted partition and
+ the actual root device name in /etc/fstab is:
+ /dev/vg/root
+ -L Add support for LVM partitions
+ -R Add support for RAID partitions
+ -V Display version number
+
+A simple example: Build an initrd for a reiserfs root partition:
+
+ mkinitrd -c -m reiserfs
+
+Another example: Build an initrd image using Linux 2.6.29.3-smp kernel
+modules for a system with an ext3 root partition on /dev/hdb3:
+
+ mkinitrd -c -k 2.6.29.3-smp -m mbcache:jbd:ext3 -f ext3 -r /dev/hdb3
+
+Note that if you are already logged in with /dev/hdb3 as your /
+partition, and it is running ext3, this command works just the same:
+
+ mkinitrd -c -m ext3
+
+If run without options, mkinitrd will rebuild an initrd image using
+the contents of the $SOURCE_TREE directory, or, if that directory
+does not exist it will be created and populated, and then mkinitrd
+will exit.
+
+EOF
+}
+
+create_new_source_tree() {
+ mkdir -p $SOURCE_TREE
+ # Make sure a kernel module directory exists:
+ mkdir -p $SOURCE_TREE/lib/modules/${KERNEL_VERSION}
+ # Add the initrd-tree skeleton:
+ ( cd $SOURCE_TREE ; tar xzf /usr/share/mkinitrd/initrd-tree.tar.gz )
+ # Make sure we have any block devices that might be needed:
+
+ SLOPPY_DEV_LIST=$(cat /proc/partitions)
+ for device in $SLOPPY_DEV_LIST ; do
+ if [ ! -r $SOURCE_TREE/dev/$device ]; then
+ if [ -b /dev/$device ]; then
+ if [ -L /dev/$device ]; then
+ cp -a --parents $(readlink -e /dev/$device) $SOURCE_TREE
+ fi
+ cp -a --parents /dev/$device $SOURCE_TREE
+ fi
+ fi
+ done
+}
+
+clear_source_tree() {
+ if [ -d "$SOURCE_TREE" ]; then
+ rm -rf $SOURCE_TREE
+ fi
+}
+
+build_initrd_image() {
+ # Make sure we have any block devices that might be needed:
+ SLOPPY_DEV_LIST=$(cat /proc/partitions)
+ for device in $SLOPPY_DEV_LIST ; do
+ if [ ! -r $SOURCE_TREE/dev/$device ]; then
+ if [ -b /dev/$device ]; then
+ if [ -L /dev/$device ]; then
+ cp -a --parents $(readlink -e /dev/$device) $SOURCE_TREE
+ fi
+ cp -a --parents /dev/$device $SOURCE_TREE
+ fi
+ fi
+ done
+ # Wrap the initrd as an initramfs image and move it into place:
+ ( cd $SOURCE_TREE
+ rm -f $OUTPUT_IMAGE
+ find . | cpio -o -H newc | gzip -9c > $OUTPUT_IMAGE
+ )
+}
+
+badconf_file() {
+ # This won't really help with what's *wrong* with the file,
+ # but it will at least give them a clue that there's a problem
+ echo "/etc/mkinitrd.conf is bad or does not exist."
+ echo "If the file does not exist, do not pass -F to mkinitrd."
+ exit 1
+}
+
+# If --help is given, print_usage and exit:
+if echo $* | grep -wq '\--help' ; then
+ print_usage
+ exit 0
+fi
+
+# If -V given, print version and exit:
+if echo $* | grep -wq '\-V' ; then
+ echo "mkinitrd version $MKINITRD_VERSION"
+ exit 0
+fi
+
+# Default values if these aren't previously set.
+# Might be set from config file or by -s and -o options too.
+SOURCE_TREE=${SOURCE_TREE:-/boot/initrd-tree}
+OUTPUT_IMAGE=${OUTPUT_IMAGE:-/boot/initrd.gz}
+KERNEL_VERSION=${KERNEL_VERSION:-"$(uname -r)"}
+
+# Default actions without options:
+if [ -z "$1" ]; then
+ # If the output tree doesn't exist, create it and then exit:
+ if [ ! -d $SOURCE_TREE ]; then
+ echo "Nothing found at location $SOURCE_TREE, so we will create an"
+ echo -n "initrd directory structure there... "
+ create_new_source_tree
+ echo "done."
+ echo
+ echo "Now cd to $SOURCE_TREE and install some modules in your"
+ echo "module directory (lib/modules/${KERNEL_VERSION}). Then see init"
+ echo "for more information (there are a few other files to edit)."
+ echo "Finally, run mkinitrd again once the initrd-tree is ready,"
+ echo "and $OUTPUT_IMAGE will be created from it."
+ echo
+ exit 0
+ else
+ # If the source tree does exist, the default is to build the initrd
+ # image from it and then exit:
+ build_initrd_image
+ echo "$OUTPUT_IMAGE created."
+ echo "Be sure to run lilo again if you use it."
+ exit 0
+ fi
+fi # default no-option actions
+
+# Parse for the use config file option first or else the other command
+# line options can not override /etc/mkinitrd.conf.
+for opt in "$@"; do
+ if [ $opt = "-F" ]; then
+ if [ -e /etc/mkinitrd.conf ]; then
+ . /etc/mkinitrd.conf || badconf_file
+ else
+ badconf_file
+ fi
+ fi
+done
+
+# Parse options:
+while [ ! -z "$1" ]; do
+ case $1 in
+ -c)
+ CLEAR_TREE=1
+ shift
+ ;;
+ -f)
+ ROOTFS="$2"
+ shift 2
+ ;;
+ -h)
+ RESUMEDEV="$2"
+ shift 2
+ ;;
+ -k)
+ KERNEL_VERSION="$2"
+ shift 2
+ ;;
+ -l)
+ KEYMAP="$2"
+ shift 2
+ ;;
+ -m)
+ MODULE_LIST="$2"
+ shift 2
+ ;;
+ -o)
+ OUTPUT_IMAGE="$2"
+ if [ ! "$(echo $OUTPUT_IMAGE | cut -b1)" = "/" ]; then
+ OUTPUT_IMAGE=$(pwd)/$OUTPUT_IMAGE
+ fi
+ shift 2
+ ;;
+ -r)
+ ROOTDEV="$2"
+ shift 2
+ ;;
+ -s)
+ SOURCE_TREE="$2"
+ shift 2
+ ;;
+ -w)
+ WAIT="$2"
+ shift 2
+ ;;
+ -C)
+ CRYPT=1
+ LUKSDEV="$2"
+ shift 2
+ ;;
+ -L)
+ LVM=1
+ shift
+ ;;
+ -R)
+ RAID=1
+ shift
+ ;;
+ *) # unknown, prevent infinite loop
+ shift
+ ;;
+ esac
+done
+
+# If kernel modules are needed but the kernel version is absent, exit now:
+if [ ! -d /lib/modules/$KERNEL_VERSION ]; then
+ echo "ERROR: No /lib/modules/$KERNEL_VERSION kernel modules tree found for kernel \"$KERNEL_VERSION\""
+ exit 1
+fi
+
+# If clearing source tree was requested, do that first
+if [ "$CLEAR_TREE" = "1" ]; then
+ clear_source_tree
+fi
+
+# If there's no $SOURCE_TREE, make one now:
+if [ ! -d "$SOURCE_TREE" ]; then
+ create_new_source_tree
+fi
+
+# If $ROOTDEV and $ROOTFS are not set, assume we want the
+# values for the currently mounted /
+# (unless we find that values are already set in the initrd-tree):
+if [ -z "$ROOTDEV" -a -z "$(cat $SOURCE_TREE/rootdev 2> /dev/null)" ]; then
+ ROOTDEV=$(mount | grep ' on / ' | cut -f 1 -d ' ')
+ if [ "$ROOTDEV" = "/dev/root" ]; then # find real root device
+ ROOTDEV="/dev/$(readlink /dev/root)"
+ fi
+fi
+if [ -z "$ROOTFS" -a -z "$(cat $SOURCE_TREE/rootfs 2> /dev/null)" ]; then
+ ROOTFS=$(mount | grep ' on / ' | cut -f 5 -d ' ')
+fi
+# If needed, write them in the initrd-tree:
+if [ ! -z "$ROOTDEV" ]; then
+ echo $ROOTDEV > $SOURCE_TREE/rootdev
+fi
+if [ ! -z "$ROOTFS" ]; then
+ echo $ROOTFS > $SOURCE_TREE/rootfs
+fi
+
+# If $WAIT is not set, assume we need only one second
+# to have all devices done
+# (unless we find that value is already set in the initrd-tree):
+if [ -z "$WAIT" -a -z "$(cat $SOURCE_TREE/wait-for-root)" ]; then
+ WAIT=1
+fi
+if [ ! -z "$WAIT" ]; then
+ echo $WAIT > $SOURCE_TREE/wait-for-root
+fi
+
+# Useful to know which initrd is running:
+INITRD_NAME=$(basename $OUTPUT_IMAGE)
+echo $INITRD_NAME > $SOURCE_TREE/initrd-name
+
+# Fill /resumedev with the swap partition holding the hibernation image
+if [ ! -z "$RESUMEDEV" ]; then
+ echo $RESUMEDEV > $SOURCE_TREE/resumedev
+fi
+
+# Add custom keymap support if one was given
+if [ ! -z "$KEYMAP" ]; then
+ echo $KEYMAP > $SOURCE_TREE/keymap
+ cp /usr/share/mkinitrd/keymaps.tar.gz $SOURCE_TREE/etc/
+fi
+
+# If LUKSDEV was set in the config file, then we need to set CRYPT=1
+if [ ! -z "$LUKSDEV" ]; then
+ CRYPT=1
+fi
+
+# Include RAID support in initrd
+if [ ! -z "$RAID" ]; then
+ if [ -r /sbin/mdadm ]; then
+ mkdir -p $SOURCE_TREE/sbin
+ cp /sbin/mdadm $SOURCE_TREE/sbin/mdadm
+ chmod 755 $SOURCE_TREE/sbin/mdadm
+ else
+ echo "ERROR: mdadm binary is missing, RAID support not installed"
+ fi
+fi
+
+# Include LVM support in initrd
+if [ ! -z "$LVM" ]; then
+ if [ -f /sbin/lvm.static ]; then
+ mkdir -p $SOURCE_TREE/sbin
+ cp /sbin/lvm.static $SOURCE_TREE/sbin/lvm.static
+ cp /sbin/dmsetup.static $SOURCE_TREE/sbin/dmsetup.static
+ ( cd $SOURCE_TREE/sbin
+ ln -s lvm.static vgchange 2>/dev/null
+ ln -s lvm.static vgscan 2>/dev/null )
+ if [ -z "${MODULE_LIST}" ] ; then
+ MODULE_LIST="dm-mod"
+ elif ! echo ${MODULE_LIST} | grep -q dm-mod ; then
+ MODULE_LIST="$MODULE_LIST:dm-mod"
+ fi
+ else
+ echo "LVM static binary is missing, LVM support isn't installed"
+ fi
+fi
+
+# Include cryptsetup (LUKS) support in initrd
+if [ ! -z "$CRYPT" ]; then
+ if [ -e /sbin/cryptsetup.static ]; then
+ mkdir -p $SOURCE_TREE/sbin
+ cp /sbin/cryptsetup.static $SOURCE_TREE/sbin/cryptsetup.static
+ ( cd $SOURCE_TREE/sbin
+ ln -s cryptsetup.static cryptsetup 2>/dev/null
+ )
+ cat << EOF > $SOURCE_TREE/sbin/udevadm
+#!/bin/sh
+sleep 3
+EOF
+ chmod 0755 $SOURCE_TREE/sbin/udevadm
+
+ if [ -z "${MODULE_LIST}" ] ; then
+ MODULE_LIST="dm-mod"
+ elif ! echo ${MODULE_LIST} | grep -q dm-mod ; then
+ MODULE_LIST="$MODULE_LIST:dm-mod"
+ fi
+ # Write the underlying luks device to the initrd-tree:
+ echo $LUKSDEV > $SOURCE_TREE/luksdev
+ else
+ echo "Cryptsetup static binary is missing, CRYPT support isn't installed"
+ fi
+fi
+
+# Make module directory:
+if [ ! -d $SOURCE_TREE/lib/modules/$KERNEL_VERSION ]; then
+ mkdir -p $SOURCE_TREE/lib/modules/$KERNEL_VERSION
+fi
+
+# If a module list was given, copy the modules into place:
+if [ ! -z "$MODULE_LIST" ]; then
+ if grep -q "#insmod /lib/modules/2.6.18.8-smp/reiserfs.ko" $SOURCE_TREE/load_kernel_modules ; then
+ rm -f $SOURCE_TREE/load_kernel_modules
+ touch $SOURCE_TREE/load_kernel_modules
+ chmod 755 $SOURCE_TREE/load_kernel_modules
+ echo "# This is a script used to load the kernel modules." >> $SOURCE_TREE/load_kernel_modules
+ echo "# To use it, chmod it 755, and then add the insmod" >> $SOURCE_TREE/load_kernel_modules
+ echo "# lines needed to load your modules, like this:" >> $SOURCE_TREE/load_kernel_modules
+ echo >> $SOURCE_TREE/load_kernel_modules
+ fi
+
+ # Count number of modules
+ # This INDEX number gives us an easy way to find individual
+ # modules and their arguments, as well as tells us how many
+ # times to run through the list
+ if ! echo $MODULE_LIST | grep ':' > /dev/null ; then # only 1 module specified
+ INDEX=1
+ else
+ INDEX=1
+ while [ ! "$(echo "$MODULE_LIST" | cut -f $INDEX -d ':' )" = "" ]; do
+ INDEX=$(expr $INDEX + 1)
+ done
+ INDEX=$(expr $INDEX - 1) # Don't include the null value
+ fi
+
+# Wrap everything in a while loop
+i=0
+while [ $i -ne $INDEX ]; do
+ i=$(( $i + 1 ))
+
+ # FULL_MOD is the module plus any arguments (if any)
+ # MODULE is the module name
+ # ARGS is any optional arguments to be passed to the kernel
+ FULL_MOD="$(echo "$MODULE_LIST" | cut -d ':' -f $i)"
+ MODULE="$(echo "$FULL_MOD" | cut -d ' ' -f 1 )"
+ # Test for arguments
+ if echo "$FULL_MOD" | grep ' ' > /dev/null; then
+ ARGS=" $(echo "$FULL_MOD" | cut -d ' ' -f 2- )"
+ else
+ unset ARGS
+ fi
+
+ # Get MODULE deps and prepare insmod lines
+ /sbin/modprobe --set-version $KERNEL_VERSION --show-depends --ignore-install $MODULE 2> /dev/null \
+ | grep "^insmod " | cut -f 2 -d ' ' | while read SRCMOD; do
+
+ if ! grep -q "$SRCMOD" $SOURCE_TREE/load_kernel_modules 2>/dev/null ; then
+ LINE="$(echo "insmod -v $SRCMOD" | sed -e "s/$KERNEL_VERSION/\$(uname -r)/")"
+
+ # Test to see if arguments should be passed
+ # Over-ride the previously defined LINE variable if so
+ if [ "$(basename $SRCMOD .ko)" = "$MODULE" ]; then
+ # SRCMOD and MODULE are same, ARGS can be passed
+ LINE="$LINE$ARGS"
+ fi
+
+ fi
+
+ if ! grep -qx "$LINE" $SOURCE_TREE/load_kernel_modules ; then
+ echo "$LINE" >> $SOURCE_TREE/load_kernel_modules
+ fi
+
+ if cp -a --parents $SRCMOD $SOURCE_TREE 2> /dev/null; then
+ echo "OK: $SRCMOD added."
+ else
+ echo "WARNING: Could not find module \"$SRCMOD\""
+ fi
+
+ done
+
+done
+
+fi
+
+# And finally, build the initrd:
+build_initrd_image
+
diff --git a/source/a/mkinitrd/mkinitrd.8 b/source/a/mkinitrd/mkinitrd.8
new file mode 100644
index 000000000..5fa957218
--- /dev/null
+++ b/source/a/mkinitrd/mkinitrd.8
@@ -0,0 +1,194 @@
+.\" -*- nroff -*-
+.ds g \" empty
+.ds G \" empty
+.\" Like TP, but if specified indent is more than half
+.\" the current line-length - indent, use the default indent.
+.de Tp
+.ie \\n(.$=0:((0\\$1)*2u>(\\n(.lu-\\n(.iu)) .TP
+.el .TP "\\$1"
+..
+.TH MKINITRD 8 "04 March 2008" "Slackware Version 12.1"
+.SH NAME
+mkinitrd \- create or rebuilt an initrd (initial ramdisk) using initramfs (simple cpio+gzip).
+.SH SYNOPSIS
+.B mkinitrd
+[
+.B \-F
+]
+[
+.B \-c
+]
+[
+.B \-f filesystem
+]
+[
+.B \-h hibernate_partition
+]
+[
+.B \-k kernel_version
+]
+[
+.B \-m module1:module2:module3...
+]
+[
+.B \-o output_file
+]
+[
+.B \-r root_device
+]
+[
+.B \-s source_tree
+]
+[
+.B \-C crypt_device
+]
+[
+.B \-L
+]
+[
+.B \-R
+]
+[
+.B \-V
+]
+.SH DESCRIPTION
+.B mkinitrd
+is used to build an initial ramdisk. An initial ramdisk is a very small
+set of files that are loaded into RAM and "mounted" (as initramfs doesn't
+actually use a filesystem) as the kernel boots (before the main root
+filesystem is mounted). The usual reason to use an initrd is because
+you need to load kernel modules before mounting the root partition.
+Usually these modules are required to support the filesystem used by the
+root partition (ext3, reiserfs, xfs), or perhaps the controller that the
+hard drive is attached to (SCSI, RAID, etc). Essentially, there are so many
+different options available in modern Linux kernels that it isn't practical
+to try to ship many different kernels to try to cover everyone's needs.
+It's a lot more flexible to ship a generic kernel and a set of kernel
+modules for it.
+.SH OPTIONS
+.TP
+.B \-F
+Use the contents of /etc/mkinitrd.conf as options to mkinitrd (optional).
+If this is used in conjunction with any other options passed on the command
+line, the command-line options will override the config file options.
+.br
+See mkinitrd.conf(5) for details.
+.TP
+.B \-c
+Clear the existing initrd tree (by default in /boot/initrd-tree/) first.
+If this is not done, running mkinitrd will add additional modules to the
+existing initrd.
+.TP
+.B \-f filesystem
+Specify the filesystem to use for the root partition. If this isn't given,
+mount will usually figure it out. This option must be used together with the
+\-r option in order to be beneficial.
+.TP
+.B \--help
+Display a help summary.
+.TP
+.B \-h hibernate_partition
+Specify the swap partition holding the hibernation image.
+.TP
+.B \-k kernel version
+Use kernel modules from the specified kernel version. mkinitrd will look
+for them in /lib/modules/(kernel version).
+.TP
+.B \-l keymap
+Load an alternative keyboard mapping. All supported keyboard mappings
+can be found in /usr/share/mkinitrd/keymaps.tar.gz
+Leave the '.bmap' out when you supply this parameter. E.g. '-l nl' will
+add support for dutch keyboard mapping to the initrd.
+.TP
+.B \-m module list
+This is a list of colon-delimited modules to build into the initrd.
+Any dependencies of requested modules will also be added to the initrd.
+Additional options may be added to use when loading the kernel modules
+(but in this case the entire list must be wrapped with double quotes).
+.TP
+.B \-o output image
+The file to write the initrd to. (default: /boot/initrd.gz)
+.TP
+.B \-r root partition
+Specify the device to be used as the root partition. If this isn't given, the
+kernel default will be used (which is usually fine). This option must be used
+together with the \-f option in order to be beneficial.
+.TP
+.B \-s source tree
+The directory to use as the source for the initrd. (default: /boot/initrd-tree/)
+.TP
+.B \-w
+The -w option specifies how long to wait in seconds before assuming that all the
+drives are spun up and ready to go.
+.TP
+.B \-C
+Use cryptsetup to enable the underlying device of an encrypted root partition.
+Requires '-r' parameter. Two scenarios are possible.
+.br
+(1) root filesystem was created on the encrypted disk/LVM partition, example:
+
+ -C /dev/sda2 -r cryptroot
+
+where /dev/sda2 is the encrypted partition and the actual root device name in /etc/fstab is:
+
+ /dev/mapper/cryptroot
+
+(2) the encrypted partition contains a LVM volume which holds the root filesystem, example:
+
+ -C /dev/sda2 -r /dev/vg/root
+
+where /dev/sda2 is the encrypted partition and the actual root device name in /etc/fstab is:
+
+ /dev/vg/root
+.TP
+.B \-L
+This option adds LVM support to the initrd, if the tools are
+available on the system.
+.TP
+.B \-R
+This option adds RAID support to the initrd, if a static mdadm binary is
+available on the system.
+.TP
+.B \-V
+Display version information and exit.
+.SH EXAMPLES
+A simple example: Build an initrd for a reiserfs root partition:
+
+ mkinitrd -c -m reiserfs
+
+Another example: Build an initrd image using Linux 2.6.24.5 kernel
+modules for a system with an ext3 root partition on /dev/hdb3:
+
+ mkinitrd -c -k 2.6.24.5 -m ext3 -f ext3 -r /dev/hdb3
+
+If run without options, mkinitrd will rebuild an initrd image using
+the contents of the $SOURCE_TREE directory, or, if that directory
+does not exist it will be created and populated, and then mkinitrd
+will exit. These options are handy for building an initrd mostly
+by hand. After creating /boot/initrd-tree/, you can add modules and
+edit files by hand, and then rerun mkinitrd to create the initrd.
+
+Once the initrd is created, you'll need to tell your boot loader
+to load it. If you boot with LILO, you will need to add an initrd
+line to /etc/lilo.conf. Here's a section of lilo.conf that shows
+how to set this up:
+
+ # Linux bootable partition config begins
+ image = /boot/vmlinuz-generic-2.6.24.5
+ initrd = /boot/initrd.gz
+ root = /dev/hda6
+ label = Linux26245
+ read-only
+ # Linux bootable partition config ends
+
+Once you've created the initrd and editing /etc/lilo.conf, you will
+need to run 'lilo' to write out the changed boot block. The next
+time you reboot the initrd should be loaded along with the kernel.
+
+Have fun!
+
+.SH SEE ALSO
+mkinitrd.conf (5)
+
+.SH AUTHOR
+Patrick J. Volkerding <volkerdi@slackware.com>
diff --git a/source/a/mkinitrd/mkinitrd.SlackBuild b/source/a/mkinitrd/mkinitrd.SlackBuild
new file mode 100755
index 000000000..10e70b997
--- /dev/null
+++ b/source/a/mkinitrd/mkinitrd.SlackBuild
@@ -0,0 +1,119 @@
+#!/bin/sh
+
+# Copyright 2007, 2008, 2009 Patrick J. Volkerding, Sebeka, MN, USA
+# All rights reserved.
+#
+# Redistribution and use of this script, with or without modification, is
+# permitted provided that the following conditions are met:
+#
+# 1. Redistributions of this script must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+VERSION=1.3.4
+BB=1.12.1
+ARCH=${ARCH:-x86_64}
+NUMJOBS=${NUMJOBS:--j7}
+BUILD=${BUILD:-3}
+
+CWD=$(pwd)
+TMP=${TMP:-/tmp}
+PKG=$TMP/package-mkinitrd
+
+rm -rf $PKG
+mkdir -p $TMP $PKG
+cd $TMP
+rm -rf busybox-$BB
+tar xvf $CWD/busybox-$BB.tar.bz2 || exit 1
+cd busybox-$BB
+
+#zcat $CWD/busybox-${BB}.remove_warning.diff.gz | patch -p1 --verbose || exit 1
+#zcat $CWD/busybox-${BB}.no-gc-sections.diff.gz | patch -p1 --verbose || exit 1
+# Needed with 2.6.27 kernel:
+zcat $CWD/busybox-1.12.1_inotify.diff.gz | patch -p1 --verbose || exit 1
+
+chown -R root:root .
+sed -e \
+ 's#^CONFIG_PREFIX=.*#CONFIG_PREFIX="'$PKG'/usr/share/mkinitrd/initrd-tree"#' \
+ $CWD/busybox-dot-config > .config
+make oldconfig
+make $NUMJOBS || make || exit 1
+
+mkdir -p $PKG/usr/share/mkinitrd/initrd-tree/{bin,sbin}
+make install || exit 1
+rm -f $PKG/usr/share/mkinitrd/initrd-tree/linuxrc
+
+# Copying additional files:
+cp $CWD/mkinitrd_command_generator.sh $PKG/usr/share/mkinitrd
+chmod 755 $PKG/usr/share/mkinitrd/mkinitrd_command_generator.sh
+cp $CWD/keymaps.tar.gz $PKG/usr/share/mkinitrd
+
+# Zip up the initrd-tree:
+( cd $PKG/usr/share/mkinitrd/initrd-tree
+ tar xf $CWD/_initrd-tree.tar.gz
+ cat $CWD/init > init
+ tar czf ../initrd-tree.tar.gz .
+)
+rm -rf $PKG/usr/share/mkinitrd/initrd-tree
+
+# Add busybox docs:
+mkdir -p $PKG/usr/doc/busybox-$BB
+cp -a AUTHORS INSTALL LICENSE README \
+ $PKG/usr/doc/busybox-$BB
+
+mkdir -p $PKG/sbin
+cat $CWD/mkinitrd > $PKG/sbin/mkinitrd
+chmod 755 $PKG/sbin/mkinitrd
+
+mkdir -p $PKG/usr/man/man{5,8}
+cat $CWD/mkinitrd.8 | gzip -9c > $PKG/usr/man/man8/mkinitrd.8.gz
+cat $CWD/mkinitrd.conf.5 | gzip -9c > $PKG/usr/man/man5/mkinitrd.conf.5.gz
+
+mkdir -p $PKG/etc
+cat $CWD/mkinitrd.conf.sample > $PKG/etc/mkinitrd.conf.sample
+
+mkdir -p $PKG/usr/doc/mkinitrd-$VERSION
+cp -a $CWD/README.initrd $PKG/usr/doc/mkinitrd-$VERSION
+
+( cd $PKG/usr/doc/mkinitrd-$VERSION
+ DATE="$(date)"
+ KERNEL_VERSION="$(uname -r)"
+ PACKAGE_VERSION="$(uname -r | tr - _)"
+ LILO_KERNEL_NAME="$(echo $(uname -r) | tr -d . | tr -d - )"
+ cat README.initrd | sed -e s/@DATE@/"$DATE"/ > README.initrd1
+ cat README.initrd1 | sed -e s/@KERNEL_VERSION@/"$KERNEL_VERSION"/ > README.initrd2
+ cat README.initrd2 | sed -e s/@PACKAGE_VERSION@/"$PACKAGE_VERSION"/ > README.initrd3
+ cat README.initrd3 | sed -e s/@LILO_KERNEL_NAME@/"$LILO_KERNEL_NAME"/ > README.initrd4
+ cat README.initrd4 | sed -e s/@MKINITRD_VERSION@/"$VERSION"/ > README.initrd5
+ cat README.initrd5 | sed -e s/@ARCH@/"$ARCH"/ > README.initrd6
+ cat README.initrd6 | sed -e s/@BUILD@/"$BUILD"/ > README.initrd
+ rm -f README.initrd{1,2,3,4,5,6}
+)
+chmod 644 $PKG/usr/doc/mkinitrd-$VERSION/*
+chown root:root $PKG/usr/doc/mkinitrd-$VERSION/*
+
+mkdir $PKG/boot
+( cd $PKG/boot
+ ln -sf /usr/doc/mkinitrd-$VERSION/README.initrd .
+)
+
+find $PKG | xargs file | grep -e "executable" -e "shared object" \
+ | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
+
+mkdir -p $PKG/install
+cat $CWD/slack-desc > $PKG/install/slack-desc
+
+cd $PKG
+/sbin/makepkg -l y -c n $TMP/mkinitrd-$VERSION-$ARCH-$BUILD.txz
+
diff --git a/source/a/mkinitrd/mkinitrd.conf.5 b/source/a/mkinitrd/mkinitrd.conf.5
new file mode 100644
index 000000000..5890e2462
--- /dev/null
+++ b/source/a/mkinitrd/mkinitrd.conf.5
@@ -0,0 +1,174 @@
+.\" mkinitrd.5 Robby Workman <rworkman@slackware.com>
+.\" 25 November 2007 "
+
+.TH MKINITRD.CONF 5 "05 Februrary 2008" "Slackware 12.1"
+.SH NAME
+.B mkinitrd.conf(5)
+.SH SYNOPSIS
+.B mkinitrd.conf - optional configuration file for
+.I mkinitrd(8)
+
+.SH DESCRIPTION
+The
+.I mkinitrd.conf
+file contains options to be passed to
+.I mkinitrd(8)
+on every run if mkinitrd is executed with the -F flag.
+.br
+It is intended as a fast and easy way for the system administrator to
+pass options to mkinitrd without having to type them on each execution.
+
+Options passed to
+.I mkinitrd(8)
+on the command line will override any
+values set in the config file.
+
+.SH OPTIONS AND SYNTAX
+
+All options are in the format of OPTION="value"
+.br
+Unset variables have no effect.
+
+.TP 5
+.I SOURCE_TREE
+This is the location for the initrd's source tree.
+.br
+Defaults to "/boot/initrd-tree"
+
+.TP 5
+.I CLEAR_TREE
+This option specifies whether to clear the initrd source tree prior to
+creating the initrd.
+.br
+This requires a value of either "0" or "1" where 0=no and 1=yes
+.br
+Examples:
+.br
+CLEAR_TREE="0" # Do not clear initrd tree first
+.br
+CLEAR_TREE="1" # Clear initrd tree first
+
+It is recommended to leave this unset and pass "-c" on the command line
+when clearing the tree is desired. Clearing the tree is not desirable
+if you wish to build support for more than one kernel into the initrd
+image.
+
+.TP 5
+.I OUTPUT_IMAGE
+This is the location for the initrd image that is created.
+.br
+Defaults to "/boot/initrd.gz"
+
+.TP 5
+.I KERNEL_VERSION
+This is the kernel version for which the initrd should be created.
+.br
+Defaults to "$(uname -r)"
+
+.TP 5
+.I KEYMAP
+This is the custom keyboard map that should be loaded instead of the
+default 'us' keymap.
+.br
+The file /usr/share/mkinitrd/keymaps.tar.gz contains all possible keymaps
+to choose from (omit the '.bmap' extension in the mkinitrd command)
+.br
+Example: KEYMAP="nl"
+
+.TP 5
+.I MODULE_LIST
+This should be a colon-separated list of modules you wish to be included
+in the initrd image.
+.br
+Example: MODULE_LIST="ext3:mbcache:jbd"
+
+If you have loadtime options that you need to specify when loading kernel
+modules, those can be added here as well.
+.br
+Example: MODULE_LIST="module1:module2 option=1:module3"
+
+.TP 5
+.I LUKSDEV
+When using cryptsetup with an encrypted root partition, use this variable to
+define the *actual* device name of the encrypted root partition and define the
+*mapped* device name as ROOTDEV.
+.br
+For example, if your actual root device name in /etc/fstab is:
+.br
+.I /dev/mapper/cryptroot
+on
+.I /dev/sda2
+
+Then you'll need to set:
+.br
+LUKSDEV="/dev/sda2"
+.br
+ROOTDEV="cryptroot"
+
+.TP 5
+.I ROOTDEV
+The device on which your root filesystem is located.
+.br
+Example: ROOTDEV="/dev/sda2"
+
+If you are using cryptsetup and an encrypted root filesystem, be sure to
+read the option above for LUKSDEV or Bad Things will happen.
+
+.TP 5
+.I ROOTFS
+The filesystem type of your root filesystem
+.br
+Example: ROOTFS="ext3"
+
+.TP 5
+.I RAID
+This option adds the mdadm binary to the initrd to support RAID.
+Additional modules may be required, depending on your kernel
+configuration. If you wish to add LVM support to the initrd, then
+set this to 1; otherwise, leave it unset or set it to 0.
+.br
+Examples:
+.br
+RAID="0" # Do not add RAID support to initrd
+.br
+RAID="1" # Add RAID support to initrd
+
+.TP 5
+.I LVM
+This option adds support for LVM partitions into the initrd.
+If you wish to add LVM support to the initrd, then set this to 1;
+otherwise, leave it unset or set it to 0.
+.br
+Examples:
+.br
+LVM="0" # Do not add LVM support to initrd
+.br
+LVM="1" # Add LVM support to initrd
+
+.TP 5
+.I WAIT
+This defines the time to wait, in seconds, until all disks are detected.
+.br
+This is useful for allowing extra time that might be needed for slow usb disks or systems with large amounts of storage to become ready.
+.br
+If not defined, the default is 1 second.
+
+.TP 5
+.I RESUMEDEV
+The swap partition holding your hibernation image.
+.br
+Example: RESUMEDEV="/dev/sda2"
+
+.SH FILES
+.I /etc/mkinitrd.conf
+.br
+See /etc/mkinitrd.conf.sample
+
+.SH "SEE ALSO"
+.BR mkinitrd "(8)"
+
+.SH BUGS
+None known :-)
+
+.SH MISCELLANEOUS
+Support for mkinitrd.conf was added in mkinitrd-1.3.0
diff --git a/source/a/mkinitrd/mkinitrd.conf.sample b/source/a/mkinitrd/mkinitrd.conf.sample
new file mode 100644
index 000000000..29e56f5f0
--- /dev/null
+++ b/source/a/mkinitrd/mkinitrd.conf.sample
@@ -0,0 +1,16 @@
+# mkinitrd.conf.sample
+# See "man mkinitrd.conf" for details on the syntax of this file
+#
+#SOURCE_TREE="/boot/initrd-tree"
+#CLEAR_TREE="0"
+#OUTPUT_IMAGE="/boot/initrd.gz"
+#KERNEL_VERSION="$(uname -r)"
+#KEYMAP="us"
+#MODULE_LIST="ext3"
+#LUKSDEV="/dev/hda1"
+#ROOTDEV="/dev/hda1"
+#ROOTFS="ext3"
+#RESUMEDEV="/dev/hda2"
+#RAID="0"
+#LVM="0"
+#WAIT="1"
diff --git a/source/a/mkinitrd/mkinitrd_command_generator.sh b/source/a/mkinitrd/mkinitrd_command_generator.sh
new file mode 100644
index 000000000..d3cdfb731
--- /dev/null
+++ b/source/a/mkinitrd/mkinitrd_command_generator.sh
@@ -0,0 +1,842 @@
+#!/bin/sh
+# $Id: mkinitrd_command_generator.sh,v 1.40 2008/12/18 23:32:56 eha Exp eha $
+# Copyright 2008, 2009 by Eric Hameleers <alien@slackware.com>, Eindhoven, Netherlands
+# Copyright 2008, 2009 by PiterPUNK <piterpunk@slackware.com>, Sao Paulo, SP, Brazil
+# All rights reserved.
+#
+# Permission to use, copy, modify, and distribute this software for
+# any purpose with or without fee is hereby granted, provided that
+# the above copyright notice and this permission notice appear in all
+# copies.
+#
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+# -----------------------------------------------------------------------------
+#
+# Create an initrd which fits the system.
+# Take into account the use of LVM/LUKS/RAID.
+# Find out about any hardware drivers the system may need in an initrd when
+# booting from a generic lightweight kernel.
+#
+# -----------------------------------------------------------------------------
+
+# The script's revision number will be displayed in the help text:
+REV=$( echo "$Revision: 1.40 $" | cut -d' ' -f2 )
+
+# Define some essential parameter values:
+USING_LVM=""
+USING_LUKS=""
+USING_RAID=""
+MLIST=""
+REALDEV="" # The device that contains the LUKS volume
+BASEDEV="" # Lowest level device (raw block device or RAID volume)
+
+FSTAB=${FSTAB:-"/etc/fstab"} # so we can test with alternate fstab files
+
+# These are needed by -c and -i options:
+SOURCE_TREE=${SOURCE_TREE:-"/boot/initrd-tree"}
+CLEAR_TREE=${CLEAR_TREE:-1}
+KEYMAP=${KEYMAP:-"us"}
+WAIT=${WAIT:-1}
+
+# A basic explanation of the commandline parameters:
+basic_usage() {
+ cat <<-EOT
+
+ *** $(basename $0) revision $REV ***
+ Usage:
+ $(basename $0) [ options ] [ kernel_filename ]
+ Options:
+ -a <"additional params"> Additional parameters to pass to mkinitrd.
+ -c | --conf Show a suitable mkinitrd configuration file.
+ -h | --help Show this help.
+ -i | --interactive Navigate through menus instead of using
+ commandline arguments.
+ --longhelp Show more detailed information/examples.
+ -k <kernelversion> Use specific kernel version.
+ -m <"additional mods"> Additional modules to pass to mkinitrd,
+ separated by colons (:).
+ -l | --lilo Only show lilo.conf section
+ (requires a kernel_filename).
+ -r | --run Only show 'mkinitrd' command.
+ EOT
+}
+
+# More of a tutorial here:
+extended_usage() {
+ cat <<-EOT
+
+ This script is useful in situations where you require an initrd image
+ to boot your computer.
+ For instance, when booting a kernel that does not have support for your
+ storage or root filesystem built in (such as the Slackware 'generic'
+ kernels').
+
+ * When you run the script without parameters, it will examine your
+ running system, your current kernel version and will output an example
+ of a 'mkinitrd' commandline that you can use to generate an initrd
+ image containing enough driver support to boot the computer.
+
+ * You can make it more specific: when you add the filename of a kernel
+ as parameter to the script, it will determine the kernel version from
+ that kernel, and also give an example of the lines that you should add
+ to your '/etc/lilo.conf' file.
+
+ * If you want your initrd image to have a custom name instead of the
+ default '/boot/initrd.gz' you can add it as another parameter to the
+ script, as follows:
+
+ $(basename $0) -a "-o /boot/custom.gz"
+
+ The arguments to the '-a' parameter will be used as additional arguments
+ to the 'mkinitrd' command.
+
+ * If you need additional modules in the initrd image, apart from what
+ the script determines, you can pass then to the script using the '-m'
+ parameter as follows:
+
+ $(basename $0) -m "uhci-hcd:usbhid"
+
+ The above example adds support for USB keyboards to the initrd - you
+ may need that if you have encrypted your root partition and need to
+ enter a passphrase using a USB keyboard.
+
+ * Instead of copying and pasting the script's output, you can create
+ an initrd by directly executing the output, like in this example:
+
+ EOT
+
+ echo " \$($(basename $0) --run /boot/vmlinuz-generic-smp-2.6.24.5-smp)"
+
+ cat <<-EOT
+
+ That used the '-r' or '--run' switch to make the script only write
+ the 'mkinitrd' commandline to the terminal.
+
+ * When you want to add a section for a specific kernel to
+ '/etc/lilo.conf' directly, use the '-l' or '--lilo' switch and use a
+ command like in this example:
+
+ EOT
+
+ echo " $(basename $0) --lilo /boot/vmlinuz-generic-smp-2.6.24.5-smp >>/etc/lilo.conf"
+
+ cat <<-EOT
+
+ That command will result in the following lines being added to your
+ '/etc/lilo.conf' file (example for my hardware):
+
+ # Linux bootable partition config begins
+ # initrd created with 'mkinitrd -c -k 2.6.24.5-smp -m ata_generic:pata_amd:mbcache:jbd:ext3 -f ext3 -r /dev/hda7'
+ image = /boot/vmlinuz-generic-smp-2.6.24.5-smp
+ initrd = /boot/initrd.gz
+ root = /dev/hda7
+ label = 2.6.24.5-smp
+ read-only
+ # Linux bootable partition config ends
+
+ The last two examples show how easy it is to configure your computer
+ for the use of an initrd if you need one. The only thing left to do
+ afterwards is running 'lilo'.
+
+ EOT
+}
+
+# Find the device that holds the root partition:
+get_root_device() {
+ if [ -e $FSTAB ]; then
+ RD=$(cat $FSTAB | tr '\t' ' ' | tr -s ' ' | grep ' / ' | cut -f1 -d' ')
+ if [ "$(echo $RD | cut -f1 -d=)" = "LABEL" -o "$(echo $RD | cut -f1 -d=)" = "UUID" ]; then
+ DKEY=$(echo $RD | cut -f1 -d=)
+ # The value can be LABEL=foo or LABEL='foo' or LABEL="foo"
+ DVAL=$(echo $RD | cut -f2 -d= | tr -d "'\042")
+ RD=$(/sbin/blkid | grep -w $DKEY | grep -w $DVAL | cut -f1 -d:)
+ fi
+ else
+ RD=$(grep -m1 "^/dev/.*[[:blank:]]/[[:blank:]]" /proc/mounts | cut -f1 -d' ')
+ fi
+ echo $RD
+}
+
+# Get the root fs information:
+get_rootfs_type() {
+ if $(type vol_id 1>/dev/null 2>&1) ; then
+ vol_id $ROOTDEV | grep ID_FS_TYPE | cut -f2 -d=
+ else
+ # Alternatively, use:
+ cat $FSTAB | tr '\t' ' ' | tr -s ' ' | grep ' / ' | cut -f3 -d' '
+ fi
+}
+
+# Add the module(s) needed for the root filesystem:
+add_rootfs_module() {
+ local FSMOD
+ FSMOD=$(/sbin/modprobe --set-version $KVER --show-depends ${ROOTFS} 2>/dev/null | while read LINE; do
+ echo $(basename $(echo $LINE | cut -d' ' -f2) .ko )
+ done)
+ if [ -n "$FSMOD" ]; then
+ [ -n "$MLIST" ] && echo "$MLIST:$(echo $FSMOD | tr ' ' ':')" \
+ || echo $FSMOD | tr ' ' ':'
+ fi
+}
+
+# Determine the list of kernel modules needed to support the root device:
+determine_blockdev_drivers() {
+ # Walk the /sys tree to find kernel modules that are
+ # required for our storage devices.
+ # Thanks to PiterPUNK for this piece of code.
+ local MLIST
+ MLIST=$(for i in $(find /sys/block -name "device" -exec ls -l {} \; | sed -ne 's:.*/\(devices.*\)/[a-zA-Z]\+[.0-9]\+/.*:/sys/\1:p' | sort -u); do
+ for j in $(find $i -name "modalias"); do
+ /sbin/modprobe --set-version $KVER --show-depends $(cat $j) 2>/dev/null | while read LINE ; do
+ echo $(basename $(echo $LINE | cut -d' ' -f2) .ko )
+ done
+ done
+ done)
+ MLIST=$( echo $MLIST | tr ' ' ':' )
+ echo $MLIST
+}
+
+# Search for USB keyboards:
+function add_usb_keyboard() {
+ local USBMOD
+ if cat /proc/bus/input/devices | sed -e 's/^$/\$/g' | \
+ tr "\n$" " \n" | grep -q " Phys=.*usb.* .*Handlers=.*kbd.*B:"; then
+ USBMOD="usbhid"
+ [ -n "$MLIST" ] && MLIST="$MLIST:$USBMOD" \
+ || MLIST="$USBMOD"
+ fi
+ echo $MLIST
+}
+
+# Determine what USB Host Controller is in use
+function add_usb_hcd() {
+ local USBMOD
+ for i in `ls -Ld /sys/module/*_hcd/drivers/*`; do
+ if ls -L $i | grep -q "[0-9a-f]*:" ; then
+ USBMOD=$( echo $i | cut -f4 -d/ | tr "_" "-")
+ [ -n "$MLIST" ] && MLIST="$MLIST:$USBMOD" \
+ || MLIST="$USBMOD"
+ fi
+ done
+ echo $MLIST
+}
+
+# Is the root partition on a (combination of) LVM/LUKS volume?
+check_luks_lvm_raid() {
+ if $( lvdisplay -c $ROOTDEV 1>/dev/null 2>/dev/null ); then
+ # Our root partition is on a LV:
+ USING_LVM=1
+ # Search the Physical Volume of our Logical Volume:
+ MYVG=$( echo $(lvdisplay -c $ROOTDEV) | cut -d: -f2 )
+ for LINE in $(pvdisplay -c) ; do
+ VG=$(echo $LINE | cut -d: -f2)
+ [ "$VG" = "$MYVG" ] && break
+ done
+ PV=$(echo $LINE | cut -d: -f1)
+ # Check if there is a LUKS device underneath:
+ if $( cryptsetup status $PV 1>/dev/null 2>/dev/null ) ; then
+ # Our root partition's LV is on a LUKS volume:
+ USING_LUKS=1
+ REALDEV=$( cryptsetup status $PV | grep 'device: ' | tr -d ' ' | cut -d: -f2 )
+ BASEDEV=$REALDEV
+ else
+ BASEDEV=$PV
+ fi
+ elif $( cryptsetup status $ROOTDEV 1>/dev/null 2>/dev/null ) ; then
+ # Our root device is on a LUKS volume:
+ USING_LUKS=1
+ REALDEV=$( cryptsetup status $ROOTDEV | grep 'device: ' | tr -d ' ' | cut -d: -f2 )
+ ROOTDEV=$(basename $ROOTDEV)
+ # Check for LVM:
+ for LV in $(lvdisplay -c | tr -d ' ' | cut -f1 -d:) ; do
+ # Note: cryptsetup shows the real device, whereas
+ # lvdisplay requires the /dev/<myvg>/... symlink to the real device.
+ if [ "$(readlink $LV)" = "$REALDEV" ]; then
+ REALDEV=$LV
+ break
+ fi
+ done
+ if $( lvdisplay -c $REALDEV 1>/dev/null 2>/dev/null ); then
+ # Our root partition's LUKS device is on a LV:
+ USING_LVM=1
+ # Search the Physical Volume of our Logical Volume:
+ MYVG=$( echo $(lvdisplay -c $REALDEV) | cut -d: -f2 )
+ for LINE in $(pvdisplay -c) ; do
+ VG=$(echo $LINE | cut -d: -f2)
+ [ "$VG" = "$MYVG" ] && break
+ done
+ PV=$(echo $LINE | cut -d: -f1)
+ BASEDEV=$PV
+ else
+ BASEDEV=$REALDEV
+ fi
+ else
+ BASEDEV=$ROOTDEV
+ fi
+
+ # Finally, we should check if base device is
+ # a real block device or a RAID volume:
+ for MD in $(cat /proc/mdstat | grep -w active | cut -d' ' -f1) ; do
+ if [ "$BASEDEV" = "/dev/$MD" ]; then
+ USING_RAID=1
+ break
+ fi
+ done
+}
+
+# Before we start
+[ -x /bin/id ] && CMD_ID="/bin/id" || CMD_ID="/usr/bin/id"
+if [ "$($CMD_ID -u)" != "0" ]; then
+ echo "You need to be root to run $(basename $0)."
+ exit 1
+fi
+
+# Parse the commandline parameters:
+while [ ! -z "$1" ]; do
+ case $1 in
+ --longhelp)
+ basic_usage
+ extended_usage
+ exit 0
+ ;;
+ -a)
+ MKINIT_PARAMS=$2
+ shift 2
+ ;;
+ -c|--conf)
+ [ -n "$EMIT" ] && { echo "Do not mix incompatible parameters!"; exit 1; }
+ EMIT="conf"
+ shift
+ ;;
+ -h|--help)
+ basic_usage
+ exit 0
+ ;;
+ -i|--interactive)
+ INTERACTIVE=1
+ shift
+ ;;
+ -k)
+ KVER=$2
+ shift 2
+ ;;
+ -m)
+ MKINIT_MODS=$2
+ shift 2
+ ;;
+ -l|--lilo)
+ [ -n "$EMIT" ] && { echo "Do not mix incompatible parameters!"; exit 1; }
+ EMIT="lilo"
+ shift
+ ;;
+ -L|--fromlilo)
+ FROMLILO=1
+ shift
+ ;;
+ -r|--run)
+ [ -n "$EMIT" ] && { echo "Do not mix incompatible parameters!"; exit 1; }
+ EMIT="run"
+ shift
+ ;;
+ -R|--rootdev)
+ ROOTDEV=$2
+ shift 2
+ ;;
+ -*)
+ echo "Unsupported parameter '$1'!"
+ exit 1
+ ;;
+ *) # Everything else but switches (which start with '-') follows:
+ if [ -f $1 ]; then
+ KFILE=$1
+ # Construction of KFILE's full filename:
+ KFILEPATH=$(cd $(dirname $KFILE) && pwd)
+ if [ -L $KFILE ]; then
+ KFILE=$(readlink $KFILE)
+ else
+ KFILE=$(basename $KFILE)
+ fi
+ KFILE=${KFILEPATH}/$KFILE
+ if [ -z "$(file $KFILE | grep 'Linux kernel x86 boot')" ]; then
+ echo "File '$KFILE' does not look like it is a kernel file!"
+ exit 1
+ fi
+ else
+ echo "File $1 not found!"
+ exit 1
+ fi
+ shift
+ ;;
+ esac
+done
+
+# Determine what to show as output (other options may have set EMIT already)
+EMIT=${EMIT:-"all"}
+
+# An EMIT value of 'lilo' requires a kernel filename as script parameter:
+if [ "$EMIT" = "lilo" ]; then
+ if [ -z "$KFILE" ]; then
+ echo "A kernel_filename is required with the '-l|--lilo' option!"
+ exit 1
+ fi
+fi
+
+# Determine kernel version to use,
+# and check if modules for this kernel are actually present:
+if [ -z "$KVER" ]; then
+ if [ -n "$KFILE" ]; then
+ KVER="$(strings $KFILE | grep '(.*@.*) #' | cut -f1 -d' ')"
+ else
+ KVER="$(uname -r)"
+ fi
+fi
+if [ ! -d /lib/modules/$KVER ]; then
+ echo "Modules for kernel $KVER aren't installed."
+ exit 1
+fi
+
+# Determine whether the user passed an alternate filename for the initrd:
+if [ -n "$MKINIT_PARAMS" ]; then
+ SRCHLIST="$MKINIT_PARAMS"
+ for ELEM in $MKINIT_PARAMS ; do
+ SRCHLIST=$(echo $SRCHLIST | cut -d' ' -f2-) # cut ELEM from the list
+ if [ "$ELEM" = "-o" ]; then
+ IMGFILE=$(echo $SRCHLIST | cut -d' ' -f1)
+ break
+ fi
+ done
+fi
+IMGFILE=${IMGFILE:-"/boot/initrd.gz"}
+
+# Get information about the root device / root filesystem:
+ROOTDEV=${ROOTDEV:-$(get_root_device)}
+ROOTFS=$(get_rootfs_type)
+
+# Determine the list of kernel modules needed to support the root device:
+MLIST=$(determine_blockdev_drivers)
+
+# Determine if a USB keyboard is in use and include usbhid to module list
+MLIST=$(add_usb_keyboard)
+
+# If we use any USB module, try to determine the Host Controller
+if echo $MLIST | grep -q "usb"; then
+ MLIST=$(add_usb_hcd)
+fi
+
+# Check what combination of LUKS/LVM/RAID we have to support:
+# This sets values for USING_LUKS, USING_LVM, USING_RAID, REALDEV and BASEDEV.
+check_luks_lvm_raid
+
+# This is the interactive part:
+if [ "$INTERACTIVE" = "1" ]; then
+ if [ "$FROMLILO" != "1" ]; then
+ dialog --stdout --title "WELCOME TO MKINITRD COMMAND GENERATOR" --msgbox "\
+The main goal of this utility is to create a good initrd to \
+fit your needs. It can detect what kernel you are running, \
+what is your root device, root filesystem, if you use encryption, \
+LVM, RAID, etc. \
+\n\n\
+Usually the probed values are OK and they will be the \
+defaults in all subsequent dialogs, but maybe you want \
+to change something. \n\
+If in doubt, leave the defaults." 0 0
+
+ KVER=$( ls -d1 --indicator-style=none /lib/modules/* | \
+ awk -F/ -vVER=$KVER '{
+ if ( VER == $NF ) {
+ ONOFF="on"
+ } else {
+ ONOFF="off"
+ } ; printf("%s \"\" %s\n",$NF,ONOFF) }' | \
+ xargs dialog --stdout --title "CHOOSE KERNEL VERSION" \
+ --default-item $KVER --radiolist "\
+Please, select the kernel version you want to create this initrd for." 0 0 4 )
+ [ -z "$KVER" ] && exit 1
+
+ OLDROOTDEV=$ROOTDEV
+ ROOTDEV=$( dialog --stdout --title "SELECT ROOT DEVICE" --inputbox "\
+Enter your root device. Root device is the one where your '/' filesystem \
+is mounted." 0 0 "$ROOTDEV" )
+ [ -z "$ROOTDEV" ] && exit 1
+
+ # We need to re-check our defaults in case the user changed the default
+ # value for ROOTDEV:
+ [ "$OLDROOTDEV" != "$ROOTDEV" ] && check_luks_lvm_raid
+ ROOTFS=$(get_rootfs_type)
+
+ ROOTFS=$( dialog --stdout --title "SELECT ROOT FILESYSTEM" --inputbox "\
+Enter the type of your root filesystem." 0 0 "$ROOTFS" )
+ [ -z "$ROOTFS" ] && exit 1
+ fi
+
+ MLIST=$(add_rootfs_module)
+
+ LLR=$( dialog --stdout --title "LVM/LUKS/RAID" --checklist "\
+Do you use some of those in your root filesystem? \
+If this is the case, please select one or more options." 12 45 3 \
+"LVM" "Logical Volume Manager" $([ "$USING_LVM" = "1" ] && echo on || echo off) \
+"LUKS" "Linux Unified Key Setup" $([ "$USING_LUKS" = "1" ] && echo on || echo off) \
+"RAID" "Linux Software RAID" $([ "$USING_RAID" = "1" ] && echo on || echo off))
+
+ if [ "$?" != "0" ]; then
+ exit 1
+ fi
+
+ echo $LLR | grep -q LUKS && USING_LUKS="1"
+ echo $LLR | grep -q LVM && USING_LVM="1"
+ echo $LLR | grep -q RAID && USING_RAID="1"
+
+ if [ "$USING_LUKS" = "1" ]; then
+ REALDEV=$( dialog --stdout --title "LUKS ROOT DEVICE" --inputbox "\
+Please, enter your LUKS root device:" 0 0 "$REALDEV" )
+ [ -z "$REALDEV" ] && exit 1
+ fi
+fi
+
+# Step out of the interactive loop for a moment. The next block needs to be
+# executed in all cases.
+
+# We need to 'undouble' the MLIST array. Some people report that walking the
+# /sys tree produces duplicate modules in the list.
+# The awk command elimitates doubles without changing the order:
+MLIST=$( echo $MLIST | tr ':' '\n' | awk '!x[$0]++' | tr '\n' ' ' )
+MLIST=$( echo $MLIST | tr ' ' ':' )
+MLIST=$(echo ${MLIST%:}) # To weed out a trailing ':' which was reported once.
+
+# Back to the interactive part:
+
+if [ "$INTERACTIVE" = "1" ]; then
+ MLIST=$( dialog --stdout --title "INITRD'S MODULE LIST" --inputbox "\
+The list here shows all modules needed to support your root filesystem \
+and boot from it. But you can change the list to use some alternative \
+or additional modules. If you don't know what to do, the default is safe." \
+0 0 "$MLIST" )
+ if [ "$?" != "0" ]; then
+ exit 1
+ fi
+
+ EXTRA=$( dialog --stdout --title "EXTRA CONFIGURATION" --checklist "\
+Now is your chance for some additional configuration. All of these \
+configurations are optional and you can stick to the defaults." 11 72 3 \
+"KEYMAP" "Select keyboard layout (default: US)" \
+ $([ $USING_LUKS = 1 ] && echo on || echo off) \
+"RESUMEDEV" "Select device for 'suspend-to-disk' feature" off \
+"WAIT" "Add delay to allow detection of slow disks at boot" off)
+ if [ "$?" != "0" ]; then
+ exit 1
+ fi
+
+ if echo $EXTRA | grep -q KEYMAP ; then
+ KEYMAP=$( dialog --stdout --title "KEYBOARD LAYOUT SELECTION" \
+ --cancel-label "Skip" \
+ --menu "You may select one of the following keyboard layouts. \
+If you do not select a keyboard map, 'us.map' \
+(the US keyboard layout) is the default. Use the UP/DOWN \
+arrow keys and PageUp/PageDown to scroll \
+through the whole list of choices." \
+22 55 11 \
+"qwerty/us.map" "" \
+"azerty/azerty.map" "" \
+"azerty/be-latin1.map" "" \
+"azerty/fr-latin0.map" "" \
+"azerty/fr-latin1.map" "" \
+"azerty/fr-latin9.map" "" \
+"azerty/fr-old.map" "" \
+"azerty/fr-pc.map" "" \
+"azerty/fr.map" "" \
+"azerty/wangbe.map" "" \
+"azerty/wangbe2.map" "" \
+"dvorak/ANSI-dvorak.map" "" \
+"dvorak/dvorak-l.map" "" \
+"dvorak/dvorak-r.map" "" \
+"dvorak/dvorak.map" "" \
+"dvorak/no-dvorak.map" "" \
+"fgGIod/tr_f-latin5.map" "" \
+"fgGIod/trf-fgGIod.map" "" \
+"olpc/es-olpc.map" "" \
+"olpc/pt-olpc.map" "" \
+"qwerty/bg-cp1251.map" "" \
+"qwerty/bg-cp855.map" "" \
+"qwerty/bg_bds-cp1251.map" "" \
+"qwerty/bg_bds-utf8.map" "" \
+"qwerty/bg_pho-cp1251.map" "" \
+"qwerty/bg_pho-utf8.map" "" \
+"qwerty/br-abnt.map" "" \
+"qwerty/br-abnt2.map" "" \
+"qwerty/br-latin1-abnt2.map" "" \
+"qwerty/br-latin1-us.map" "" \
+"qwerty/by-cp1251.map" "" \
+"qwerty/by.map" "" \
+"qwerty/bywin-cp1251.map" "" \
+"qwerty/cf.map" "" \
+"qwerty/cz-cp1250.map" "" \
+"qwerty/cz-lat2-prog.map" "" \
+"qwerty/cz-lat2.map" "" \
+"qwerty/cz-qwerty.map" "" \
+"qwerty/defkeymap.map" "" \
+"qwerty/defkeymap_V1.0.map" "" \
+"qwerty/dk-latin1.map" "" \
+"qwerty/dk.map" "" \
+"qwerty/emacs.map" "" \
+"qwerty/emacs2.map" "" \
+"qwerty/es-cp850.map" "" \
+"qwerty/es.map" "" \
+"qwerty/et-nodeadkeys.map" "" \
+"qwerty/et.map" "" \
+"qwerty/fi-latin1.map" "" \
+"qwerty/fi-latin9.map" "" \
+"qwerty/fi-old.map" "" \
+"qwerty/fi.map" "" \
+"qwerty/gr-pc.map" "" \
+"qwerty/gr.map" "" \
+"qwerty/hu101.map" "" \
+"qwerty/il-heb.map" "" \
+"qwerty/il-phonetic.map" "" \
+"qwerty/il.map" "" \
+"qwerty/is-latin1-us.map" "" \
+"qwerty/is-latin1.map" "" \
+"qwerty/it-ibm.map" "" \
+"qwerty/it.map" "" \
+"qwerty/it2.map" "" \
+"qwerty/jp106.map" "" \
+"qwerty/kazakh.map" "" \
+"qwerty/kyrgyz.map" "" \
+"qwerty/la-latin1.map" "" \
+"qwerty/lt.baltic.map" "" \
+"qwerty/lt.l4.map" "" \
+"qwerty/lt.map" "" \
+"qwerty/mk-cp1251.map" "" \
+"qwerty/mk-utf.map" "" \
+"qwerty/mk.map" "" \
+"qwerty/mk0.map" "" \
+"qwerty/nl.map" "" \
+"qwerty/nl2.map" "" \
+"qwerty/no-latin1.map" "" \
+"qwerty/no.map" "" \
+"qwerty/pc110.map" "" \
+"qwerty/pl.map" "" \
+"qwerty/pl1.map" "" \
+"qwerty/pl2.map" "" \
+"qwerty/pl3.map" "" \
+"qwerty/pl4.map" "" \
+"qwerty/pt-latin1.map" "" \
+"qwerty/pt-latin9.map" "" \
+"qwerty/pt.map" "" \
+"qwerty/ro.map" "" \
+"qwerty/ro_std.map" "" \
+"qwerty/ru-cp1251.map" "" \
+"qwerty/ru-ms.map" "" \
+"qwerty/ru-yawerty.map" "" \
+"qwerty/ru.map" "" \
+"qwerty/ru1.map" "" \
+"qwerty/ru2.map" "" \
+"qwerty/ru3.map" "" \
+"qwerty/ru4.map" "" \
+"qwerty/ru_win.map" "" \
+"qwerty/ruwin_alt-CP1251.map" "" \
+"qwerty/ruwin_alt-KOI8-R.map" "" \
+"qwerty/ruwin_alt-UTF-8.map" "" \
+"qwerty/ruwin_cplk-CP1251.map" "" \
+"qwerty/ruwin_cplk-KOI8-R.map" "" \
+"qwerty/ruwin_cplk-UTF-8.map" "" \
+"qwerty/ruwin_ct_sh-CP1251.map" "" \
+"qwerty/ruwin_ct_sh-KOI8-R.map" "" \
+"qwerty/ruwin_ct_sh-UTF-8.map" "" \
+"qwerty/ruwin_ctrl-CP1251.map" "" \
+"qwerty/ruwin_ctrl-KOI8-R.map" "" \
+"qwerty/ruwin_ctrl-UTF-8.map" "" \
+"qwerty/se-fi-ir209.map" "" \
+"qwerty/se-fi-lat6.map" "" \
+"qwerty/se-ir209.map" "" \
+"qwerty/se-lat6.map" "" \
+"qwerty/se-latin1.map" "" \
+"qwerty/sk-prog-qwerty.map" "" \
+"qwerty/sk-qwerty.map" "" \
+"qwerty/speakup-jfw.map" "" \
+"qwerty/speakupmap.map" "" \
+"qwerty/sr-cy.map" "" \
+"qwerty/sv-latin1.map" "" \
+"qwerty/tr_q-latin5.map" "" \
+"qwerty/tralt.map" "" \
+"qwerty/trf.map" "" \
+"qwerty/trq.map" "" \
+"qwerty/ttwin_alt-UTF-8.map.gz" "" \
+"qwerty/ttwin_cplk-UTF-8.map.gz" "" \
+"qwerty/ttwin_ct_sh-UTF-8.map.gz" "" \
+"qwerty/ttwin_ctrl-UTF-8.map.gz" "" \
+"qwerty/ua-cp1251.map.gz" "" \
+"qwerty/ua-utf-ws.map" "" \
+"qwerty/ua-utf.map" "" \
+"qwerty/ua-ws.map" "" \
+"qwerty/ua.map" "" \
+"qwerty/uk.map" "" \
+"qwerty/us-acentos.map" "" \
+"qwerty/us.map" "" \
+"qwertz/croat.map" "" \
+"qwertz/cz-us-qwertz.map" "" \
+"qwertz/cz.map" "" \
+"qwertz/de-latin1-nodeadkeys.map" "" \
+"qwertz/de-latin1.map" "" \
+"qwertz/de.map" "" \
+"qwertz/de_CH-latin1.map" "" \
+"qwertz/fr_CH-latin1.map" "" \
+"qwertz/fr_CH.map" "" \
+"qwertz/hu.map" "" \
+"qwertz/sg-latin1-lk450.map" "" \
+"qwertz/sg-latin1.map" "" \
+"qwertz/sg.map" "" \
+"qwertz/sk-prog-qwertz.map" "" \
+"qwertz/sk-qwertz.map" "" \
+"qwertz/slovene.map" "" )
+ [ -n "$KEYMAP" ] && KEYMAP=$(basename $KEYMAP .map)
+ fi
+
+ if echo $EXTRA | grep -q RESUMEDEV ; then
+ # Print information about swap partitions:
+ FREERAM=$(free -k | grep "^Mem:" | tr -s ' ' | cut -d' ' -f2)
+ SWPINFO=""
+ for SWPDEV in $(grep -w swap $FSTAB | cut -d' ' -f1) ; do
+ SWPINFO="$SWPINFO $SWPDEV Linux swap partition $(fdisk -s $SWPDEV) KB \\n"
+ [ $(fdisk -s $SWPDEV) -gt $FREERAM ] && RESUMEDEV=$SWPDEV
+ done
+ FREERAM=$(free -m | grep "^Mem:" | tr -s ' ' | cut -d' ' -f2)
+ RESUMEDEV=$( dialog --stdout --no-collapse --title "HIBERNATE RESUME DEVICE" --inputbox "\
+When using suspend-to-disk feature (hibernate), your computer's RAM is copied \
+to a swap device when it shuts down. The kernel will resume from that RAM \
+image at boot. This means that the swap partition must not be smaller than \
+the amount of RAM you have ($FREERAM MB). \n\
+$SWPINFO \n\
+Please specify a swap partition to be used for hibernation:" \
+0 0 "$RESUMEDEV")
+ [ -z "$RESUMEDEV" ] && exit 1
+ fi
+
+ if echo $EXTRA | grep -q WAIT ; then
+ WAIT=$( dialog --stdout --title "WAIT FOR ROOT DEVICE" --inputbox "\
+Some block devices are too slow to be detected properly at boot. USB storage \
+devices and some disk arrays have this 'feature'. To make your machine \
+boot properly, you can add some delay here, to wait until all your disks are \
+probed and detected. The time is in seconds:" 0 0 "$WAIT")
+ [ -z "$WAIT" ] && exit 1
+ fi
+
+ IMGFILE=$( dialog --stdout --title "INITRD IMAGE NAME" --inputbox "\
+Enter your initrd image filename." 0 0 "$IMGFILE" )
+ [ -z "$IMGFILE" ] && exit 1
+
+else
+ MLIST=$(add_rootfs_module)
+fi
+
+# Add any modules passed along on the commandline:
+if [ -n "$MKINIT_MODS" ]; then
+ [ -n "$MLIST" ] && MLIST="$MLIST:$(echo $MKINIT_MODS | tr ' ' ':')" \
+ || MLIST="$(echo $MKINIT_MODS | tr ' ' ':')"
+fi
+
+# Constructing the mkinitrd command:
+MKINIT="mkinitrd -c -k $KVER -f $ROOTFS -r $ROOTDEV"
+
+# If we have a module list, add them:
+if ! [ -z "$MLIST" -o "$MLIST" = ":" ]; then
+ MKINIT="$MKINIT -m $MLIST"
+fi
+
+# Deal with LUKS/LVM/RAID:
+if [ "$USING_LUKS" = "1" ]; then
+ MKINIT="$MKINIT -C $REALDEV"
+fi
+if [ "$USING_LVM" = "1" ]; then
+ MKINIT="$MKINIT -L"
+fi
+if [ "$USING_RAID" = "1" ]; then
+ MKINIT="$MKINIT -R"
+fi
+
+if [ -n "$RESUMEDEV" ]; then
+ # Add hibernation partition:
+ MKINIT="$MKINIT -h $RESUMEDEV"
+fi
+if [ -n "$KEYMAP" -a "$KEYMAP" != "us" ]; then
+ # Add non-us keyboard mapping:
+ MKINIT="$MKINIT -l $KEYMAP"
+fi
+if [ -n "$WAIT" -a $WAIT -ne 1 ]; then
+ # Add non-default wait time:
+ MKINIT="$MKINIT -w $WAIT"
+fi
+if ! echo "$MKINIT_PARAMS" | grep -q ' -o ' ; then
+ # Add non-default output filename:
+ MKINIT="$MKINIT -o $IMGFILE"
+fi
+if [ -n "$MKINIT_PARAMS" ]; then
+ # Add user-supplied additional parameters:
+ MKINIT="$MKINIT $MKINIT_PARAMS"
+fi
+
+# Notify the user:
+if [ "$EMIT" = "all" ]; then
+ cat <<-EOT
+ #
+ # $(basename $0) revision $REV
+ #
+ # This script will now make a recommendation about the command to use
+ # in case you require an initrd image to boot a kernel that does not
+ # have support for your storage or root filesystem built in
+ # (such as the Slackware 'generic' kernels').
+ # A suitable 'mkinitrd' command will be:
+
+ $MKINIT
+ EOT
+elif [ "$EMIT" = "run" ]; then
+ echo "$MKINIT"
+elif [ "$EMIT" = "conf" ]; then
+ cat <<-EOT
+ SOURCE_TREE="$SOURCE_TREE"
+ CLEAR_TREE="$CLEAR_TREE"
+ OUTPUT_IMAGE="$IMGFILE"
+ KERNEL_VERSION="$KVER"
+ KEYMAP="$KEYMAP"
+ MODULE_LIST="$(echo $MLIST | cut -f2 -d\ )"
+ LUKSDEV="$REALDEV"
+ ROOTDEV="$ROOTDEV"
+ ROOTFS="$ROOTFS"
+ RESUMEDEV="$RESUMEDEV"
+ RAID="$USING_RAID"
+ LVM="$USING_LVM"
+ WAIT="$WAIT"
+ EOT
+fi
+
+if [ -n "$KFILE" ]; then
+ if [ "$EMIT" = "all" ]; then
+ cat <<-EOT
+ # An entry in 'etc/lilo.conf' for kernel '$KFILE' would look like this:
+ EOT
+ fi
+ if [ "$EMIT" = "all" -o "$EMIT" = "lilo" ]; then
+ # Compensate for the syntax used for the LUKS-on-LVM case:
+ [ "$(basename $ROOTDEV)" = "$ROOTDEV" ] && BASE="/dev/mapper/" || BASE=""
+ cat <<-EOT
+ # Linux bootable partition config begins
+ # initrd created with '$MKINIT'
+ image = $KFILE
+ initrd = $IMGFILE
+ root = $BASE$ROOTDEV
+ label = $KVER
+ read-only
+ # Linux bootable partition config ends
+ EOT
+ fi
+fi
diff --git a/source/a/mkinitrd/mkinitrd_kernelcheck.diff b/source/a/mkinitrd/mkinitrd_kernelcheck.diff
new file mode 100644
index 000000000..e1302f54e
--- /dev/null
+++ b/source/a/mkinitrd/mkinitrd_kernelcheck.diff
@@ -0,0 +1,15 @@
+--- mkinitrd.orig 2008-11-30 15:35:58.000000000 +0100
++++ mkinitrd 2008-12-11 11:16:37.000000000 +0100
+@@ -277,6 +277,12 @@
+ esac
+ done
+
++# If kernel modules are needed but the kernel version is absent, exit now:
++if [ ! -d /lib/modules/$KERNEL_VERSION ]; then
++ echo "No modules tree found for kernel \"$KERNEL_VERSION\""
++ exit 1
++fi
++
+ # If clearing source tree was requested, do that first
+ if [ "$CLEAR_TREE" = "1" ]; then
+ clear_source_tree