Increase swap to file

My system has 4gb of ram, At time of installation I selected “swap to File”(btrfs), and it created 512mb of /swap/swapfile. Now I think it should be larger, or of be other swap type. Help me increase or change it show I can easily run nodejs and lots of browsing tab.

  1. Turn off all swap processes

sudo swapoff -a

  1. Resize the swap to be 8GB for example

sudo dd if=/dev/zero of=/swapfile bs=1M count=8192

For 4GB will have to be 4086

if = input file
of = output file
bs = block size
count = multiplier of blocks

  1. Change permission

sudo chmod 600 /swapfile

  1. Make the file usable as swap

sudo mkswap /swapfile

  1. Activate the swap file

sudo swapon /swapfile

  1. Edit /etc/fstab and add the new swapfile entry if it isn’t already there
/swapfile none swap sw 0 0
  1. Check the amount of swap available:

grep SwapTotal /proc/meminfo

5 Likes

   ~  sudo swapon /swapfile  :heavy_check_mark:
swapon: /swapfile: swapon failed: Invalid argument

Are you using bash or zsh? What kernel?
If any doubt, please check Swap - ArchWiki

zsh with kernel 5.14

Try with bash and if that doesn’t work, try with a LTS kernel.

ok trying

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.