From caedd595563a3f11dea08e9bb9b9d4f345fce8b7 Mon Sep 17 00:00:00 2001 From: /rootzoll Date: Sun, 8 Jun 2025 17:33:25 +0200 Subject: [PATCH] #5046 swapfile (#5049) * prevent swap file on sd card --- home.admin/_provision_.sh | 6 +++--- home.admin/config.scripts/blitz.data.sh | 17 +++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/home.admin/_provision_.sh b/home.admin/_provision_.sh index 4a7ea9ee8..d79f9ec4a 100755 --- a/home.admin/_provision_.sh +++ b/home.admin/_provision_.sh @@ -111,11 +111,11 @@ cd ###### SWAP File source <(/home/admin/config.scripts/blitz.data.sh status) -if [ ${isSwapExternal} -eq 0 ]; then - echo "No external SWAP found - creating ... " +if [ ${bootFromSD} -eq 0 ] && [ ${swapActive} -eq 0 ]; then + echo "No SWAP found - creating ... " /home/admin/config.scripts/blitz.data.sh swap on else - echo "SWAP already OK" + echo "SWAP already OK - dont add swap when running from SD card or already active" fi ####### FIREWALL - just install (not configure) diff --git a/home.admin/config.scripts/blitz.data.sh b/home.admin/config.scripts/blitz.data.sh index 81371ed1a..3384057bc 100644 --- a/home.admin/config.scripts/blitz.data.sh +++ b/home.admin/config.scripts/blitz.data.sh @@ -51,6 +51,9 @@ storageFullMinGB=890 dataMinGB=32 systemMinGB=32 +# swap file path +swapFilePath="/swapfile" + # check if started with sudo if [ "$EUID" -ne 0 ]; then echo "error='run as root'" @@ -78,7 +81,6 @@ fi if [ "$action" = "swap" ]; then swapAction=$2 - swapFilePath="/swapfile" swapSizeGB=8 if [ "$swapAction" = "on" ]; then @@ -115,7 +117,7 @@ if [ "$action" = "swap" ]; then exit 1 fi # make permanent - if ! grep -q "${swapFilePath} none swap sw 0 0" /etc/fstab; then + if ! grep -q "${swapFilePath}" /etc/fstab; then echo "${swapFilePath} none swap sw 0 0" >> /etc/fstab echo "# Added swapfile to /etc/fstab" fi @@ -137,9 +139,9 @@ if [ "$action" = "swap" ]; then echo "# Swapfile ${swapFilePath} is not active." fi # remove from fstab - if grep -q "${swapFilePath} none swap sw 0 0" /etc/fstab; then + if grep -q "${swapFilePath}" /etc/fstab; then echo "# Removing swapfile entry from /etc/fstab ..." - sed -i "\#${swapFilePath} none swap sw 0 0#d" /etc/fstab + sed -i "\#^${swapFilePath}#d" /etc/fstab fi # delete file if [ -f "${swapFilePath}" ]; then @@ -174,10 +176,9 @@ if [ "$action" = "status" ]; then ########################## # CHECK SWAP STATUS - isSwapExternal=0 - swapFilePath="/swapfile" + swapActive=0 if swapon --show | grep -q "${swapFilePath}"; then - isSwapExternal=1 + swapActive=1 fi ########################## @@ -915,7 +916,7 @@ if [ "$action" = "status" ]; then echo "combinedDataStorage='${combinedDataStorage}'" echo "bootFromStorage='${bootFromStorage}'" echo "bootFromSD='${bootFromSD}'" - echo "isSwapExternal='${isSwapExternal}'" + echo "swapActive='${swapActive}'" # save to cache when -inspect if [ ${userWantsInspect} -eq 1 ]; then