Add swap drive to linux

My tiny lightsail ubuntu server is running a java-based application along with a MySQL/MariaDB database backend with a small 2GB of RAM allotment. Every 30 or so days the system would lock up and I’d have to force a stop and start from the Lightsail AWS interface.

My workaround was to schedule a monthly reboot. Then it started happening more frequently, so I changed the scheduled reboot to be weekly. But now we’re down to an almost 8 hour maximum uptime before it locks up. Great.

Running free I see that there’s no swap. Probably a RAM usage issue from the database side, so I need to run the following:

fallocate -l 2G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile && sed -i '$ a\/swapfile swap swap defaults 0 0' /etc/fstab

Leave a Reply

Your email address will not be published. Required fields are marked *