Skip to content

Instantly share code, notes, and snippets.

@niotech
Last active May 2, 2024 13:37
Show Gist options
  • Save niotech/af5b0df942429a4436d50540abda7a5d to your computer and use it in GitHub Desktop.
Save niotech/af5b0df942429a4436d50540abda7a5d to your computer and use it in GitHub Desktop.
Increase Linux (Debian / Ubuntu) Swap Size

Resize Swap to 8GB

Turn swap off

This moves stuff in swap to the main memory and might take several minutes

sudo swapoff -a

Create an empty swapfile

Note that "1G" is basically just the unit and count is an integer.

Together, they define the size. In this case 8GB.

sudo dd if=/dev/zero of=/swapfile bs=1G count=8

or

sudo dd if=/dev/zero of=/swapfile bs=512M count=16

Set the correct permissions

sudo chmod 0600 /swapfile

sudo mkswap /swapfile # Set up a Linux swap area sudo swapon /swapfile # Turn the swap on

Check if it worked

grep Swap /proc/meminfo

Make it permanent (persist on restarts) Add this line to the end of your /etc/fstab:

/swapfile swap swap sw 0 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment