[arch-projects] [mkinitcpio][PATCH 1/6] install/autodetect: avoid adding empty rootfstype
Make the logic similar to how we treat usrfstype. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- install/autodetect | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/install/autodetect b/install/autodetect index 1b5b438..47c8c23 100644 --- a/install/autodetect +++ b/install/autodetect @@ -25,15 +25,15 @@ build() { auto_modules >"$MODULE_FILE" - if ! rootfstype=$(findmnt -uno fstype "${BASEDIR:-/}"); then + # detect filesystem for root + if rootfstype=$(findmnt -uno fstype "${BASEDIR:-/}"); then + add_if_avail "$rootfstype" + else error "failed to detect root filesystem" fs_autodetect_failed=1 fi - # filesystem module might be a builtin - add_if_avail "$rootfstype" - - # detect separate /usr + # detect filesystem for separate /usr if usrfstype=$(findmnt -snero fstype --tab-file "$BASEDIR/etc/fstab" /usr); then add_if_avail "$usrfstype" fi -- 1.7.9.2
e2fsprogs makes a lot of hardlinks for its fsck tools. If ext[234] is detected, add the fsck.ext4 binary and add symlinks. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- I'm not thrilled with the ext[234] hack, but I also don't like the idea of duplicating hardlinks as separate files on the image. install/fsck | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/install/fsck b/install/fsck index 9d9943b..b820063 100644 --- a/install/fsck +++ b/install/fsck @@ -3,12 +3,22 @@ build() { local added=0 + add_fsck() { + if [[ $1 = ext[234] ]]; then + add_binary fsck.ext4 + add_symlink /usr/bin/fsck.ext2 fsck.ext4 + add_symlink /usr/bin/fsck.ext3 fsck.ext4 + else + add_binary "fsck.$1" + fi + } + if (( ! fs_autodetect_failed )) && [[ $rootfstype$usrfstype ]]; then if [[ $rootfstype ]]; then - add_binary fsck.$rootfstype && (( ++added )) + add_fsck $rootfstype && (( ++added )) fi if [[ $usrfstype && $usrfstype != $rootfstype ]]; then - add_binary fsck.$usrfstype && (( ++added )) + add_fsck $usrfstype && (( ++added )) fi else for fsck in "$BASEDIR"/sbin/fsck.*; do -- 1.7.9.2
On Sat, Mar 3, 2012 at 4:47 PM, Dave Reisner <d@falconindy.com> wrote:
e2fsprogs makes a lot of hardlinks for its fsck tools. If ext[234] is detected, add the fsck.ext4 binary and add symlinks.
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- I'm not thrilled with the ext[234] hack, but I also don't like the idea of duplicating hardlinks as separate files on the image.
Looks good to me; if mkfs.ext? binaries ever appear in initcpio images the same would apply there as well.
install/fsck | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/install/fsck b/install/fsck index 9d9943b..b820063 100644 --- a/install/fsck +++ b/install/fsck @@ -3,12 +3,22 @@ build() { local added=0
+ add_fsck() { + if [[ $1 = ext[234] ]]; then + add_binary fsck.ext4 + add_symlink /usr/bin/fsck.ext2 fsck.ext4 + add_symlink /usr/bin/fsck.ext3 fsck.ext4 + else + add_binary "fsck.$1" + fi + } + if (( ! fs_autodetect_failed )) && [[ $rootfstype$usrfstype ]]; then if [[ $rootfstype ]]; then - add_binary fsck.$rootfstype && (( ++added )) + add_fsck $rootfstype && (( ++added )) fi if [[ $usrfstype && $usrfstype != $rootfstype ]]; then - add_binary fsck.$usrfstype && (( ++added )) + add_fsck $usrfstype && (( ++added )) fi else for fsck in "$BASEDIR"/sbin/fsck.*; do -- 1.7.9.2
Relying on blkid to do tag resolution will fail when the root device doesn't yet exist. This is, of course, bad for USB root devices. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- Also fixes a really unfortunate typo that I'm surprised hasn't caused more issues... init_functions | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/init_functions b/init_functions index e9a0cb9..5bcc159 100644 --- a/init_functions +++ b/init_functions @@ -156,14 +156,29 @@ fsck_root() { resolve_device() { local major minor dev device=$1 + # do lazy resolution of devices by tag when udev is + # available. this allows us to wait on disks that + # might not show up immediately (e.g. USB). If udev + # isn't running, fall back on using blkid. case $device in - # resolve tag name to block device - UUID=*|LABEL=*) - dev=$(blkid -lt "$device" -o device) - [ -n "$device" ] && device=$dev + UUID=*) + if [ "$udevd_running" -eq 1 ]; then + dev=/dev/disk/by-uuid/${device#UUID=} + else + dev=$(blkid -lt "$device" -o device) + fi + ;; + LABEL=*) + if [ "$udevd_running" -eq 1 ]; then + dev=/dev/disk/by-label/${device#LABEL=} + else + dev=$(blkid -lt "$device" -o device) + fi ;; esac + [ -n "$dev" ] && device=$dev + case $device in /dev/*) if poll_device "$device" "$rootdelay"; then -- 1.7.9.2
This is a really ugly patch, but allows mkinitcpio to read hooks from multiple locations, namely: /usr/lib/initcpio/{install,hooks} /lib/initcpio/{install,hooks} Preference is given to the first. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- Makefile | 24 ++++++++-------- functions | 18 ++++++++++-- install/base | 4 +-- install/shutdown | 2 +- mkinitcpio | 82 ++++++++++++++++++++++++++++++++---------------------- 5 files changed, 79 insertions(+), 51 deletions(-) diff --git a/Makefile b/Makefile index e1fe5aa..a9c6351 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,9 @@ DIRS = \ /usr/bin \ /etc/bash_completion.d \ /etc/mkinitcpio.d \ - /lib/initcpio/hooks \ - /lib/initcpio/install \ - /lib/initcpio/udev \ + /usr/lib/initcpio/hooks \ + /usr/lib/initcpio/install \ + /usr/lib/initcpio/udev \ /usr/share/man/man8 DIST_EXTRA = \ @@ -20,26 +20,26 @@ install: all $(foreach dir,${DIRS},install -dm755 ${DESTDIR}${dir};) sed -e 's|^CONFIG=.*|CONFIG=/etc/mkinitcpio.conf|' \ - -e 's|^FUNCTIONS=.*|FUNCTIONS=/lib/initcpio/functions|' \ - -e 's|^HOOKDIR=.*|HOOKDIR=/lib/initcpio/hooks|' \ - -e 's|^INSTDIR=.*|INSTDIR=/lib/initcpio/install|' \ + -e 's|^FUNCTIONS=.*|FUNCTIONS=/usr/lib/initcpio/functions|' \ + -e 's|^HOOKDIR=.*|HOOKDIR=({/usr,}/lib/initcpio/hooks)|' \ + -e 's|^INSTDIR=.*|INSTDIR=({/usr,}/lib/initcpio/install)|' \ -e 's|^PRESETDIR=.*|PRESETDIR=/etc/mkinitcpio.d|' \ -e 's|%VERSION%|${VERSION}|g' \ < mkinitcpio > ${DESTDIR}/usr/bin/mkinitcpio - sed -e 's|\(^declare FUNCTIONS\)=.*|\1=/lib/initcpio/functions|' \ + sed -e 's|\(^declare FUNCTIONS\)=.*|\1=/usr/lib/initcpio/functions|' \ -e 's|%VERSION%|${VERSION}|g' \ < lsinitcpio > ${DESTDIR}/usr/bin/lsinitcpio 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 shutdown - install -m644 -t ${DESTDIR}/lib/initcpio init_functions functions - install -m644 01-memdisk.rules ${DESTDIR}/lib/initcpio/udev/01-memdisk.rules + install -m755 -t ${DESTDIR}/usr/lib/initcpio init shutdown + install -m644 -t ${DESTDIR}/usr/lib/initcpio init_functions functions + install -m644 01-memdisk.rules ${DESTDIR}/usr/lib/initcpio/udev/01-memdisk.rules - install -m644 -t ${DESTDIR}/lib/initcpio/hooks hooks/* - install -m644 -t ${DESTDIR}/lib/initcpio/install install/* + install -m644 -t ${DESTDIR}/usr/lib/initcpio/hooks hooks/* + install -m644 -t ${DESTDIR}/usr/lib/initcpio/install install/* install -m644 -t ${DESTDIR}/etc/mkinitcpio.d mkinitcpio.d/* install -m644 mkinitcpio.8 ${DESTDIR}/usr/share/man/man8/mkinitcpio.8 diff --git a/functions b/functions index c85806a..5485578 100644 --- a/functions +++ b/functions @@ -337,7 +337,7 @@ parse_hook() { # prior to the start of hook processing, and after each hook's build # function is run. - local item= + local item= script= for item in $MODULES; do if [[ ${item:(-1)} = '?' ]]; then @@ -355,7 +355,21 @@ parse_hook() { add_file "$item" done - [[ $SCRIPT ]] && add_file "$HOOKDIR/$SCRIPT" "/hooks/$SCRIPT" + if [[ $SCRIPT ]]; then + script=$(find_in_dirs "$SCRIPT" "${HOOKDIR[@]}") && + add_file "$script" "/hooks/$SCRIPT" + fi +} + +find_in_dirs() { + for dir in "${@:2}"; do + if [[ -e $dir/$1 ]]; then + printf '%s' "$dir/$1" + return 0 + fi + done + + return 1 } # vim: set ft=sh ts=4 sw=4 et: diff --git a/install/base b/install/base index 3b7632f..db82fdc 100644 --- a/install/base +++ b/install/base @@ -31,8 +31,8 @@ build() { # Add an empty fstab to avoid mount warning when -o remount is used >"$BUILDROOT/etc/fstab" - add_file "/lib/initcpio/init_functions" "/init_functions" - add_file "/lib/initcpio/init" "/init" + add_file "/usr/lib/initcpio/init_functions" "/init_functions" + add_file "/usr/lib/initcpio/init" "/init" add_file "/lib/modprobe.d/usb-load-ehci-first.conf" # write a new config file. re-source the config as we can't guarantee the diff --git a/install/shutdown b/install/shutdown index 7c6b7bc..5b56f17 100644 --- a/install/shutdown +++ b/install/shutdown @@ -4,7 +4,7 @@ build() { BINARIES='cp' SCRIPT='shutdown' - add_file "/lib/initcpio/shutdown" "/shutdown" + add_file "/usr/lib/initcpio/shutdown" "/shutdown" } help() { diff --git a/mkinitcpio b/mkinitcpio index 637795f..9d59f0b 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -110,32 +110,34 @@ trap 'cleanup 130' INT trap 'cleanup 143' TERM while getopts ':c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do - case "${arg}" in - c) CONFIG="${OPTARG}" ;; + case $arg in + c) CONFIG=$OPTARG ;; k) optkver=$OPTARG ;; - s) SAVELIST=1; ;; - b) BASEDIR="${OPTARG}" ;; - g) GENIMG="${OPTARG}" ;; + s) SAVELIST=1 ;; + b) BASEDIR=$OPTARG ;; + g) GENIMG=$OPTARG ;; h) usage ;; - p) PRESET="${OPTARG}" ;; + p) PRESET=$OPTARG ;; n) COLOR=0 ;; v) QUIET=0 ;; S) IFS=, read -r -a SKIPHOOKS <<< "$OPTARG" ;; - H) if [[ ! -r "${INSTDIR}/${OPTARG}" ]]; then - error "No hook ${OPTARG}" + H) if script=$(find_in_dirs "$OPTARG" "${INSTDIR[@]}"); then + . "$script" + if [[ $(type -t help) != function ]]; then + error "No help for hook $OPTARG" + exit 1 + fi + else + error "No hook '$OPTARG'" exit 1 fi - . "${INSTDIR}/${OPTARG}" - if [[ $(type -t help) != function ]]; then - error "No help for hook ${OPTARG}" - exit 1 - fi - msg "Help for hook '${OPTARG}':" + msg "Help for hook '$OPTARG':" help exit 0 ;; L) msg "Available hooks" - cd "$INSTDIR" >/dev/null - printf ' %s\n' * | column -c$(tput cols) + for dir in "${INSTDIR[@]}"; do + ( cd "$dir" >/dev/null; printf ' %s\n' * ) + done | column -c$(tput cols) exit 0 ;; M) SHOW_AUTOMODS=1 ;; t) TMPDIR=$OPTARG ;; @@ -276,9 +278,10 @@ fi if (( SHOW_AUTOMODS )); then msg "Modules autodetected" - . "${INSTDIR}/autodetect" + autodetect=$(find_in_dirs 'autodetect' "${INSTDIR[@]}") + . "$autodetect" build - cat "${MODULE_FILE}" + cat "$MODULE_FILE" cleanup 0 fi @@ -307,26 +310,37 @@ done for hook in ${HOOKS}; do in_array "$hook" "${SKIPHOOKS[@]}" && continue unset MODULES BINARIES FILES SCRIPT - build () { error "$hook: no build function..."; } - - # A hook is considered deprecated if it is a symlink within $INSTDIR. - if [[ -L "$INSTDIR/$hook" ]]; then - newhook=$(readlink -e "$INSTDIR/$hook") - if [[ $newhook && "$INSTDIR/${newhook##*/}" -ef "$newhook" ]]; then - newhook=${newhook##*/} - warning "Hook '%s' is deprecated. Replace it with '%s' in your config" "$hook" "$newhook" - hook=$newhook + build() { error "$hook: no build function..."; return 1; } + + # find script in install dirs + if ! script=$(find_in_dirs "$hook" "${INSTDIR[@]}"); then + error "Hook '$hook' cannot be found." + (( ++builderrors )) + continue + fi + + # check for deprecation + if [[ -L $script ]]; then + if ! realscript=$(readlink -e "$script"); then + error "$script is a broken symlink to $(realpath "$script")" + (( ++builderrors )) + continue fi + warning "Hook '%s' is deprecated. Replace it with '%s' in your config" "$script" "$realscript" + script=$realscript fi - if [[ -r "${INSTDIR}/${hook}" ]]; then - . "${INSTDIR}/${hook}" - msg2 "Parsing hook: [%s]" "$hook" - build - parse_hook - else - error "Hook '$hook' can not be found." + + # source + if ! . "$script"; then + error 'Failed to read %s' "$script" (( ++builderrors )) + continue fi + + # run + msg2 "Parsing hook: [%s]" "${script##*/}" + build + parse_hook done # restore $CONFIG vars add to image -- 1.7.9.2
On Sat, Mar 3, 2012 at 11:47 PM, Dave Reisner <d@falconindy.com> wrote:
This is a really ugly patch, but allows mkinitcpio to read hooks from multiple locations, namely:
/usr/lib/initcpio/{install,hooks} /lib/initcpio/{install,hooks}
Preference is given to the first.
Thanks for implementing this! -t
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- mkinitcpio | 4 +++- mkinitcpio.8.txt | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mkinitcpio b/mkinitcpio index 9d59f0b..58979bf 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -120,7 +120,9 @@ while getopts ':c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do p) PRESET=$OPTARG ;; n) COLOR=0 ;; v) QUIET=0 ;; - S) IFS=, read -r -a SKIPHOOKS <<< "$OPTARG" ;; + S) IFS=, read -r -a skip <<< "$OPTARG" + SKIPHOOKS+=("${skip[@]}") + unset skip ;; H) if script=$(find_in_dirs "$OPTARG" "${INSTDIR[@]}"); then . "$script" if [[ $(type -t help) != function ]]; then diff --git a/mkinitcpio.8.txt b/mkinitcpio.8.txt index beb3e9c..eda5b58 100644 --- a/mkinitcpio.8.txt +++ b/mkinitcpio.8.txt @@ -64,6 +64,7 @@ Options *-S* 'hooks':: Skip 'hooks' when generating the image. Several hooks should be comma-separated. + This option can be specified multiple times. *-s*:: Saves the build directory for the initial ramdisk. Default: no; This means -- 1.7.9.2
Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- mkinitcpio | 7 +++++-- mkinitcpio.8.txt | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/mkinitcpio b/mkinitcpio index 58979bf..9f39d56 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -109,8 +109,11 @@ get_kernver() { trap 'cleanup 130' INT trap 'cleanup 143' TERM -while getopts ':c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do +while getopts ':A:c:k:sb:g:p:m:nvH:LMhS:t:z:' arg; do case $arg in + A) IFS=, read -r -a add <<< "$OPTARG" + ADDHOOKS+=("${add[@]}") + unset add ;; c) CONFIG=$OPTARG ;; k) optkver=$OPTARG ;; s) SAVELIST=1 ;; @@ -309,7 +312,7 @@ for var in MODULES BINARIES FILES; do declare "cfg_$var=${!var}" done -for hook in ${HOOKS}; do +for hook in ${HOOKS} "${ADDHOOKS[@]}"; do in_array "$hook" "${SKIPHOOKS[@]}" && continue unset MODULES BINARIES FILES SCRIPT build() { error "$hook: no build function..."; return 1; } diff --git a/mkinitcpio.8.txt b/mkinitcpio.8.txt index eda5b58..ea68cfe 100644 --- a/mkinitcpio.8.txt +++ b/mkinitcpio.8.txt @@ -24,6 +24,11 @@ other features. Options ------- +*-A* 'hooks':: + Add the additional 'hooks' to the image. These will be processed in order + after all other hooks from the config file. Multiple hooks should be + comma-separated. This option can be specified multiple times. + *-b* 'basedir':: Use 'basedir' as a starting point for gathering information about the currently running system. Default: /. @@ -63,7 +68,7 @@ Options file. *-S* 'hooks':: - Skip 'hooks' when generating the image. Several hooks should be comma-separated. + Skip 'hooks' when generating the image. Multiple hooks should be comma-separated. This option can be specified multiple times. *-s*:: -- 1.7.9.2
participants (3)
-
Dan McGee
-
Dave Reisner
-
Tom Gundersen