{"id":2630,"date":"2016-09-02T12:53:11","date_gmt":"2016-09-02T16:53:11","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=2630"},"modified":"2018-01-12T14:07:32","modified_gmt":"2018-01-12T19:07:32","slug":"create-swap-file-ubuntu-16","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/","title":{"rendered":"How to create a swap file in Ubuntu 16"},"content":{"rendered":"<h1>How to create a swap file in Ubuntu 16<\/h1>\n<p>A swap file is a method of extending virtual memory. Unix and Linux systems commonly have a dedicated swap partition available for virtual memory, but occasionally you may be tasked with running a server without one, or with one that isn&#8217;t large enough for the server&#8217;s tasks. In that case, it&#8217;s a good idea to create a swap file as a replacement for or aid to a swap partition.<\/p>\n<h2>Getting started<\/h2>\n<p>To follow our guide to setting up a swap file, you&#8217;ll need:<br \/>\n\u2022 1 Node (<a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\" target=\"_blank\">Cloud Server<\/a> or <a href=\"http:\/\/www.globo.tech\/dedicated-server-hosting\" target=\"_blank\">Dedicated Server<\/a>) running Ubuntu 16.<br \/>\n\u2022 Root access to the server<\/p>\n<h2>Tutorial<\/h2>\n<p>First, verify your system&#8217;s current SWAP space configuration by using the swapon command:<br \/>\n<code>swapon -s<\/code><\/p>\n<p>With swap available, you&#8217;ll see something like this output.<br \/>\n<code class=\"gris\">swapon -s<br \/>\nFilename        Type            Size    Used    Priority<br \/>\n\/dev\/sda2       partition       8388604 9820    -1<\/code><\/p>\n<p>If running this command produces no output, then your system unfortunately doesn&#8217;t have a swap file. In order to add swap space to your system, you can proceed with the following steps.<\/p>\n<p>The first task is to check the available space that your system has. To do so, use the &#8220;disk free&#8221; command with the &#8220;human readable&#8221; flag, or df -h.<br \/>\n<code>df -h<\/code><\/p>\n<p><code class=\"gris\">df -h<br \/>\nFilesystem      Size  Used Avail Use% Mounted on<br \/>\nudev            491M     0  491M   0% \/dev<br \/>\ntmpfs           100M  4.4M   95M   5% \/run<br \/>\n\/dev\/sda1       9.7G  877M  8.8G   9% \/<br \/>\ntmpfs           497M     0  497M   0% \/dev\/shm<br \/>\ntmpfs           5.0M     0  5.0M   0% \/run\/lock<br \/>\ntmpfs           497M     0  497M   0% \/sys\/fs\/cgroup<br \/>\ntmpfs           100K     0  100K   0% \/run\/lxcfs\/controllers<br \/>\ntmpfs           100M     0  100M   0% \/run\/user\/0<\/code><\/p>\n<p>Choose a partition with plenty of space, as swap files are nowadays a gigabyte or more in size. You can now use the fallocate command to create a swap file. In our example below, we&#8217;re making a 2GB swap file in the root directory with a filename of swap2.<br \/>\n<code>fallocate -l 2G \/swap2<\/code><\/p>\n<p><code class=\"rouge\">If you system have more than one disk, you may put the swapfile on a disk that have low Input\/Output usage. SWAP on a primary disc may slowdown a lot your system in case the Input\/Output usage is already high.<\/code><\/p>\n<p>A vital step that you should be sure not to skip is to set the new swap file permissions readable and writable by root only.<br \/>\n<code>chmod 600 \/swap2<\/code><\/p>\n<p>Verify the size and permissions of the file.<br \/>\n<code>ls -lh \/swap2<\/code><\/p>\n<p>Here&#8217;s the output of our example swap file.<br \/>\n<code class=\"gris\">ls -lh \/swap2<br \/>\n-rw------- 1 root root 2.0G Aug  2 23:04 \/swap2<\/code><\/p>\n<p>Now that you&#8217;ve got the file, you can use it to create a new swap space.<br \/>\n<code>mkswap \/swap2<\/code><\/p>\n<p>Mount the new swap space as you would a swap partition.<br \/>\n<code>swapon \/swap2<\/code><\/p>\n<p>You can check that it was mounted successfuly by using the swapon command.<br \/>\n<code>swapon -s<\/code><\/p>\n<p><code class=\"gris\">swapon -s<br \/>\nFilename          Type            Size    Used    Priority<br \/>\n\/dev\/sda2         partition       8388604 9820    -1<br \/>\n\/swap2            file            2097148 0       -2<\/code><\/p>\n<p>It&#8217;s time to make this a permanent change by adding the new swap file to your system&#8217;s fstab in order for it to mount on boot.<\/p>\n<p>Open the fstab in your favorite file editor.<br \/>\n<code>nano \/etc\/fstab<\/code><\/p>\n<p>Add the following line at the end of the fstab, then save and exit.<br \/>\n<code class=\"gris\">swap2   swap    swap    sw  0 0<\/code><\/p>\n<h2>Conclusion<\/h2>\n<p>You&#8217;ve now successfully created a swap file and added to your system. This is a useful skill to know whenever you don&#8217;t have access to a proper swap partition. Be sure to invite your friends, and to share this article with them if they&#8217;re interested in creating swap file.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>How to create a swap file in Ubuntu 16 A swap file is a method of extending virtual memory. Unix and Linux systems commonly have a dedicated swap partition available for virtual memory, but occasionally you may be tasked with running a server without one, or with one that isn&#8217;t large enough for the server&#8217;s<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71],"tags":[],"class_list":["post-2630","post","type-post","status-publish","format-standard","hentry","category-applications"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to create a swap file in Ubuntu 16 - Globo.Tech<\/title>\n<meta name=\"description\" content=\"This tutorial will show you how to create a swap file in your Ubuntu 16 server. Read now &amp; Extend your sever&#039;s virtual memory.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create a swap file in Ubuntu 16 - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"This tutorial will show you how to create a swap file in your Ubuntu 16 server. Read now &amp; Extend your sever&#039;s virtual memory.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2016-09-02T16:53:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-12T19:07:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"963\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/\",\"name\":\"How to create a swap file in Ubuntu 16 - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\"},\"datePublished\":\"2016-09-02T16:53:11+00:00\",\"dateModified\":\"2018-01-12T19:07:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"This tutorial will show you how to create a swap file in your Ubuntu 16 server. Read now & Extend your sever's virtual memory.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.globo.tech\/learning-center\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to create a swap file in Ubuntu 16\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\/\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create a swap file in Ubuntu 16 - Globo.Tech","description":"This tutorial will show you how to create a swap file in your Ubuntu 16 server. Read now & Extend your sever's virtual memory.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/","og_locale":"en_US","og_type":"article","og_title":"How to create a swap file in Ubuntu 16 - Globo.Tech","og_description":"This tutorial will show you how to create a swap file in your Ubuntu 16 server. Read now & Extend your sever's virtual memory.","og_url":"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/","og_site_name":"Globo.Tech","article_published_time":"2016-09-02T16:53:11+00:00","article_modified_time":"2018-01-12T19:07:32+00:00","og_image":[{"width":1920,"height":963,"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png","type":"image\/png"}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/","url":"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/","name":"How to create a swap file in Ubuntu 16 - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"datePublished":"2016-09-02T16:53:11+00:00","dateModified":"2018-01-12T19:07:32+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"This tutorial will show you how to create a swap file in your Ubuntu 16 server. Read now & Extend your sever's virtual memory.","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/create-swap-file-ubuntu-16\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How to create a swap file in Ubuntu 16"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=2630"}],"version-history":[{"count":4,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2630\/revisions"}],"predecessor-version":[{"id":4085,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2630\/revisions\/4085"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=2630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=2630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=2630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}