Currently, VM instances are more and more widely used. System images of some VM instances do not automatically mount swap partitions, which will definitely affect the performance of the machines,
The solution is as follows:
1. Some VM instance vendors allocate swap partitions for VM instances, but do not enable automatic system mounting. Run the fdisk-l command to check whether a swap partition is created.
Swap partitions, as shown in the following figure:
As shown in the figure above, the system has created a swap partition. In this case, you only need to write the swap partition to/etc/fstab and enable the system to automatically mount it.
2. If the system does not create a swap partition, we need to create a space by ourselves. The specific steps are as follows:
A. Use the dd command to create a swap partition file
# Dd if =/dev/zero of =/opt/swap bs = 1024 count = 4096000
# Create a 4G swap partition file
B. Format the new partition.
# Mkswap/opt/swap
C. Convert the new partition into a swap partition
# Swapon/opt/swap
Note: the command to disable SWAP partitioning is: # swapoff/opt/swap
D. Run the free command to check the swap partition. If it is a 4G swap partition, it indicates no problem.
E. Automatically mount swap upon startup
# Echo "/opt/swap defaults 0 0">/etc/fstab
F. Restart the system and check whether the swap partition is automatically mounted.