Linux – Estendendo a SWAP
Ai você tem uma instalação do Linux em LVM a qual necessita estender o tamanho da SWAP:
1 2 3 4 |
[root@centos ~]# free -m total used free shared buff/cache available Mem: 1998 78 1574 8 346 1748 Swap: 4135 0 4135 |
1 – Preparar o disco
1 2 3 4 5 6 |
[root@centos ~]# fdisk /dev/sdb Command (m for help): n Select (default p): p Command (m for help): t Hex code (type L to list all codes): 8e Command (m for help): w |
2 – Estender o VG
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@centos ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created. [root@centos ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 2 0 wz--n- 31.50g 0 [root@centos ~]# vgextend centos /dev/sdb1 Volume group "centos" successfully extended [root@centos ~]# swapoff -va [root@centos ~]# lvextend -l +100%FREE /dev/mapper/centos-swap Size of logical volume centos/swap changed from 4.04 GiB (1034 extents) to 6.04 GiB (1545 extents). Logical volume centos/swap successfully resized. |
3 – Formatar e ativar a SWAP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@centos ~]# mkswap /dev/mapper/centos-swap mkswap: /dev/mapper/centos-swap: warning: wiping old swap signature. Setting up swapspace version 1, size = 6328316 KiB no label, UUID=c12a0b91-01ff-4d56-a991-c3dabe79a1a2 [root@centos ~]# swapon -va swapon /dev/mapper/centos-swap swapon: /dev/mapper/centos-swap: found swap signature: version 1, page-size 4, same byte order swapon: /dev/mapper/centos-swap: pagesize=4096, swapsize=6480199680, devsize=6480199680 [root@centos ~]# free -m total used free shared buff/cache available Mem: 1998 79 1572 8 346 1746 Swap: 6179 0 6179 [root@centos ~]# cat /proc/swaps Filename Type Size Used Priority /dev/dm-1 partition 6328316 0 -1 |
E se precisar reduzir
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[root@centos ~]# swapoff -a [root@centos ~]# lvreduce --size -4G /dev/mapper/centos-swap WARNING: Reducing active logical volume to <2.04 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce centos/swap? [y/n]: y Size of logical volume centos/swap changed from <6.04 GiB (1545 extents) to <2.04 GiB (521 extents). Logical volume centos/swap successfully resized. [root@centos ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <29.51g 8.00m /dev/sdb1 centos lvm2 a-- <2.00g <2.00g /dev/sdd1 centos lvm2 a-- <2.00g <2.00g [root@centos ~]# vgreduce centos /dev/sdd1 Removed "/dev/sdd1" from volume group "centos" [root@centos ~]# vgreduce centos /dev/sdb1 Removed "/dev/sdb1" from volume group "centos" [root@centos ~]# mkswap /dev/mapper/centos-swap [root@centos ~]# swapon -a |
Referência: https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s2-swap-extending-lvm2.html https://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-swap-reducing-lvm2.html
Continue reading →