Last active
October 6, 2020 21:53
-
-
Save sarpavci/b5f1aecb2837cc8131dbb24036a40778 to your computer and use it in GitHub Desktop.
Ubuntu create swap space
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| swapsize=2048 | |
| grep -q "swapfile" /etc/fstab | |
| if [ $? -ne 0 ]; then | |
| echo 'swapfile not found. Adding swapfile.' | |
| fallocate -l ${swapsize}M /swapfile | |
| chmod 600 /swapfile | |
| mkswap /swapfile | |
| swapon /swapfile | |
| echo '/swapfile none swap defaults 0 0' >> /etc/fstab | |
| sysctl vm.swappiness=10 | |
| echo 'vm.swappiness=10' >> /etc/sysctl.conf | |
| sysctl vm.vfs_cache_pressure=50 | |
| echo 'vm.vfs_cache_pressure=50' >> /etc/sysctl.conf | |
| else | |
| echo 'swapfile found. No changes made.' | |
| fi | |
| cat /proc/swaps | |
| cat /proc/meminfo | grep Swap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment