[arch-projects] [mkinitcpio][PATCH 0/9] Resend of pre-kill gen-init-cpio
At Thomas's request, this is a resend of the patchwork that precedes the patch series to kill off gen_init_cpio. I've made some minor tweaks, the only notable one being that I've dropped support for PARTUUID= out of patch 7. It's not right to use PARTUUID as a synonym for UUID because PARTUUID actually refers to the GPT partition UUID, and not the filesystem UUID. blkid can't (currently) resolve this, so we'll stash this for now and await proper support in libblkid. d
sort/uniq the modaliases files' contents, before passing _all_ of them to modprobe -a. This cuts back on execution time as well as cleaning up the resulting list of modules. Signed-off-by: Dave Reisner <d@falconindy.com> --- functions | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-) diff --git a/functions b/functions index 4cd3136..f179135 100644 --- a/functions +++ b/functions @@ -41,16 +41,13 @@ in_array() { auto_modules () { - aliases="$(find /sys/devices/ -name modalias -exec cat {} +)" - mods="" - for a in $aliases; do - m="$(modprobe --set-version ${KERNELVERSION} --resolve-alias "$a")" - [ -n "$m" ] && mods="$mods $m" - done + IFS=$'\n' read -rd '' -a mods < \ + <(find /sys/devices -name modalias -exec sort -zu {} + | + xargs -0 modprobe -aRS "$KERNELVERSION" | + sort -u) - echo "${mods}" | tr '-' '_' - [ -z "${mods}" ] && return 1 - return 0 + printf "%s\n" "${mods[@]//-/_}" + (( ${#mods[*]} )) } all_modules () -- 1.7.5.4
sanitize and print during module discovery. We also strip path names during this process and null terminate path names for safety. Signed-off-by: Dave Reisner <d@falconindy.com> --- functions | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/functions b/functions index f179135..9df4d44 100644 --- a/functions +++ b/functions @@ -52,11 +52,16 @@ auto_modules () all_modules () { - mods=$(find ${MODULEDIR} -name '*.ko' -or -name '*.ko.gz' 2>/dev/null | grep $@ | sort -u) + local -i count=0 + while read -r -d '' mod; do + (( ++count )) + mod=${mod##*/} + mod="${mod%.ko.*}" + printf '%s\n' "${mod//-/_}" + done < <(find "$MODULEDIR" -name '*.ko*' -print0 2>/dev/null | + grep -Zz "$@" | sort -zu) - echo "${mods}" - [ -z "${mods}" ] && return 1 - return 0 + (( count )) } checked_modules () -- 1.7.5.4
Am 06.06.2011 22:02, schrieb Dave Reisner:
--- a/functions +++ b/functions @@ -52,11 +52,16 @@ auto_modules ()
all_modules () { - mods=$(find ${MODULEDIR} -name '*.ko' -or -name '*.ko.gz' 2>/dev/null | grep $@ | sort -u) + local -i count=0 + while read -r -d '' mod; do + (( ++count )) + mod=${mod##*/} + mod="${mod%.ko.*}" + printf '%s\n' "${mod//-/_}" + done < <(find "$MODULEDIR" -name '*.ko*' -print0 2>/dev/null | + grep -Zz "$@" | sort -zu)
I don't understand this 'sort' call. You are sorting the file names before stripping the paths. The file names are always unique.
On Tue, Jun 07, 2011 at 08:18:02PM +0200, Thomas Bächler wrote:
Am 06.06.2011 22:02, schrieb Dave Reisner:
--- a/functions +++ b/functions @@ -52,11 +52,16 @@ auto_modules ()
all_modules () { - mods=$(find ${MODULEDIR} -name '*.ko' -or -name '*.ko.gz' 2>/dev/null | grep $@ | sort -u) + local -i count=0 + while read -r -d '' mod; do + (( ++count )) + mod=${mod##*/} + mod="${mod%.ko.*}" + printf '%s\n' "${mod//-/_}" + done < <(find "$MODULEDIR" -name '*.ko*' -print0 2>/dev/null | + grep -Zz "$@" | sort -zu)
I don't understand this 'sort' call. You are sorting the file names before stripping the paths. The file names are always unique.
You're right, this makes no sense. It's gone and pushed to my github repo[1]. d [1] git://github.com/falconindy/mkinitcpio.git
Do a single grep to compare the contents of the module file (if exists) against the results of all_modules for the provided arguments. If there's no module file, this is still just pass through to all_modules. Signed-off-by: Dave Reisner <d@falconindy.com> --- functions | 11 +++-------- 1 files changed, 3 insertions(+), 8 deletions(-) diff --git a/functions b/functions index 9df4d44..7ebe709 100644 --- a/functions +++ b/functions @@ -66,16 +66,11 @@ all_modules () checked_modules () { - if [ -e "${MODULE_FILE}" ]; then - for mod in $(all_modules $@); do - modname=$(get_module_name "${mod}") - if grep -q "^${modname}$" "${MODULE_FILE}"; then - echo ${modname} - fi - done + if [[ -s "$MODULE_FILE" ]]; then + grep -xFf "$MODULE_FILE" <(all_modules "$@") return 1 else - all_modules ${@} + all_modules "$@" fi } -- 1.7.5.4
We can condense this logic into a loop as well, which cuts back on repetative code. Signed-off-by: Dave Reisner <d@falconindy.com> --- mkinitcpio | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index 0ebf7c9..c6428bb 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -275,9 +275,9 @@ if [ "${HAS_MODULES}" = "y" ]; then install -m 644 -D "${BASEDIR}${mod}" "${TMPDIR}${mod}" done /sbin/depmod -b ${TMPDIR} ${KERNELVERSION} - add_file "${TMPDIR}/lib/modules/${KERNELVERSION}/modules.dep" "/lib/modules/${KERNELVERSION}/modules.dep" - add_file "${TMPDIR}/lib/modules/${KERNELVERSION}/modules.alias" "/lib/modules/${KERNELVERSION}/modules.alias" - add_file "${TMPDIR}/lib/modules/${KERNELVERSION}/modules.symbols" "/lib/modules/${KERNELVERSION}/modules.symbols" + for dmfile in modules.{dep,alias,symbols}.bin; do + add_file "${TMPDIR}/lib/modules/${KERNELVERSION}/$dmfile" "/lib/modules/${KERNELVERSION}/$dmfile" + done fi status=0 -- 1.7.5.4
This is no longer supported, as m-i-t supports modprobe.blacklist= syntax on the kernel cmdline. We load all modules from the config at once with --all and --use-blacklist flags in order to honor the cmdline blacklisting. Signed-off-by: Dave Reisner <d@falconindy.com> --- init | 14 +------------- 1 files changed, 1 insertions(+), 13 deletions(-) diff --git a/init b/init index a99940a..f63cbaf 100644 --- a/init +++ b/init @@ -45,12 +45,6 @@ if [ -n "${disablehooks}" ]; then done fi -if [ -n "${disablemodules}" ]; then - for d in $(echo "${disablemodules}" | sed 's|,| |g'); do - eval "mod_${d}=disabled" - done -fi - if [ -n "${earlymodules}" ]; then for m in $(echo "${earlymodules}" | sed 's|,| |g'); do /sbin/modprobe -q ${m} > /dev/null 2>&1 @@ -59,13 +53,7 @@ fi . /config -for m in ${MODULES}; do - TST="" - eval "TST=\$mod_${m}" - if [ "${TST}" != "disabled" ]; then - /sbin/modprobe -q ${m} > /dev/null 2>&1 - fi -done +/sbin/modprobe -qab $MODULES # If rootdelay is empty or not a non-negative integer, set it to 10 if [ -z "${rootdelay}" ] || ! [ "${rootdelay}" -ge 0 ]; then -- 1.7.5.4
Signed-off-by: Dave Reisner <d@falconindy.com> --- init | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/init b/init index f63cbaf..1f6bc4e 100644 --- a/init +++ b/init @@ -46,9 +46,7 @@ if [ -n "${disablehooks}" ]; then fi if [ -n "${earlymodules}" ]; then - for m in $(echo "${earlymodules}" | sed 's|,| |g'); do - /sbin/modprobe -q ${m} > /dev/null 2>&1 - done + /sbin/modprobe -qab ${earlymodules//,/ } fi . /config -- 1.7.5.4
use blkid to resolve a tag name to a block device. Signed-off-by: Dave Reisner <d@falconindy.com> --- init_functions | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/init_functions b/init_functions index be3599e..d9ffe4a 100644 --- a/init_functions +++ b/init_functions @@ -73,6 +73,15 @@ parse_cmdline() { } default_mount_handler() { + # resolve tag name to block device + if [ "${root:0:5}" = 'UUID=' ] || [ "${root:0:6}" = 'LABEL=' ]; then + device=$(blkid -t "$root" -o device) + if [ -n "$device" ]; then + root=$device + fi + unset device + fi + if [ ${root:0:5} != "/dev/" ] || ! poll_device "${root}" ${rootdelay}; then msg "Root device '${root}' doesn't exist. Attempting to create it." major="" -- 1.7.5.4
/sys/class/block contains all of our block devices, including the partitions of each parent block device, so directly check for the existance of the dev file rather than looping. Signed-off-by: Dave Reisner <d@falconindy.com> --- init_functions | 14 +++++--------- 1 files changed, 5 insertions(+), 9 deletions(-) diff --git a/init_functions b/init_functions index d9ffe4a..a94f525 100644 --- a/init_functions +++ b/init_functions @@ -87,15 +87,11 @@ default_mount_handler() { major="" minor="" if [ ${root:0:5} = "/dev/" ]; then - # It might be a block device (/dev/sda) -> /sys/block/sda/dev - # or a partition (/dev/sda1) -> /sys/block/sda/sda1/dev - for dir in /sys/block /sys/block/*; do - if [ -f ${dir}/${root:5}/dev ]; then - major="$(cat ${dir}/${root:5}/dev | cut -d: -f1)" - minor="$(cat ${dir}/${root:5}/dev | cut -d: -f2)" - break - fi - done + # It might be a block device (/dev/sda) -> /sys/class/block/sda/dev + if [ -e /sys/class/block/${root:5}/dev ]; then + IFS=':' read major minor < "/sys/class/block/${root:5}/dev" + break + fi # It might be a major/minor pair (8:1) elif echo ${root} | grep -q :; then major="$(echo ${root} | cut -d: -f1)" -- 1.7.5.4
--- init | 2 ++ init_functions | 2 +- 2 files changed, 3 insertions(+), 1 deletions(-) diff --git a/init b/init index a1398b6..a5e6103 100644 --- a/init +++ b/init @@ -8,8 +8,10 @@ /bin/mount -t sysfs sys /sys -o nosuid,noexec,nodev if grep -q devtmpfs /proc/filesystems 2>/dev/null; then /bin/mount -n -t devtmpfs udev /dev -o mode=0755,size=10M,nosuid + devtmpfs_mounted=1 else /bin/mount -n -t tmpfs udev /dev -o mode=0755,size=10M,nosuid + devtmpfs_mounted=0 # We don't have devtmpfs, so add the most important standard devices /bin/mknod /dev/null c 1 3 /bin/mknod /dev/zero c 1 5 diff --git a/init_functions b/init_functions index a94f525..ef938b4 100644 --- a/init_functions +++ b/init_functions @@ -86,7 +86,7 @@ default_mount_handler() { msg "Root device '${root}' doesn't exist. Attempting to create it." major="" minor="" - if [ ${root:0:5} = "/dev/" ]; then + if [ ${devtmpfs_mounted} -eq 0 -a ${root:0:5} = "/dev/" ]; then # It might be a block device (/dev/sda) -> /sys/class/block/sda/dev if [ -e /sys/class/block/${root:5}/dev ]; then IFS=':' read major minor < "/sys/class/block/${root:5}/dev" -- 1.7.5.4
We preserve TERM, but everything else can be destroyed from the environment. Signed-off-by: Dave Reisner <d@falconindy.com> --- init | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/init b/init index 1f6bc4e..a1398b6 100644 --- a/init +++ b/init @@ -117,4 +117,4 @@ for d in proc sys dev run; do /bin/umount /${d} fi done -exec /sbin/switch_root -c /dev/console /new_root ${init} "$@" +exec env -i TERM=$TERM /sbin/switch_root -c /dev/console /new_root ${init} "$@" -- 1.7.5.4
participants (2)
-
Dave Reisner
-
Thomas Bächler