The modules init script needs to handle same-numbered kernels with different extra versions. 2.6.0-test1 could have a different set of modules than 2.6.0-test11 Reproducible: Always Steps to Reproduce: 1. Edit Kernel makefile to have a -extraversion 2. Compile kernel 3. Reboot! Actual Results: Loads modules for generic 2.6 Expected Results: Load modules for 2.6.0-test11-20031201-01, or try to load for 2.6.0, then for 2.6, and then try some reasonably sane default. I've hacked together some functionality along these lines, and it seems to work for me. If anyone's got any bright ideas about how to produce meaningful error messages, such as "could not find kernel-x.y.z-name, trying kernel-x.y.z" I'd be most appreciative. /sbin/functions.sh: 565a566,581 > # char *KV_extra(string) > # > # Return the Extra version part of given kernel version. > # > KV_extra() { > local KV= > > [ -z "$1" ] && return 1 > > KV="$(echo "$1" | \ > awk '{ tmp = $0; gsub(/^[0-9\.]*/, "", tmp); print tmp}')" > echo "${KV}" | awk -- 'BEGIN { FS = "-" } { print $2 }' > > return 0 > } > /etc/init.d/modules: 96a97,98 > local KV_MICRO="`KV_micro "${KV}"`" > local KV_EXTRA="`KV_extra "${KV}"`" 98,100c100,109 < # New support for /etc/modules.autoload/kernel-$KV < if [ "$(get_KV)" -ge "$(KV_to_int '2.5.48')" ] && \ < [ -f /etc/modules.autoload.d/kernel-"${KV_MAJOR}.${KV_MINOR}" ] --- > # New support for /etc/modules.autoload/kernel-X.Y.Z-EXTRA > # Search for less and less specific configs > if [ -f /etc/modules.autoload.d/kernel-"${KV_MAJOR}.${KV_MINOR}.${KV_MICRO}-${KV_EXTRA}" ] > then > load_modules /etc/modules.autoload.d/kernel-"${KV_MAJOR}.${KV_MINOR}.${KV_MICRO}-${KV_EXTRA}" > elif [ -n "`ewarn "foo"`" ] && \ > [ -f /etc/modules.autoload.d/kernel-"${KV_MAJOR}.${KV_MINOR}.${KV_MICRO}" ] > then > load_modules /etc/modules.autoload.d/kernel-"${KV_MAJOR}.${KV_MINOR}.${KV_MICRO}" > elif [ -f /etc/modules.autoload.d/kernel-"${KV_MAJOR}.${KV_MINOR}" ] 103d111 < 106,108c114 < ewarn "Missing /etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}" < load_modules /etc/modules.autoload.d/kernel-2.4 < else --- > ewarn "Missing /etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}}"
Hi there, I did something equivalent some days ago (http://forums.gentoo.org/viewtopic.php?t=149836), but today I had a better idea on how to archieved that. I even find it pretty :). Here is how all that stuff works : - it gets the kernel version number with uname - try to found a file with this version as a name - if not found, try again without the last token of the version number - etc, until it found something - if no file match, it take the first one returned by ls and print a warning - the modules listed in the file are finally loaded - if /etc/modules.autoload.d is empty, nothing is done Here is a heavily commented preview of my code : -------------------------------------------------------------------------------- # New support for /etc/modules.autoload/kernel-$KV # The kernel version is stored in a question-mark field # separator format, like "2?4?26?rc3?gentoo?r2?1", where the # final 1 is the build number. # local KV=kernel-$(uname -rv | awk '{gsub("[.\\-#]","?"); print $1$2}') # This weird format acts here as a wilcard pattern. The # purpose is to find a file whose name is at least part of # our kernel version. # while [ ! $(ls /etc/modules.autoload.d/${KV} 2>/dev/null) ] do # Let's drop the last field in the version number # to check if the corresponding file exists # KV_reduced=$(echo ${KV} | awk '{sub("\\?[^\\?]*$",""); print}') # If we tried all the possibilities unsucessfully, # then fallback with the ligther name (hopefully the # most general, like kernel-2.4) and print a warning. # if [ ${KV_reduced} == ${KV} ] then KV=$(ls -1 /etc/modules.autoload.d/ | awk '{if(!drop)print;drop++}') ewarn "Missing /etc/modules.autoload.d/kernel-VERSION" break fi KV=${KV_reduced} done # Now we have found the file with the closest name, we just # need to load the modules it lists. Note that if # /etc/modules.autoload.d/ is empty, KV is an empty string. # [ ${KV} ] && load_modules $(ls /etc/modules.autoload.d/${KV}) -------------------------------------------------------------------------------- And here is the patch, without the comments : -------------------------------------------------------------------------------- --- ./modules 2004-03-18 23:31:29.000000000 +0000 +++ /etc/init.d/modules 2004-03-18 23:48:50.000000000 +0000 @@ -92,25 +92,28 @@ if [ -f /etc/modules.autoload -a ! -L /etc/modules.autoload ] then # Loop over every line in /etc/modules.autoload. + # load_modules /etc/modules.autoload else - local KV="$(uname -r)" - local KV_MAJOR="`KV_major "${KV}"`" - local KV_MINOR="`KV_minor "${KV}"`" - # New support for /etc/modules.autoload/kernel-$KV - if [ "$(get_KV)" -ge "$(KV_to_int '2.5.48')" ] && \ - [ -f /etc/modules.autoload.d/kernel-"${KV_MAJOR}.${KV_MINOR}" ] - then - load_modules /etc/modules.autoload.d/kernel-"${KV_MAJOR}.${KV_MINOR}" + + local KV=kernel-$(uname -rv | awk '{gsub("[.\\-#]","?"); print $1$2}') + + while [ ! $(ls /etc/modules.autoload.d/${KV} 2>/dev/null) ] + do + KV_reduced=$(echo ${KV} | awk '{sub("\\?[^\\?]*$",""); print}') + + if [ ${KV_reduced} == ${KV} ] + then + KV=$(ls -1 /etc/modules.autoload.d/ | awk '{if(!drop)print;drop++}') + ewarn "Missing /etc/modules.autoload.d/kernel-VERSION" + break + fi - elif [ ! -f /etc/modules.autoload.d/kernel-"${KV_MAJOR}.${KV_MINOR}" ] - then - ewarn "Missing /etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}" - load_modules /etc/modules.autoload.d/kernel-2.4 - else - load_modules /etc/modules.autoload.d/kernel-2.4 - fi + KV=${KV_reduced} + done + + [ ${KV} ] && load_modules $(ls /etc/modules.autoload.d/${KV}) fi # -------------------------------------------------------------------------------- I would be pleased to receive feedback. Yoann
I forgot to illustrate my work with examples. Here are some : /etc/modules.autoload.d/kernel -> for all the kernel versions (if no file matches) /etc/modules.autoload.d/kernel-2 -> for all the kernel with major verion 2 /etc/modules.autoload.d/kernel-2.4 etc ... At home, I have /etc/modules.autoload.d/kernel-2.4.26-rc3-gentoo and /etc/modules.autoload.d/kernel-2.4.26-rc3-gentoo#3 , specificaly for the third kernel build from those sources. Yoann
Hi, I use the following patch to the modules init script to handle different kernel versions. It is somewhat simpler than the above and functions similar to the original report, but there's no need to extract the KV_EXTRA part. (BTW., a nice way to extract the extra part is: KV_EXTRA=${KV#${KV_MAJOR}.${KV_MINOR}.${KV_MICRO}} ). For a kernel version 2.6.7-gentoo-r5 my patch will subsequently try kernel-2.6.7-gentoo-r5 kernel-2.6.7 kernel-2.6 and if that doesn't exist, write a warning and try kernel-2.4 if it exists. It does not handle the kernel build #, but this could easily be included. --- modules.orig 2004-06-25 13:39:48.000000000 +0200 +++ modules 2004-06-25 13:40:03.000000000 +0200 @@ -95,19 +95,29 @@ load_modules /etc/modules.autoload else local KV="$(uname -r)" - local KV_MAJOR="`KV_major "${KV}"`" - local KV_MINOR="`KV_minor "${KV}"`" # New support for /etc/modules.autoload/kernel-$KV - if [ "$(get_KV)" -ge "$(KV_to_int '2.5.48')" ] && \ - [ -f /etc/modules.autoload.d/kernel-"${KV_MAJOR}.${KV_MINOR}" ] + if [ "$(KV_to_int $KV)" -ge "$(KV_to_int '2.5.48')" ] then - load_modules /etc/modules.autoload.d/kernel-"${KV_MAJOR}.${KV_MINOR}" + local KV_MAJOR="`KV_major "${KV}"`" + local KV_MINOR="`KV_minor "${KV}"`" + local KV_MICRO="`KV_micro "${KV}"`" + local KV_TRY="${KV} ${KV_MAJOR}.${KV_MINOR}.${KV_MICRO} ${KV_MAJOR}.${KV_MINOR} none" + local KV_i + for KV_i in ${KV_TRY} + do + if [ "${KV_i}" = "none" ] + then + ewarn "Missing /etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}" + KV_i="2.4" + fi + if [ -f /etc/modules.autoload.d/kernel-"${KV_i}" ] + then + load_modules /etc/modules.autoload.d/kernel-"${KV_i}" + break + fi + done - elif [ ! -f /etc/modules.autoload.d/kernel-"${KV_MAJOR}.${KV_MINOR}" ] - then - ewarn "Missing /etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}" - load_modules /etc/modules.autoload.d/kernel-2.4 else load_modules /etc/modules.autoload.d/kernel-2.4 fi PS. I kept the test against version 2.5.48 (though I have no idea why it is there), but I changed the get_KV to KV_to_int $KV, because it saves an extra call to uname. BV
bump. could this please be included?
Created attachment 60331 [details, diff] modules.patch how does this patch look ?
vapier: looks ideal to me.
added to cvs