[arch-projects] [PATCH 0/3] Fixes for master
One of my commits wasn't merged, which actually breaks the current state of the repo -- or at least the autodetect hook. I foolishly ripped out a variable which I didn't quite grok the full point of. So... it's back in along with some delicious other improvements. Also a fix for the one call to modprobe which doesn't respect $BASEDIR. And along the same lines, proper BASEDIR support _should_ be more or less complete. It needs glorious amounts of testing, of course, so please help out if can. Last patch is at Thomas's request -- it just adds the Makefile itself as a build dep of the man page so that when the VERSION in the Makefile changes, the doc will rebuild itself. Hurray! Thanks again, Thomas, for merging all this. I'm really excited about the next release! Dave Reisner (3): install/autodetect: refactor and simplify hook functions: support $BASEDIR in modprobe Makefile: the Makefile itself is a dep for the manpage Makefile | 2 +- functions | 2 +- install/autodetect | 89 +++++++++++++++----------------------------------- install/filesystems | 25 ++++++-------- 4 files changed, 40 insertions(+), 78 deletions(-) -- 1.7.5.4
From: Dave Reisner <d@falconindy.com> Bashify and refactor to cut back on unnecessary churn. Since our {all,checked}_modules functions always return clean module names, we can add these directly to the autodetect file instead of aggregating them during the autodetect hook and then cleansing one at a time. There's a small speed increase here for the simplest code path. Signed-off-by: Dave Reisner <d@falconindy.com> --- install/autodetect | 89 +++++++++++++++----------------------------------- install/filesystems | 25 ++++++-------- 2 files changed, 38 insertions(+), 76 deletions(-) diff --git a/install/autodetect b/install/autodetect index b195913..fe7e684 100644 --- a/install/autodetect +++ b/install/autodetect @@ -1,75 +1,40 @@ -# vim: set ft=sh: +#!/bin/bash -build() -{ - MODULE_FILE="${TMPDIR}/autodetect_modules" - #blegh, we'll let /tmp clean itself up - AUTODETECT="$(auto_modules | \ - sed -e 's/ata_generic//g' -e 's/ide_generic//g')" +build() { + MODULE_FILE=$TMPDIR/autodetect_modules + auto_modules | grep -xEv '(ata|ide)_generic' >"$MODULE_FILE" - #Filesystem detection, only probe the device for / - findfs () - { - local rootdev - - if [ -f /proc/self/mountinfo -a -x /bin/findmnt ]; then - /bin/findmnt -n -u -o fstype / 2>/dev/null - fi - } + if [[ ! -d /sys/devices ]]; then + error "/sys does not appear to be mounted. Unable to use autodetection" + return 1 + fi - if [ ${UID} -eq 0 -o "$(groups | grep disk)" != "" ]; then - fss=$(findfs | sort | uniq) - if [ -z "${fss}" ]; then - error "Root file system type detection failed." - autodetect_fs_detection_failed=1 + if (( $UID == 0 )) || in_array 'disk' $(groups); then + if ! findmnt -uno fstype "${BASEDIR:-/}" >>"$MODULE_FILE"; then + error "failed to detect root filesystem" + fs_autodetect_failed=1 fi - for fs in ${fss}; do - allfs="${fs} $(modprobe --set-version ${KERNELVERSION} --resolve-alias ${fs})" - for mod in ${allfs}; do - for modfile in $(find "${MODULEDIR}" -type f -name "${mod}.ko" -or -name "${mod}.ko.gz"); do - if [ -n "${modfile}" ]; then - AUTODETECT="${AUTODETECT} ${modfile}" - fi - done - done - done - if [ -e /sbin/mdadm ]; then - for raidmod in $(/sbin/mdadm -E -s -v /dev/hd* /dev/sd* /dev/rd/* /dev/ida/* /dev/cciss/* /dev/ataraid/* /dev/mapper/* \ - | awk -Flevel= '{print $2}' | awk '{print $1}'); do - case "${raidmod}" in - raid4|raid5|raid6) - AUTODETECT="${AUTODETECT} raid456" ;; - *) - AUTODETECT="${AUTODETECT} ${raidmod}" ;; - esac - done + if [[ -x /sbin/mdadm ]]; then + /sbin/mdadm -Esv /dev/[hrsv]d* /dev/{ida,cciss,ataraid,mapper}/* | + sed -n 's/.*level=\([^ ]\+\) .*/\1/p' | + sed 's/\<raid[456]\>/raid456/g' | sort -u >>"$MODULE_FILE" fi else - autodetect_fs_detection_failed=1 - autodetect_raid_detection_failed=1 - error "User does not have proper permissions to read superblocks, raid and filesystem modules are not detected" + error "Insufficient permission to autodetect root filesystem" + fs_autodetect_failed=1 fi - - for m in ${AUTODETECT}; do - modname="$(get_module_name "${m}")" - echo "${modname}" >> "${MODULE_FILE}" - done - - BINARIES="" - FILES="" - SCRIPT="" } -help () -{ -cat <<HELPEOF - This hook shrinks your initramdisk to a smaller size - by autodetecting your needed modules. Be sure to verify - included modules are correct and none are missing. - This hook must be run before other subsystem hooks in - order to take advantage of auto-detection. Any hooks - placed before 'autodetect' will be installed in full. +help() { + cat <<HELPEOF +This hook shrinks your initramdisk to a smaller size by autodetecting your +needed modules. Be sure to verify included modules are correct and none are +missing. This hook must be run before other subsystem hooks in order to take +advantage of auto-detection. Any hooks placed before 'autodetect' will be +installed in full. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/filesystems b/install/filesystems index 337a6a5..64227bc 100644 --- a/install/filesystems +++ b/install/filesystems @@ -1,21 +1,18 @@ -# vim: set ft=sh: +#!/bin/bash -build() -{ - if [ "${autodetect_fs_detection_failed}" = "1" ]; then - MODULES=" $(all_modules '/kernel/fs' | grep -v "nls")" +build() { + if (( fs_autodetect_failed )); then + MODULES=$(all_modules '/kernel/fs' | grep -v "nls") else - MODULES=" $(checked_modules '/kernel/fs' | grep -v "nls")" + MODULES=$(checked_modules '/kernel/fs' | grep -v "nls") fi - BINARIES="" - FILES="" - SCRIPT="" } -help () -{ -cat<<HELPEOF - This hook adds filesystems modules to the image. If you would like to - minimize the modules installed in the image, add the autodetect hook too. +help() { + cat<<HELPEOF +This hook adds filesystems modules to the image. If you would like to minimize +the modules installed in the image, add the autodetect hook too. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: -- 1.7.5.4
From: Dave Reisner <d@falconindy.com> Signed-off-by: Dave Reisner <d@falconindy.com> --- functions | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/functions b/functions index ab0f850..ee6921c 100644 --- a/functions +++ b/functions @@ -69,7 +69,7 @@ auto_modules() { IFS=$'\n' read -rd '' -a mods < \ <(find /sys/devices -name modalias -exec sort -zu {} + | - xargs -0 modprobe -aRS "$KERNELVERSION" | + xargs -0 modprobe -d "$BASEDIR" -aRS "$KERNELVERSION" | sort -u) printf "%s\n" "${mods[@]//-/_}" -- 1.7.5.4
From: Dave Reisner <d@falconindy.com> This will force the doc to be regenerated if there is a version bump in the Makefile. Signed-off-by: Dave Reisner <d@falconindy.com> --- Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Makefile b/Makefile index b77e088..0c86ac0 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ install: all install -m644 mkinitcpio.5 ${DESTDIR}/usr/share/man/man5/mkinitcpio.5 doc: mkinitcpio.5 -mkinitcpio.5: mkinitcpio.5.txt +mkinitcpio.5: mkinitcpio.5.txt Makefile a2x -d manpage \ -f manpage \ -a mansource=mkinitcpio \ -- 1.7.5.4
From: Dave Reisner <d@falconindy.com> Bashify and refactor to cut back on unnecessary churn. Since our {all,checked}_modules functions always return clean module names, we can add these directly to the autodetect file instead of aggregating them during the autodetect hook and then cleansing one at a time. There's a small speed increase here for the simplest code path. We also no longer need special permissions to determine the root filesystem, as findmnt reads from /proc/self/mountinfo. This could still possibly fail, so continue to protect it with the variable which install/filesystem reads. Signed-off-by: Dave Reisner <d@falconindy.com> --- And one more resend of a resend... install/autodetect | 91 ++++++++++++++++----------------------------------- install/filesystems | 25 ++++++-------- 2 files changed, 39 insertions(+), 77 deletions(-) diff --git a/install/autodetect b/install/autodetect index b195913..7f22235 100644 --- a/install/autodetect +++ b/install/autodetect @@ -1,75 +1,40 @@ -# vim: set ft=sh: +#!/bin/bash -build() -{ - MODULE_FILE="${TMPDIR}/autodetect_modules" - #blegh, we'll let /tmp clean itself up - AUTODETECT="$(auto_modules | \ - sed -e 's/ata_generic//g' -e 's/ide_generic//g')" +build() { + MODULE_FILE=$TMPDIR/autodetect_modules + auto_modules | grep -xEv '(ata|ide)_generic' >"$MODULE_FILE" - #Filesystem detection, only probe the device for / - findfs () - { - local rootdev - - if [ -f /proc/self/mountinfo -a -x /bin/findmnt ]; then - /bin/findmnt -n -u -o fstype / 2>/dev/null - fi - } + if [[ ! -d /sys/devices ]]; then + error "/sys does not appear to be mounted. Unable to use autodetection" + return 1 + fi - if [ ${UID} -eq 0 -o "$(groups | grep disk)" != "" ]; then - fss=$(findfs | sort | uniq) - if [ -z "${fss}" ]; then - error "Root file system type detection failed." - autodetect_fs_detection_failed=1 - fi - for fs in ${fss}; do - allfs="${fs} $(modprobe --set-version ${KERNELVERSION} --resolve-alias ${fs})" - for mod in ${allfs}; do - for modfile in $(find "${MODULEDIR}" -type f -name "${mod}.ko" -or -name "${mod}.ko.gz"); do - if [ -n "${modfile}" ]; then - AUTODETECT="${AUTODETECT} ${modfile}" - fi - done - done - done + if ! findmnt -uno fstype "${BASEDIR:-/}" >>"$MODULE_FILE"; then + error "failed to detect root filesystem" + fs_autodetect_failed=1 + fi - if [ -e /sbin/mdadm ]; then - for raidmod in $(/sbin/mdadm -E -s -v /dev/hd* /dev/sd* /dev/rd/* /dev/ida/* /dev/cciss/* /dev/ataraid/* /dev/mapper/* \ - | awk -Flevel= '{print $2}' | awk '{print $1}'); do - case "${raidmod}" in - raid4|raid5|raid6) - AUTODETECT="${AUTODETECT} raid456" ;; - *) - AUTODETECT="${AUTODETECT} ${raidmod}" ;; - esac - done + if (( UID == 0 )) || in_array 'disk' $(groups); then + if [[ -x /sbin/mdadm ]]; then + /sbin/mdadm -Esv /dev/[hrsv]d* /dev/{ida,cciss,ataraid,mapper}/* | + sed -n 's/.*level=\([^ ]\+\) .*/\1/p' | + sed 's/\<raid[456]\>/raid456/g' | sort -u >>"$MODULE_FILE" fi else - autodetect_fs_detection_failed=1 - autodetect_raid_detection_failed=1 - error "User does not have proper permissions to read superblocks, raid and filesystem modules are not detected" + error "Insufficient permission to perform autodetection for mdadm devices" + raid_autodetect_failed=1 fi - - for m in ${AUTODETECT}; do - modname="$(get_module_name "${m}")" - echo "${modname}" >> "${MODULE_FILE}" - done - - BINARIES="" - FILES="" - SCRIPT="" } -help () -{ -cat <<HELPEOF - This hook shrinks your initramdisk to a smaller size - by autodetecting your needed modules. Be sure to verify - included modules are correct and none are missing. - This hook must be run before other subsystem hooks in - order to take advantage of auto-detection. Any hooks - placed before 'autodetect' will be installed in full. +help() { + cat <<HELPEOF +This hook shrinks your initramdisk to a smaller size by autodetecting your +needed modules. Be sure to verify included modules are correct and none are +missing. This hook must be run before other subsystem hooks in order to take +advantage of auto-detection. Any hooks placed before 'autodetect' will be +installed in full. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/filesystems b/install/filesystems index 337a6a5..64227bc 100644 --- a/install/filesystems +++ b/install/filesystems @@ -1,21 +1,18 @@ -# vim: set ft=sh: +#!/bin/bash -build() -{ - if [ "${autodetect_fs_detection_failed}" = "1" ]; then - MODULES=" $(all_modules '/kernel/fs' | grep -v "nls")" +build() { + if (( fs_autodetect_failed )); then + MODULES=$(all_modules '/kernel/fs' | grep -v "nls") else - MODULES=" $(checked_modules '/kernel/fs' | grep -v "nls")" + MODULES=$(checked_modules '/kernel/fs' | grep -v "nls") fi - BINARIES="" - FILES="" - SCRIPT="" } -help () -{ -cat<<HELPEOF - This hook adds filesystems modules to the image. If you would like to - minimize the modules installed in the image, add the autodetect hook too. +help() { + cat<<HELPEOF +This hook adds filesystems modules to the image. If you would like to minimize +the modules installed in the image, add the autodetect hook too. HELPEOF } + +# vim: set ft=sh ts=4 sw=4 et: -- 1.7.5.4
participants (1)
-
Dave Reisner