Safe way to shrink lvm vg_*-lv_swap partition and reclaim freed space on Linux?

Hello,

[root@host2 ~]# lsblk
NAME                        MAJ:MIN    RM  SIZE RO TYPE MOUNTPOINT
sr0                          11:0       1 1024M  0 rom
sda                           8:0       0 38.2G  0 disk
├─sda1                        8:1       0  500M  0 part /boot
└─sda2                        8:2       0 37.7G  0 part
  ├─vg_host2-lv_root (dm-0) 253:0       0   31G  0 lvm  /
  └─vg_host2-lv_swap (dm-1) 253:1       0  6.7G  0 lvm  [SWAP]
ploop38874                  182:621984  0  9.8G  0 disk
└─ploop38874p1              182:621985  0  9.8G  0 part /vz/root/1810

.

My aim is to SAFELY shrink my swap partition (lvm vg_host2-lv_swap) so its size is 4GB and assign freed space to my root partition (lvm vg_host2-lv_root (dm-0)). I am on CentOS 6.10 64bit and i am wondering if i can do it on a running system without need to go into recovery - maybe i can go this way Change swap file size Fedora 23 - Super User (without reboot), maybe i can unmounting swap lvm on live system, but not lvresize (grow) root partition? How can i automatically grow root lvm partition during next boot (like editing boot parameters in grub)?

Releasing a certain logical disk is easy: just swapoff it (that can take some time if swap is in use - the swapped blocks need to be shuffled into RAM).
Then you can lvresize it.
Then swapon -v it - it will see the new size.

To grow (and shrink) a filesystem, lvresize --resizefs --size ... seems to be most easy (but I have never used it).

man lvresize

and the --resizefs option points to

man fsadm

Hi,

On Centos 6.10 and RHEL 6.10 in the lvreduce there is also the -r, --resizefs switch. This would allow things to be done in a single command line.

Please note if the system is swapping/paging the command will possibly take along time.

It should also be noted that reducing the swap can be done to an absolute value or by a specific amount, please read the man page and if possible test to ensure you get the expected result.

Regards

Gull04