First step is to create empty file (I’ll create 1GB one). You can do that by issuing one of the following commands (you’ll need to be root
):
fallocate -l 1G /swapfile
or
dd if=/dev/zero of=/swapfile bs=1M count=1024
After that change permissions on that file so nobody else can read it:
chmod 600 /swapfile
Make swap:
mkswap /swapfile
And at last, activate it:
swapon /swapfile
If you want your system to mount that swap automatically on boot you should add following entry to your /etc/fstab file:
/swapfile swap swap defaults 0 0