centos8关闭swap分区

root@kg128 ~]# free
              total        used        free      shared  buff/cache   available
Mem:        2865164      975048     1075120       17504      814996     1711896
Swap:       2128892           0     2128892

查看swap分区是否开启

临时关闭swapoff -a

方式1(不好用就使用方法2):

如果开启vim注释掉swap分区盘符

 vim /etc/fstab


#
# /etc/fstab
# Created by anaconda on Tue Dec 28 14:40:17 2021
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=f7001d95-9491-4675-9fbc-b647de54f3a2 /                       xfs     defaults        0 0
UUID=b6a0cb32-173e-4e8a-afd9-397176ec5690 /boot                   xfs     defaults        0 0
#UUID=ab784cf2-f29f-4919-8df9-f1c44aad8189 none                    swap    defaults        0 0
#注释掉swap分区
#需要注释/etc/default/grub中/etc/fstab对应的交换设备
vim /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
#GRUB_CMDLINE_LINUX="crashkernel=auto resume=UUID=ab784cf2-f29f-4919-8df9-f1c44aad8189 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
#重载grub配置
grub2-mkconfig -o /boot/grub2/grub.cfg
#reboot重启后生效
[root@kg128 ~]# free
              total        used        free      shared  buff/cache   available
Mem:        3029004      587528     1992920       10864      448556     2272028
Swap:             0           0           0

方法2:通过systemctl 禁止swap交换分区

#查看分区对应的服务
systemctl | grep swap
  dev-disk-by\x2duuid-ab784cf2\x2df29f\x2d4919\x2d8df9\x2df1c44aad8189.swap                                loaded active active    
/dev/disk/by-uuid/ab784cf2-f29f-4919-8df9-f1c44aad8189                                                        swap.target                                                                                              loaded active active    Swap 
#禁止交换分区
systemctl mask  dev-sda3.swap 
Created symlink /dev-disk-by\x2duuid-ab784cf2\x2df29f\x2d4919\x2d8df9\x2df1c44aad8189.swap → /dev/null.                                           
#重新允许使用systemctl unmask dev-sda3.swap  

#注释掉 /etc/fstab 下的swap交换设备
#
# /etc/fstab
# Created by anaconda on Tue Dec 28 14:40:17 2021
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=f7001d95-9491-4675-9fbc-b647de54f3a2 /                       xfs     defaults        0 0
UUID=b6a0cb32-173e-4e8a-afd9-397176ec5690 /boot                   xfs     defaults        0 0
#UUID=ab784cf2-f29f-4919-8df9-f1c44aad8189 none                    swap    defaults        0 0

#reboot重启生效                                   

你可能感兴趣的:(linux,服务器,运维)