How to enable swapfile on your rpi board under ubuntu

quick guide for swap-file under ubuntu…
pls read this complete thread there are several methods…the last being the best of them so far…

should work on all rpi series boards…the more physical onboard ram the larger the automated swap file will be ,that is to say an 8 G.b board will have around 6 gig of swap…not tested as yet but i will when i get my 8 gig board…
large or small it will be invoked in some manner of size…
you can increase the size if you like but you must invoke some more code…coming soon…w/i/p.

open a terminal as root

apt install zram-config

open terminal and create this file… it does not exist you are creating it…
nano /etc/rc.local
enter code into etc/rc.local
zram-config

hit ctrl+x
hit yes or “y” the file will be saved with contents…

it will put 2.8 G.b of mem /swapfile into place…on a 4 gig board…

close all terminals
reboot
after it boots to the gui go into the menus
and find system tools==>>then==>>system monitor.
open it you should now see 2.8G.b of swap file…virtual mem
done …enjoy…im presently using the mate desktop so i am not shure how to find the system monitor under the standard interface..you should find it there some where ..i have to do it over again for the standard gui with the ape face on it....work to be done...this is a works in progress guys/gal`s…
will get it all sorted in the next few days …but the code will work…

if you want to see it on the command line open a terminal as root and code free -t it will be in front of you on the screen …just another way to check to see if it loaded…

it is using part of your file system media as swap space so make shore you using a minimum of 16 G.B sd-card …

Personally, I would use mkswap and swapon to make a real swapfile, and not use a compressed RAM disk for swap. Seems it would be the reason you need a swap file in the first place.

ok so i just tried both methods the latter is the simplest way to installl it …the echo codes are not valid because the kernel does not have the ability to perform them seems max limit is dependent on your physical ram onboard …i could not get more than 2.8 gig of swap ram …seems to be set maybe some body with more code exp than me could be of assistance needed here… however way you choose to do it i left both posts here…for Ubuntu users… for Debian i have not tested itt i`ll try get round to it today if i can…

seems none of the code or adjustments work with this version of ubuntu… just code this into your rc.local and let the system manage your swap memory

apt install zram-config

for the /etc/rc.local file just enter this code
zram-config

i also found this as well…
all you need do for this is
apt install zram-config
dont bother changing or editing the rc.local file you can leave it or delete it…

`sudo nano /usr/bin/init-zram-swapping`

and
at line

totalmem=`LC_ALL=C free | grep -e "^Mem:" | sed -e 's/^Mem: *//' -e 's/  *.*//'`
mem=$(((totalmem / 2 / ${NRDEVICES}) * 1024))

change 1024 to 2048 it will double its size to 4 gig approxx… i set it to 4096 and my total ram listed including swap was 12 gig…i am using a m:2 sata 6gb hdd so if your using an sd card be careful how you change this value…

also scroll down you will see a line that has its priority it states " P 5 " you can change this to what order it is i set mine to 1 just for a test…
so now i checked my system monitor and it states 8.3 gig of swap memory…

all i did for Ubuntu 21-04 was edit the file above ,i removed zram-config and then modded the file …
seems it changes from image to image at times … one of the above will work depending on what release of Ubuntu your using