diff options
Diffstat (limited to 'source/a/mkinitrd/mkinitrd')
-rw-r--r-- | source/a/mkinitrd/mkinitrd | 144 |
1 files changed, 89 insertions, 55 deletions
diff --git a/source/a/mkinitrd/mkinitrd b/source/a/mkinitrd/mkinitrd index 4cd97296b..1a5b7731f 100644 --- a/source/a/mkinitrd/mkinitrd +++ b/source/a/mkinitrd/mkinitrd @@ -1,7 +1,7 @@ #!/bin/sh # Copyright 2004 Slackware Linux, Inc., Concord, CA, USA # Copyright 2004 Patrick J. Volkerding, Concord, CA, USA -# Copyright 2007, 2008, 2009, 2010 Patrick J. Volkerding, Sebeka, MN, USA +# Copyright 2007, 2008, 2009, 2010, 2011 Patrick J. Volkerding, Sebeka, MN, USA # All rights reserved. # # Redistribution and use of this script, with or without modification, is @@ -43,7 +43,14 @@ # load-kernel-modules if that file is executable. # Yada yada yada. -MKINITRD_VERSION=1.4.5 +MKINITRD_VERSION=1.4.6 + +# Don't include these things from /lib/udev/ in the initrd image +LIBUDEV_BLACKLIST="\ + ipod-set-info \ + check-mtp-camera \ + check-ptp-camera \ + udev-configure-printer" print_usage() { cat << EOF @@ -90,6 +97,7 @@ initrd, and the script is easy to modify. Be creative. :-) For example, if your USB thumb drive has a FAT partition with label "TRAVELSTICK" and the actual keyfile is called "/keys/alien.luks", then you need to pass: -K LABEL=TRAVELSTICK:/keys/alien.luks + -M Add the files in /etc/modprobe.d/ to the initrd -R Add support for RAID partitions -V Display version number @@ -97,15 +105,15 @@ 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.6-smp kernel -modules for a system with an ext3 root partition on /dev/hdb3: +Another example: Build an initrd image using Linux 2.6.35.4-smp kernel +modules for a system with an ext4 root partition on /dev/sdb3: - mkinitrd -c -k 2.6.29.6-smp -m mbcache:jbd:ext3 -f ext3 -r /dev/hdb3 + mkinitrd -c -k 2.6.35.4-smp -m mbcache:jbd:ext4 -f ext4 -r /dev/sdb3 -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: +Note that if you are already logged in with /dev/sdb3 as your / +partition, and it is running ext4, this command works just the same: - mkinitrd -c -m ext3 + mkinitrd -c -m ext4 If run without options, mkinitrd will rebuild an initrd image using the contents of the $SOURCE_TREE directory, or, if that directory @@ -187,7 +195,7 @@ unify_libs() { copy_libs() { # First copy the essential glibc files: - find /lib* -name "ld-*so*" -o -name "libnss_files*so*" -o -name "libnss_compat*so*" | xargs -I'{}' cp -P --parents '{}' $SOURCE_TREE/ + find /lib /lib64 -name "ld-*so*" -o -name "libnss_files*so*" -o -name "libnss_compat*so*" 2> /dev/null | xargs -I'{}' cp -P --parents '{}' $SOURCE_TREE/ # Then copy all remaining libs our initrd files link against: COUNT=1 @@ -197,11 +205,18 @@ copy_libs() { find $SOURCE_TREE -type f -exec ldd {} 2>/dev/null \; | unify_libs > $TMPFILE while [ "$COUNT" != "0" ]; do COUNT=$((COUNT+1)) - for i in $(cat $TMPFILE) ; do + for i in $(cat ${TMPFILE}) ; do ldd $i 2>/dev/null done | unify_libs > ${PRFX}${COUNT} - TMPFILE=${PRFX}${COUNT} - [ $(cat $TMPFILE | wc -l) -eq 0 ] && COUNT=0 + if [ $(cat $TMPFILE ${PRFX}${COUNT} | sort |uniq -u | wc -l) -eq 0 ]; then + COUNT=0 + else + TMPFILE=${PRFX}${COUNT} + fi + # emergency eject lever: + if [ "$COUNT" = "42" ]; then + COUNT=0 + fi done for i in $(cat ${PRFX}* | sort -u) ; do @@ -218,6 +233,11 @@ copy_libs() { rm ${PRFX}* } +copy_modconf() { + mkdir -p $SOURCE_TREE/etc + cp -a /etc/modprobe.d $SOURCE_TREE/etc +} + # If --help is given, print_usage and exit: if echo $* | grep -wq '\--help' ; then print_usage @@ -302,10 +322,8 @@ while [ ! -z "$1" ]; do shift 2 ;; -o) - OUTPUT_IMAGE="$2" - if [ ! "$(echo $OUTPUT_IMAGE | cut -b1)" = "/" ]; then - OUTPUT_IMAGE=$(pwd)/$OUTPUT_IMAGE - fi + # canonicalize filename: + OUTPUT_IMAGE="$(readlink -m $2)" shift 2 ;; -r) @@ -313,7 +331,8 @@ while [ ! -z "$1" ]; do shift 2 ;; -s) - SOURCE_TREE="$2" + # canonicalize filename: + SOURCE_TREE="$(readlink -m $2)" shift 2 ;; -u) @@ -337,6 +356,10 @@ while [ ! -z "$1" ]; do LVM=1 shift ;; + -M) + MODCONF=1 + shift + ;; -R) RAID=1 shift @@ -449,6 +472,10 @@ fi if [ ! -z "$UDEV" ]; then cp /sbin/udev* $SOURCE_TREE/sbin/ cp -a /lib/udev $SOURCE_TREE/lib/ + # But we don't want all of /lib/udev + for file in $(echo $LIBUDEV_BLACKLIST) ; do + rm -f $SOURCE_TREE/lib/udev/$file ; + done fi # Include LVM support in initrd @@ -457,7 +484,7 @@ if [ ! -z "$LVM" ]; then mkdir -p $SOURCE_TREE/sbin cp /sbin/lvm $SOURCE_TREE/sbin/lvm cp /sbin/dmsetup $SOURCE_TREE/sbin/dmsetup - find /lib* -name "libdevmapper*so*" | xargs -I'{}' cp -P --parents '{}' $SOURCE_TREE/ + find /lib /lib64 -name "libdevmapper*so*" 2> /dev/null | xargs -I'{}' cp -P --parents '{}' $SOURCE_TREE/ ( cd $SOURCE_TREE/sbin ln -s lvm vgchange 2>/dev/null ln -s lvm vgscan 2>/dev/null ) @@ -505,12 +532,12 @@ fi # we assume you will want to load the kernel modules mentioned in there. # This means, you do not have to explicitly add those on the commandline: if [ -x $SOURCE_TREE/load_kernel_modules ]; then - MODULE_LIST="${MODULE_LIST}:$(cat $SOURCE_TREE/load_kernel_modules |grep "^insmod" |rev |cut -d/ -f1 |rev |cut -d. -f1)" + MODULE_LIST="${MODULE_LIST}:$(cat $SOURCE_TREE/load_kernel_modules |grep "^modprobe" |rev |cut -d/ -f1 |rev |cut -d. -f1)" fi # If the module list is not empty, 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 + if grep -q "#modprobe reiserfs" $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 @@ -522,8 +549,7 @@ if [ ! -z "$MODULE_LIST" ]; then # Sanitize the modules list first, before any further processing. # The awk command eliminates doubles without changing the order: - MODULE_LIST=$(echo $MODULE_LIST |tr -s ':' '\n' |awk '!x[$0]++' |tr '\n' ' ') - MODULE_LIST=$(echo $MODULE_LIST | tr ' ' ':') + MODULE_LIST=$(echo $MODULE_LIST |tr -s ':' '\n' |awk '!x[$0]++' |tr '\n' ':') MODULE_LIST=$(echo ${MODULE_LIST%:}) # Weed out a trailing ':' # Count number of modules @@ -542,55 +568,63 @@ if [ ! -z "$MODULE_LIST" ]; then 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 + # 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 + # Get MODULE deps and prepare modprobe 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)/")" + if ! grep -q "$(basename $SRCMOD .ko)" $SOURCE_TREE/load_kernel_modules 2>/dev/null ; then + LINE="$(echo "modprobe -v $(basename $SRCMOD .ko)" )" - # 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 + # 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 + fi - if ! grep -qx "$LINE" $SOURCE_TREE/load_kernel_modules ; then - echo "$LINE" >> $SOURCE_TREE/load_kernel_modules - fi + if ! grep -qx "$LINE" $SOURCE_TREE/load_kernel_modules ; then + echo "$LINE" >> $SOURCE_TREE/load_kernel_modules + fi - if [ ! -f ${SOURCE_TREE}${SRCMOD} ]; then - # We did not yet copy this module into the initrd-tree + # Try to add the module to the initrd-tree. This should be done + # even if it exists there already as we may have changed compilers + # or otherwise caused the modules in the initrd-tree to need + # replacement. if cp -a --parents $SRCMOD $SOURCE_TREE 2>/dev/null; then echo "OK: $SRCMOD added." else echo "WARNING: Could not find module \"$SRCMOD\"" fi - fi + done done -done + # Pregenerate the module dependency information + depmod -a -b $SOURCE_TREE ${KERNEL_VERSION} + + # Copy /etc/modprobe.d/* if desired + if [ ! -z $MODCONF ]; then + copy_modconf + fi fi |