How can I fake the amount of installed RAM for a specific program in Linux?

Create a fake meminfo and mount it over an original /proc/meminfo:

$ mkdir fake-meminfo && cd fake-meminfo
$ cp /proc/meminfo .
$ chmod +w meminfo
$ sed -Ei 's,^MemTotal:        [0-9]+ kB,MemTotal:        8839012 kB,' meminfo   # replace 8839012 with an amount of RAM you want to pretend you have
$ free -m  # check how much RAM you have now
              total        used        free      shared  buff/cache   available
Mem:           7655        1586        3770         200        2298        5373
$ sudo mount --bind meminfo /proc/meminfo                                 
$ free -m  # check how much RAM you pretend to have after replacing /proc/meminfo
              total        used        free      shared  buff/cache   available
Mem:           8631        2531        3800         201        2299        5403
$ sudo umount /proc/meminfo # restore an original /proc/meminfo
$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7655        1549        3806         200        2299        5410

You can also run the above commands in a mount namespace isolated from the rest of the system. References: Recover from faking /proc/meminfo


After some thinking, I did this:

Started with nano /proc/meminfo

Changed MemTotal, MemFree, MemAvailable, SwapTotal and SwapFree to desired values and saved to ~./meminfo

Gave the user boinc password sudo passwd boinc and shell -- sudo nano /etc/passwd , found the line boinc:x:129:141:BOINC core client,,,:/var/lib/boinc-client:/usr/sbin/nologin and changed the /usr/sbin/nologin part to /bin/bash

Then I faked RAM info using examples from here Recover from faking /proc/meminfo

unshare -m bash    #unshares mount spaces, for specific program "bash" only (and for whatever you want to launch from it)
mount --bind ~./meminfo /proc/meminfo      #substitutes real meminfo data with fake one

and confirmed with free that it worked

          total        used        free         shared     buff/cache  available
Mem:     2321456       21456     2300000           0           0     2300000
Swap:     5000000     1000000     4000000

Then switched to user su - boinc and just launched the program with

boinc --check_all_logins --redirectio --dir /var/lib/boinc-client

BOINC Manager can be launched then as usual

Total success, tasks which previously refused to run, started to download and then ran with no complications

Tags:

Linux

Ram