Create Swap #
In this guide, we’ll create a swap file on CentOS.
This guide will provide steps on the quickest way to create a swap file on CentOS, should work on both CentOS 7, 8 and Stream. Before proceeding with this tutorial, check if your CentOS installation already has swap enabled by typing:
sudo swapon --show
- Create file
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
- Lock to root perms
sudo chmod 600 /swapfile
- Make Swap and enable it
sudo mkswap /swapfile
sudo swapon /swapfile
- Persist on boot
sudo vi /etc/fstab
/swapfile swap swap defaults 0 0
- Change swappiness
vi /etc/sysctl.conf
vm.swappiness=10