main/postmarketos-mkinitfs: avoid storing initramfs-extra twice (!932)

At the moment we store the same initramfs-extra twice on the file system:
  - /boot/initramfs-<flavor>-extra
  - /var/cache/postmarketos-mkinitfs/initramfs-<flavor>-extra_<hash>

The second copy is exactly the same file, just with the <hash> (for caching)
appended to the filename.

We can avoid this by appending the hash directly to the filename
on the boot partition, i.e.
  - /boot/initramfs-<flavor>-extra_<hash>

This is possible because we only reference initramfs-extra from the main
initramfs, and we already replace the path in it dynamically.
It will just let the main initramfs load -extra_<hash> instead of just -extra.

This saves a few megabytes of disk space on the rootfs.
This commit is contained in:
Minecrell 2020-02-05 20:32:16 +01:00 committed by Alexey Min
parent a415548b1d
commit 24fa68c9b6
No known key found for this signature in database
GPG key ID: EBF5ECFFFEE34DED
2 changed files with 13 additions and 15 deletions

View file

@ -1,5 +1,5 @@
pkgname=postmarketos-mkinitfs
pkgver=0.9.0
pkgver=0.9.1
pkgrel=0
pkgdesc="Tool to generate initramfs images for postmarketOS"
url="https://postmarketos.org"
@ -23,6 +23,7 @@ package() {
"$pkgdir/sbin/mkinitfs"
mkdir -p "$pkgdir/etc/postmarketos-mkinitfs/hooks/"
}
sha512sums="1d49db8a48ad513cc548b8a0ea23cc64518e71c93863155b4e9d2271fb46090506331c03d6955d693c8568c248ecc76b218efe4a6f6bba57c41c5f6d775dc61b init.sh.in
3bcec7b35ced7e87c301f71a892e54aa40983396e2ebaa3c8cbd84c91f711b3ca0e30fbc3104b1a1018ec1af51844ba90a63d380359b51db6242562d21776ed0 init_functions.sh
eaad43a846eea96abe1bb876369b0925ab52a141545b13099c634f9422017b5e57f809274ae89c0b53ade1db2c5cc4e96bb9841ad933d68f7664543992e8391b mkinitfs.sh"
3f46fc98f1f8839153858efb390abd6e2ef655ad46e471d14ab21c2a187776b4b5612aa4f25f136bb52cdcb9143169163ad73d539194459fcad3a8d42fc97bcd mkinitfs.sh"

View file

@ -335,10 +335,10 @@ append_or_copy_dtb()
}
# Create the initramfs-extra archive
# $1: outfile
# Updates $outfile_extra with path to cached file (hash appended to filename)
generate_initramfs_extra()
{
echo "==> initramfs: creating $1"
echo "==> initramfs: creating $outfile_extra"
osk_conf="$(get_osk_config)"
if [ $? -eq 1 ]; then
@ -346,19 +346,15 @@ generate_initramfs_extra()
exit 1
fi
# Ensure cache folder exists
mkinitfs_cache_dir="/var/cache/postmarketos-mkinitfs"
mkdir -p "$mkinitfs_cache_dir"
# Generate cache output filename (initfs_extra_cache) by hashing all input files
# Generate output filename (initfs_extra_cache) by hashing all input files
initfs_extra_files=$(echo "$BINARIES_EXTRA$osk_conf" | xargs -0 -I{} sh -c 'ls $1 2>/dev/null' -- {} | sort -u)
initfs_extra_files_hashes="$(md5sum $initfs_extra_files)"
initfs_extra_hash="$(echo "$initfs_extra_files_hashes" | md5sum | awk '{ print $1 }')"
initfs_extra_cache="$mkinitfs_cache_dir/$(basename $1)_${initfs_extra_hash}"
initfs_extra_cache="${outfile_extra}_${initfs_extra_hash}"
if ! [ -e "$initfs_extra_cache" ]; then
# If a cached file is missing, clear the whole cache and create it
rm -f ${mkinitfs_cache_dir}/*
# Delete old initramfs-extra_<hash> files
rm -f "$outfile_extra"_*
# Set up initramfs-extra in temp folder
tmpdir_extra=$(mktemp -d /tmp/mkinitfs.XXXXXX)
@ -369,13 +365,16 @@ generate_initramfs_extra()
rm -rf "$tmpdir_extra"
fi
cp "$initfs_extra_cache" "$1"
outfile_extra="$initfs_extra_cache"
}
# initialize
source_deviceinfo
parse_commandline "$1" "$2" "$3"
check_hook_files
generate_initramfs_extra
echo "==> initramfs: creating $outfile"
tmpdir=$(mktemp -d /tmp/mkinitfs.XXXXXX)
@ -402,6 +401,4 @@ create_bootimg
rm -rf "$tmpdir"
generate_initramfs_extra "$outfile_extra"
exit 0