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:
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:
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:
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:
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.
Contact Us