为Ubuntu系统增加swap分区

创建swap文件

$ sudo su root
$ cd /
$ dd if=/dev/zero of=swapfile bs=16M count=1k status=progress

备注:swap分区文件的大小:16M✖️1K = 16G

格式化swap分区文件

$ mkswap -f swapfile

挂载swap分区文件

$ swapon swapfile
$ free -h

重启后有效

$ vi /etc/fstab
root@xrny-iot-os:~# cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/vda1 during installation
UUID=bbd3ea56-da3b-4e1a-b14e-159e41299ea3 /               ext4    errors=remount-ro 0       1
/swapfile                                 swap            swap    sw                0       0