Linux Tip | How To Create A Swap File

Video is ready, Click Here to View ×

In this video, I show you how to create a swap file on Ubuntu/Linux Mint.

How To Create A Swap File

Stat swap:

sudo swapon -s

free -m

Turn swap off:

sudo swapoff -av

Create new swap file:

sudo fallocate -l 4G /.swapfile

Secure the swap file:

sudo chmod 600 /.swapfile

Verify the swap file:

ls -lh /.swapfile

Format the swap sapce:

sudo mkswap /.swapfile

Turn swap on with new swap file:

sudo swapon /.swapfile

Verify that the system is using the new swap file:

sudo swapon…


  1. Hi Joe. Thanks for your many helpful videos. As I recall at the start of this one you commented about the time and not wanting to wake anyone. I was wondering if you were a little sleepy too! As I completed your video I noticed you had in your outline the last line 'remove any unwanted mount points'. Doesn't seem to be in the video? Were you checking to see if we were awake? 🙂

  2. I try to turn off Swap, but sometimes turn on automatically. Does anyone have an idea how to turn off forever ? I have enough memory and I don't need it

  3. Thank you for this video! Every time I dual, triple or quadruple boot my PC the last OS I install steals all swap partitions from all other OSs and I was looking for a fix! And this was it!!!

  4. i have tons of question:
    1) how do i delete the file
    2) how do i allocate the 4gb of my swap partition to the systeme partition
    i run elementary os on dual boot with w10 and i want to reduce the righting on my ssd how do i allocate the swap to my hdd.
    how do i explore the hdd on elemebtary os

  5. Like the Linux tutorials one question ! does a small Linux distribution which may run entirely within ram need swap space? 4 o'clock is the time I'm awake every morning. Great time of day to watch Linux YouTube videos, no distractions.

  6. The reason that some of your commands auto executed when you pasted them is that you highlighted beyond the last character and picked up the carriage return. Also, how do you remove the old swap partition? Can you use gparted to delete the partition and add the space back to your main partition?

  7. can the virtual machines be a solution for the linux's drivers problem for exemple the printers and webcams drivers????? can also be a solution for avoiding doing dual boot????

Leave a Reply

Your email address will not be published.