The swap partition is created to make up for the lack of physical memory, that is, the concept of virtual memory. Part of the hard disk is divided into virtual memory, but the larger the space, the better, the speed of the hard disk is much lower than that of the memory. If the hard disk is not set properly, the speed of the system is slowed down.
By default, Alibaba Cloud hosts do not have swap partitions. You can run the free command to view them:
This is the screenshot after swap partition is created on CentOS 7. The following describes how to create a swap partition on CentOS 7:
① Use the dd command to create a swap partition
Dd if =/dev/zero of =/home/swap bs = 1024 count = 1048576
The value of count is: size (MB) * 1024. Here I set 1 GB virtual memory, that is, count = 1024000.
② Format swap partitions
Mkswap/home/swap
③ Set the formatted file partition to a swap partition.
Swapon/home/swap
(Run the [root @ localhost Desktop] # swapoff/home/SWAP command to disable swap Partitioning)
At this point, the swap partition has been created. Run the free command to view the details. You can see that there is an additional Mount partition.
④ Automatically mount swap partitions
Vi/etc/fstab
Add
/Home/swap default 0 0