Be aware that to create a SWAP, it doesn’t necessarily have to be a partition. The SWAP can be created in a file, which we’ll learn about in this post.
The first thing is to decide on the location of the SWAP file we are going to create. In our tutorial we will use the system’s Root partition and a 1 GB SWAP:
dd if=/dev/zero of=/swapfile bs=1024 count=1048576
Replace the value of count=1048576 with the size in KBytes of your partition. For example, if you want a 16 GB partition, the calculation would be 16 * 1024 * 1024 = 16777216.
Change the file permissions:
chmod 600 /swapfile
Turn the file into a SWAP:
mkswap /swapfile
Almost done! Now activate SWAP:
swapon /swapfile
That’s it! SWAP has been activated. To have it automatically activated at system startup, add the following line to the end of your /etc/fstab file:
/swapfile none swap sw 0 0
- Tags:
- swap