Add SWAP partition in CentOS/Linux, centosswap
Usage of swap partitioning: swap puts data into swap when the physical memory is insufficient. Therefore, swap plays a role in virtual memory, in a sense, memory space is also increased. Generally, the swap partition is set when the system is installed. If you forget to divide the swap partition when installing the system, it will be okay and there is a remedy. The following describes how to add a swap partition after installing the system.
Scenario: After the system is installed, it is hard to find that SWAP partitions are not divided. This obviously does not work for production servers. Therefore, you need to add SWAP partitions.
1. First check the swap size
# Free
total used free shared buffers cachedMem: 3922944 158168 3764776 0 6948 37384-/+ buffers/cache: 113836 3809108Swap: 0 0 0
Obviously, it is displayed as zero.
2. Run the dd command to create a swap partition.
# Dd if =/dev/zero of =/doiido/swap bs = 1024 count = 8388608
Calculation Formula of count: count = SIZE * 1024 (size in MB)
In this way, create a/doiido/swap partition file with a size of 8 GB.
3. format the new partition.
# Mkswap/doiido/swap
4. Change the new partition to a swap partition.
# Swapon/doiido/swap
Note: The command to disable SWAP partitioning is: # swapoff/doiido/swap
5. Check the swap size first.
# Free
total used free shared buffers cachedMem: 3922944 158168 3764776 0 6948 37384-/+ buffers/cache: 113836 3809108Swap: 8388608 0 8388608
6. automatically mount swap upon startup
# Echo "/doiido/swap defaults 0 0">/etc/fstab
The SWAP partition is created.