系统安装后自动从镜像文件挂载的分区:

/etc/fstab
/swap.img	none	swap	sw	0	0


swapon --show
NAME      TYPE SIZE USED PRIO
/swap.img file 1.9G   0B   -2

停止 SWAP 分区:

swapoff /swap.img

调整大小:

fallocate -l 16G /swap.img
或:
dd if=/dev/zero of=/swap.img bs=1G count=16(蜗牛一样的速度)
# fallocate 是预分配,所以速度比 dd 快的多得多。
chmod 600 /swap.img

格式化:

mkswap /swap.img
Setting up swapspace version 1, size = 16 GiB (17179865088 bytes)
no label, UUID=f65b4da2-53cd-46a7-a782-aee321cd4329
# mkswap 可将磁盘分区或文件设为 Linux 的交换区

启用 SWAP 分区:

swapon /swap.img

swapon --show
NAME      TYPE SIZE USED PRIO
/swap.img file  16G   0B   -2

free -h
               total        used        free      shared  buff/cache   available
Mem:           31Gi       265Mi        23Gi       1.0Mi       7.6Gi        30Gi
Swap:          15Gi          0B        15Gi