VPS

Increase Ubuntu Swap Space

I regretted that I initially configured my swap space to just 1GB.

I am running out of memory with intensive apps such as GitLab.

And so I needed to increase swap.

It is rather simple, and very similar to the original post on adding swap memory.

Steps:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Assume I need another 2GB
# Allocate 2GB in another file. Let's call it swapfile2g.
sudo fallocate -l 2G /swapfile2g

# Make it secure
sudo chmod 600 /swapfile2g

# Activate it
sudo mkswap /swapfile2g
sudo swapon /swapfile2g

# Confirm again there's indeed more memory now
free -m
sudo swapon -s

# Configure fstab to use swap when instance restart
sudo nano /etc/fstab

# Add this line to /etc/fstab, save and exit
/swapfile2g   none    swap    sw    0   0

Comments