How to create a Linux swap file

www‮ual.‬tturi.com
How to create a Linux swap file

To create a Linux swap file, you can follow these steps:

  1. Determine the size of the swap file you want to create. The recommended size of the swap file is double the amount of physical memory (RAM) in your system. For example, if your system has 4GB of RAM, you should create a swap file of at least 8GB.

  2. Create a file of the desired size using the dd command. For example, to create an 8GB swap file, you can use the following command:

dd if=/dev/zero of=/path/to/swapfile bs=1G count=8

Replace /path/to/swapfile with the path and name you want to give to the swap file.

  1. Set the permissions of the swap file to be readable and writable only by the root user:
chmod 600 /path/to/swapfile
  1. Mark the file as a swap file using the mkswap command:
mkswap /path/to/swapfile
  1. Enable the swap file by running the following command:
swapon /path/to/swapfile
  1. To make the swap file permanent, you will need to add an entry for it in the /etc/fstab file. Open the file in a text editor and add a line like the following:
/path/to/swapfile swap swap defaults 0 0
Created Time:2017-10-28 21:39:01  Author:lautturi