I would like to install Ubuntu to a 8GB USB stick so really don't have space for swap. I have 8GB RAM and the most memory intense apps I use are Firefox and LibreOffice. I don't use hibernate. I know you can have a swap file in Linux but can you have one that grows and shrinks as needed? That would give me a safety net and most likely not make me loose any space with low swappiness. I researched the topic and found these steps:

sudo mkdir -p /var/cache/swap/

sudo fallocate -l 1G /var/cache/swap/swap0

or alternatively if the above fails:

sudo dd if=/dev/zero of=/var/cache/swap/swap0 bs=1M count=1024


sudo chmod 0600 /var/cache/swap/swap0

sudo mkswap /var/cache/swap/swap0

sudo swapon /var/cache/swap/swap0

The add this t /etc/fstab:

/var/cache/swap/swap0    none    swap    sw      0 0

Then install swapspace to make the swap file dynamic:

sudo apt-get install swapspace

And that is it? Just installing swapspace will decrease my swap file from 1GB to zero and let it grow up to 1GB?


Well you can try of course mentioned approaches. One more simple thing is to install Ubuntu just without swap partition at all. Linux will not block you from this, it can work without swap.


swapspace is your friend - it dynamically resizes a swap file when you need extra memory (but goes away when you don't).

  • Could you elaborate? – Zanna May 9 '17 at 15:16
  • 2
    Although swapspace may be a good solution for some installations, the fact that it is an unmaintained package and has not been updates since 2013 may cause it to be less than fully compatible with current systems. – Charles Green May 9 '17 at 15:19

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.