CentOS7.7 the installation default swap, swap done using the lvm lv, when necessary to increase the swap space, may be considered as follows:
1. Current state
[root@syk01 ~]# swapon -s
文件名 类型 大小 已用 权限
/dev/dm-1 partition 2097148 0 -2
[root@syk01 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 36.99g
swap centos -wi-ao---- 2.00g
2. Close the current swap
[root@syk01 ~]# swapoff -v /dev/mapper/centos-swap
swapoff /dev/mapper/centos-swap
[root@syk01 ~]# swapon -s
3. The size of the expansion lv
[root@syk01 ~]# lvresize /dev/mapper/centos-swap -L +1g
Size of logical volume centos/swap changed from 2.00 GiB (512 extents) to 3.00 GiB (768 extents).
Logical volume centos/swap successfully resized.
[root@syk01 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 36.99g
swap centos -wi-a----- 3.00g
4. Format swap space
[root@syk01 ~]# mkswap -f /dev/mapper/centos-swap
mkswap: /dev/mapper/centos-swap: warning: wiping old swap signature.
正在设置交换空间版本 1,大小 = 3145724 KiB
无标签,UUID=26c45e5f-636f-4569-9c8f-197bee4dd56e
5. Open a new swap space
[root@syk01 ~]# swapon -v /dev/mapper/centos-swap
swapon /dev/mapper/centos-swap
swapon: /dev/mapper/centos-swap:找到交换区签名:版本为 1,页面大小为 4,相同 字节顺序
swapon: /dev/mapper/centos-swap:页大小=4096,交换区大小=3221225472,设备大小=3221225472
[root@syk01 ~]# free -m
total used free shared buff/cache available
Mem: 1837 140 1519 8 178 1660
Swap: 3071 0 3071
[root@syk01 ~]#