optimize library handling

This commit is contained in:
Tobias Powalowski 2023-10-18 16:34:21 +02:00
parent ee159bf309
commit cb19bc0a3b
4 changed files with 27 additions and 21 deletions

View file

@ -82,6 +82,7 @@ for i in "${_HOOKS[@]}"; do
_run_hook "${i}" _run_hook "${i}"
_HOOK_COUNT="$((_HOOK_COUNT+1))" _HOOK_COUNT="$((_HOOK_COUNT+1))"
done done
_install_libs
_install_modules "${!_MOD_PATH[@]}" _install_modules "${!_MOD_PATH[@]}"
ldconfig -r "${_ROOTFS}" &>"${_NO_LOG}" || exit 1 ldconfig -r "${_ROOTFS}" &>"${_NO_LOG}" || exit 1
# remove /var/cache/ldconfig/aux-cache for reproducibility # remove /var/cache/ldconfig/aux-cache for reproducibility

View file

@ -168,27 +168,8 @@ _file_rename() {
} }
_binary() { _binary() {
if [[ "${1:0:1}" != '/' ]]; then
_BIN="$(type -P "${1}")" _BIN="$(type -P "${1}")"
else
_BIN="${1}"
fi
_file "${_BIN}" _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() { _init_rootfs() {
@ -238,6 +219,28 @@ _install_modules() {
rm "${_ROOTFS}${_MODULE_DIR}"/modules.!(*.bin|*.modinfo|devname|softdep) 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() { _create_cpio() {
case "${_COMP}" in case "${_COMP}" in
cat) echo "Creating uncompressed image: ${_GENERATE_IMAGE}" cat) echo "Creating uncompressed image: ${_GENERATE_IMAGE}"

View file

@ -164,7 +164,7 @@ var/lib/pacman/local \
# mask systemd-gpt-auto-generator, errors out on initramfs usage # mask systemd-gpt-auto-generator, errors out on initramfs usage
_symlink /etc/systemd/system-generators/systemd-gpt-auto-generator /dev/null _symlink /etc/systemd/system-generators/systemd-gpt-auto-generator /dev/null
### add udev ### add udev
_map _binary /usr/lib/systemd/systemd-udevd udevadm systemd-tmpfiles logger _map _binary udevadm systemd-tmpfiles logger
# add schedule rules file # add schedule rules file
_file_rename /usr/share/archboot/base/etc/udev/rules.d/60-ioschedulers.rules /etc/udev/rules.d/60-ioschedulers.rules _file_rename /usr/share/archboot/base/etc/udev/rules.d/60-ioschedulers.rules /etc/udev/rules.d/60-ioschedulers.rules

View file

@ -8,6 +8,8 @@ _run() {
_map _binary bash sh blkid mount mountpoint switch_root bsdcpio mkfs.btrfs setfont \ _map _binary bash sh blkid mount mountpoint switch_root bsdcpio mkfs.btrfs setfont \
/usr/lib/systemd/systemd-udevd udevadm systemd-tmpfiles kmod insmod modprobe \ /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 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 /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-v16n.psf.gz /consolefont-16.psf.gz
_file_rename /usr/share/kbd/consolefonts/ter-v32n.psf.gz /consolefont-32.psf.gz _file_rename /usr/share/kbd/consolefonts/ter-v32n.psf.gz /consolefont-32.psf.gz