Activate the swap file & finalize

Step 1: Activate the swap file:

Now we can finally activate the swap file, for this, we will have to use the following command:

sudo swapon /swapfile

This command is used in Ubuntu to enable a swap area on a specified file. lets understand the command:

  • swapon: This is the command used to activate a swap area.

Note: Other commands are same as above so no explanation is needed.

Output:

sudo swapon /swapfile

Step 2: Make permanent changes:

Now we will have to make the changes permanent in the system, we will have to open the path “/etc/fstab” For this enter the following command:

sudo nano /etc/fstab

This command opens the /etc/fstab file using the nano text editor with superuser privileges. lets understand what this command does:

  • nano: This is a command-line text editor in Linux. its used for making it easy for users to edit text files from the terminal.
  • /etc/fstab: This is the path to the file being opened, the /etc/fstab file is a system configuration file used by linux in order to control how filesystems are managed during the boot process.

Output:

sudo nano /etc/fstab

Step 3: Paste the code:

Now we will have to paste the following line into the file that we have just opened:

/swapfile swap swap defaults 0 0

The command we are using above is used for an entry in the /etc/fstab file. lets understand this command:

  • defaults: This field is required for the mount options, defaults is a placeholder for a set of default options suitable for most systems, these options are used because they include enabling read/write access and other settings.
  • 0: This field is used by the dump command to determine if the filesystem needs to be dumped, for the swap partitions, this is set to 0, which says that no dump is needed.
  • 0: This field is used by the fsck command to determine the order in which filesystems are checked during the boot time. for the swap partitions, we set this to 0, which means that no filesystem check is necessary.

Output:

/swapfile swap swap defaults 0 0

Note: after this, save the file using the shortcut CTRL + T.

Step 4: Verify the swap file:

Now we will have to check whether the swap file is created and activated or not, by entering the following command:

sudo swapon --show

The swapon –show command is used to display a list of currently active swap devices or files, lets understand this command:

  • swapon: This command is used to set and then configure swap space on the system.
  • –show: This option is used with swapon so that we can display the currently active swap devices.

Output:

sudo swapon –show

This means that we have successfully created and activated the swap file on the Ubuntu system.

How to Add Swap Space on Ubuntu 20.04

Swap file takes space in the disk storage and later act as a memory for computation whenever the RAM in our system is full, it is important to create swap space in the Ubuntu system if you feel like your physical RAM is not enough to compute the work, the swap space can be created without any third party software because the ubuntu has a built-in feature for creating swap space files.

Similar Reads

What is swap space in Ubuntu?

The swap file is used to fulfill the need for the physical RAM when the RAM is full but the system still needs additional computational power then it can use the swap space we create to fulfill this need, so in this article, we will understand how to add swap space on ubuntu system step by step....

How to add swap space on Ubuntu:

Adding the swap space in Ubuntu follows two steps, in the first step we create the swap file and then in the second step we activate the swap space on Ubuntu, so let’s understand each of these steps one by one:...

Activate the swap file & finalize:

Step 1: Activate the swap file:...

How to Add Swap Space on Ubuntu 20.04 – FAQs

How do I check if my Ubuntu 20.04 system has swap space enabled?...

Conclusion

Swap files are handy when you are running full of physical RAM, in this article we have understood how we can create the swap file and also activate it so that whenever the Ubuntu system runs out of physical RAM then the system can easily use the swap file as memory, follow this article step by step to understand how you can create swap files in ubuntu....

Contact Us