Created
November 9, 2021 05:00
-
-
Save tennisonchan/1567a3dd4d4777002f1aa889f9fab59f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /bin/bash | |
# Create a file that will be used for swap | |
sudo fallocate -l 1G /swapfile | |
# If `fallocate` is not installed or if you get an error message saying fallocate failed: `Operation not supported` | |
# You can use the following command to create the swap file | |
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576 | |
# Only the root user should be able to write and read the swap file. To set the correct permissions type | |
sudo chmod 600 /swapfile | |
# Use the mkswap utility to set up the file as Linux swap area | |
sudo mkswap /swapfile | |
# Enable the swap with the following command | |
sudo swapon /swapfile | |
# To make the change permanent open the /etc/fstab file and append the following line | |
``` | |
# in file /etc/fstab | |
LABEL=SWAP_FILE swap defaults 0 0 | |
``` | |
# To verify that the swap is active, use either the swapon or the free command as shown below: | |
sudo swapon --show | |
``` | |
NAME TYPE SIZE USED PRIO | |
/swapfile file 1024M 507.4M -1 | |
``` | |
sudo free -h | |
``` | |
total used free shared buff/cache available | |
Mem: 488M 158M 83M 2.3M 246M 217M | |
Swap: 1.0G 506M 517M | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment