How to delete a swap file?

May 26, 2014 22.8k views
I was trying to delete the swapfile on a digital ocean virtual server using the instructions given here: However, when I type: sudo rm /swapfile I get the following error: rm: cannot remove `swapfile': Operation not permitted I have changed the permissions on the swap file to 777 and I believe I have root privileges. I still cannot delete it. It may be helpful to know that I created this instance of a server from an image of another server that I had configures. The swap was enabled in that original server. How do I delete this file? Thank you.
3 Answers
Thank you, Jerzy. I am almost certain that I had run swapoff /swapfile.
Anyhow, I did it again and this time it worked.

Thanks again.
You maybe missing an entry in /etc/fstab and turn on the swap somewhere else.

Therefore sudo swapoff -a -v take no effect.

If that's the case, check init scripts and remove the swapon script.

The following command may helps.

grep -r "swapon" /etc/init*
grep -r "swapon" /etc/rc*
Have another answer? Share your knowledge.