{"id":179,"date":"2020-10-23T07:31:15","date_gmt":"2020-10-23T07:31:15","guid":{"rendered":"http:\/\/localhost\/anviam-blog\/?p=179"},"modified":"2024-09-26T04:29:10","modified_gmt":"2024-09-26T04:29:10","slug":"setup-swap-memory-on-ubuntu","status":"publish","type":"post","link":"https:\/\/anviam.com\/blog\/setup-swap-memory-on-ubuntu\/","title":{"rendered":"Setup Swap Memory on Linux"},"content":{"rendered":"\r\n<p>Swap memory is a virtual memory. When we have low server configuration and our system is running out of memory then to reduce cost and increase performance we need swap memory. By default swap is not set-up on any AWS or other server.<br><br>So to setup swap below commands must be consider.<br><br>1. Use command free -mh  to check we have swap already enabled or not<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img decoding=\"async\" src=\"http:\/\/localhost\/anviam-blog\/wp-content\/uploads\/2020\/10\/Swap.jpg\" alt=\"\" data-id=\"180\" data-full-url=\"http:\/\/localhost\/anviam-blog\/wp-content\/uploads\/2020\/10\/Swap.jpg\" data-link=\"http:\/\/localhost\/anviam-blog\/?attachment_id=180\" class=\"wp-image-180\"\/><\/figure><\/li><\/ul><\/figure>\r\n\r\n\r\n\r\n<p>You can see there is no memory available.<br><br>Now the further process start<br><br>Use df -h command to check we have enough space to create swap.<br><br>Create a swap file using the following command<br><br>sudo \/bin\/dd if=\/dev\/zero of=\/var\/rpswap bs=1M count=2048<\/p>\r\n\r\n\r\n\r\n<p>Now we can mark the file to swap by the following command:<br>sudo \/sbin\/mkswap \/var\/rpswap<br><br>File must be accessible to root user only use :<br>sudo chmod 600 \/var\/rpswap<br><br>To enable the swap to work <br>sudo \/sbin\/swapon \/var\/rpswap<br><br>To make this swap partition permanently in the system  add below code in \/etc\/fstab<br>\/var\/rpswap swap swap defaults 0 0<\/p>\r\n\r\n\r\n\r\n<p>Now the final step to make swap ready to use<br>sudo swapon -a<\/p>\r\n\r\n\r\n\r\n<p>Now restart the system by init 6 and check again free -mh<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img decoding=\"async\" src=\"https:\/\/anviam.com\/blog\/wp-content\/uploads\/2024\/09\/Swap2-1.jpg\" alt=\"\" data-id=\"182\" data-full-url=\"https:\/\/anviam.com\/blog\/wp-content\/uploads\/2024\/09\/Swap2-1.jpg\" data-link=\"http:\/\/localhost\/anviam-blog\/?attachment_id=182\" class=\"wp-image-182\"\/><\/figure><\/li><\/ul><\/figure>\r\n\r\n\r\n\r\n<p><br>You can see now swap is available for use.<\/p>\r\n\r\n\r\n\r\n<p><\/p>\r\n\r\n\r\n\r\n<p><br><br><\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Swap memory is a virtual memory. When we have low server configuration and our system is running out of memory then to reduce cost and increase performance we need swap memory. By default swap is not set-up on any AWS or other server. So to setup swap below commands must be consider. 1. Use command [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":1637,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[55,78,86],"class_list":["post-179","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-anviam","tag-linux","tag-swap","tag-ubuntu"],"rttpg_featured_image_url":{"full":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2023\/01\/internet.png",396,255,false],"landscape":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2023\/01\/internet.png",396,255,false],"portraits":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2023\/01\/internet.png",396,255,false],"thumbnail":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2023\/01\/internet-150x150.png",150,150,true],"medium":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2023\/01\/internet-300x193.png",300,193,true],"large":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2023\/01\/internet.png",396,255,false],"1536x1536":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2023\/01\/internet.png",396,255,false],"2048x2048":["https:\/\/anviam.com\/blog\/wp-content\/uploads\/2023\/01\/internet.png",396,255,false]},"rttpg_author":{"display_name":"kubbiblog","author_link":"https:\/\/anviam.com\/blog\/author\/kubbiblog\/"},"rttpg_comment":51,"rttpg_category":"<a href=\"https:\/\/anviam.com\/blog\/category\/anviam\/\" rel=\"category tag\">Anviam<\/a>","rttpg_excerpt":"Swap memory is a virtual memory. When we have low server configuration and our system is running out of memory then to reduce cost and increase performance we need swap memory. By default swap is not set-up on any AWS or other server. So to setup swap below commands must be consider. 1. Use command&hellip;","_links":{"self":[{"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/posts\/179"}],"collection":[{"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/comments?post=179"}],"version-history":[{"count":2,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/posts\/179\/revisions"}],"predecessor-version":[{"id":2007,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/posts\/179\/revisions\/2007"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/media\/1637"}],"wp:attachment":[{"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/media?parent=179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/categories?post=179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anviam.com\/blog\/wp-json\/wp\/v2\/tags?post=179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}