diff --git a/arch-setup.sh b/arch-setup.sh index ab3bd42..e6d70c6 100755 --- a/arch-setup.sh +++ b/arch-setup.sh @@ -335,15 +335,23 @@ fi step "Swap file" -if [ ! -f /swapfile ]; then - fallocate -l 2G /swapfile - chmod 600 /swapfile - mkswap /swapfile +if swapon --show --noheadings 2>/dev/null | grep -q .; then + warn "Swap already active — skipping:" + swapon --show +elif [ -f /swapfile ]; then + warn "Swap file already exists — skipping" +else + # fallocate swapfiles fail on btrfs (needs NOCOW) — use the proper tool + if [ "$(findmnt -n -o FSTYPE /)" = "btrfs" ]; then + btrfs filesystem mkswapfile --size 2g /swapfile + else + dd if=/dev/zero of=/swapfile bs=1M count=2048 status=none + chmod 600 /swapfile + mkswap /swapfile + fi swapon /swapfile grep -q '/swapfile' /etc/fstab || echo '/swapfile none swap sw 0 0' >> /etc/fstab log "2GB swap created and enabled" -else - warn "Swap file already exists — skipping" fi # =============================================================================