How to Add Swap Space on Ubuntu 20.04 - MS TV Life.COM

How to Add Swap Space on Ubuntu 20.04

How to Add Swap Space on Ubuntu 20.04

We hope this post helped you to find out  How to Add Swap Space on Ubuntu 20.04

Swap is an area on a disk that’s used when the quantity of bodily RAM reminiscence is full. When a Linux system runs out of RAM, inactive pages are moved from the RAM to the swap area.

Swap area can take the type of both a devoted swap partition or a swap file. Usually, when operating Ubuntu on a digital machine, a swap partition isn’t current, and the one choice is to create a swap file.

How to Add Swap Space on CentOS 8

This tutorial explains easy methods to add a swap file on Ubuntu 20.04 methods.

Earlier than You Start #

Swap shouldn’t be seen as a alternative to bodily reminiscence. Since swap area is a piece of the laborious drive, it has a slower entry time than bodily reminiscence. In case your system always runs out of reminiscence, you need to add extra RAM.

Typically, the dimensions of the swap file is determined by how a lot RAM your system has:

  • Techniques with lower than 2 GB RAM – 2 occasions the quantity of RAM.
  • Techniques with 2 to eight GB RAM – the identical dimension as the quantity of RAM.
  • Techniques with greater than eight GB RAM – not less than four GB of Swap.

Solely root or consumer with sudo privileges can activate the swap file.

Stop 1 Making a Swap File #

On this instance, we’ll create 2 GB swap file. If you wish to add extra swap, substitute 2G with the dimensions of the swap area you want.

Full the steps beneath so as to add swap area on Ubuntu 20.04:

Step 2. First, create a file that will be used as swap:

sudo fallocate -l 2G /swapfile

Step 3. If the fallocate utility is not present on your system, or you get an error message saying fallocate failed: Operation not supported, use the following command to create the swap file:

sudo dd if=/dev/zero of=/swapfile bs=1024 count=2097152

Step 4. Set the file permissions to 600 to prevent regular users to write and read the file:

sudo chmod 600 /swapfile

Step 5. Create a Linux swap area on the file:

sudo mkswap /swapfile
 Setting up swapspace version 1, size = 2 GiB (2147479552 bytes) no label, UUID=fde7d2c8-06ea-400a-9027-fd731d8ab4c8

Step 6. Activate the swap file by running the following command:

sudo swapon /swapfile 

To make the change permanent open the /etc/fstab file:

 sudo nano /etc/fstab

and paste the following line:

/etc/fstab 
/swapfile swap swap defaults 0 0

Step 7. Verify that the swap is active by using either the swapon or the free command, as shown below:

sudo swapon --show
NAME TYPE SIZE USED PRIO /swapfile file 2G 0B -1
sudo free -h 
total used free shared buff/cache available Mem: 981Mi 97Mi 68Mi 0.0Ki 814Mi 735Mi Swap: 2.0Gi 10Mi 1.9Gi

Adjusting the Swappiness Value #

Swappiness is a Linux kernel property that defines how usually the system will use the swap area. It may possibly have a price between Zero and 100. A low worth will make the kernel to attempt to keep away from swapping at any time when doable, whereas the next worth will make the kernel to make use of the swap area extra aggressively.

On Ubuntu, the default swappiness worth is ready to 60. You possibly can examine the present worth by typing the next command:

cat /proc/sys/vm/swappiness
60

Whereas the swappiness worth of 60 is OK for many Linux methods, for manufacturing servers, you might must set a decrease worth.

For instance, to set the swappiness worth to 10, run:

sudo sysctl vm.swappiness=10

To make this parameter persistent across reboots, append the following line to the /etc/sysctl.conf file:

/etc/sysctl.conf

The optimum swappiness worth is determined by your system workload and the way the reminiscence is getting used. It’s best to modify this parameter in small increments to seek out an optimum worth.

Eradicating a Swap File #

To deactivate and delete the swap file, comply with these steps:

First, deactivate the swap area:

sudo swapoff -v /swapfile

Next, remove the swap file entry /swapfile swap swap defaults 0 0 from the /etc/fstab file.

Finally, remove the actual swapfile file using the rm command:

sudo rm /swapfile

Conclusion #

We have now proven you easy methods to create a swap file and activate and configure swap area in your Ubuntu 20.04 system.

FAQ

We hope the How to Add Swap Space on Ubuntu 20.04 help you. If you have any query regarding How to Add Swap Space on Ubuntu 20.04 drop a comment below and we will get back to you at the earliest.

We hope this post helped you to find out  How to Add Swap Space on Ubuntu 20.04  . You may also want to see – How to Install Google Chrome Web Browser on Ubuntu 20.04

Copy link
Powered by Social Snap