How to Enable Swap is Ubuntu 12,14,16
How to Enable Swap on Ubuntu 12.14.16 ? Swap is very useful for the system that requires more RAM that is physically available. If the memory is full and the system needs more RAM to run the programs properly, then check for swap space and transfer files there. In general terms, swap is a part of the hard disk used as RAM on system. I have a virtual machine running which has no swap on it. Many times services got crashed due to insufficient memory. In this situation, creating a swap file is better to keep them up. This article will help you to create a swap file on a Linux server after installation.
- Check System Swap - Before working make sure that the system has already swap enabled. If there is no swap, you will get output header only.
$ sudo swapon -s
- Create Swap File - Lets create a file to use for swap in a system of required size. Before making file make sure you have enough free space on disk. Generally it recommends that the swap should be equal to double the installed physical memory. I have 2GB of memory in my system. So I am creating a swap of 4GB in size.
$ sudo fallocate -l 4G / swapfile $ chmod 600 / swapfile
- Make It Swap - Now make a swap a usable file using mkswap command.
$ sudo mkswap / swapfile
- Enable Swap - Now set up swap for system using swapon command.
$ sudo swapon / swapfileNow check that swap is enabled or not. You will see results like something below.
$ sudo swapon -s Filename Type Size Used Priority / swapfile file 4194300 0 -1
- Setup Swap Permanent - Append the following entry to / etc / fstab file to enable swap on system reboot.
# vim / etc / fstab
/ swapfile no swap sw 0 0
- Setup Kernel Parameter - Now change the swappiness kernel parameter as per your requirement. It tells the system how often the system utilizes this swap area. Edit /etc/sysctl.conf file and append the following configuration in file.
$ sudo vim /etc/sysctl.conf
vm.swappiness = 10Now reload the sysctl configuration file
$ sudo sysctl -p
At this point, you have successfully enabled the swap on your Ubuntu system.