How to reclaim freed disk space after Telegraf filled all swap on Raspberry Pi Zero running Raspbian 9 Stretch?

/var/swap grew to 14GB, so I disabled swap with dphys-swapfile and deleted the swap file. cat /proc/swaps shows no open swap files, but df -h still reports 100% in use.

du -m | sort -n shows 14GB at ., but I can't see a way to reclaim any of that freed space. Tried rebooting. Can't install lsof because...Zero disk space.

  • This is a minor possibility, but I have seen this kind of behavior when an SD card has met its write limit. Raspbian will act normal as long as all writes fit in the write cache. When that fills up, there may be errors and even when everything looked fine with the cache, a reboot will reveal that the card is effectively read-only. If Telegraf has been swapping a long time, this is a possibility. – ferrix Feb 21 '19 at 7:52
  • Thanks @ferrix, that sounds possible. How to get the card out of its write limit? – Petrus Theron Feb 21 '19 at 8:00
  • That's permanent. After a certain amount of writes, a flash drive can only set a value for a single block a limited amount of times. At first, the card may migrate that data to another spare block internally but those will run out. The SD cards are bad at being verbose about it. An SSD would give out S.M.A.R.T. warnings for end of life ahead of time. For writing-heavy operations, prefer writing to ram or if you need swap, an external media or network share is a good option. I boot most of my raspberries from the network. – ferrix Feb 21 '19 at 8:07
  • What a terrible design. Is there a way to confirm this? It's a pretty new SD card. – Petrus Theron Feb 21 '19 at 8:38
  • Terrific if you consider that you can fit 128 gigs on a fingernail and not in a ROM format. For an operating system disk, yes terrible. The best way to confirm is to make a change on the card, pull the card out and see if the change persists. – ferrix Feb 21 '19 at 8:40
sudo swapoff -a
sudo swapon -a


sudo systemctl disable dphys-swapfile
sudo systemctl enable dphys-swapfile
  • 'The swapon and swapoff commands enable (and disable, respectively) devices and files for paging and swapping.' – Christo Goosen Feb 21 '19 at 11:17
  • If I remember the swapoff command needs an appropriate amount of RAM free to do this operation. Then swapon will start swap again. – Christo Goosen Feb 21 '19 at 11:18
  • Please don't explain details in comments instead do it in the answer. What is the difference between swapoff/swapon and disable/enable dphys-swapfile? We're looking for long answers that provide some explanation and context. – Ingo Feb 21 '19 at 20:54

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.