{"id":12234,"date":"2024-04-04T12:55:58","date_gmt":"2024-04-04T07:25:58","guid":{"rendered":"https:\/\/www.skynats.com\/?p=12234"},"modified":"2025-01-08T20:36:53","modified_gmt":"2025-01-08T15:06:53","slug":"how-to-add-swap-space-on-alma-linux-8","status":"publish","type":"post","link":"https:\/\/www.skynats.com\/blog\/how-to-add-swap-space-on-alma-linux-8\/","title":{"rendered":"How To Add Swap Space on Alma Linux 8"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"509\" height=\"99\" sizes=\"(max-width: 509px) 100vw, 509px\" src=\"https:\/\/www.skynats.com\/blog\/wp-content\/uploads\/2024\/04\/images-1.png\" alt=\"\" class=\"wp-image-12253\" style=\"width:313px;height:auto\" srcset=\"https:\/\/www.skynats.com\/blog\/wp-content\/uploads\/2024\/04\/images-1.png 509w, https:\/\/www.skynats.com\/blog\/wp-content\/uploads\/2024\/04\/images-1-300x58.png 300w\" \/><\/figure>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">Swap space is an important part of memory management since it protects the server from memory overloads and increases system stability. Here is how to set up swap space on an Almalinux8 server<a href=\"https:\/\/almalinux.org\/\" target=\"_blank\" rel=\"noopener\">.<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-small-font-size\" id=\"h-steps-for-setting-up-swap-space-on-almalinux-8\">Steps for setting up Swap Space on AlmaLinux 8 :<\/h3>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">To do this, we need to check the information on currently active swap spaces. The swapon command gives a list of active swap devices or files, with their sizes and utilisation.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>#swapon -s<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">To check the system&#8217;s current memory and swap utilisation, run the <strong>\u201cfree\u201d<\/strong> command:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>#free -g<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading has-small-font-size\" id=\"h-output\"><strong>Output :<\/strong><\/h5>\n\n\n\n<figure style=\"font-size:15px\" class=\"wp-block-table\"><table><tbody><tr><td><\/td><td>total<\/td><td>used<\/td><td>free<\/td><td>shared<\/td><td>buff\/cache<\/td><td>available<\/td><\/tr><tr><td>Mem<\/td><td>251<\/td><td>196<\/td><td>30<\/td><td>0<\/td><td>25<\/td><td>58<\/td><\/tr><tr><td>Swap<\/td><td>4<\/td><td>3<\/td><td>1<\/td><td><\/td><td><\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">Also check the disk usage and availability using df -h command<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>#df -h<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">Now, Create a new swap file of 8GB using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>#dd if=\/dev\/zero of=\/swap bs=1M count=8192<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">In this command, <strong>\u2018of\u2019<\/strong> specifies the output file. ie, the partition or disk name where you want to write the data, here I am using the partition name \/swap.<\/p>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\"><strong>\u2018Bs\u2019<\/strong> is the block size (bs) for both reading and writing data. In this command, 1M sets the block size to 1 megabyte. And <strong>\u2018count\u2019<\/strong> is the number of blocks to copy. In this command, 8192 is the count of blocks. Since the block size is set to 1 megabyte, this will create a swap file of 8GB.<\/p>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">We can use the ls -lh command to view and verify the space reserved for the swap<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>#ls -lh \/swap<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">Also, specify the correct permissions for the swap file for improved security.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>#chmod 600 \/swap<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">The next step is to format it as a swap space using the mkswap command.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>#mkswap \/swap<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">Then activate the swap space located at \/swap using the \u2018swapon\u2019 command<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>#swapon \/swap<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">Now, use the \u2018swapon -s\u2019 command to check that the swap space is active<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>#swapon -s<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">Always remember to configure the partition to mount at boot time. This can be accomplished by configuring the fstab file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Obtain the UUID of the filesystem \/swap using the blkid command:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>#blkid \/swap<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\"><strong>\/swap: UUID=&#8221;7e00b266-887a-49f8-a2ca-e0b417899c1a&#8221; TYPE=&#8221;swap&#8221;<\/strong><\/p>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">Now edit the fstab file to define how filesystems should be mounted at boot time.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>#vim \/etc\/fstab<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:15px\"><strong>UUID=364e9b36-4d85-46a2-91fe-25443efaea87e9 &nbsp; &nbsp; \/ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xfs &nbsp; &nbsp; &nbsp; defaults &nbsp; &nbsp; 0&nbsp; &nbsp; &nbsp; 1<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:15px\"><strong>UUID=6f11dd66-bfa0-40c7-8e5b-a1b39e567d72&nbsp; &nbsp; &nbsp; &nbsp; \/boot&nbsp; &nbsp; xfs &nbsp; &nbsp; &nbsp; defaults &nbsp; &nbsp; 0&nbsp; &nbsp; &nbsp; 0<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:15px\"><strong>UUID=512e47f5-3d6a-48f4-8eaf-dfccefec109e &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; swap &nbsp; swap&nbsp; &nbsp; defaults &nbsp; &nbsp; 0&nbsp; &nbsp; &nbsp; 0<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\" style=\"font-size:15px\"><strong>UUID=7e00b266-887a-49f8-a2ca-e0b417899c1a&nbsp; &nbsp; &nbsp; &nbsp; swap &nbsp; swap&nbsp; &nbsp; defaults &nbsp; &nbsp; 0&nbsp; &nbsp; &nbsp; 0<\/strong><\/p>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">At last, run the \u2018free\u2019 command to verify that the changes made to the swap space configurations were applied correctly.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>#free -g<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading has-small-font-size\" id=\"h-output-0\">Output :<\/h5>\n\n\n\n<figure class=\"wp-block-table is-style-regular\" style=\"font-size:15px\"><table><tbody><tr><td><\/td><td>total<\/td><td>used<\/td><td>free<\/td><td>shared<\/td><td>buff\/cache<\/td><td>available<\/td><\/tr><tr><td>Mem<\/td><td>251<\/td><td>190<\/td><td>36<\/td><td>0<\/td><td>25<\/td><td>58<\/td><\/tr><tr><td>Swap<\/td><td>12<\/td><td>4<\/td><td>8<\/td><td><\/td><td><\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">This is how we can add swap space to an Almalinux8 server. The expanded swap space setup will allow the server to meet the needs of your workload, ensuring an efficient and uninterrupted computing experience.<\/p>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">The members of our&nbsp;<a href=\"https:\/\/www.skynats.com\/blog\/\">Support Team<\/a>&nbsp;are available to help you with &#8220;How To Add Swap Space on Alma Linux 8&#8221; in case you experience any problems or glitches.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Swap space is an important part of memory management since it protects the server from memory overloads and increases system stability. Here is how to set up swap space on an Almalinux8 server. Steps for setting up Swap Space on AlmaLinux 8 : To do this, we need to check the information on currently active [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[766,778,5],"tags":[841,840],"class_list":["post-12234","post","type-post","status-publish","format-standard","hentry","category-almalinux-8","category-almalinux-server","category-blog","tag-almalinux8","tag-swap-space"],"_links":{"self":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/12234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/comments?post=12234"}],"version-history":[{"count":0,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/12234\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/media?parent=12234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/categories?post=12234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/tags?post=12234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}