建立
1.建立一个1G的大文件(文件大小根据需要的SWAP分区大小建立)
dd if=/dev/zero of=/swapfile bs=1G count=1

2.将文件格式化成swap分区
mkswap /swapfile

3.写入到配置文件/etc/fstab

4.让配置文件生效
swapon -a

5.因为默认/swapfile其他人可读,所以不安全,更改权限为600
chmod 600 /swapfile

删除
1.先确定准备需要删除的swap分区没有在使用:
swapon -s

2.禁用需要删除的swap分区
swapoff /swapfile

3.删除配置文件对应的swap
4.删除文件
rm -f /swapfile
利用文件建立与删除swap分区
原文:https://www.cnblogs.com/lqynkdcwy/p/9463755.html