Skip to content

Instantly share code, notes, and snippets.

@sgnl
Created April 29, 2021 23:59
Show Gist options
  • Save sgnl/71f538458085b79cd3c65685ac5b1cec to your computer and use it in GitHub Desktop.
Save sgnl/71f538458085b79cd3c65685ac5b1cec to your computer and use it in GitHub Desktop.
Ubuntu Check for Swapfile or Create it (4096 default)
#!/bin/sh
swapon_results=$(swapon -s)
if [[ $swapon_results != 0]]; then
dd if=/dev/zero of=/swapfile count=4096 bs=1M
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab
else
echo "Swap file found. Nothing to do :E"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment