Linux基本操作记录

105 阅读1分钟

1. 关闭SWAP分区

1.1 临时关闭

1.1.1 关闭swap分区

[root@192 /]# swapoff -a

查看效果

[root@192 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G        280M        3.2G        8.8M        191M        3.2G
Swap:            0B          0B          0B

1.1.2 临时关闭后开启swap分区

[root@192 /]# swapon -a

查看效果

[root@192 conf]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G        302M        197M        8.7M        3.2G        3.1G
Swap:          3.9G        1.0M        3.9G

1.2 永久关闭

注释 /etc/fstab 中关于swap分区的内容

[root@192 conf]# vim /etc/fstab
......
# 
# vim 展示内容
# /etc/fstab
# Created by anaconda on Sun Jul 16 18:42:28 2023
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos_192-root /                       xfs     defaults        0 0
UUID=af492c39-47fe-46a4-b802-eddc2e10e6e1 /boot                   xfs     defaults        0 0
# /dev/mapper/centos_192-swap swap                    swap    defaults        0 0

重启机器

[root@192 conf]# systemctl reboot

查看效果

[root@192 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.7G        280M        3.2G        8.8M        191M        3.2G
Swap:            0B          0B          0B