Skip to content

Instantly share code, notes, and snippets.

@MarkGavalda
Last active June 9, 2016 19:28
Show Gist options
  • Save MarkGavalda/595f62f0099d6fcd2859 to your computer and use it in GitHub Desktop.
Save MarkGavalda/595f62f0099d6fcd2859 to your computer and use it in GitHub Desktop.
Create a swap file on Ubuntu of 1GB with 15% swappiness
#!/bin/bash
# Creating a 1G swap file
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
# Changing the file permission
sudo chmod 600 /swapfile
sudo chown root:root /swapfile
# Formatting the file as a swap type
sudo mkswap /swapfile
# Adding the swap file to the system initialization
sudo echo /swapfile none swap defaults 0 0 | sudo tee -a /etc/fstab
# Adjusting swappiness to 15%
sudo bash -c "echo 'vm.swappiness = 15' >> /etc/sysctl.conf"
# Activating the swap file
sudo swapon -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment