mirror of
https://gitlab.archlinux.org/tpowa/archboot.git
synced 2024-09-20 03:50:37 +02:00
fixup cpio
This commit is contained in:
parent
fa3e24e6ee
commit
b27c585abf
3 changed files with 35 additions and 36 deletions
|
@ -2,7 +2,7 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# archboot-cpio.sh - modular tool for building initramfs images
|
||||
# focused and optimized for size and speed
|
||||
# optimized for size and speed
|
||||
# by Tobias Powalowski <tpowa@archlinux.org>
|
||||
|
||||
shopt -s extglob
|
||||
|
@ -40,7 +40,7 @@ while [ $# -gt 0 ]; do
|
|||
done
|
||||
|
||||
#shellcheck disable="SC1090"
|
||||
! . "${_CONFIG}" 2>"${_NO_LOG}" && _abort "Failed to read ${_CONFIG} configuration file"
|
||||
. "${_CONFIG}" 2>"${_NO_LOG}" || _abort "Failed to read ${_CONFIG} configuration file"
|
||||
if [[ -z "${_KERNEL}" ]]; then
|
||||
echo "Trying to autodetect ${_RUNNING_ARCH} kernel..."
|
||||
[[ "${_RUNNING_ARCH}" == "x86_64" || "${_RUNNING_ARCH}" == "riscv64" ]] && _KERNEL="/usr/lib/modules/*/vmlinuz"
|
||||
|
@ -57,14 +57,15 @@ _KERNELVERSION="$(_kver "${_KERNEL}")"
|
|||
_MODULE_DIR="/lib/modules/${_KERNELVERSION}"
|
||||
[[ -d "${_MODULE_DIR}" ]] || _abort "${_MODULE_DIR} is not a valid kernel module directory!"
|
||||
_BUILD_DIR="$(_init_rootfs "${_KERNELVERSION}" "${_TARGET_DIR}")" || exit 1
|
||||
_ROOTFS="${_TARGET_DIR}:-${_BUILD_DIR}/root}"
|
||||
_ROOTFS="${_TARGET_DIR:-${_BUILD_DIR}/root}"
|
||||
if (( ${#_HOOKS[*]} == 0 )); then
|
||||
_abort "No hooks found in config file!"
|
||||
fi
|
||||
echo "Using kernel version: ${_KERNELVERSION}"
|
||||
if [[ -n "${_GENERATE_IMAGE}" || -n "${_TARGET_DIR}" ]]; then
|
||||
echo "Starting build: ${_KERNELVERSION}"
|
||||
echo "Starting build..."
|
||||
else
|
||||
echo "Starting dry run: ${_KERNELVERSION}"
|
||||
echo "Starting dry run..."
|
||||
fi
|
||||
_builtin_modules
|
||||
_map _run_hook "${_HOOKS[@]}"
|
||||
|
@ -78,9 +79,9 @@ umask 077
|
|||
if [[ -n "${_GENERATE_IMAGE}" ]]; then
|
||||
_create_cpio "${_GENERATE_IMAGE}" "${_COMP}" || exit 1
|
||||
elif [[ -n "${_TARGET_DIR}" ]]; then
|
||||
msg "Build complete."
|
||||
echo "Build complete."
|
||||
else
|
||||
msg "Dry run complete, use -g IMAGE to generate a real image"
|
||||
echo "Dry run complete."
|
||||
fi
|
||||
|
||||
# vim: set ft=sh ts=4 sw=4 et:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# archboot-cpio.sh - modular tool for building an initramfs image
|
||||
# simplified, stripped down, optimized for size and speed
|
||||
# optimized for size and speed
|
||||
# by Tobias Powalowski <tpowa@archlinux.org>
|
||||
|
||||
_CONFIG=""
|
||||
|
@ -37,27 +37,6 @@ _abort() {
|
|||
exit 1
|
||||
}
|
||||
|
||||
_create_cpio() {
|
||||
case "${_COMP}" in
|
||||
cat) echo "Creating uncompressed initcpio image: ${_OUT}"
|
||||
unset _COMP_OPTS
|
||||
;;
|
||||
*) echo "Creating ${_COMP} compressed initcpio image: ${_OUT}"
|
||||
;;&
|
||||
xz) _COMP_OPTS=('-T0' '--check=crc32' "${_COMP_OPTS[@]}")
|
||||
;;
|
||||
lz4) _COMP_OPTS=('-l' "${_COMP_OPTS[@]}")
|
||||
;;
|
||||
zstd) _COMP_OPTS=('-T0' "${_COMP_OPTS[@]}")
|
||||
;;
|
||||
esac
|
||||
# Reproducibility: set all timestamps to 0
|
||||
find . -mindepth 1 -execdir touch -hcd "@0" "{}" +
|
||||
find . -mindepth 1 -printf '%P\0' | sort -z | LANG=C bsdtar --null -cnf - -T - |
|
||||
LANG=C bsdtar --null -cf - --format=newc @- |
|
||||
${_COMP} "${_COMP_OPTS[@]}" > "${_OUT}" || _abort "initcpio image creation failed!"
|
||||
}
|
||||
|
||||
_builtin_modules() {
|
||||
# Prime the _INCLUDED_MODS list with the builtins for this kernel.
|
||||
# kmod>=27 and kernel >=5.2 required!
|
||||
|
@ -231,7 +210,7 @@ _file() {
|
|||
if [[ "${_SRC}" != "${_DEST}" ]]; then
|
||||
command tar --hard-dereference --transform="s|${_SRC}|${_DEST}|" -C / -cpf - ."${_SRC}" | tar -C "${_ROOTFS}" -xpf - || return 1
|
||||
else
|
||||
command tar --hard-dereference -C / -cpf - ."${_SRC}" | tar -C "${_DEST}" -xpf - || return 1
|
||||
command tar --hard-dereference -C / -cpf - ."${_SRC}" | tar -C "${_ROOTFS}" -xpf - || return 1
|
||||
fi
|
||||
if [[ -L "${_SRC}" ]]; then
|
||||
_LINK_SOURCE="$(realpath -- "${_SRC}")"
|
||||
|
@ -296,6 +275,7 @@ _init_rootfs() {
|
|||
: >"${_ROOTFS}/etc/fstab"
|
||||
# add a blank ld.so.conf to keep ldconfig happy
|
||||
: >"${_ROOTFS}/etc/ld.so.conf"
|
||||
echo "${_TMPDIR}"
|
||||
}
|
||||
|
||||
_run_hook() {
|
||||
|
@ -327,3 +307,27 @@ _install_modules() {
|
|||
# and builtin.modinfo for checking on builtin modules)
|
||||
rm "${_ROOTFS}${_MODULE_DIR}"/modules.!(*.bin|*.modinfo|devname|softdep)
|
||||
}
|
||||
|
||||
_create_cpio() {
|
||||
case "${_COMP}" in
|
||||
cat) echo "Creating uncompressed image: ${_GENERATE_IMAGE}"
|
||||
unset _COMP_OPTS
|
||||
;;
|
||||
*) echo "Creating ${_COMP} compressed image: ${_GENERATE_IMAGE}"
|
||||
;;&
|
||||
xz) _COMP_OPTS=('-T0' '--check=crc32' "${_COMP_OPTS[@]}")
|
||||
;;
|
||||
lz4) _COMP_OPTS=('-l' "${_COMP_OPTS[@]}")
|
||||
;;
|
||||
zstd) _COMP_OPTS=('-T0' "${_COMP_OPTS[@]}")
|
||||
;;
|
||||
esac
|
||||
|
||||
# Reproducibility: set all timestamps to 0
|
||||
pushd "${_ROOTFS}" >"${_NO_LOG}" || return
|
||||
find . -mindepth 1 -execdir touch -hcd "@0" "{}" +
|
||||
find . -mindepth 1 -printf '%P\0' | sort -z | LANG=C bsdtar --null -cnf - -T - |
|
||||
LANG=C bsdtar --null -cf - --format=newc @- |
|
||||
${_COMP} "${_COMP_OPTS[@]}" > "${_GENERATE_IMAGE}" || _abort "Image creation failed!"
|
||||
popd >"${_NO_LOG}" || return
|
||||
}
|
||||
|
|
|
@ -39,10 +39,4 @@ _run() {
|
|||
done
|
||||
}
|
||||
|
||||
help() {
|
||||
cat <<HELPEOF
|
||||
Inital setup for archboot ISO booting.
|
||||
HELPEOF
|
||||
}
|
||||
|
||||
# vim: set ft=sh ts=4 sw=4 et:
|
||||
|
|
Loading…
Reference in a new issue