Swap: skip when already active, btrfs-aware creation (fallocate fails on btrfs)
This commit is contained in:
parent
18e97e75ff
commit
67f10da503
1 changed files with 14 additions and 6 deletions
|
|
@ -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
|
||||
|
||||
# =============================================================================
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue