How To Add Swap On Linux
Swap is a type of filesystem and is a virtual memory. Whenever your RAM is full, your operating system will look for further memory in your swap space. For this reason, you reserve some part of the hard disk to create a swap partition.
Identifying Current Swap Space Usage
[root@localhost ~]# cat /proc/swaps Filename Type Size Used Priority /dev/sda7 partition 1951740 4 -1
Alternatively, use the swapon command:
[root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/sda7 partition 1951740 4 -1
Finally, the free command may also be used:
[root@localhost ~]# free total used free shared buffers cached Mem: 895112 721656 173456 0 36592 310156 -/+ buffers/cache: 374908 520204 Swap: 1952736 4 1952732
Adding a Swap File
Additional swap may be quickly added to the system by creating a file and assigning it as swap. This is achieved as follows. The following dd command example creates a swap file with the name swap with a size of 1Gb.
Create the swap file using the dd command:
[root@localhost ~]# dd if=/dev/zero of=/swap bs=1M count=1024 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 17.4283 s, 61.6 MB/s
Configure the file as swap
Change the permission of the swap file so that only root can access it
[root@localhost ~]# chmod 600 /root/swap [root@localhost ~]# mkswap /swap Setting up swapspace version 1, size = 1048572 KiB Enable the newly created swapfile : [root@localhost ~]# swapon /swap
Finally, modify the /etc/fstab file to automatically add the new swap at system boot time by adding the following line:
# cat /etc/fstab /swap none swap sw 0 0
Once the swap space has been activated, verify that it is in use using the swapon –s command:
[root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/sda7 partition 1951740 142884 -1 /swap file 1048572 0 -2
[root@localhost ~]# free -k total used free shared buffers cached Mem: 895112 828484 66628 0 2144 539552 -/+ buffers/cache: 286788 608324 Swap: 3000312 142876 2857436
If you don’t want to reboot to verify whether the system takes all the swap space mentioned in the /etc/fstab, use following to enable or disable swap.
[root@localhost ~]# swapoff -a
[root@localhost ~]# swapon -a
De-activate the additional swap space at any time using the swapoff command as follows:
[root@localhost ~]# swapoff /newswap
Like us on Facebook
We need your assistance to stay live
This week Top Posts
- Top Things To Do After Installing Ubuntu 13.10 'Saucy Salamander' : Ubuntu 13.10 Saucy Salamander will be released on coming October 17th with many new salient featur...0 comments |
- Install Power Commands 0.1.5 On Ubuntu 14.04/13.10/12.10/12.04 : Power Commands, power management application created by the Atareao team , this app helps users to...0 comments |
- Install Uget Download Manager In Ubuntu, Fedora, Debian : uGet is a very light-weight and powerful open source download manager. On March 4th, 2014 Uget Do...0 comments |
- Install Crashplan backup tool in Linux : CashPlan is an automated backup solution that either uses the CrashPlan Central server or any other ...0 comments |
- Download Elementary OS 'Luna' Official Wallpapers : Hi Guys, Am a great lover of Elementary OS, so I like to move almost everywhere with some its beaut...0 comments |
- How To Upgrade From Ubuntu 13.04 Raring To Ubuntu 13.10 Saucy Salamander : Ubuntu 13.10 Saucy will be released on October 17th. Hope it will come with lot of improvements and ...0 comments |
- Install Uget Download Manager In Ubuntu, Fedora, Debian
- Download Elementary OS ‘Luna’ Official Wallpapers
- Install Power Commands 0.1.5 On Ubuntu 14.04/13.10/12.10/12.04
- 5 Android Apps that’s Going to Make Running Your Business Less Stressful
- Puppet agent Install Using Script
- Install Corosync and Pacemaker On CentOS 6.5
- Install Fail2Ban On Ubuntu Server 13.04/13.10
- How To Install Google Chrome in Fedora 20, 19, 18
- How to surf using Tor Browser Bundle
- New Games got Greenlit on Linux by Steam Today!
This work by unixmen.com is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Copyright © 2008-2013 Unixmen.com .