DEV Community

hub
hub

Posted on

swapfile vs swap-partition: some steps to organize swapiness in linux

to do this - we can go round to create swap in partition - we easily do it with the file-creation
here we go:

This process is allmost completly done in terminal.

that said - you will see that allmost every command lines will be listed here and

step 1 start the terminal and type in this command to create a swap file:

sudo fallocate -l 2G /swapfil

note: this tiny command will do alot: it just creates a 2 GB swapfile. So, if you need a even taller size of the so called swap file, just replace the number above 2G in the command you like more with the number you want. 2G represents a very cool swap file size. That said. If you need to have 4 GB or 8 GB swap file, then we need to type in 4G or even 8G in the command

Next step is to set permissions for the swap file. this is pretty very important: we here use the command:

sudo chmod 600 /swapfile

note: i think that this is very important.

Now we go ahead and do even more: we now need to format the file as swap. Type the command:

`sudo mkswap /swapfile

this is very important.`

After this command- now we can activate the swap with this tiny following command:

sudo swapon /swapfile

so far so good: the next step is to make the changes durable - in other words they should last long.
so the next what we need to do is to make these changes really lets say permanent and make it so that the swap is active all the time.

that said - we now need to go to the fstab and finally have to edit the fstab file with an text editor of our choice. for example we can use nano text editor and access the fstab file with this command:

sudo nano /etc/fstab

and besides this - we can now do the following: in the fstab file, add the following line:

/swapfile swap swap defaults 0 0

ready - now we need to restart the notebook and then we are done

Top comments (0)