1

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?

2
  • Um, did you try swapoff? Mar 13, 2016 at 19:04
  • Well that did the trick. I didn't even know that that existed. I don't suppose you could hazard a guess as to why this happened? Or why I couldn't find an associated PID?
    – igal
    Mar 13, 2016 at 19:37

1 Answer 1

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .