How to create swapfile?

Moderator: BarryK

Post Reply
esos
Posts: 154
Joined: Thu Feb 18, 2021 4:33 am
Been thanked: 17 times

How to create swapfile?

Post by esos »

How to create swapfile in easyos for low RAM pc?
Thanks.

FeodorF
Posts: 161
Joined: Tue Jul 14, 2020 7:52 pm
Has thanked: 8 times
Been thanked: 24 times

Re: How to create swapfile?

Post by FeodorF »

Create a new partition with file type '82 Linux swap' will do it.
The Linux kernel will auto detect the swap partition at boot.

Menu > System > Pdisk partition manager
or
Menu > Filesystem > GParted partition manager

User avatar
BarryK
Posts: 2316
Joined: Tue Dec 24, 2019 1:04 pm
Has thanked: 98 times
Been thanked: 583 times

Re: How to create swapfile?

Post by BarryK »

@esos
That is a very good question. I haven't thought about a swap file for a very long time.
As Feodor reported, you can create a swap partition.

Here is the relevant code in /etc/rc.d/rc.sysinit, line 97:

Code: Select all

loadswap_func() { #w481 made into a function.
 echo "LOAD SWAP"
 for ONESWAP in `fdisk -l | grep ' Linux swap' | cut -f 1 -d ' ' | tr '\n' ' '`
 do
  echo -n "Loading swap partition $ONESWAP..." >/dev/console #loading swap partition
  swapon $ONESWAP
  status_func $?
  [ $? -eq 0 ] && SWAPON="yes"
 done
 #if no go, try for a swap file...
 if [ "$SWAPON" != "yes" ];then
  SWAPFILE="/mnt/wkg/pupswap.swp" #20230413
  if [ -f $SWAPFILE ];then
   echo -n "Loading swap file ${SWAPFILE}..." >/dev/console
   swapon $SWAPFILE
   status_func $?
   [ $? -eq 0 ] && SWAPON="yes"
  fi
 fi
}

...it first looks for a swap partition. Failing that, it looks for a swap file.

I have changed the path for $SWAPFILE, appended "/mnt/wkg", so that is in the working-partition.

Here is how to create 'pupswap.swp':

https://www.cyberciti.biz/faq/linux-add ... ile-howto/

If you do that on an SSD, it needs to be a high quality SSD that can sustain lots of writes.

Post Reply

Return to “EasyOS”