To create and enable a swap file on your Linux system, follow these steps:
Create the Swap File
First, create a file that will be used as the swap space. In this example, we are creating a 2 GB swap file:
|
|
Set the Correct Permissions
For security reasons, only the root user should have read and write access to the swap file. Set the appropriate permissions using the following command:
|
|
Set Up the Swap Area
Use the mkswap
tool to configure the file as a Linux swap area:
|
|
- Activate the Swap File
Enable the swap file so the system can start using it immediately:
|
|
Make the Change Permanent
To ensure the swap file is activated automatically at system startup, you need to edit the /etc/fstab
file. Open the file with a text editor, for example:
|
|
Add the following line to the file:
|
|
Save and close the file. The swap file will now be permanently enabled.