Advertisement
niammuddin

membuat swap di linux otomatis

Aug 23rd, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.52 KB | None | 0 0
  1. #!/bin/bash
  2. if [ "$*" == "" ]; then
  3.     echo
  4.     echo "Usage:"
  5.     echo
  6.     echo "$0 <swap size>"
  7.     echo
  8.     echo "$0 2G"
  9.     echo "to create a 2GB swap file"
  10.     echo
  11.     echo
  12.     exit 1
  13. fi
  14.  
  15. TAMANHO=$1;
  16.  
  17. fallocate -l $TAMANHO /swapfile
  18. chmod 600 /swapfile
  19. mkswap /swapfile
  20. swapon /swapfile
  21.  
  22. echo "/swapfile   none    swap    sw    0   0" >> /etc/fstab
  23.  
  24. echo "vm.swappiness=10" >> /etc/sysctl.conf
  25. echo "vm.vfs_cache_pressure = 50" >> /etc/sysctl.conf
  26. sysctl -p
  27.  
  28. echo "Swap file created and enabled."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement