Swap Space Management

Swap Space Management

Wikis > Swap Space Management

Swap Space

Linux swap space is a special area for the OS that can be used as additional system RAM. The more traditional approach to swap space used a Swap Partition on your disk system. The more modern approach, as used by Bodhi Linux 6.0.0 (based upon Ubuntu 20.04), is the use of a Swap File.

Swap File

The main advantage of a swap file (over a swap partition), is easier resizing.

Below you find detail son how to management the swap file using Terminology.

Show current

Check that your Bodhi installation already has swap enabled

sudo swapon --show

which will output something like

NAME TYPE SIZE USED PRIO
/dev/sda1 partition 1.0G 0B -2

Create

If a swap file doesn’t exist, create a file which will be used for swap, in this example a 1GB file will be created.

NOTE: G: Gigabyte; M: Megabyte.

sudo fallocate -l 1G /swapfile

Set the correct permissions for the file:

sudo chmod 600 /swapfile

Now make a swap area within the file and activate:

sudo mkswap /swapfile
sudo swapon /swapfile

To make the changes permanent, make an entry into fstab (if it isn’t already there)

NOTE: extreme caution should be taken when modifying fstab. An incorrectly stated fstab will result in a failure to boot the Bodhi Linux.

Using your preferred editor (leafpad, nano, vim), make the following change to /etc/fstab

/swapfile none swap sw 0 0

Verify the swap was created and usable (see: Show Current above)

Resize

Effectively we are deleting the swap file, and recreating the file.

Follow Remove (below), omitting the change to /etc/fstab
Follow Create (above), omitting the change to /etc/fstab

Verify the swap was created and usable (see: Show Current above)

Remove

Delete the swap

sudo swapoff -v /swapfile

Delete the swap file
rm -v /swapfile

Remove the line /swapfile none swap sw 0 0 (using your preferred editor) from the file: /etc/fstab

Category: