Add Swap RAM on CentOS 8 (one line, automatically)

Paste the following code into a terminal on CentOS 8. It also works on CentOS 7 and will work on Red Hat 8, RHEL8, as well.

Where the first line has 4G, you can increase or decrease this number which refers to the size of the Swap RAM partition.

fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
swapon -s
echo '/swapfile swap swap sw 0 0' >> /etc/fstab

Leave a Reply

Your email address will not be published. Required fields are marked *