Increase SWAP size in CentOS7.7
CentOS7.7的swap默认安装下,使用lvm的lv做swap,当需要增大swap空间时,可以考虑如下操作:
1.当前状态
[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.关闭当前swap
[root@syk01 ~]# swapoff -v /dev/mapper/centos-swap
swapoff /dev/mapper/centos-swap
[root@syk01 ~]# swapon -s
3.扩大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.格式化swap空间
[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.打开新的swap空间
[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 ~]#