Link Search Menu Expand Document

SwapFile

Table of contents

System update and upgrade

sudo apt update & sudo apt upgrade 
htop 
    # Shows CPU and memory usage 
    # Not recommended for SSD server
q 
    # q to exit

Create Swap file

sudo fallocate -l 1G /swapfile   
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
sudo chmod 600 /swapfile
    # make this file readable
sudo mkswap /swapfile
    # output: Setting up swapspace version 1, 
    # size = 1024 MiB (1073737728 bytes), no label, 
    # UUID=6******3-****f-4****-****0-c********6
sudo swapon /swapfile
sudo nano /etc/fstab 
    # add `/swapfile swap swap defaults 0 0`,
    # to the end of the file
sudo mount -a 
    # to check syntax error 
sudo free -h 
    # check the swapfile

Delete Swap file

sudo swapoff -v /swapfile
    # to switch off swap file
sudo rm /swapfile
sudo fallocate -l 2G /swapfile 
    # change `2` to any other number to change swap file size 
sudo nano /etc/fstab
    # remove the last line of swap file to remove 
cat /proc/sys/vm/swappiness 
    # check value of the swappiness 
sudo nano /etc/sysctl.conf
    # change swappiness value, 
    # at the end add this [vm.swappiness=10],
    # 10 is the most common value.