Files
build/extensions/cleanup-space-final-image.sh
Ricardo Pardini 2b28f29ebe rootfs/image: avoid apt junk leftover by debootstrap; add warnings and debugs over target cache and general rootfs sizes
- rootfs: rootfs-create: show a summary of the 20 biggest dirs, right before tarring the rootfs (for debugging)
- rootfs: rootfs-create: show usage of caches between first and second stages
- rootfs: rootfs-create: cleanup junk left by `debootstrap` after second stage
- rootfs: rootfs-create: _always_ clean apt stuff at the end
- rename `apt_purge_unneeded_packages()` to `apt_purge_unneeded_packages_and_clean_apt_caches()` for clarity
- image: `apt_purge_unneeded_packages_and_clean_apt_caches()`: warn if apt caches not empty; clean them off, always.
- host-utils: `local_apt_deb_cache_prepare()`: also test the target, warn if not empty
- extension: cleanup-space-final-image: do NOT clean apt stuff. done in core now
- the metric shit-ton of debugs added should help the next person who faces this in the future
2023-04-18 16:27:06 +02:00

37 lines
1.4 KiB
Bash

function add_host_dependencies__cleanup_space_final_image_zerofree() {
declare -g EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} zerofree"
}
function post_customize_image__998_cleanup_apt_stuff() {
# This used to clean apt caches, but no longer; we do that in the core now.
declare -a too_big_firmware=("netronome" "qcom" "mrv" "qed" "mellanox") # maybe: "amdgpu" "radeon" but I have an AMD GPU.
for big_firm in "${too_big_firmware[@]}"; do
local firm_dir="${SDCARD}/usr/lib/firmware/${big_firm}"
if [[ -d "${firm_dir}" ]]; then
display_alert "Cleaning too-big firmware" "${big_firm}" "info"
rm -rf "${firm_dir}"
fi
done
}
# Zerofree the image early after umounting it
function post_umount_final_image__200_zerofree() {
display_alert "Zerofreeing image" "${EXTENSION}" "info"
for partDev in "${LOOP}"p?; do
local partType
partType="$(file -s "${partDev}" | awk -F ': ' '{print $2}')"
if [[ "${partType}" == *"ext4"* ]]; then
display_alert "Zerofreeing ext4 partition ${partDev}" "${EXTENSION}" "info"
run_host_command_logged zerofree "${partDev}"
else
display_alert "Skipping zerofreeing partition ${partDev} of type '${partType}'" "${EXTENSION}" "info"
fi
done
}
function pre_umount_final_image__999_show_space_usage() {
display_alert "Calculating used space in image" "${EXTENSION}" "info"
run_host_command_logged "cd ${MOUNT} && " du -h -d 4 -x "." "| sort -h | tail -20"
}