summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlake Romero <blake@blkrom.com>2023-05-24 02:08:35 +0100
committerBlake Romero <blake@blkrom.com>2023-05-24 02:08:35 +0100
commit6f27ca5cb40f56e8c99442992364d087c5fad4bf (patch)
treeb546a540b56cbe6c254f4a3dfbb4245cebe74fd6
parent5f375e2ab40f74688572b00b11ff6edacb0f8c87 (diff)
Add auto calculate swap size
-rwxr-xr-xinstall-artix.sh13
1 files changed, 12 insertions, 1 deletions
diff --git a/install-artix.sh b/install-artix.sh
index 6f7fabf..2497773 100755
--- a/install-artix.sh
+++ b/install-artix.sh
@@ -29,7 +29,6 @@ drive=/dev/DRIVE
boot="${drive}1"
swap="${drive}2"
root="${drive}3"
-swap_size="16G"
timezone=Europe/London
locale=en_GB
@@ -70,6 +69,18 @@ while true; do
fi
done
+# Use RAM size to calculate SWAP size
+# Note: if swap_size is set in CONFIG, that value will be used instead
+if [[ -z $swap_size ]]; then
+ pacman --needed --noconfirm -Sy bc
+ ram_kB=$(awk 'FNR==1 {print $2}' /proc/meminfo)
+ ram_gb=$(bc <<< "${ram_kB} / 1000^2")
+ swap_size="$(bc <<< "sqrt(${ram_gb})) * 4")G"
+fi
+
+# Check at least 1GB of swap
+[ "${ram_gb}" -lt 1 ] && { echo "ERR: not enough ram for SWAP"; exit; }
+
# Create partitions
boot_type="BIOS Boot"
[ -d /sys/firmware/efi/efivars/ ] && boot_type=U