From 4c68c97ce703b02d84b4203786f17e94dd9fa291 Mon Sep 17 00:00:00 2001 From: Austin Lane Date: Sun, 9 Nov 2025 18:05:27 -0500 Subject: [PATCH] LowMem: Slim down initramfs and set /run size --- extensions/lowmem.sh | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/extensions/lowmem.sh b/extensions/lowmem.sh index c2344ff80..a0a45ee65 100644 --- a/extensions/lowmem.sh +++ b/extensions/lowmem.sh @@ -8,6 +8,28 @@ # at build time. # +function post_family_tweaks_bsp__initramfs() { + local LOWMEM_TMPFS_RUN_MB=${LOWMEM_TMPFS_RUN_MB:-20} + display_alert "${EXTENSION}" "Set initramfs config for low memory" "debug" + + # Create /etc/initramfs-tools/conf.d/armbian-lowmem.conf configuration file + if [ ! -f "$destination/etc/initramfs-tools/conf.d/armbian-lowmem.conf" ]; then + mkdir -p "$destination/etc/initramfs-tools/conf.d" + install -m 644 /dev/null "$destination/etc/initramfs-tools/conf.d/armbian-lowmem.conf" + + # Load only modules needed for boot + echo "MODULES=dep" >> "$destination/etc/initramfs-tools/conf.d/armbian-lowmem.conf" + + # /run is 10% of RAM by default + # systemd throws errors when <16MB is *free* in this partition + # during daemon-reload operations. + # Address with a fixed /run size of ${LOWMEM_TMPFS_RUN_MB} + echo "RUNSIZE=${LOWMEM_TMPFS_RUN_MB}M" >> "$destination/etc/initramfs-tools/conf.d/armbian-lowmem.conf" + fi + + return 0 +} + function post_family_tweaks_bsp__copy_lowmem_config() { display_alert "${EXTENSION}" "Installing default configuration" "debug" @@ -41,7 +63,6 @@ function post_family_tweaks__enable_lowmem_mkswap() { } function pre_umount_final_image__memory_optimize_defaults() { - local LOWMEM_TMPFS_RUN_MB=${LOWMEM_TMPFS_RUN_MB:-20} # Optimize /etc/default settings to reduce memory usage display_alert "${EXTENSION}" "Disabling ramlog by default to save memory" "debug" sed -i "s/^ENABLED=.*/ENABLED=false/" "${MOUNT}"/etc/default/armbian-ramlog @@ -49,15 +70,5 @@ function pre_umount_final_image__memory_optimize_defaults() { display_alert "${EXTENSION}" "Disabling zram swap by default" "debug" sed -i "s/^#\?\s*SWAP=.*/SWAP=false/" "${MOUNT}"/etc/default/armbian-zram-config - # /run is 10% of RAM by default - # systemd throws errors when <16MB is *free* in this partition - # during daemon-reload operations. - # Address with a fixed /run size of ${LOWMEM_TMPFS_RUN_MB} - if ! grep -qE "tmpfs[[:space:]]+/run[[:space:]]+tmpfs" "${MOUNT}/etc/fstab"; then - # Skip if /run entry already exists in fstab (userpatches, etc) - display_alert "${EXTENSION}" "Fixing /run size in /etc/fstab" "debug" - echo "tmpfs /run tmpfs rw,nosuid,nodev,noexec,relatime,size=${LOWMEM_TMPFS_RUN_MB}M,mode=755 0 0" >> "${MOUNT}"/etc/fstab - fi - return 0 }