{"id":5786,"date":"2015-01-05T21:51:58","date_gmt":"2015-01-05T13:51:58","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=5786"},"modified":"2023-04-28T09:47:21","modified_gmt":"2023-04-28T09:47:21","slug":"add-linux-swap-space-on-centos","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/add-linux-swap-space-on-centos\/","title":{"rendered":"How to Add Linux Swap Space on CentOS 6 VPS"},"content":{"rendered":"<p>Swap space is a disk space that is used as a temporary memory extension when the physical memory is full. CentOS 6 is an older version of the CentOS operating system that may still be used in some environments. In this guide, we will show you how to add Linux swap space on CentOS 6 VPS.<\/p>\n<h2>Step 1: Check Available Disk Space<\/h2>\n<p>Before adding swap space, you need to check the available disk space on your VPS. Run the following command to view the disk usage:<\/p>\n<pre>df -h<\/pre>\n<p>This command will display a list of mounted file systems and their disk usage information.<\/p>\n<h2>Step 2: Create a Swap File<\/h2>\n<p>Next, you need to create a swap file using the dd command. Run the following command to create a 1 GB swap file:<\/p>\n<pre>sudo dd if=\/dev\/zero of=\/swapfile bs=1024 count=1048576<\/pre>\n<p>This command will create a file called swapfile in the root directory with a size of 1 GB.<\/p>\n<h2>Step 3: Set File Permissions<\/h2>\n<p>After creating the swap file, you need to set the correct file permissions using the chmod command. Run the following command:<\/p>\n<pre>sudo chmod 600 \/swapfile<\/pre>\n<p>This command will set the file permissions to 600, which means that only the root user can read and write to the file.<\/p>\n<h2>Step 4: Set Up Swap Space<\/h2>\n<p>Now that you have created the swap file, you need to set it up as swap space using the mkswap command. Run the following command:<\/p>\n<pre>sudo mkswap \/swapfile<\/pre>\n<p>This command will set up the swap file as swap space on your VPS.<\/p>\n<h2>Step 5: Enable the Swap File<\/h2>\n<p>Finally, you need to enable the swap file using the swapon command. Run the following command:<\/p>\n<pre>sudo swapon \/swapfile<\/pre>\n<p>This command will enable the swap file as swap space on your VPS.<\/p>\n<h2>Step 6: Configure Swap Space<\/h2>\n<p>To make the swap file permanent, you need to configure it in the \/etc\/fstab file. Run the following command to open the file in the nano text editor:<\/p>\n<pre>sudo nano \/etc\/fstab<\/pre>\n<p>Add the following line at the end of the file:<\/p>\n<pre>\/swapfile swap swap defaults 0 0<\/pre>\n<p>Save the changes and exit the editor by pressing Ctrl + X, then Y, and finally Enter.<\/p>\n<h2>Step 7: Verify Swap Space<\/h2>\n<p>To verify that the swap space has been set up correctly, you can run the following command:<\/p>\n<pre>free -m<\/pre>\n<p>This command will display the memory and swap usage information on your VPS.<\/p>\n<h2>Commands Mentioned:<\/h2>\n<ul>\n<li><span class=\"fw-bold\">df -h<\/span> &#8211; Check available disk space<\/li>\n<li><span class=\"fw-bold\">sudo dd if=\/dev\/zero of=\/swapfile bs=1024 count=1048576<\/span> &#8211; Create a swap file<\/li>\n<li><span class=\"fw-bold\">sudo chmod 600 \/swapfile<\/span> &#8211; Set file permissions<\/li>\n<li><span class=\"fw-bold\">sudo mkswap \/swapfile<\/span> &#8211; Set up swap space<\/li>\n<li><span class=\"fw-bold\">sudo swapon \/swapfile<\/span> &#8211; Enable the swap file<\/li>\n<li><span class=\"fw-bold\">sudo nano \/etc\/fstab<\/span> &#8211; Configure swap space<\/li>\n<li><span class=\"fw-bold\">free -m<\/span> &#8211; Verify swap space<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>In this guide, we have shown you how to add Linux swap space on CentOS 6 VPS. By following these steps, you can create and enable a swap file to extend the physical memory of your VPS. It is important to remember that adding swap space is not a replacement for physical memory and should only be used as a temporary solution. We hope this guide has been helpful to you. If you have any comments or suggestions for improvements, please feel free to share them below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Swap space is a disk space that is used as a temporary memory extension when the physical memory is full. CentOS 6 is an older version of the CentOS operating&#8230;<\/p>\n","protected":false},"author":6,"featured_media":6280,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[2055,1066],"tags":[1251,1536,1815],"class_list":["post-5786","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-system-performance","tag-centos-6","tag-linux","tag-swap"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=5786"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5786\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/6280"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=5786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=5786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=5786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}