How to create or add a SWAP partition in Ubuntu and Linux Mint

The SWAP partition is an essential feature to get the best performance and stability, especially in a PC with smaller RAM. In a nutshell, SWAP space is like adding a RAM, but not a physical one, but allocating some amount of hard disk space as RAM – like a virtual RAM!

It makes sense to make a SWAP file for those who run resource-intensive applications like video convention, virtual machines, etc.. You don’t want RAM to overflow, and the system becomes non-responsive. It is possible that you initially assumed that you don’t need SWAP and completed the Ubuntu/Linux Mint installation, but now you figured out that you need SWAP too.

No worries, you don’t need to reinstall the entire operating system again to add the SWAP partition. You can add the SWAP anytime.

Creating a SWAP partition in Ubuntu, Linux Mint and derivatives

METHOD 1: Command-line Way from Terminal (Fastest way!)

STEP 1: First step is to check if by chance is there any SWAP partition already created in your PC. Use the see ‘swapon’ command:

sudo swapon --show

Enter your root password. If you see no output, it means that the SWAP doesn’t exist.

STEP 2: Next, let’s see the current partition structure of your computer’s hard disk. Use the ‘df’ command:

df -h

You should see the partition structure like the one I got in my test PC.

Terminal - Showing Current Partitions
Terminal – Showing Current Partitions

STEP 3: Now it’s time to create the SWAP file. Make sure you have enough hard disk space. It’s a matter of preference on how much SWAP size you need.

Typically, it is good to have twice as much as your RAM for the SWAP size. But you can even go ahead with exactly as much as your RAM – your choice.

In this example, I choose to go with twice that of RAM. I have my test PC with 2 GB memory. So, I will set 4 GB as SWAP. Run the following command. Use your number instead of 4:

Terminal Showing all Steps (Sorry about a typo command!)
Terminal Showing all Steps (Sorry about a typo command!)

sudo fallocate -l 4G /swapfile

STEP 4: SWAP file is created. Let’s give root-only permissions to it.

sudo chmod 600 /swapfile

STEP 5: Mark the file as SWAP space:

sudo mkswap /swapfile

STEP 6: Finally enable the SWAP.

sudo swapon /swapfile

STEP 7: You can now check using the same swapon command to check if SWAP is created.

sudo swapon --show

STEP 8: Also recheck the final partition structure.

free -h

STEP 9: Once everything is set, you must set the SWAP file as permanent, else you will lose the SWAP after reboot. Run this command:

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

That’s it! Exit the terminal.

You can launch the ‘System Monitor’ utility and check SWAP status. It should be enabled!

System Monitor -Resources shows SWAP usage
System Monitor -Resources shows SWAP usage

METHOD 2: GUI Way using GParted

STEP 1: First thing to know before you do anything is to figure out the SWAP size. Typically, it is good to have twice as much as your RAM. But you can even go ahead with exactly as much as your RAM – your choice. In this example, I choose to go with twice that of RAM. I have my test PC with 2 GB memory.  So, I will set 4 GB as SWAP.

STEP 2: Once you figured out the size of SWAP space, it’s time to create a partition of that size. You need to be careful here. Any wrongdoing here may mean a significant data loss! So for beginners, I would recommend taking a backup of your data to an external hard disk drive before moving ahead.

You can create a partition in several ways, but I recommend GParted, free software for partitioning and formatting needs, and is available from Software Center of Ubuntu/Linux Mint/elementary OS. But since you can’t resize and create a new partition on an active partition on which you are currently running Linux, I suggest you create a GParted Live USB drive and come back to this tutorial for next step. Alternatively, you can use an Ubuntu or Linux Mint Live USB drive too because it comes packaged with GParted.

STEP 3: Boot your PC into the GParted Live USB drive. Ubuntu/Linux Mint live USB users need to start GParted after booting into live desktop.

STEP 4: In the GParted window, select the Partition which you want to resize. Right-click on it and choose ‘Resize’.

GParted - Resize Partition
GParted – Resize Partition

STEP 5: You can drag the box and resize the partition. Or enter the SWAP size in MB in the box ‘Free space following (MiB). For example, I have added 4000 to indicate 4 GB partition.

Resizing a current partition will automatically create an ‘Unallocated’ new partition which is going to be the SWAP partition. Note that the actions you are doing now on GParted are not applied immediately. It processes all the commands as a batch process when you initiate it. But that’s at last. Proceed as follows.

STEP 6: You will see unallocated file system of the size you created. Right-click on it and select ‘New’. In the context menu, select ‘File system’ as ‘linux-swap’. You can enter ‘SWAP’ in the ‘Label’ field just for easier identifying.

SWAP Partition
SWAP Partition

STEP 7: Click ‘Add’.

STEP 8: Click ‘Apply’. Now GParted will shrink the partition and then add a new SWAP partition.

STEP 9: After the operations are complete, click ‘Close’.

STEP 10: You should now see the new Linux-Swap partition that you created.

STEP 11: Once everything is set, you must set the SWAP file as permanent, else you will lose the SWAP after reboot. Select the SWAP and then click ‘Partition’ > ‘Swapon’. You should see a lock added.

Make SWAP permanent using Swapon
Make SWAP permanent using Swapon

STEP 11: Close GParted and click the ‘Exit’ button on the GParted desktop and then reboot into your Linux system.

Your Linux system will automatically recognize the SWAP partition you have created! You don’t need to do anything. You can confirm if SWAP is active from the ‘System Monitor’.

Launch ‘System Monitor’ which is included in Ubuntu and Linux Mint by default (elementary OS users need to install it from AppCenter) and check the resources tab. You should see SWAP active.

System Monitor -Resources shows SWAP usage
System Monitor – Resources shows SWAP usage

Kiran Kumar
Hi there! I'm Kiran Kumar, founder of I'm an avid Linux lover and enjoy hands-on with new promising distros. Currently, I'm using Ubuntu as a daily driver and run several other distros such as Fedora, Solus, Manjaro, Debian, and some new ones on my test PC and virtual machines. I have a day job as an Engineer, and this website is one of my favorite past time activities especially during Winter ;). When I'm not writing for FOSSLinux, I'm seen biking and hiking on scenic trails. Hope you enjoy using this website as much as I do writing for it. Feedback from readers is something that inspires me to do more, and spread Linux love!. If you find a time, drop me an email or feedback from the 'Contact' page. Or simply leave a comment below if you found this article useful. Have a good day!


  1. Thanks!
    Tried the first method of creating a swap file.
    My kernel wouldn’t update due to low memory, and while investigating I noticed I had no swap drive.
    All sorted.


Please enter your comment!
Please enter your name here




In this article, we will take a look at 10 of the best PDF editors and tools out there in 2019 that are available for Linux platforms. The editors are going to be judged on the basis of their functionalities, portability, ease of installation, price, and convenience.
best linux distros beginners
Making the shift to Linux is not as complicated as some people make it out to be. There is a variety of Linux distributions available that cater to the needs of people who are planning on making the jump to Linux from any other operating system.