Skip to content

Instantly share code, notes, and snippets.

@thebearingedge
Created December 2, 2022 01:58
Show Gist options
  • Save thebearingedge/acc1fc643a638ea4101ba3005cef893d to your computer and use it in GitHub Desktop.
Save thebearingedge/acc1fc643a638ea4101ba3005cef893d to your computer and use it in GitHub Desktop.
Resize swap memory on t2.micro EC2 instance (Ubuntu)
#!/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