Created
December 18, 2021 15:28
-
-
Save lajosbencz/a260516d064543237d932880b3cbdb8c to your computer and use it in GitHub Desktop.
Ubuntu 20 create swap space on disk
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 | |
SIZE="$1" | |
FILE="/var/swap.img" | |
SWPS=10 | |
CHPR=50 | |
if [ -z "$SIZE" ]; then | |
echo "first argument must be size (fallocate -l)" | |
exit | |
fi | |
if [ ! -z "$2" ]; then | |
FILE="$2" | |
fi | |
if [ -f "$FILE" ]; then | |
echo "file ${FILE} already exist!" | |
exit | |
fi | |
fallocate -l "$SIZE" "$FILE" | |
chmod 600 "$FILE" | |
mkswap "$FILE" | |
swapon "$FILE" | |
echo -e "${FILE}\tnone\tswap\tsw\t0 0" >> /etc/fstab | |
echo -e "\nvm.swappiness=${SWPS}\nvm.vfs_cache_pressure=${CHPR}" >> /etc/sysctl.conf | |
sysctl "vm.swappiness=${SWPS}" | |
sysctl "vm.vfs_cache_pressure=${CHPR}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment