banner
LAPLACE

LAPLACE By 王友元

那些娇艳欲滴姿态万千的花朵其实都依赖于某种神秘的养料——那就是人类幽微而真挚的情感故事
telegram
x
email

Set up swap virtual memory for Linux

This article takes centos7 as an example

First, it's simple#

We create a 2Gb file, then assign permissions, then set it as swap, and finally set it to be added permanently

However: Some methods I found online did not mention the need to assign permissions, which caused errors, so pay attention!#

↑ Similar to this

Detailed commands#

To set up a 2GB swap partition in CentOS 7, follow these steps:

  1. Check the current swap situation:
    Enter the following command in the terminal to confirm the current system's swap situation:

  2. Create a swap file:
    If there is not enough unallocated space in the system to create a new swap partition, you can create a swap file. First, create a 2GB file (assuming the file name is swapfile) using the following command:

    If the fallocate command is not available, you can use the following command to create it:

  3. Set file permissions:

  4. Convert the file to swap format:

  5. Enable the swap file:

  6. Add the swap file permanently:
    You can use the echo command-line tool to append content to the /etc/fstab file, which avoids manual editing. Here is how to execute the sixth step in the command line:

echo '/swapfile   none    swap    sw    0   0' | sudo tee -a /etc/fstab
  1. Confirm that the swap is active:
    Re-run the swapon --show command to confirm that the new swap file is active.

By following the above steps, you should have successfully created a 2GB swap partition in CentOS 7.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.