Created
December 2, 2022 01:58
-
-
Save thebearingedge/acc1fc643a638ea4101ba3005cef893d to your computer and use it in GitHub Desktop.
Resize swap memory on t2.micro EC2 instance (Ubuntu)
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/sh | |
swap_file=/var/swap.img | |
if [ ! -f $swap_file ]; then | |
echo 'creating 1gb swap file...' | |
touch $swap_file | |
dd if=/dev/zero of=$swap_file bs=1024k count=1000 | |
chmod 600 $swap_file | |
mkswap $swap_file | |
swapon $swap_file | |
else | |
echo 'swap file exists' | |
fi | |
free | |
if [ $(grep -c $swap_file /etc/fstab) = '0' ]; then | |
echo "$swap_file none swap sw 0 0" >> /etc/fstab | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment