Upgrade SWAP in Raspberry Pi to 8GB
First approach #
Check the content of file /etc/dphys-swapfile if exists. This file will control your swap file creation and configuration. If this file exists, modify it.
cat /etc/dphys-swapfileSet the CONF_SWAPSIZE value to appropriate size (in MB). By default, you will see something like CONF_SWAPSIZE=200 meaning the swap size is 200MB.
Am testing on my Raspberry Pi 5 with 16GB RAM and a 512GB SD card. For experimentation, I've updated my swap to 8GB, by updating CONF_SWAPSIZE=8192.
sudo systemctl restart dphys-swapfileManual process #
cat /proc/swaps
swapon -s
free-hTurn off SWAP.
sudo swapoff -a
free -hRemove the existing SWAP file.
sudo rm /var/swap
free -hCreate new SWAP. This will take a while to run.
sudo dd if=/dev/zero of=/var/swap bs=1024 count=8388608
sudo fallocate -l 8G /var/swap
sudo chmod 0600 /var/swap
sudo mkswap /var/swap
ls -l /var/swap
swapon -s
free -h