Yes, you can create multiple swap files in Linux. Here’s how you can do it:
-
Create the swap files using the
fallocateorddcommand. For example, to create three swap files of 1GB each:sudo fallocate -l 1G /swapfile1 sudo fallocate -l 1G /swapfile2 sudo fallocate -l 1G /swapfile3Alternatively, using
dd:sudo dd if=/dev/zero of=/swapfile1 bs=1G count=1 sudo dd if=/dev/zero of=/swapfile2 bs=1G count=1 sudo dd if=/dev/zero of=/swapfile3 bs=1G count=1 -
Set the correct permissions for the swap files:
sudo chmod 600 /swapfile1 /swapfile2 /swapfile3 -
Set up the swap area:
sudo mkswap /swapfile1 sudo mkswap /swapfile2 sudo mkswap /swapfile3 -
Enable the swap files:
sudo swapon /swapfile1 sudo swapon /swapfile2 sudo swapon /swapfile3 -
Verify that the swap files are active:
sudo swapon --show -
To make the changes permanent, add the following lines to your
/etc/fstabfile:/swapfile1 none swap sw 0 0 /swapfile2 none swap sw 0 0 /swapfile3 none swap sw 0 0
This will allow your system to use the swap files on boot.
