Add a /swapfile

From Manjaro Linux
Jump to: navigation, search


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).

/swapfile creation

Set the size

Use M for megabytes & G for gigabytes, the following creates a 4GB /swapfile.

# fallocate -l 4G /swapfile

Set the correct permissions (very important for security)

# chmod 600 /swapfile

Format the /swapfile

# mkswap /swapfile

Activate the /swapfile

# swapon /swapfile

Add the following line to your /etc/fstab

/swapfile none swap defaults 0 0 

Removing the /swapfile

The swapfile if very easily removed.

Turn it off

# swapoff /swapfile

You can also simply turn off all swap; both (swapfile and swap-partition) for this

# swapoff -a

Remove it

# 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:

sudo gedit /etc/fstab

Change gedit for the editor that you use.


Following is a link to this page's forum counterpart where you can post any related feedback: [1]