Advertisement
s4ros

create-swap.sh

Feb 7th, 2022
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.47 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [[ $1 == "-d" ]];then
  4.   shift
  5.   set -x
  6. fi
  7.  
  8. [ $(id -u) -ne 0 ] && {
  9.   echo You need to be root; exit 1
  10. }
  11.  
  12. _usage() {
  13.   echo "
  14. Usage: $0 [-d] <size>
  15.  -d  - (optional) debug mode
  16.  <size> - size of the SWAP file in GB
  17.  "
  18. }
  19.  
  20. if [[ $# -lt 1 ]]; then
  21.   _usage
  22.   exit 1
  23. fi
  24.  
  25. fallocate -l ${1}G /${1}GB.swap
  26. chmod 0600 /${1}GB.swap
  27. mkswap /${1}GB.swap
  28. swapon /${1}GB.swap
  29. cat << EOF | tee -a /etc/fstab
  30. /${1}GB.swap none swap sw 0 0
  31. EOF
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement