[arch-projects] [mkinitcpio][PATCH 1/4] add 'strip' install hook
Mostly a convenience for myself, and anyone else who runs builds of things like util-linux or kmod, where having debug symbols on these libraries can add a large amount of weight to the image. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- install/strip | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 install/strip diff --git a/install/strip b/install/strip new file mode 100644 index 0000000..8ed9240 --- /dev/null +++ b/install/strip @@ -0,0 +1,32 @@ +#!/bin/bash + +build() { + find "$BUILDROOT" -type f -perm -u+w -print0 2>/dev/null | while read -d '' bin; do + case $(file -bi "$bin") in + *application/x-sharedlib*) + # Libraries (.so) + strip --strip-unneeded "$bin" + ;; + *application/x-archive*) + # Libraries (.a) + strip --strip-debug "$bin" + ;; + *application/x-executable*) + # Binaries + strip --strip-all "$bin" + ;; + esac + done +} + +help() { + cat <<HELPEOF +This hook will locate and strip binaries on your image before archival and +compression. This hook should be last, as any binaries added to the image after +this hook runs will not be stripped. This is mostly useful for users who run +local debug builds but whom do not want or need the extra weight of debug +symbols on their image. +HELPEOF +} + +# vim: set ft=sh ts=4 sw=4 et: -- 1.7.11.2
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- mkinitcpio | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mkinitcpio b/mkinitcpio index 43a89df..0834dc0 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -55,6 +55,8 @@ EOF } cleanup() { + local err=${1:-$?} + if [[ $workdir ]]; then # when PRESET is set, we're in the main loop, not a worker process if (( SAVELIST )) && [[ -z $PRESET ]]; then @@ -64,7 +66,7 @@ cleanup() { fi fi - exit ${1:0} + exit $err } resolve_kernver() { -- 1.7.11.2
mkinitcpio needs to be able to more tightly control the layout of the image. By moving this outside the control of the base hook, it's more reasonable to believe that a drop-in replacement for the base hook could be written, as it now only contains the utilities required for the /init that it provides. Being that initialize_buildroot is outside of a hook, we can make "raw" calls to coreutils that create the directories and symlinks, saving some overhead and forking. This also symlinks /usr/local/{lib,bin} into the common /usr/lib and /usr/bin, respectively, so that there's always a way to override libs and bins, and they're automatically pulled into our strict early init path of /usr/bin. Finally, we lump all this generally a little "later" in the early setup. This addresses an unseen "bug" wherein an extra temp directory that never gets used is created when leveraging a preset. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- The lofty goal this is wanted for is possible/eventual inclusion of systemd in early userspace. functions | 26 ++++++++++++++++++++++++++ install/base | 11 +---------- mkinitcpio | 35 +++++++++-------------------------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/functions b/functions index e9fb81a..e17e46e 100644 --- a/functions +++ b/functions @@ -606,6 +606,32 @@ write_image_config() { ) >"$BUILDROOT/config" } +initialize_buildroot() { + # creates a temporary directory for the buildroot and initialize it with a + # basic set of necessary directories and symlinks + + local workdir= kernver=$1 + + if ! workdir=$(mktemp -d --tmpdir mkinitcpio.XXXXXX); then + error 'Failed to create temporary working directory in %s' "${TMPDIR:-/tmp}" + return 1 + fi + + # base directory structure + install -dm755 "$workdir/root"/{new_root,proc,sys,dev,run,tmp,usr/{local,lib,bin}} + ln -s "usr/lib" "$workdir/root/lib" + ln -s "../lib" "$workdir/root/usr/local/lib" + ln -s "bin" "$workdir/root/usr/sbin" + ln -s "usr/bin" "$workdir/root/bin" + ln -s "usr/bin" "$workdir/root/sbin" + ln -s "../bin" "$workdir/root/usr/local/bin" + + # kernel module dir + install -dm755 "$workdir/root/usr/lib/modules/$kernver/kernel" + + printf '%s' "$workdir" +} + run_build_hook() { local hook=$1 script= realscript= local MODULES= BINARIES= FILES= SCRIPT= diff --git a/install/base b/install/base index 30ad3fa..7bb23a8 100644 --- a/install/base +++ b/install/base @@ -1,16 +1,7 @@ #!/bin/bash build() { - local dir applet - - for dir in new_root proc sys dev run tmp usr/bin; do - add_dir "/$dir" - done - - add_symlink /lib usr/lib - add_symlink /sbin usr/bin - add_symlink /bin usr/bin - add_symlink /usr/sbin bin + local applet add_binary /usr/lib/initcpio/busybox /bin/busybox diff --git a/mkinitcpio b/mkinitcpio index 0834dc0..5202e7f 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -195,7 +195,7 @@ while :; do SHOW_AUTOMODS=1 ;; -t|--builddir) shift - TMPDIR=$1 ;; + export TMPDIR=$1 ;; -z|--compress) shift optcompress=$1 ;; @@ -232,24 +232,6 @@ readonly NC BOLD BLUE GREEN RED YELLOW [[ -e /proc/self/mountinfo ]] || die "/proc must be mounted!" [[ -e /dev/fd ]] || die "/dev must be mounted!" -KERNELVERSION=$(resolve_kernver "$optkver") || cleanup 1 - -if [[ $TMPDIR ]]; then - if [[ ! -d $TMPDIR ]]; then - error "Temporary directory does not exist or is not a directory: \`%s'" "$TMPDIR" - cleanup 1 - fi - if [[ ! -w $TMPDIR ]]; then - error "Temporary directory is not writeable: \`%s'" "$TMPDIR" - cleanup 1 - fi -fi -workdir=$(TMPDIR=$TMPDIR mktemp -d --tmpdir mkinitcpio.XXXXXX) -BUILDROOT=$workdir/root - -# explicitly create the buildroot -mkdir -p "$BUILDROOT/usr/lib/modules/$KERNELVERSION/kernel" - # use preset $PRESET if [[ $PRESET ]]; then # allow absolute path to preset file, else resolve it @@ -304,10 +286,14 @@ if [[ $PRESET ]]; then fi fi -if [[ ! -f $CONFIG ]]; then - die "Config file does not exist: \`%s'" "$CONFIG" -fi -. "$CONFIG" +KERNELVERSION=$(resolve_kernver "$optkver") || cleanup 1 +MODULEDIR=$(find_moduledir "$KERNELVERSION") || cleanup 1 + +# initialize the working directory and buildroot +workdir=$(initialize_buildroot "$KERNELVERSION") || cleanup 1 +BUILDROOT=$workdir/root + +. "$CONFIG" || die "Failed to read configuration \`%s'" "$CONFIG" # after returning, hooks are populated into the array 'hooks' # HOOKS should not be referenced from here on @@ -317,8 +303,6 @@ if (( ${#hooks[*]} == 0 )); then die "Invalid config: No hooks found" fi -MODULEDIR=$(find_moduledir "$KERNELVERSION") || cleanup 1 - if [[ ! -d $MODULEDIR ]]; then die "'$MODULEDIR' is not a valid kernel module directory" fi @@ -332,7 +316,6 @@ if (( SHOW_AUTOMODS )); then cleanup 0 fi - if [[ -z $GENIMG ]]; then msg "Starting dry run: %s" "$KERNELVERSION" else -- 1.7.11.2
I almost deleted this, replacing it with only bsdtar. Add a comment so I'm not tempted to do this again. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- lsinitcpio | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lsinitcpio b/lsinitcpio index 4b9f77b..980596a 100755 --- a/lsinitcpio +++ b/lsinitcpio @@ -141,7 +141,9 @@ if (( analyze )); then ratio=.$(( zsize * 1000 / fullsize % 1000 )) fi - # decompress the image since we need to read from it multiple times + # decompress the image since we need to read from it multiple times. we + # have to pass this through decomp() since the image might be lzop which + # bsdtar can't read. decomp "$image" | bsdtar -C "$workdir" -xf - # collect stats -- 1.7.11.2
participants (1)
-
Dave Reisner