How to create and use a Swap file
December 27, 2022 03:55PM
This instruction will be revised to add more detailed discussion. Below are the basic steps to create a swap file and activate it.

1. Create the swap file of 512MB at the rootfs top directory
cd /
dd if=/dev/zero of=swapfile1 bs=1024 count=524288
mkswap swapfile1 
chmod 0600 swapfile1

2. Turn on swap
swapon /swapfile1

3. Check the swap space

free -h
total        used        free      shared  buff/cache   available
.....
Swap:          511Mi          0B       511Mi

swapon
NAME       TYPE SIZE USED PRIO
/swapfile1 file 512M   0B   -2


4. Add swapfile1 entry to fstab so that it will be automatically on during boot.

cat /etc/fstab
# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
LABEL=rootfs   /               ext3    noatime,user_xattr,acl,errors=remount-ro 0 1
/swapfile1     swap            swap    defaults          0       0
tmpfs          /tmp            tmpfs   defaults          0       0

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 4 time(s). Last edit at 12/27/2022 08:03PM by bodhi.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: