Centos – How toncrease swap space in a CentOS VM

centoslvmswapvirtualbox

While trying to RPM install Oracle XE in a CentOS 7 VM running inside Virtualbox 5.1 I get the following error message:

This system does not meet the minimum requirements for swap space.  Based on
the amount of physical memory available on the system, Oracle Database 11g
Express Edition requires 2048 MB of swap space. This system has 1279 MB
of swap space.  Configure more swap space on the system and retry the 
installation.

How can I increase the swap space?

So far I have tried with lvm following the instructions here and here without success. I must start with an already provisioned minimal CentOS VM so tweaking the original image is not an option.

A swapon -s command informs me:

Filename                Type        Size    Used    Priority
/dev/dm-1               partition   1310716 0       -1

and lvdisplay output is:

  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                rdNgH4-Sili-NpwP-Ny3S-xtU9-MlEC-ttE5JI
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-12-19 22:50:56 +0000
  LV Status              available
  # open                 2
  LV Size                1.25 GiB
  Current LE             320
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                H737Lq-OMhE-F9Lf-BlTg-3PL1-0T7O-1Ciusi
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-12-19 22:50:56 +0000
  LV Status              available
  # open                 1
  LV Size                12.39 GiB
  Current LE             3172
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

and df -h

Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   13G  9.4G  3.1G  76% /
devtmpfs             907M     0  907M   0% /dev
tmpfs                920M  4.0K  920M   1% /dev/shm
tmpfs                920M  8.7M  912M   1% /run
tmpfs                920M     0  920M   0% /sys/fs/cgroup
/dev/sda1           1014M  239M  776M  24% /boot
tmpfs                184M     0  184M   0% /run/user/1002
tmpfs                184M     0  184M   0% /run/user/1001
tmpfs                184M   12K  184M   1% /run/user/1000
tmpfs                184M     0  184M   0% /run/user/2
/dev/sr0              57M   57M     0 100% /run/media/vagrant/VBOXADDITIONS_5.1.33_120529
vagrant              102G   77G   26G  76% /vagrant

Edit:

Content of /etc/fstab

/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=41388da5-fc65-4a34-a3da-58bb81daf744 /boot                   xfs     defaults        0 0
/dev/mapper/cl-swap     swap                    swap    defaults        0 0

Output of vgs

VG #PV #LV #SN Attr   VSize  VFree
cl   1   2   0 wz--n- 13.64g 4.00m

Best Answer

You can increase your swap space by first shrinking the root logical volume to free up space, which you can then reallocate to the swap logical volume. You need to increase your swap LV by 769 MB to get it up to 2048 MB, and your root LV has 3.1 GB free, so you can try the following:

  1. Shrink your root LV. The -r option causes the filesystem to be resized as well: lvresize -L -769M -r c1/root
  2. Temporarily turn off your swap, since you're going to be modifying it: swapoff
  3. Resize your swap LV. Alternatively, delete it and recreate it using contiguous allocation so that the physical extends are adjacent to each other for potentially better performance: lvresize -L +769M c1/swap
  4. Turn swap back on: swapon
Related Question