From 6f27ca5cb40f56e8c99442992364d087c5fad4bf Mon Sep 17 00:00:00 2001 From: Blake Romero Date: Wed, 24 May 2023 02:08:35 +0100 Subject: Add auto calculate swap size --- install-artix.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'install-artix.sh') 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 -- cgit