Introduction
The swapfile will add swap memory on top of whatever swap partition you may have. If you don't have a swap partition, then you can easily use a swapfile instead. It can easily be turned on/off separately '''OR''' together with an existing swap partition - treating all swap as one.
Creating a /swapfile
This is a really quick & simple process (unsupported by BTRFS).
Following is how we create a /swapfile:
Set the size
Use M for megabytes & G for gigabytes, the following creates a 4GB /swapfile.
Code: Select all
# fallocate -l 4G /swapfile
Code: Select all
# chmod 600 /swapfile
Code: Select all
# mkswap /swapfile
Code: Select all
# swapon /swapfile
Code: Select all
/swapfile none swap defaults 0 0
Removing the /swapfile
The swapfile if very easily removed.
Turn it off
Code: Select all
# swapoff /swapfile
Code: Select all
# swapoff -a
Code: Select all
# rm -rf /swapfile
Edit your /etc/fstab
The line that calls the '''/swapfile''' needs to be either removed from '''/etc/fstab''' or commented out by placing a '''#''' at the beginning of its line.
To do this you need to open your favourite text editor with root privileges.
As an example, you could open gedit in the Terminal using the following command:
Code: Select all
sudo gedit /etc/fstab