diff --git a/usr/bin/archboot-cpio.sh b/usr/bin/archboot-cpio.sh index 371d38081..9aabc58ee 100755 --- a/usr/bin/archboot-cpio.sh +++ b/usr/bin/archboot-cpio.sh @@ -79,9 +79,8 @@ ldconfig -r "${_ROOTFS}" &>"${_NO_LOG}" || exit 1 # remove /var/cache/ldconfig/aux-cache for reproducibility rm -f -- "${_ROOTFS}/var/cache/ldconfig/aux-cache" if [[ -n "${_GENERATE_IMAGE}" ]]; then - _create_cpio "${_GENERATE_IMAGE}" "${_COMP}" || exit 1 + _create_cpio "${_ROOTFS}" "${_GENERATE_IMAGE}" || exit 1 _cleanup - echo "Build complete." elif [[ -n "${_TARGET_DIR}" ]]; then _cleanup echo "Build directory complete." diff --git a/usr/lib/archboot/common.sh b/usr/lib/archboot/common.sh index e51e86ca6..c519b5e97 100644 --- a/usr/lib/archboot/common.sh +++ b/usr/lib/archboot/common.sh @@ -306,4 +306,39 @@ _pacman_keyring() { systemctl stop pacman-init.service fi } + +_create_cpio() { + # Reproducibility: + # set all timestamps to 0 + # fd . -u --min-depth 1 -X touch -hcd "@0" + # Pipe needed as is, bsdcpio is faster but not reproducible! + # cpio, pax, tar are slower than bsdtar! + # LC_ALL=C.UTF-8 bsdtar --null -cnf - -T - | + # LC_ALL=C.UTF-8 bsdtar --null -cf - --format=newc @- + # Compression: + # use zstd it has best compression and decompression + # Result: + # Multi CPIO archive, extractable with 3cpio + pushd "${1}" >"${_NO_LOG}" || return + echo "Creating initramfs:" + fd . -u --min-depth 1 -X touch -hcd "@0" + echo "Appending directories..." + fd . -u -t d -0 | sort -z | + LC_ALL=C.UTF-8 bsdtar --null -cnf - -T - | + LC_ALL=C.UTF-8 bsdtar --null -cf - --format=newc @- > "${2}" || _abort "Image creation failed!" + echo "Appending compressed files..." + fd . -t f -t l -u -e 'bz2' -e 'gz' -e 'xz' -e 'zst' --min-depth 1 -0 | sort -z | + LC_ALL=C.UTF-8 bsdtar --null -cnf - -T - | + LC_ALL=C.UTF-8 bsdtar --null -cf - --format=newc @- >> "${2}" || _abort "Image creation failed!" + # remove compressed files, timestamps need reset! + fd . -u -e 'bz2' -e 'gz' -e 'xz' -e 'zst' --min-depth 1 -X rm + fd . -u --min-depth 1 -X touch -hcd "@0" + echo "Appending zstd compressed image..." + fd . -t f -t l -u --min-depth 1 -0 | sort -z | + LC_ALL=C.UTF-8 bsdtar --null -cnf - -T - | + LC_ALL=C.UTF-8 bsdtar --null -cf - --format=newc @- | + zstd -T0 -19 >> "${2}" || _abort "Image creation failed!" + popd >"${_NO_LOG}" || return + echo "Build complete." +} # vim: set ft=sh ts=4 sw=4 et: diff --git a/usr/lib/archboot/cpio/cpio.sh b/usr/lib/archboot/cpio/cpio.sh index 92e2bfdeb..b13052153 100644 --- a/usr/lib/archboot/cpio/cpio.sh +++ b/usr/lib/archboot/cpio/cpio.sh @@ -244,37 +244,3 @@ _install_libs() { _LIB_COUNT2="$(echo "${_ROOTFS}"/lib/*.so* | wc -w)" done } - -_create_cpio() { - # Reproducibility: - # set all timestamps to 0 - # fd . -u --min-depth 1 -X touch -hcd "@0" - # Pipe needed as is, bsdcpio is faster but not reproducible! - # cpio, pax, tar are slower than bsdtar! - # LC_ALL=C.UTF-8 bsdtar --null -cnf - -T - | - # LC_ALL=C.UTF-8 bsdtar --null -cf - --format=newc @- - # Compression: - # use zstd it has best compression and decompression - # Result: - # Multi CPIO archive, extractable with 3cpio - pushd "${_ROOTFS}" >"${_NO_LOG}" || return - echo "Creating initramfs:" - fd . -u --min-depth 1 -X touch -hcd "@0" - echo "Appending directories..." - fd . -u -t d -0 | sort -z | - LC_ALL=C.UTF-8 bsdtar --null -cnf - -T - | - LC_ALL=C.UTF-8 bsdtar --null -cf - --format=newc @- > "${_GENERATE_IMAGE}" || _abort "Image creation failed!" - echo "Appending compressed files..." - fd . -t f -t l -u -e 'bz2' -e 'gz' -e 'xz' -e 'zst' --min-depth 1 -0 | sort -z | - LC_ALL=C.UTF-8 bsdtar --null -cnf - -T - | - LC_ALL=C.UTF-8 bsdtar --null -cf - --format=newc @- >> "${_GENERATE_IMAGE}" || _abort "Image creation failed!" - # remove compressed files, timestamps need reset! - fd . -u -e 'bz2' -e 'gz' -e 'xz' -e 'zst' --min-depth 1 -X rm - fd . -u --min-depth 1 -X touch -hcd "@0" - echo "Appending zstd compressed image..." - fd . -t f -t l -u --min-depth 1 -0 | sort -z | - LC_ALL=C.UTF-8 bsdtar --null -cnf - -T - | - LC_ALL=C.UTF-8 bsdtar --null -cf - --format=newc @- | - zstd -T0 -19 >> "${_GENERATE_IMAGE}" || _abort "Image creation failed!" - popd >"${_NO_LOG}" || return -} diff --git a/usr/lib/archboot/release.sh b/usr/lib/archboot/release.sh index 82485ca50..91e561b8f 100644 --- a/usr/lib/archboot/release.sh +++ b/usr/lib/archboot/release.sh @@ -31,30 +31,6 @@ _create_initrd_dir() { -k ${_KERNEL} -c /etc/archboot/${1} -d /tmp/initrd" || exit 1 } -_compress_initrd() { - pushd "${_W_DIR}/tmp/initrd" >"${_NO_LOG}" || return - echo "Creating initramfs:" - fd . -u --min-depth 1 -X touch -hcd "@0" - echo "Appending directories..." - fd . -u -t d -0 | sort -z | - LC_ALL=C.UTF-8 bsdtar --null -cnf - -T - | - LC_ALL=C.UTF-8 bsdtar --null -cf - --format=newc @- > "../../${1}" || _abort "Image creation failed!" - echo "Appending compressed files..." - fd . -t f -t l -u -e 'bz2' -e 'gz' -e 'xz' -e 'zst' --min-depth 1 -0 | sort -z | - LC_ALL=C.UTF-8 bsdtar --null -cnf - -T - | - LC_ALL=C.UTF-8 bsdtar --null -cf - --format=newc @- >> "../../${1}" || _abort "Image creation failed!" - # remove compressed files, timestamps need reset! - fd . -u -e 'bz2' -e 'gz' -e 'xz' -e 'zst' --min-depth 1 -X rm - fd . -u --min-depth 1 -X touch -hcd "@0" - echo "Appending zstd compressed image..." - fd . -t f -t l -u --min-depth 1 -0 | sort -z | - LC_ALL=C.UTF-8 bsdtar --null -cnf - -T - | - LC_ALL=C.UTF-8 bsdtar --null -cf - --format=newc @- | - zstd -T0 -19 >> "../../${1}" || _abort "Image creation failed!" - popd >"${_NO_LOG}" || return - echo "Build complete." -} - _create_iso() { mkdir -p "${1}" cd "${1}" || exit 1 @@ -71,24 +47,24 @@ _create_iso() { # init ramdisk _create_initrd_dir "${_ARCH}-init.conf" . "/etc/archboot/${_ARCH}-init.conf" - _compress_initrd "init-${_ARCH}.img" + _create_cpio "${_W_DIR}/tmp/initrd" "init-${_ARCH}.img" if ! [[ "${_ARCH}" == "riscv64" ]]; then # local ramdisk echo "Generating local initramfs..." - _create_initrd_dir "${_CONFIG_LOCAL}" + _create_initrd_dir "${_W_DIR}/tmp/initrd" "${_CONFIG_LOCAL}" . "/etc/archboot/${_CONFIG_LOCAL}" - _compress_initrd "initrd-local-${_ARCH}.img" + _create_cpio "${_W_DIR}/tmp/initrd" "initrd-local-${_ARCH}.img" # latest ramdisk echo "Generating latest initramfs..." _create_initrd_dir "${_CONFIG_LATEST}" . "/etc/archboot/${_CONFIG_LATEST}" - _compress_initrd "initrd-latest-${_ARCH}.img" + _create_cpio "${_W_DIR}/tmp/initrd" "initrd-latest-${_ARCH}.img" fi # normal ramdisk echo "Generating normal initramfs..." _create_initrd_dir "${_ARCH}.conf" . "/etc/archboot/${_ARCH}.conf" - _compress_initrd "initrd-${_ARCH}.img" + _create_cpio "${_W_DIR}/tmp/initrd" "initrd-${_ARCH}.img" fi # riscv64 does not support kexec at the moment if ! [[ "${_ARCH}" == "riscv64" ]]; then