diff --git a/usr/bin/archboot-cpio.sh b/usr/bin/archboot-cpio.sh index 9ddde3e5e..a92dd339d 100755 --- a/usr/bin/archboot-cpio.sh +++ b/usr/bin/archboot-cpio.sh @@ -82,6 +82,7 @@ for i in "${_HOOKS[@]}"; do _run_hook "${i}" _HOOK_COUNT="$((_HOOK_COUNT+1))" done +_install_libs _install_modules "${!_MOD_PATH[@]}" ldconfig -r "${_ROOTFS}" &>"${_NO_LOG}" || exit 1 # remove /var/cache/ldconfig/aux-cache for reproducibility diff --git a/usr/lib/archboot/cpio/cpio.sh b/usr/lib/archboot/cpio/cpio.sh index 1aeb996a6..9632a8747 100644 --- a/usr/lib/archboot/cpio/cpio.sh +++ b/usr/lib/archboot/cpio/cpio.sh @@ -168,27 +168,8 @@ _file_rename() { } _binary() { - if [[ "${1:0:1}" != '/' ]]; then - _BIN="$(type -P "${1}")" - else - _BIN="${1}" - fi + _BIN="$(type -P "${1}")" _file "${_BIN}" - # non-binaries - if ! _LDD="$(ldd "${_BIN}" 2>"${_NO_LOG}")"; then - return 0 - fi - # resolve libraries - _REGULAR_EXPRESSION='^(|.+ )(/.+) \(0x[a-fA-F0-9]+\)' - while read -r i; do - if [[ "${i}" =~ ${_REGULAR_EXPRESSION} ]]; then - _LIB="${BASH_REMATCH[2]}" - fi - if [[ -f "${_LIB}" && ! -e "${_ROOTFS}${_LIB}" ]]; then - _file "${_LIB}" - fi - done <<< "${_LDD}" - return 0 } _init_rootfs() { @@ -238,6 +219,28 @@ _install_modules() { rm "${_ROOTFS}${_MODULE_DIR}"/modules.!(*.bin|*.modinfo|devname|softdep) } +_install_libs() { + # add libraries for binaries in bin/ and /lib/systemd + echo "Adding libraries for / and /lib/systemd..." + _LIBS="$(objdump -p "${_ROOTFS}"/bin/* "${_ROOTFS}"/lib/systemd/{systemd-*,libsystemd*} 2>${_NO_LOG} | + grep 'NEEDED' | sort -u | sed -e 's#NEEDED##g' -e 's# .* #/lib/#g')" + while read -r i; do + [[ -e "${i}" ]] && _file "${i}" + done <<< "${_LIBS}" + echo "Checking libraries in /lib..." + _LIB_COUNT="" + while true; do + _LIBS="$(objdump -p "${_ROOTFS}"/lib/*.so* | + grep 'NEEDED' | sort -u | sed -e 's#NEEDED##g' -e 's# .* #/lib/#g')" + while read -r i; do + [[ -e "${i}" ]] && _file "${i}" + done <<< "${_LIBS}" + _LIB_COUNT2="$(ls "${_ROOTFS}"/lib/*.so* | wc -l)" + [[ "${_LIB_COUNT}" == "${_LIB_COUNT2}" ]] && break + _LIB_COUNT="${_LIB_COUNT2}" + done +} + _create_cpio() { case "${_COMP}" in cat) echo "Creating uncompressed image: ${_GENERATE_IMAGE}" diff --git a/usr/lib/archboot/cpio/hooks/base_common b/usr/lib/archboot/cpio/hooks/base_common index 8606a1152..602c2f9e0 100644 --- a/usr/lib/archboot/cpio/hooks/base_common +++ b/usr/lib/archboot/cpio/hooks/base_common @@ -164,7 +164,7 @@ var/lib/pacman/local \ # mask systemd-gpt-auto-generator, errors out on initramfs usage _symlink /etc/systemd/system-generators/systemd-gpt-auto-generator /dev/null ### add udev - _map _binary /usr/lib/systemd/systemd-udevd udevadm systemd-tmpfiles logger + _map _binary udevadm systemd-tmpfiles logger # add schedule rules file _file_rename /usr/share/archboot/base/etc/udev/rules.d/60-ioschedulers.rules /etc/udev/rules.d/60-ioschedulers.rules diff --git a/usr/lib/archboot/cpio/hooks/init b/usr/lib/archboot/cpio/hooks/init index 91d2e2c08..cd95d21aa 100644 --- a/usr/lib/archboot/cpio/hooks/init +++ b/usr/lib/archboot/cpio/hooks/init @@ -8,6 +8,8 @@ _run() { _map _binary bash sh blkid mount mountpoint switch_root bsdcpio mkfs.btrfs setfont \ /usr/lib/systemd/systemd-udevd udevadm systemd-tmpfiles kmod insmod modprobe \ gzip uname cat cp dmesg grep ln ls mv rm umount lsblk rmmod cut sed find mkdir dialog + # needed library for udevadm! + _map _file /usr/lib/systemd/libsystemd-shared* _file /usr/share/terminfo/l/linux _file_rename /usr/share/kbd/consolefonts/ter-v16n.psf.gz /consolefont-16.psf.gz _file_rename /usr/share/kbd/consolefonts/ter-v32n.psf.gz /consolefont-32.psf.gz