centos8 swap分区关闭方法

1、临时关闭

swapoff -a

[root@loongson ~]# free                                                                                                                                                                       
              total        used        free      shared  buff/cache   available                                                                                                               
Mem:       16535264      533056    15548416       41424      453792    14618288                                                                                                               
Swap:       8333296           0     8333296                                                                                                                                                   
[root@loongson ~]# swapoff -a                                                                                                                                                                 
[root@loongson ~]# free                                                                                                                                                                 
              total        used        free      shared  buff/cache   available                                                                                                               
Mem:       16535264      531280    15550880       41424      453104    14620416                                                                                                               
Swap:             0           0           0                                       

2、永久关闭

2.1通过修改grub进行关闭swap分区

查看交换设备信息

[root@loongson ~]# cat /etc/fstab 
UUID=078770b7-9017-4119-8863-5545673dc1f5 /                       ext4    defaults        1 1
UUID=f3d7d9a2-7e45-4165-a93c-a8e5a3286e49 /boot                   ext4    defaults        1 2
UUID=A5E9-3050          /boot/efi               vfat    umask=0077,shortname=winnt 0 2
UUID=07af0edf-b4ba-4592-bc02-299d156f173a /home                   ext4    defaults        1 2
#UUID=9a127488-c05d-4ce1-987e-d37e19dc4d8c none                    swap    defaults        0 0

删除/etc/default/grub中/etc/fstab对应的交换设备

[root@loongson ~]# cat /etc/default/grub.bac 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=false
GRUB_CMDLINE_LINUX_DEFAULT=' '
GRUB_TERMINAL_OUTPUT="console"
#GRUB_CMDLINE_LINUX="crashkernel=auto resume=UUID=9a127488-c05d-4ce1-987e-d37e19dc4d8c rhgb quiet"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

重新生成grub.cfg

grub2-mkconfig -o /boot/efi/EFI/loongnix-server/grub.cfg

重启后生效

2.2 如果2.1不生效,可参考此方法通过systemctl进行禁止交换分区

查看交换分区对应的服务

[root@loongson ~]# systemctl | grep swap
  dev-sda3.swap                                                                             loaded active active    Swap Partition                                                               
  swap.target                                                                               loaded active active    Swap 

禁止交换分区

[root@loongson ~]# systemctl mask dev-sda3.swap
Created symlink /etc/systemd/system/dev-sda3.swap → /dev/null.

注意:重新打开使用systemctl unmask dev-sda3.swap
注释掉交换设备

[root@loongson ~]# cat /etc/fstab 
UUID=078770b7-9017-4119-8863-5545673dc1f5 /                       ext4    defaults        1 1
UUID=f3d7d9a2-7e45-4165-a93c-a8e5a3286e49 /boot                   ext4    defaults        1 2
UUID=A5E9-3050          /boot/efi               vfat    umask=0077,shortname=winnt 0 2
UUID=07af0edf-b4ba-4592-bc02-299d156f173a /home                   ext4    defaults        1 2
#UUID=9a127488-c05d-4ce1-987e-d37e19dc4d8c none                    swap    defaults        0 0

重启进行验证

[root@loongson ~]# reboot

参考:https://www.zutuanxue.com/home/4/4_254

你可能感兴趣的:(龙芯,linux,虚拟机,linux,windows,运维)