[arch-projects] [mkinitcpio][PATCH 1/8] functions: display proper name on file not found
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- functions | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/functions b/functions index 0af586d..306c077 100644 --- a/functions +++ b/functions @@ -301,7 +301,7 @@ add_binary() { binary=$BASEDIR$1 fi - [[ -f "$binary" ]] || { error "file not found: \`%s'" "$binary"; return 1; } + [[ -f "$binary" ]] || { error "file not found: \`%s'" "$1"; return 1; } dest=${2:-$binary} mode=$(stat -c %a "$binary") -- 1.7.8.1
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- lsinitcpio | 9 --------- 1 files changed, 0 insertions(+), 9 deletions(-) diff --git a/lsinitcpio b/lsinitcpio index aa27e71..37d2764 100755 --- a/lsinitcpio +++ b/lsinitcpio @@ -27,15 +27,6 @@ USAGE exit 1 } -in_array() { - local item needle=$1; shift - - for item; do - [[ "$item" == $needle ]] && return 0 # Found - done - return 1 # Not Found -} - decomp() { ${compress:-cat} ${compress:+-cd} "$@" } -- 1.7.8.1
Follow suit with lsinitcpio (change 0495018d) and make output colorless on redirecting/piping stdout. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- mkinitcpio | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index 475b197..b6581ed 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -148,7 +148,7 @@ while getopts ':c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do done shift $((OPTIND - 1)) -if [[ -t 2 ]] && (( COLOR )); then +if [[ -t 1 ]] && (( COLOR )); then # prefer terminal safe colored and bold text when tput is supported if tput setaf 0 &>/dev/null; then NC="$(tput sgr0)" -- 1.7.8.1
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- install/autodetect | 4 ++-- mkinitcpio | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/install/autodetect b/install/autodetect index 5537f7c..c787fcb 100644 --- a/install/autodetect +++ b/install/autodetect @@ -16,8 +16,8 @@ build() { fi if (( UID == 0 )) || in_array 'disk' $(groups); then - if [[ -x /sbin/mdadm ]]; then - /sbin/mdadm -Esv /dev/[hrsv]d* /dev/{ida,cciss,ataraid,mapper}/* | + if [[ -x $(type -P mdadm) ]]; then + 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 diff --git a/mkinitcpio b/mkinitcpio index b6581ed..bcf56e9 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -353,7 +353,7 @@ if (( ${#ADDED_MODULES[*]} )); then popd >/dev/null msg "Generating module dependencies" - /sbin/depmod -b "$BUILDROOT" "${KERNELVERSION}" + depmod -b "$BUILDROOT" "${KERNELVERSION}" rm "$BUILDROOT/lib/modules/$KERNELVERSION"/modules.!(dep.bin|alias.bin|symbols.bin) else warning "No modules were added to the image. This is probably not what you want." -- 1.7.8.1
Avoiding adding a filesystem module to the whitelist when it doesn't actually exist as a module (in case its compiled in staticly). Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- install/autodetect | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/install/autodetect b/install/autodetect index c787fcb..abc0fa0 100644 --- a/install/autodetect +++ b/install/autodetect @@ -10,11 +10,16 @@ build() { auto_modules | grep -xEv '(ata|ide)_generic' >"$MODULE_FILE" - if ! rootfstype=$(findmnt -uno fstype "${BASEDIR:-/}" | tee -a "$MODULE_FILE"); then + if ! rootfstype=$(findmnt -uno fstype "${BASEDIR:-/}"); then error "failed to detect root filesystem" fs_autodetect_failed=1 fi + # filesystem module might be a builtin + if modinfo -k "$KERNELVERSION" "$rootfstype" &>/dev/null; then + printf '%s\n' "$rootfstype" >>"$MODULE_FILE" + fi + if (( UID == 0 )) || in_array 'disk' $(groups); then if [[ -x $(type -P mdadm) ]]; then mdadm -Esv /dev/[hrsv]d* /dev/{ida,cciss,ataraid,mapper}/* | -- 1.7.8.1
kmod is a bit noisier about unresolvable aliases, but we don't really care for the purposes of creating the module whitelist. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- This is backwards compat with m-i-t. functions | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/functions b/functions index 306c077..e5b4195 100644 --- a/functions +++ b/functions @@ -129,7 +129,7 @@ auto_modules() { IFS=$'\n' read -rd '' -a mods < \ <(find /sys/devices -name modalias -exec sort -u {} + | # delimit each input by a newline, expanded in place - xargs -d $'\n' modprobe -d "$BASEDIR" -aRS "$KERNELVERSION" | + xargs -d $'\n' modprobe -qd "$BASEDIR" -aRS "$KERNELVERSION" | sort -u) printf "%s\n" "${mods[@]//-/_}" -- 1.7.8.1
When present, modules.order will allow depmod to order the binary module indicies for faster lookups and more deterministic behavior in resolving aliases. We can discard this file from the buildroot after depmod is called. modules.builtin.bin is added as well (generated from modules.builtin), to allow modprobe to not fail when a symbol is provided as a builtin. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- Part of this is also to keep kmod a little quieter -- it spews some warnings when modules.order and modules.builtin don't exist, and I'd rather not hide errors/warnings if we can fix them another way. These files are, of course, not strictly necessary, but the cost is sufficiently low enough that I consider this a wash. mkinitcpio | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index bcf56e9..54b7891 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -353,8 +353,11 @@ if (( ${#ADDED_MODULES[*]} )); then popd >/dev/null msg "Generating module dependencies" + install -m644 -t "$BUILDROOT/lib/modules/$KERNELVERSION" \ + "$BASEDIR/lib/modules/$KERNELVERSION"/modules.{builtin,order} depmod -b "$BUILDROOT" "${KERNELVERSION}" - rm "$BUILDROOT/lib/modules/$KERNELVERSION"/modules.!(dep.bin|alias.bin|symbols.bin) + rm "$BUILDROOT/lib/modules/$KERNELVERSION"/modules.!(@(dep|alias|symbols|builtin).bin) + else warning "No modules were added to the image. This is probably not what you want." fi -- 1.7.8.1
On Thu, Jan 5, 2012 at 1:26 PM, Dave Reisner <d@falconindy.com> wrote:
When present, modules.order will allow depmod to order the binary module indicies for faster lookups and more deterministic behavior in resolving aliases. We can discard this file from the buildroot after depmod is called.
modules.builtin.bin is added as well (generated from modules.builtin), to allow modprobe to not fail when a symbol is provided as a builtin.
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- Part of this is also to keep kmod a little quieter -- it spews some warnings when modules.order and modules.builtin don't exist, and I'd rather not hide errors/warnings if we can fix them another way. These files are, of course, not strictly necessary, but the cost is sufficiently low enough that I consider this a wash.
mkinitcpio | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/mkinitcpio b/mkinitcpio index bcf56e9..54b7891 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -353,8 +353,11 @@ if (( ${#ADDED_MODULES[*]} )); then popd >/dev/null
msg "Generating module dependencies" + install -m644 -t "$BUILDROOT/lib/modules/$KERNELVERSION" \ + "$BASEDIR/lib/modules/$KERNELVERSION"/modules.{builtin,order} depmod -b "$BUILDROOT" "${KERNELVERSION}" - rm "$BUILDROOT/lib/modules/$KERNELVERSION"/modules.!(dep.bin|alias.bin|symbols.bin) + rm "$BUILDROOT/lib/modules/$KERNELVERSION"/modules.!(@(dep|alias|symbols|builtin).bin) No order.bin gets generated?
And on that note, what is the benefit/reason to removing these files? Do they not offer a speed benefit to modprobe module insertion on boot?
+ else warning "No modules were added to the image. This is probably not what you want." fi -- 1.7.8.1
On Thu, Jan 05, 2012 at 01:57:21PM -0600, Dan McGee wrote:
On Thu, Jan 5, 2012 at 1:26 PM, Dave Reisner <d@falconindy.com> wrote:
When present, modules.order will allow depmod to order the binary module indicies for faster lookups and more deterministic behavior in resolving aliases. We can discard this file from the buildroot after depmod is called.
modules.builtin.bin is added as well (generated from modules.builtin), to allow modprobe to not fail when a symbol is provided as a builtin.
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- Part of this is also to keep kmod a little quieter -- it spews some warnings when modules.order and modules.builtin don't exist, and I'd rather not hide errors/warnings if we can fix them another way. These files are, of course, not strictly necessary, but the cost is sufficiently low enough that I consider this a wash.
mkinitcpio | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/mkinitcpio b/mkinitcpio index bcf56e9..54b7891 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -353,8 +353,11 @@ if (( ${#ADDED_MODULES[*]} )); then popd >/dev/null
msg "Generating module dependencies" + install -m644 -t "$BUILDROOT/lib/modules/$KERNELVERSION" \ + "$BASEDIR/lib/modules/$KERNELVERSION"/modules.{builtin,order} depmod -b "$BUILDROOT" "${KERNELVERSION}" - rm "$BUILDROOT/lib/modules/$KERNELVERSION"/modules.!(dep.bin|alias.bin|symbols.bin) + rm "$BUILDROOT/lib/modules/$KERNELVERSION"/modules.!(@(dep|alias|symbols|builtin).bin) No order.bin gets generated?
There is need for an order.bin -- the file isn't used other than for ordering the module indicies (when it exists).
And on that note, what is the benefit/reason to removing these files? Do they not offer a speed benefit to modprobe module insertion on boot?
We're removing everything _but_ those files (yay extglobs). The files that _do_ get discarded are things like modules.ieee1394map and modules.pcimap -- we definitely don't need these files for booting. related to the glob: i don't know why i made it so complex. modules.!(*.bin) does what I need it to do. d
+ else warning "No modules were added to the image. This is probably not what you want." fi -- 1.7.8.1
This adds functionality to pivot to back to the initramfs on shutdown, thereby allowing the system to unmount the real root device. This will be necessary for anyone with /usr as a separate partition. --- Makefile | 2 +- hooks/shutdown | 7 +++++++ install/shutdown | 17 +++++++++++++++++ shutdown | 29 +++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletions(-) create mode 100644 hooks/shutdown create mode 100644 install/shutdown create mode 100755 shutdown diff --git a/Makefile b/Makefile index 3e7966d..e1fe5aa 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ install: all chmod 755 ${DESTDIR}/usr/bin/lsinitcpio ${DESTDIR}/usr/bin/mkinitcpio install -m644 mkinitcpio.conf ${DESTDIR}/etc/mkinitcpio.conf - install -m755 -t ${DESTDIR}/lib/initcpio init + install -m755 -t ${DESTDIR}/lib/initcpio init shutdown install -m644 -t ${DESTDIR}/lib/initcpio init_functions functions install -m644 01-memdisk.rules ${DESTDIR}/lib/initcpio/udev/01-memdisk.rules diff --git a/hooks/shutdown b/hooks/shutdown new file mode 100644 index 0000000..7c5d9e8 --- /dev/null +++ b/hooks/shutdown @@ -0,0 +1,7 @@ +#!/usr/bin/ash + +run_hook() { + cp -ax / /run/initramfs +} + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/install/shutdown b/install/shutdown new file mode 100644 index 0000000..2c533b6 --- /dev/null +++ b/install/shutdown @@ -0,0 +1,17 @@ +#!/bin/bash + +build() { + BINARIES='cp findmnt' + SCRIPT='shutdown' + + add_file "/lib/initcpio/shutdown" "/shutdown" +} + +help() { + cat <<HELPEOF +This hook copies the contents of the initramfs into /run/initramfs for reuse +on shutdown. This is needed when you have /usr mounted on a separate partition. +HELPEOF +} + +# vim: set ft=sh ts=4 sw=4 et: diff --git a/shutdown b/shutdown new file mode 100755 index 0000000..100f505 --- /dev/null +++ b/shutdown @@ -0,0 +1,29 @@ +#!/usr/bin/ash + +findmnt -Rruno TARGET /oldroot | awk ' +BEGIN { i = 0 } +! /^\/(proc|dev|sys)/ { + i++ + mounts[i] = $0 +} +END { + for (j = i; j > 0; j--) { + print mounts[j] + } +} +' | while read -r mount; do + umount -l "$mount" +done + +case $1 in + reboot) + type kexec >/dev/null && kexec -e + reboot -f + ;; + poweroff|shutdown|halt) + "$1" -f + ;; + *) + poweroff -f + ;; +esac -- 1.7.8.1
participants (2)
-
Dan McGee
-
Dave Reisner