-1
df -h

Filesystem                      Size  Used Avail Use% Mounted on

/dev/mapper/vg00-LogVol00_root  2.0G  929M  1.1G  46% /
devtmpfs                        3.8G     0  3.8G   0% /dev
tmpfs                           3.9G     0  3.9G   0% /dev/shm
tmpfs                           3.9G  8.6M  3.9G   1% /run
tmpfs                           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/vg00-LogVol00_usr    10G  3.1G  6.9G  31% /usr
/dev/sda2                      1014M  189M  826M  19% /boot
/dev/mapper/vg00-LogVol00_home  2.0G   33M  2.0G   2% /home
/dev/mapper/vg00-LogVol00_tmp   5.0G   89M  5.0G   2% /tmp
/dev/mapper/vg00-LogVol00_var   5.0G  707M  4.3G  14% /var
/dev/mapper/vg00-LogVol00_opt   6.0G  1.3G  4.8G  21% /opt
tmpfs                           781M     0  781M   0% /run/user/1000

How to increase swap space from 3.9G to 10G. The available RAM is 8G.

  • 4
    In /etc/fstab what is the line about swap? What is the result of lvs? – Romeo Ninov Feb 11 '19 at 09:02
  • 2
    Seems there's a confusion between swap and RAM based (or swap based...) filesystem. This hinders the possible answers. – A.B Feb 11 '19 at 20:43

4 Answers4

2

You might have two scenarios here. The easiest one is if your swap partition is an LVM partition. Check in /etc/fstab to see if /dev/mapper/vg00-LogVol00-swap (or something like it is mounted as swap. If so, then run

sudo swapoff /dev/mapper/vg00-LogVol00-swap
sudo lvresize -L 10G /dev/mapper/vg00-LogVol00-swap
sudo mkswap /dev/mapper/vg00-LogVol00-swap
sudo swapon -a

If you don't have a partition defined for swap, you can use a swap file. Pick a partition that has lots of space (let's choose /home)

sudo fallocate -l 10G /home/swapfile 
sudo mkswap /home/swapfile
echo "/home/swapfile    none    swap    sw    0   0" | sudo tee -a /etc/fstab
sudo swapon -a

Both solutions will persist past a reboot.

doneal24
  • 5,059
2

first, swap is some storage resource other than RAM. You state the available RAM is 8gb. What you see as tmpfs under the Filesystem column is RAM, not SWAP.

Per your output of the df -h command, that shows file systems and SWAP is not a file system.

Know that all your tmpfs mounts as 3.9gb as /dev/shm and /run and /sys/fs/cgroup is a dynamic allocation of RAM. What this means is it will use at most 3.9gb of RAM for each of those mount points. There are three mount points, thus if you were to fill each mount point somehow then 3.9 + 3.9 + 3.9 = 11.7gb which is more than your total physical RAM of 8gb. Fill any of those and exceed the total physical ram and system will halt, but I would not worry about these tmpfs numbers they are typically automatically generated by RHEL at install time and are never a problem.

A typical entry in /etc/fstab for swap would be something like /dev/sda2 swap swap defaults 0 0 where /dev/sda2 is partition 2 on the disk at N gigabytes. So if you have this in your /etc/fstab then verify how much SWAP you actually have, then to increase it your options are

  1. repartition that disk so you have some larger partition that you can mount as swap {typically not possible and not easy to do since never free disk left over}
  2. add another disk and format and mount that as swap {probably better to spend the money on more ram unless you have spare disks and unused SATA ports}
  3. if you truly need swap space and cannot increase RAM abouve 8gb then create a swap file per https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/deployment_guide/s1-swap-adding or https://docs.fedoraproject.org/en-US/Fedora/14/html/Storage_Administration_Guide/s2-swap-creating-file.html or https://www.thegeekstuff.com/2010/08/how-to-add-swap-space/
ron
  • 6,575
  • also, if you have just one disk then look at all the partitions on it and find which one is formatted as swap. How big that partition is, is how much swap you currently have to work with. And the mount command i think might show a disk partition mounted as swap and the size of it. – ron Feb 11 '19 at 20:00
0

This post is informational of how to view your current swap configuration, which is important information not covered in the above posts:

To view current swap:

cat /proc/swaps

For example:

$ cat /proc/swaps
Filename                Type        Size    Used    Priority
/dev/dm-2               partition   8204284 344320  -

And to find out what /dev/dm-2 points to view the contents of /dev/mapper; the directory used by device mapper (dm) for things such as dm-crypt, dm-raid, dm-multipath:

$ ll /dev/mapper/
total 0
crw-------. 1 root root 10, 236 Feb 11 08:35 control
lrwxrwxrwx. 1 root root       7 Feb 11 08:35 fedora_localhost--live-home -> ../dm-3
lrwxrwxrwx. 1 root root       7 Feb 11 08:35 fedora_localhost--live-root -> ../dm-1
lrwxrwxrwx. 1 root root       7 Feb 11 08:35 fedora_localhost--live-swap -> ../dm-2
lrwxrwxrwx. 1 root root       7 Feb 11 08:35 luks-abcdef01-2345-6789-abcd-ef0123456789 -> ../dm-0
Phil
  • 11
-5

mount -o remount,size=10g /dev/shm