User Tools

Site Tools


ubuntu:swap:increase_swap_size

Ubuntu - Swap - Increase Swap Size

Recent releases of Ubuntu use swap file instead of the traditional swap partition.

  • The swap file is simply a file under the root which is used as swap to share the burden on the RAM.
  • The biggest advantage of using a swap file is that it is easy to resize.
    • That’s not always the case when a dedicated swap partition is used.

IMPORTANT:

  • If you are using a swap partition and want to increase the swap size, you can still go ahead and create a swap file.
  • Linux can use multiple swap spaces as needed; and this way, there is no need to touch the partition.

Check if there is a swap file in the system

swapon --show

returns:

NAME      TYPE SIZE USED PRIO
/swapfile file   4G 2.1G   -2

NOTE: This shows that there is a swapfile.

  • TYPE: If this shows file, it indicates that a swap file is being used.

Take the swap file offline

Before resizing the swap file, turn the swap off.

sudo swapoff /swapfile

NOTE: The command does not produce any output and it may take a few minutes to complete.

Make sure that there is enough free RAM available to take the data from swap file.

  • Otherwise, create a temporary swap file.

Resize the swap file

sudo fallocate -l 4G /swapfile

Mark this file as a swap file

sudo mkswap /swapfile

NOTE: There should be some output where it warns you that the old swap signature is being wiped.


Enable the swap file

sudo swapon /swapfile

NOTE: All done!

  • The new swap file is created with the increased swap size.

Check the swap size

swapon --show

free -h

returns:

               total        used        free      shared  buff/cache   available
Mem:            62Gi        10Gi       886Mi       364Mi        50Gi        50Gi
Swap:          4.0Gi       2.1Gi       1.9Gi

ubuntu/swap/increase_swap_size.txt · Last modified: 2024/07/30 16:02 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki