zombie lxc swap file: text file busy but no pid

igal asked:

I have a server running Ubuntu 12.04.5 LTS (Precise Pangolin). On that server I created a new Linux container:

$ sudo lxc-create -n mycontainer

After a while I decided to get rid of this container:

$ sudo lxc-destroy -n mycontainer

However I got the following error:

rm: cannot remove `/var/lib/lxc/mycontainer/rootfs/swapfile': Operation not permitted

I tried to delete the offending file manually:

$ sudo rm /var/lib/lxc/mycontainer/rootfs/swapfile

But, sure enough, this gave me the same error message.

I checked the extended file attributes with lsattr to make sure it wasn’t immutable:

$ sudo lsattr /var/lib/lxc/mycontainer/rootfs/swapfile
-------------e- /var/lib/lxc/mycontainer/rootfs/swapfile

As an experiment I tried to overwrite the file:

$ echo '' > /var/lib/lxc/mycontainer/rootfs/swapfile

This gave me a new error message:

bash: /var/lib/lxc/mycontainer/rootfs/swapfile: Text file busy

So I tried to use lsof to get the pid of the process which is using the file:

$ sudo lsof /var/lib/lxc/mycontainer/rootfs/swapfile

This produced no output. I tried the same thing with fuser:

$ sudo fuser /var/lib/lxc/mycontainer/rootfs/swapfile

Again, no output.

I’ll also mention that I checked the size of the file:

$ sudo du -h /var/lib/lxc/mycontainer/rootfs/swapfile
1.1G    /var/lib/lxc/mycontainer/rootfs/swapfile

What’s going on here and how do I get rid of this file?

My answer:

The name swapfile gives a very strong hint as to the file’s purpose and what is using it.

That is: The system is using it as swap, because someone created the swap file and added it to the system with swapon.

Try removing it from active swap with swapoff:

swapoff /var/lib/lxc/mycontainer/rootfs/swapfile

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.