ddedic
6/9/2016 - 7:28 PM

Create a swap file on Ubuntu of 1GB with 15% swappiness

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