6

So, without really thinking too much, I ran this script:

#!/bin/bash
SWAP="${1:-512}"
NEW="$[SWAP*1024]"; TEMP="${NEW//?/ }"; OLD="${TEMP:1}0"
sed "/^Swap\(Total\|Free\):/s,$OLD,$NEW," /proc/meminfo > /etc/fake_meminfo
mount --bind /etc/fake_meminfo /proc/meminfo

from here: http://linux-problem-solver.blogspot.com.ee/2013/08/create-fake-swap-in-openvz-vps-if-you-get-swapon-failed-operation-not-permitted-error.html

It worked really well for lying about my swap-space, but now I'd like good old commands like

free -m

to work again, but /proc/meminfo is totally empty and the server doesn't seem to know anything about it's RAM any more, even with atop or somesuch.

Thanks for reading.

2
  • 1
    Does it work to simply umount /etc/fake_meminfo? – s3lph Jan 27 '16 at 23:27
  • Maybe it would have worked? I failed to mention I already tried fixing it by running a bunch of mount/unmount commands, just not the right one. – Lauri Elias Jan 28 '16 at 7:37
7

Just unmount it: umount /proc/meminfo

All those programs (free, top, atop, etc.) have to get their information from somewhere. And that somewhere is /proc/meminfo.

If you want to provide fake information for one program, run it in a mount namespace:

$ unshare -m bash
$$ mount --bind … /proc/meminfo
$$ myprogram

If you want to lie only about the swap space, make the fake meminfo file a dynamic file via a FUSE filesystem. (Note: a named pipe also works, but only if it's accessed by a single program at a time.)

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.