Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Increasing swap size. Only tested on the ubuntu/trusty64 Vagrant box. CREDIT GOES TO --->
# size of swapfile in megabytes
# does the swap file already exist?
grep -q "swapfile" /etc/fstab
# if not then create it
if [ $? -ne 0 ]; then
echo 'swapfile not found. Adding swapfile.'
fallocate -l ${swapsize}M /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap defaults 0 0' >> /etc/fstab
echo 'swapfile found. No changes made.'
# output results to terminal
df -h
cat /proc/swaps
cat /proc/meminfo | grep Swap

great script, thanks!!

fcarrega commented Apr 1, 2016

Thanks !

luizs81 commented Jul 5, 2016

For me it only worked putting sudo in front of every command and replaced

echo '/swapfile none swap defaults 0 0' >> /etc/fstab


echo '/swapfile none swap defaults 0 0' | sudo tee -a /etc/fstab

I'm calling this script from my Vagrantfile.

@luizs81 normally Vagrant runs the provision script with sudo. Maybe you have something like this config.vm.provision :shell, privileged: false, path: "", with privileged: false. It could be intentional, though.

luizs81 commented Jul 21, 2016

@sergiopereiraTT You are right! I indeed had the privileged: false in my Vagrantfile. Thanks for the heads up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment