{"id":1700,"date":"2021-12-16T12:09:09","date_gmt":"2021-12-16T09:09:09","guid":{"rendered":"https:\/\/files2.tojikon.net\/files-cloud\/2021\/02\/26\/ubuntu-increase-swap-guide-2\/https:\/\/files2.tojikon.net\/files-cloud\/2021\/02\/26\/ubuntu-increase-swap-guide-2\/"},"modified":"2021-12-16T12:09:09","modified_gmt":"2021-12-16T09:09:09","slug":"ubuntu-increase-swap-guide","status":"publish","type":"post","link":"https:\/\/tojikon.net\/en\/1700-ubuntu-increase-swap-guide\/","title":{"rendered":"Ubuntu: increase swap [Guide]"},"content":{"rendered":"<section id=\"related_posts\">\n<div class=\"block-head\">\n<h3>Related Articles<\/h3>\n<\/div>\n<\/section>\n<p>When installing Ubuntu, a swap file is created. The swap file is usually about 2 GB, though sometimes it can be larger. This swap file can do the trick for most Ubuntu users these days, as most modern PCs have a lot of performance and RAM.<\/p>\n<p>If you rely on swap a lot on Ubuntu because you\u2019re regularly using up your physical RAM, the 2-4 GB swap file isn\u2019t enough. Thankfully, it is possible to increase the swap\u2019s size from the default to something much larger.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-396198 size-full\" src=\"https:\/\/files2.tojikon.net\/files-cloud\/wp-content\/uploads\/2021\/12\/ubuntu-increase-swap-guide.png\" alt=\"Ubuntu: increase swap\" width=\"1200\" height=\"622\"\/>To start the process of increasing your swap size, you\u2019ll need to open up a terminal window. Sadly, the Ubuntu swap file is a system-level file, and it requires root terminal access to modify.<\/p>\n<p>To open up a terminal window on the Ubuntu desktop, press\u00a0<strong>Ctrl + Alt + T\u00a0<\/strong>on the keyboard. Alternatively, you can launch the terminal by searching for \u201cTerminal\u201d in the app menu.<\/p>\n<h3>Turn off default swap<\/h3>\n<p>Before you can create a new swap file, you must turn off the old one. To turn off the old swap, go to the Linux terminal and execute the\u00a0<strong>swapoff\u00a0<\/strong>command on the Ubuntu swapfile located in the <code>\/<\/code> directory.<\/p>\n<pre>\nsudo swapoff \/swapfile\n<\/pre>\n<p>Once the default Ubuntu swap file is disabled, verify it. You can verify the swap by executing the\u00a0<strong>free\u00a0<\/strong>command with the\u00a0<strong>-h\u00a0<\/strong>command-line switch.<\/p>\n<pre>\nfree -h\n<\/pre>\n<p>Look at the \u201cSwap:\u201d column. If it says 0B in each spot, you\u2019ve effectively shut off the Ubuntu default swap file. If not, re-run the\u00a0<strong>swapoff\u00a0<\/strong>command and try again.<\/p>\n<h3>Delete the existing swap file<\/h3>\n<p>Now that the default Ubuntu swap file has been turned off, it needs to be deleted from the system. Why? If we do not delete the default swap file, it could conflict with the new swap file we create, as they will be using similar file names.<\/p>\n<p>To delete the default swap file from your Ubuntu system, you must elevate your terminal session to the root account. The root account is the only account on your Ubuntu system that can delete files and folders from the <code>\/<\/code> directory.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-396198 size-full\" src=\"https:\/\/files2.tojikon.net\/files-cloud\/wp-content\/uploads\/2021\/12\/ubuntu-increase-swap-guide.png\" alt=\"\" width=\"1200\" height=\"622\"\/><\/p>\n<p>To access the root account in Ubuntu, make use of the\u00a0<strong>sudo -s\u00a0<\/strong>command below.<\/p>\n<pre>\nsudo -s\n<\/pre>\n<p>Once you\u2019ve got root access in the terminal, use the\u00a0<strong>rm\u00a0<\/strong>command to delete the default Ubuntu swap file from your computer.\u00a0<\/p>\n<pre>\ncd \/\nrm swapfile\n<\/pre>\n<p>When the\u00a0<strong>rm\u00a0<\/strong>command is run, the default Ubuntu swap file will be gone from your system. To confirm that it is gone, execute the\u00a0<strong>ls\u00a0<\/strong>command in the <code>\/<\/code> directory. If you do not see \u201cswapfile\u201d in the files\u2019 list, it has been successfully deleted.<\/p>\n<pre>\nls\n<\/pre>\n<h3>Create a new swap file<\/h3>\n<p>Now that the default Ubuntu swap file has been deleted from your system, it is time to create a new one. To make a new swap file, you\u2019ll need to use the <strong>dd<\/strong> command. The\u00a0<strong>dd<\/strong> command is handy and will be able to create a new swap file as big or as small as you like.<\/p>\n<p>To create a new swap file, you must first determine the size in Megabytes, as that\u2019s what <strong>dd<\/strong> uses. For example, to make an 8 GB swap file, you\u2019d do 8 x 1024, which calculates to 8192 MB.<\/p>\n<p>Once you\u2019ve calculated how large you want your new Ubuntu swap file to be, enter it into the command below to create a new swap file.<\/p>\n<pre>\nsudo -s\ndd if=\/dev\/zero of=\/swapfile bs=1M count=YOUR_MEGABYTE_NUMBER_HERE\n<\/pre>\n<p>The\u00a0<strong>dd<\/strong> command will take a bit of time to complete. When it is done, your new swap file will be in the <code>\/<\/code> directory, where the old swap file was.<\/p>\n<p>After creating the new swap file, use the\u00a0<strong>chmod\u00a0<\/strong>command to update the swap file to the correct permissions.\u00a0<\/p>\n<pre>\nchmod 600 \/swapfile\n<\/pre>\n<h3>Enable new swap\u00a0<\/h3>\n<p>With the new swap file created and its permissions up to date, it is time to enable the new swap on your system. To do that, we\u2019ll need to make use of the <strong>mkswap\u00a0<\/strong>command. It will scan the new swap file and allow it to be used as swap space.<\/p>\n<p>Using the\u00a0<strong>mkswap\u00a0<\/strong>command below, enable your new swap file in Ubuntu.<\/p>\n<pre>\nmkswap \/swapfile\n<\/pre>\n<p>Once the\u00a0<strong>mkswap\u00a0<\/strong>command is executed, you\u2019ll see a command-line output that says \u201csetting up swap space,\u201d followed by the swap UUID and its size.\u00a0<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-396197 size-full\" src=\"https:\/\/files2.tojikon.net\/files-cloud\/wp-content\/uploads\/2021\/12\/ubuntu-increase-swap-guide-1.png\" alt=\"\" width=\"1200\" height=\"1146\"\/><\/p>\n<p>After executing the\u00a0<strong>mkswap\u00a0<\/strong>command, it is time to use the\u00a0<strong>swapon\u00a0<\/strong>command to turn on the new swap file in Ubuntu. Using the\u00a0<strong>swapon\u00a0<\/strong>command below, turn on the new swap in Ubuntu.<\/p>\n<pre>\nswapon \/swapfile\n<\/pre>\n<p>When the new swap file is turned on, you will be able to verify it by executing the\u00a0<strong>free -h\u00a0<\/strong>command. Look under the \u201cSwap:\u201d column to confirm that it is working.\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Related Articles When installing Ubuntu, a swap file is created. The swap file is usually about 2 GB, though sometimes it can be larger. This swap file can do the trick for most Ubuntu users these days, as most modern PCs have a lot of performance and RAM. If you rely on swap a lot &hellip;<\/p>\n","protected":false},"author":1,"featured_media":1701,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[33],"_links":{"self":[{"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/posts\/1700"}],"collection":[{"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/comments?post=1700"}],"version-history":[{"count":0,"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/posts\/1700\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/media\/1701"}],"wp:attachment":[{"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/media?parent=1700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/categories?post=1700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tojikon.net\/en\/wp-json\/wp\/v2\/tags?post=1700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}