{"id":1585,"date":"2026-04-02T13:08:56","date_gmt":"2026-04-02T18:08:56","guid":{"rendered":"https:\/\/it.thelibrarie.com\/weblog\/?p=1585"},"modified":"2026-04-02T13:08:56","modified_gmt":"2026-04-02T18:08:56","slug":"add-swap-drive-to-linux","status":"publish","type":"post","link":"https:\/\/it.thelibrarie.com\/weblog\/2026\/04\/add-swap-drive-to-linux\/","title":{"rendered":"Add swap drive to linux"},"content":{"rendered":"\n<p>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&#8217;d have to force a stop and start from the Lightsail AWS interface.<\/p>\n\n\n\n<p>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&#8217;re down to an almost 8 hour maximum uptime before it locks up. Great.<\/p>\n\n\n\n<p>Running free I see that there&#8217;s no swap. Probably a RAM usage issue from the database side, so I need to run the following:<\/p>\n\n\n\n<p><code>fallocate -l 2G \/swapfile &amp;&amp; chmod 600 \/swapfile &amp;&amp; mkswap \/swapfile &amp;&amp; swapon \/swapfile &amp;&amp; sed -i '$ a\\\/swapfile swap swap defaults 0 0' \/etc\/fstab<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;d have to force a stop and start from the Lightsail AWS interface. My workaround was to schedule a monthly reboot. &hellip; <a href=\"https:\/\/it.thelibrarie.com\/weblog\/2026\/04\/add-swap-drive-to-linux\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Add swap drive to linux<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1585","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/1585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/comments?post=1585"}],"version-history":[{"count":1,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/1585\/revisions"}],"predecessor-version":[{"id":1586,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/1585\/revisions\/1586"}],"wp:attachment":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/media?parent=1585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/categories?post=1585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/tags?post=1585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}