How To Change Swap Space on Ubuntu 18.04
1 min readAug 2, 2023
here are the steps to change the swap settings in Ubuntu 18.04:
- First, make sure that your current swap is inactive. To do this, run the following command in the terminal:
sudo swapoff -a
- Then, delete the existing swap file:
sudo rm /swapfile
(If you have used a separate partition for swap, disregard the following steps.)
- Create a new swap file with the desired size. For example, if you want to create a 4GB swap file:
sudo fallocate -l 4G /swapfile
- Set the swap file’s permissions to read and write only:
sudo chmod 600 /swapfile
- Format the swap file:
sudo mkswap /swapfile
- Activate the new swap file:
sudo swapon /swapfile
- Set up the new swap file in the
/etc/fstab
file to be used during system boot:
Open the /etc/fstab
file using a text editor like nano or vi:
sudo nano /etc/fstab
Add the following line at the end of the file:
/swapfile none swap sw 0 0
- Test the swap settings with the following command:
sudo swapon --show
The output should display your new swap settings.
Now your current swap has been replaced with the new settings. You can adjust the size or location of the swap accordingly. Please note that changing the swap size may be limited by partitioning and disk space constraints on your system.