查看是否启用
$ sudo swapon --show点击复制复制失败已复制
如果输出为空,则表示当前系统尚未启用 SWAP
空间。一般阿里云这类的云服务器默认是不会启用这个的,个人工作电脑一般都会启用。
启用的输出示例
$ sudo swapon --show NAME TYPE SIZE USED PRIO /swap.img file 3.9G 0B -2点击复制复制失败已复制
临时关闭
$ swapoff -a点击复制复制失败已复制
提示
重启失效
永久关闭
编辑 /etc/fstab
文件,注释其中 swap
所在行即可。
本地虚拟机的 /etc/fstab
文件关闭 swap
示例(虚拟机为 Ubuntu20.04 LTS
版本)
# /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/ubuntu-vg/ubuntu-lv during curtin installation /dev/disk/by-id/dm-uuid-LVM-Y94mfo5IKwVbljdGS9krcWMNyehlLlrWoaZzDlqhHAFrDZ2cctdzaydePVVy0hG2 / ext4 defaults 0 0 # /boot was on /dev/sda2 during curtin installation /dev/disk/by-uuid/402bb414-5ebb-480b-a4a6-f158cb1e9978 /boot ext4 defaults 0 0 # /swap.img none swap sw 0 0 点击复制复制失败已复制
番外
阿里云云服务器的/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=13843fcc-f592-4868-b87f-3784967cd0c4 / ext4 errors=remount-ro 0 1 /dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0