If you have already made a swap file during setup of ubuntu, would the commands mkswap and swapon add to it or it replaces it? Is there a way to add to it rather than replace it? Is there a way to do it while you are not sudoer?

  • In parallel to your question, see this answer and consider removing SWAP altogether Jul 11, 2018 at 11:46
  • @RobertRiedl This is bad advice. Swap has advantages even when you have a lot of RAM. See chrisdown.name/2018/01/02/in-defence-of-swap.html for a detailed discussion. TL;DR: Swap won't hurt if you do not need it (and may be used to make place for better caching), but there are times when you will need it and having it avoids a lot of trouble.
    – allo
    Jul 11, 2018 at 12:07
  • @allo, I said consider removing. No amount of swap will ultimately protect you from the OOM and if you have swap, linux will use it and it will be slower than without swap. If you don't have the diskspace to spare or if your disks are old and slow, I would advise against. Interestingly we just discussed the merits of swap in server and VM environments. But this is not the place to discuss the pro and cons of swap, I just wanted to point out to OP that you might consider doing away with swap. Jul 11, 2018 at 12:21
  • Yes and you should not consider removing it, as swap is an elementary feature of linux memory management and the kernel does a good job managing it so it does not slow down your pc. Please read the accepted answer about tuning it in the question you linked.
    – allo
    Jul 11, 2018 at 13:43
  • 1
    Thanks guys for the valuable input. I asked this question because I am running metagenome sequence assembly on the department's server using SPAdes which is a memory greedy algorithm. When it reaches the end of the RAM, it crashes wherever it is in the assembly, sometimes so close to the end. So, I needed to extend the RAM by some extra gigabytes for it to finish. Server admin says that there is already a swap file. Can I extend on it then removing this extra? Jul 11, 2018 at 14:10

2 Answers 2


You can

  • create a partition and make it a swap partition with mkswap or gparted

  • add a corresponding line in the file /etc/fstab to make it active at boot. You can use

    sudo swapon -a

    to make all swap devices (files and partitions in /etc/fstab) active.

  • You can also create a second swapfile (with another name), or maybe better, replace the current swapfile with a new one.

But first you should consider, if you really need more swap and in that case why and how much.

Managing swap is a typical task, where you need sudo permissions.

  • Good point regarding the second swapfile. Sadly, for the last statement. Thanks dear Jul 11, 2018 at 14:16

The command swapon <specialfile> adds a swap area prepared with mkswap <device>.

swapon --show displays the active swap areas.

  • This makes an extra swap area, isn't it? Jul 11, 2018 at 14:13
  • Yes, each swapon adds a swap area, as you can verify with swapn --show.
    – muclux
    Jul 11, 2018 at 18:27

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.