extend swap space

Latest response

I have a RHEL box with 16G Ram and 8G swap. I want to extend the swap space to 16G (+8G).

There is not enough space for extending swap lvm so I would like to reallocate some space from /home to swap.

Please kindly advise the steps by steps for this reallocation.

Version : RHEL 7.2 workstation

$ df
Filesystem            1K-blocks     Used Available Use% Mounted on
/dev/mapper/rhel-root  52403200  8841648  43561552  17% /
devtmpfs                8063804        0   8063804   0% /dev
tmpfs                   8080448       24   8080424   1% /dev/shm
tmpfs                   8080448   429828   7650620   6% /run
tmpfs                   8080448        0   8080448   0% /sys/fs/cgroup
/dev/nvme0n1p2           508588   212216    296372  42% /boot
/dev/nvme0n1p1           204580     9964    194616   5% /boot/efi
/dev/mapper/rhel-home 188561452 63225364 125336088  34% /home
tmpfs                   1616092      136   1615956   1% /run/user/1000
/dev/sda1               3947824  3947824         0 100% /run/media/xxxx/RHEL-7.2 Server.x86_64

$ sudo lvdisplay 
[sudo] password for xxxx: 
  --- Logical volume ---
  LV Path                /dev/rhel/swap
  LV Name                swap
  VG Name                rhel
  LV UUID                nztdi1-tX67-eH1e-5W9K-r6LZ-yJYX-MM5dhm
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-04-07 19:19:21 +0800
  LV Status              available
  # open                 2
  LV Size                7.81 GiB
  Current LE             2000
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/rhel/home
  LV Name                home
  VG Name                rhel
  LV UUID                YS62cD-arv7-OJEo-D60g-eavo-Kklu-K6WPzz
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-04-07 19:19:21 +0800
  LV Status              available
  # open                 1
  LV Size                179.91 GiB
  Current LE             46058
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/rhel/root
  LV Name                root
  VG Name                rhel
  LV UUID                fAyjNt-XULs-SS61-7QrX-JLO8-aXZF-9eHGmx
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-04-07 19:19:22 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

$ sudo vgs
 VG   #PV #LV #SN Attr   VSize    VFree 
  rhel   1   3   0 wz--n- <237.79g 64.00m

Responses

Reducing volume is not good. instead of that you can create an 8GB swap file in /home directory and enable swap on that file.

for creating swap file and configuration you can follow the URL https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/ch-swapspace#swap-creating-file

Being mindful that swap performance against swap-files is even worse than raw disk-based swap.

One wonders, however, why so much swap is "needed". If something actually needs to swap out, you've probably got some fairly serious performance problems going on and really need to consider if your system is right-sized for the task at hand.

You can't shrink/reduce an xfs file system be it on lvm or standard partition, that is not possible. As Arul said you could create a file and make it as a swap space.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.