{"id":3322,"date":"2017-02-28T19:26:25","date_gmt":"2017-02-28T19:26:25","guid":{"rendered":"https:\/\/qbytes.cloud\/?p=3322"},"modified":"2017-02-28T19:26:25","modified_gmt":"2017-02-28T19:26:25","slug":"create-swap-space","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2017\/02\/28\/create-swap-space\/","title":{"rendered":"Use a File for Additional Swap Space"},"content":{"rendered":"<p>The following dd command example creates a swap file with the name \u201cswapfile\u201d under \/root directory with a size of 8192MB (8GB). <\/p>\n<p>To create the swap space (non-persistent):<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# dd if=\/dev\/zero of=\/root\/myswapfile bs=1m count=8192;\n8192+0 records in\n8192+0 records out\n<\/pre>\n<p>Change the permission of the swap file so that only root can access it.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# chmod 0600 \/root\/myswapfile;\n\n<\/pre>\n<p>Make this file as a swap file using mkswap command.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# mkswap \/root\/myswapfile\n<\/pre>\n<p>Enable the newly created swapfile.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# swapon \/root\/myswapfile\n<\/pre>\n<p>To make this swap file available as a swap area even after the reboot, add the following line to the \/etc\/fstab file.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# cat \/etc\/fstab\n\/root\/myswapfile               swap                    swap    defaults        0 0\n<\/pre>\n<p>Verify whether the newly created swap area is available for your use.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# swapon -s\nFilename                        Type            Size    Used    Priority\n\/dev\/sda2                       partition       4192956 0       -1\n\/root\/myswapfile                file            1048568 0       -2\n\n# free -k\n             total       used       free     shared    buffers     cached\nMem:       3082356    3022364      59992          0      52056    2646472\n-\/+ buffers\/cache:     323836    2758520\nSwap:      5241524          0    5241524\n<\/pre>\n<p>Note: In the output of swapon -s command, the Type column will say \u201cfile\u201d if the swap space is created from a swap file.<\/p>\n<p>If you don\u2019t want to reboot to verify whether the system takes all the swap space mentioned in the \/etc\/fstab, you can do the following, which will disable and enable all the swap partition mentioned in the \/etc\/fstab<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# swapoff -a\n\n# swapon -a\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following dd command example creates a swap file with the name \u201cswapfile\u201d under \/root directory with a size of 8192MB (8GB). To create the swap space (non-persistent): # dd if=\/dev\/zero of=\/root\/myswapfile bs=1m count=8192; 8192+0 records in 8192+0 records out Change the permission of the swap file so that only root can access it. # &#8230; <a title=\"Use a File for Additional Swap Space\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2017\/02\/28\/create-swap-space\/\" aria-label=\"Read more about Use a File for Additional Swap Space\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-3322","post","type-post","status-publish","format-standard","hentry","category-administration"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/3322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=3322"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/3322\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=3322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=3322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=3322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}