{"id":827,"date":"2013-08-23T16:35:05","date_gmt":"2013-08-23T13:35:05","guid":{"rendered":"http:\/\/www.fatihacar.com\/blog\/?p=827"},"modified":"2013-08-23T16:38:58","modified_gmt":"2013-08-23T13:38:58","slug":"how-to-increase-swap-space-size-in-linux-system","status":"publish","type":"post","link":"https:\/\/www.fatihacar.com\/blog\/how-to-increase-swap-space-size-in-linux-system\/","title":{"rendered":"How to Increase Swap Space Size in Linux System"},"content":{"rendered":"<p>Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.fatihacar.com\/blog\/resimler\/swapspace.jpg\" alt=\"swapspace\" width=\"400\" height=\"315\" class=\"aligncenter size-full wp-image-829\" srcset=\"https:\/\/www.fatihacar.com\/blog\/resimler\/swapspace.jpg 400w, https:\/\/www.fatihacar.com\/blog\/resimler\/swapspace-300x236.jpg 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/p>\n<p>You can either use a dedicated harddisk partition to add new swap space, or create a swap file on an existing filesystem and use it as swap space.<\/p>\n<p><strong>Show Swap Size<\/strong><\/p>\n<blockquote><p>\n<strong>Note :<\/strong> free command displays RAM and Swap space of system.<br \/>\n# free<br \/>\n<strong>Note :<\/strong> swapon -s command displays partion of swap space.<br \/>\n# swapon -s\n<\/p><\/blockquote>\n<p><!--more--><br \/>\n<strong>Method 1 : Add New Harddisk<\/strong><\/p>\n<p>If you have an additional hard disk or space available in an existing disk, you can create a partition using fdisk command. For example, this disk partion is \/dev\/sde1<br \/>\nNow setup this newly created partition as swap area using the <strong>mkswap<\/strong> command as shown below.<\/p>\n<blockquote><p>\n# mkswap \/dev\/sde1<br \/>\n<strong>Note :<\/strong> Enable the swap partition for usage using swapon command as shown below.<br \/>\n# swapon \/dev\/sde1<br \/>\n<strong>Note :<\/strong> To make this swap space partition available even after the reboot, add the following line to the \/etc\/fstab file.<br \/>\n# vi \/etc\/fstab<br \/>\n\/dev\/sde1               swap                    swap    defaults        0 0<\/p>\n<p><strong>Note :<\/strong> After all of that, you can see swap size with swapon -s command.\n<\/p><\/blockquote>\n<p><strong>Method 2 : Using A File For Swap Space<\/strong><\/p>\n<p>If you don\u2019t have any additional disks, you can create a file somewhere on your filesystem, and use that file for swap space.<\/p>\n<blockquote><p>\n<strong>Note :<\/strong> The following dd command example creates a swap file with the name \u201cmynewswap&#8221; under \/root directory with a size of 1024MB (1GB).<br \/>\n# dd if=\/dev\/zero of=\/root\/mynewswap bs=1M count=1024<br \/>\n1024+0 records in<br \/>\n1024+0 records out<\/p>\n<p><strong>Note :<\/strong> Change the permission of the swap file so that only root can access it.<\/p>\n<p># chmod 600 \/root\/mynewswap<\/p>\n<p><strong>Note :<\/strong> Make this file as a swap file using mkswap command.<\/p>\n<p># mkswap \/root\/mynewswap<br \/>\nSetting up swapspace version 1, size = 1073737 kB<\/p>\n<p><strong>Note :<\/strong> Enable the newly created swapfile.<\/p>\n<p># swapon \/root\/myswapfile<\/p>\n<p><strong>Note :<\/strong> 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<p># cat \/etc\/fstab<br \/>\n\/root\/mynewswap               swap                    swap    defaults        0 0<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a&#8230;<\/p>\n","protected":false},"author":37,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[18],"tags":[14,22],"class_list":["post-827","post","type-post","status-publish","format-standard","hentry","category-linux-unix","tag-database-administration","tag-system-administration"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p39NFI-dl","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/comments?post=827"}],"version-history":[{"count":2,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/827\/revisions"}],"predecessor-version":[{"id":830,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/827\/revisions\/830"}],"wp:attachment":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/media?parent=827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/categories?post=827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/tags?post=827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}