CentOS7 add, delete, modify swap partition

First check whether the current system swap exists swap partition, the following command will display the swap partition size, 0 means no partition.

Free -h

1. Add swap partition
dd if=/dev/zero of=/data/swapfile bs=1024 count=4096k

If (ie, input file), dev/zero is a special character input device for Linux that creates an empty file of a specified length for initialization.
of (ie output file). /data/swapfile is the swap file address.
bs=1024: The unit data block is simultaneously read and written. The block size is 1024 bytes.
count=4096K : The number of data blocks is 4096*1024.
calculate the capacity of the swap partition: 1KB*4096*1024=4G.

convert to swap partition:
dkswap /data/swapfile
Mount and activate the partition:
swapon /data/swapfile
Set permissions to root to operate
chmod -R 0600 /data/swapfile
Set the boot to automatically mount the partition:
vi /etc/fstab
UUDI=swapfile UUID swap swap defaults 0 0

2. Delete a swap partition

Stop using the swap partition first:
swapoff /data/swapfile
Delete swap partition file
rm -rf /data/swapfile
Remove the configuration from /etc/fstab
UUDI=swapfile UUID swap swap defaults 0 0

3. Change the Swap configuration. The higher the swappiness value, the higher the priority of the swap partition. The default is 30.

View the current swappiness values:
cat /proc/sys/vm/swappiness
Modify the swappiness value, here is 10 as an example.
sysctl vm.swappiness=10
Permanently effective
echo "vm.swappiness = 10" >> /etc/sysctl.conf

if you want to reproduce, please indicate the source:
CentOS7 add, delete, modify swap partition - CodeDay