1. add a swap file with a size of 2 GB. by default, the of =/swapfile is created in the/var/directory. If I create a file in the/opt/image/directory, change/swapfile in all the operations below to/opt/image/swap # ddif =/dev/zeroof =/swapfilebs = 1 kcount = 2048 1. add a swap file with a size of 2 GB
By default,of=/swapfileThat is, the swapfile file is created under the/var/directory.
If I create a directory in the/opt/image/directory/swapfileAll must be changed/opt/image/swap
# dd if=/dev/zero of=/swapfile bs=1k count=2048000
2. create a SWAP file
# mkswap /swapfile
3. activate the SWAP file
# swapon /swapfile
4. check whether SWAP information is correct.
# swapon -s
5. add it to the fstab file to enable automatic startup during system boot.
Note that the default path of the swapfile file is used, that is,/var/swapfile. If the swapfile file is not in the/var/directory/var/swapfileYou also need to modify it to your own.
# echo "/var/swapfile swap swap defaults 0 0" >> /etc/fstab
6. run the free command to check whether the 2 GB swap partition takes effect.
# free -m
Or, check the meminfo file.
# grep SwapTotal /proc/meminfo
7. release the SWAP file
# swapoff /swapfile
8. delete the SWAP file
# rm -fr /swapfile