Platform: Ubuntu 16.04
- It is common practice to create swap that equals to your RAM. So firstly, you should find out your RAM:
free -m
Which outputs like:
total used free shared buff/cache available
Mem: 32046 18549 4831 1273 8665 11644
In my case RAM = 32046 (mb). So the amount of swap should be around that value. The command to determine RAM automatically:
free -m |sed -n 2p| awk '{print $2}'
- After you've found your $SWAP_SIZE you can add swap:
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=${SWAP_SIZE}
sudo /sbin/mkswap /var/swap.1
sudo chmod 600 /var/swap.1
sudo /sbin/swapon /var/swap.1
sudo bash -c "echo '/var/swap.1 swap swap defaults 0 0' >> /etc/fstab"