I just recently increased my RAM, so I wanted to increase the swap size too. I know Elementary OS is based off Ubuntu, so I've been following Ubuntu information since there isn't much documentation for this stuff for Elementary OS specifically. I have 8GBs of ram now, and from what I understand, Ubuntu recommends that you allocate 11GBs of ram if you're planning on using hibernation, or 3GBs if you're not using hibernation. Is this true for Elementary OS too?


Anyways, I was following the following guide to increase the swap size:


But when I got to the part where we use the follocate command to increase the swap file size, I get the following error:

fallocate: fallocate failed: Invalid argument

I figured I'd allocate 11GBs of space just to be safe, so I was using the following command:

sudo fallocate -l 11G /dev/dm-2

Any ideas as to what I'm doing wrong here? Is 11GBs a good size for the swap for Elementary OS with 8GBs of RAM? Am I getting GiB mixed up with GB in the follocate command?

Thanks in advance.

  • 1
    Add the output of swapon --show. Swap can be a file or it can be a partition and that changes the steps you need to follow.
    – Maccer
    Oct 26 at 13:13

Generally a swap file would not be written in /dev, which contains device APIs, but in the root (/) directory. So long as you don’t mind having a file there, you can do something like this:

sudo fallocate -l 12G /swapfile

Note: The 12G size is different from what you specified not because 11GB is “wrong”, but because I generally leave 4GB of swap for buffers on machines that need to hibernate. Feel free to set any value you are comfortable with.

From here it would be a good idea to verify the file exists and is the right size with:

ls -lh /swapfile

You should see a single file of the same size you specified in the fallocate command.

The next step is to enable the swap file. This is done by setting the permissions:

sudo chmod 600 /swapfile

Then marking the file as being for swapping purposes:

sudo mkswap /swapfile

If everything goes properly, you’ll see something like:

Setting up swapspace version 1, size = 12288 MiB (12884901888 bytes)
no label, UUID=6ecf2854-2ab9-4437-1ee0-577e740897ff

Now you can tell the system to use that space:

sudo swapon /swapfile

You can verify Elementary OS is using the swap file with the swapon command:

sudo swapon --show

You should see something like this:

/swapfile file 12288M   0B   -2

Finally, to make your swap file operational at boot time, you need to edit your fstab (File System Table) file:

sudo vi /etc/fstab

Note: Feel free to use any text editor you are familiar with. It does not need to be vi.

Add this to the end of the file:

/swapfile     none     swap    sw   0   0

While this looks like a lot of steps, it’s not too bad when you step through the process to see what’s going on 👍🏻

  • Thank you for that detailed answer! I just have two questions. First, should I delete the old swapfile being used that was in /dev/dm-2? Second, in the fstab file, there is already a line that says "/dev/mapper/data-swap none swap defaults 0 0". Should I delete that line and replace it with the one you mentioned?
    – Link1600
    Nov 5 at 12:48
  • To answer your questions: (1) Yes, but only after you have disabled it and restarted the system (to ensure it's not being accessed) (2) If you do not have a swapfile at /dev/mapper/data-swap, then I would suggest first commenting out the line by adding a # to the very start. If nothing breaks, then you can delete the line 👍🏻
    – matigo
    Nov 5 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.