Skip to main content

Q.How do I add more swap space without formatting/deleting files on Ubuntu machine?

Q.How do I add more swap space without formatting/deleting files on Ubuntu machine?

A: Swap space is an area on disk that temporarily holds a process memory image. When physical memory demand is sufficiently low, process memory images are brought back into physical memory from the swap area on disk. Having sufficient swap space enables the system to keep some physical memory free at all times.

Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files.

The size of your swap space should be equal to twice of your machine's memory.

First to determine the amount of available swap space, use the "swapon" command:

root@techgyaan:~#swapon -s
Filename Type Size Used Priority
/dev/cciss/c0d0p5 partition 2907724 0 -1

swapon - enable/disable devices and files for paging and swapping

root@techgyaan:~#free -m
total used free shared buffers cached
Mem: 3547 670 2877 0 78 385
-/+ buffers/cache: 206 3341
Swap: 8839 0 8839

free - Display amount of free and used memory in the system

The value in the free column indicates the number of free blocks, where a block is 512 bytes.
To convert blocks to KB, divide the number by 2. For example, 2,000,000 free blocks is equivalent to 1,000,000 KB.

If you do not have enough swap space, perform the following tasks:
First you need to create a empty file:

root@techgyaan:~#dd if=/dev/zero of=/swap_file count=4096 bs=1M

dd - convert and copy a file, dd command, /dev/zero can be used to fill a file with a given number of the '\0' (nul) character
count=BLOCKS copy only BLOCKS input blocks, count='4096' is the size of your swap file in MB
bs=BYTES force ibs=BYTES and obs=BYTES
The size of your swap space should be equal to twice of your machine's memory.

root@techgyaan:~#chown root:root /swap_file
root@techgyaan:~#chmod 600 /swap_file

root@techgyaan:~#mkswap /swap_file
mkswap sets up a Linux swap area on a device or in a file

To make use of swap space which you create you need to start swapon
root@techgyaan:~#swapon /swap_file

To make it permanently turn on at every bootup edit "/etc/fstab"
root@techgyaan:~#vi /etc/fstab

Add this line to the end of the file
/swap_file none swap sw 0 0

Note: Take a backup of your fstab before editing which has static information about the filesystems.

Related: How to create swap file when there is no enough swap space in server

Comments

Popular posts from this blog

Download of the Day!

Amarok 2.0.2 has released Amarok is an open source alternative music player for iTunes. Amarok supports Linux, Unix, MacOSX and windows Operating system. It is smiliar to iTunes just drag & drop the songs to play list. Amarok also lets you listen to internet radio ( mp3 streaming ) including music from last.fm . Features Automatic cover Lyrics download Dynamic playlists Visualizations and Podcasting. These are only some of the great new features of Amarok 2. Give it a try! Download here An least but not last - Amarok will also synchronize your music to your iPod. For the more technical users a scripting interface allows you to extend the functionality of Amarok. Print Page Feedbacks: We appreciate feedbacks and suggestions about our website info@techgyaan.org

How to install WebLogic 8 on Solaris 10

Lets start the installation Login to solaris box use sudo command to install the application. $ ./server814_solaris32.bin Extracting 0%……………………………………………………………………………………….100% Unable to instantiate GUI, defaulting to console mode. Welcome: ——– ————— This installer will guide you through the installation of WebLogic Server 8.1 SP4. Type “ Next” or enter to proceed to thenext prompt. If you want to change data entered previously, type “Previous”. You may quit the installer at any time by typing “ Exit”. Enter [Exit][Next]> BEA Systems License Agreement: —————————— BEA SYSTEMS, INC. SOFTWARE LICENSE AGREEMENT USE OF SOFTWARE ORDERED FROM BEA SYSTEMS, INC. (”BEA”) IS PROVIDED ONLY UNDER LICENSE FROM BEA. PLEASE READ THE FOLLOWING LICENSE CAREFULLY AND INDICATE YOUR ACCEPTANCE BY CLICKING THE ACCEPTANCE BOX. CERTAIN CAPITALIZED TERMS ARE DEFINED IN SECTION 11. 1. LICENSE TERMS a. Workshop Free Use. The terms of this Section 1(a) are applicable to you if you h...

Sysadmin Daily Commands

Some of these commands are used by unix/linux administrator in his/her day-to-day activities  cat to concatenate files to standard output chgrp to change file group ownership chmod to change file access permissions chown to change file owner and group cp to copy files and directories date to print or set the system data and time dd to convert and copy a file df to report filesystem disk space usage dmesg to print or control the kernel message buffer echo to display a line of text hostname to show or set the system's host name kill to send signals to processes ln to make links between files login to begin a session on the system ls to list directory contents mkdir to make directories mknod to make block or character special files more to page through text mount to mount a filesystem mv to move/rename files ps to report process status pwd to print na...