add vps-addswap
[webi-installers/.git] / vps-addswap / install.sh
1 #!/bin/bash
2
3 {
4     set -e
5     set -u
6
7     default_size=2G
8     my_size=${1:-$default_size}
9
10     # Allocate a swapfile
11     fallocate -l "$my_size" /var/swapfile
12
13     # Only allow root to read it
14     # (this is not sufficient security for sensitive data)
15     chmod 0600 /var/swapfile
16
17     # Activate the swap
18     mkswap /var/swapfile
19     swapon /var/swapfile
20
21     # Cause swap to be activated on boot
22     echo '/var/swapfile none swap sw 0 0' | tee -a /etc/fstab
23
24 }