From 24fa68c9b64ccba97a8be3993169e6ba51ed6266 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Wed, 5 Feb 2020 20:32:16 +0100 Subject: [PATCH] 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--extra - /var/cache/postmarketos-mkinitfs/initramfs--extra_ The second copy is exactly the same file, just with the (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--extra_ 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_ instead of just -extra. This saves a few megabytes of disk space on the rootfs. --- main/postmarketos-mkinitfs/APKBUILD | 5 +++-- main/postmarketos-mkinitfs/mkinitfs.sh | 23 ++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/main/postmarketos-mkinitfs/APKBUILD b/main/postmarketos-mkinitfs/APKBUILD index 7fcb59d28..1275047e8 100644 --- a/main/postmarketos-mkinitfs/APKBUILD +++ b/main/postmarketos-mkinitfs/APKBUILD @@ -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" diff --git a/main/postmarketos-mkinitfs/mkinitfs.sh b/main/postmarketos-mkinitfs/mkinitfs.sh index 5e3b7556b..c8ccfcc2d 100644 --- a/main/postmarketos-mkinitfs/mkinitfs.sh +++ b/main/postmarketos-mkinitfs/mkinitfs.sh @@ -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_ 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