default Ubuntu 12.04 LTS doesn\'t create swap for some reason. Is there \"proper\" way to add it after install?
root@aux3:/root# df -h Filesystem Size Used Avai
I set up swapspace
first (had to build one from sources), but then decided to fall back to a manual solution since I prefer more control over memory in production environment.
I assume that mounting of 2 instance block devices is already configured in /etc/fstab
as /.inst0
and /.inst1
.
Add something like this in /etc/rc.local
:
setup_swap()
{
for D in /.inst0 /.inst1; do
findmnt $D || continue
cd $D || continue
test -r swapfile || dd if=/dev/zero of=swapfile bs=1M count=12292
chmod 600 swapfile
mkswap swapfile
swapon swapfile
done
}
setup_swap
The code is fully compatible with EC2 instance storage (aka SSD, aka "ephemeral", which is destroyed every time you stop the instance), and is reboot-friendly.
Please keep in mind it takes a while to create and/or enable the swapfiles, so give it a little time once you reboot to see if it worked. :)