Magpiny
Mo Nov 28, 2022A swap file is a system file that creates temporary memory space when the system runs low on memory. A swap file allows the Operating System to use hard drive space to simulate extra memory on your system.
When the Operating System is running low on memory, inactive programs are then moved from Random Access Memory (RAM) into the swap file. This prevents your PC from freezing.
1. Check for swap partitions
$ swapon --show
2. Next create a swap partition
$ sudo dd if=/dev/zero of=/myswap/ bs=4096 count=1048576
if = the input file (/dev/zero)
of = the output file (/myswap)
bs = block size in bytes (4096)
amount = amount of blocks to read & write
3. Hit Enter and type your system root password and hit enter key
4. Check for your new swap file
$ ls /
5. Prepare swap
$ sudo mkswap /myswap
6. Set permission
$ sudo chmod 600 /myswap
7. Activate swap file
$ sudo swapon /myswap
8. Add swap file into fstab file
$ sudo gedit /etc/fstab
NOTE: here we're opening fstab file using gedit text editor but you can use nano, vim, emacs,micro or any other text editor of your choice.Add the following lines to the fstab file
/myswap none swap sw 0 0
use tabs instead of spaces for spacing here.Allow me to explain the last line (line 13 above) using an infographic
9. Display it
$ swapon --show
Here is a SUMMARY of all the commands i typed.
If you got this far, thanks for reading, be knowledge thirsty, i hope to see you again and I hope i helped.