Skip to main content

Adding Extra Swap Space

There are situations where we have to expand the SWAP space after installation. For example, suppose you are upgrading RAM 512MB to 1 GB MB, but there is only 1 GB of swap space available which was created during installation. It might be an advantage to increase the amount of swap space to Double the RAM(2 GB) as per the UNIX/Linux guidance and will help you to perform memory eaters.

You have two options: add a swap partition or add a swap file. It is recommended to add a swap partition, but this is not possible if you don't have free Disk space available.

Option 1

Its better to reboot the server to SINGLE USER mode(if possible) before adding the extra SWAP Space
And you can do an optional "swapoff" command to turn off all the swap spaces.

Create the swap partition fdisk.

# fdisk /dev/hda (Assuming Hard drive is hda)
Type n ( for new partition)
Determine the size for the partition
then Toggle the partiotion label to Linux Swap.Its id is 82

Save the partition table,exit fdisk and do a "partprobe" to make it effective

# partprobe

Now you have the swap partition, use the command mkswap to setup the swap partition.
At a shell prompt as root, type the following:

# mkswap /dev/hdaX

To enable the swap partition immediately, type the following command:

# swapon /dev/hdaX

To enable it at boot time, edit /etc/fstab to include:

/dev/hdaX swap swap defaults 0 0

The next time the system boots, it will enable the new swap partition.

After adding the new swap partition and enabling it, make sure it is enabled by viewing the output of the command
# cat /proc/swaps

# free

Option 2

Determine the size of the new swap file and multiply it by 1024 to determine the block size. For example, the block size of a 64 MB swap file is 65536.

At a shell prompt as root, type the following command with count being equal to the desired block size:

# dd if=/dev/zero of=/swapfile bs=1024 count=65536

Make it a SWAP file

# mkswap /swapfile

To enable the swap file immediately

# swapon /swapfile

To enable it at boot time, edit /etc/fstab and insert the following

/swapfile swap swap defaults 0 0


Popular posts from this blog

Check remote UDP connectivity from Linux

Hi there, You all know how to check TCP port connectivity from a Linux or UNIX machine to a remote machine using telnet as per th example below $ telnet 25 but we can't adopt TELNET to check UDP connectivity. Linux and most of the UNIXes come with a network layer utility called nc (abbreviation for netcat) which is very useful to check UDP connectivity and to explore a lot with both TCP and UDP. An example is shown below # nc -v -u -z -w 3 123 Connection to 123 port [udp/ntp] succeeded!

The best putty package available

Bored of Black screened Task bar filling putty? Issues with porting Saved sessions from machine to machine? Do you like tabbed SSH sessions? Start using portaputty instead of normal putty and link it with puttycm . Puttycm supports sessions to be saved in its own Database files. You can use the Putty sessions you have saved already right inside putty. You can have any number of databases which allow you to arrange Remote servers in folders and convenient namings. I personally recommend creating Database with puttycm rather than using the sessions saved in putty which doesn't offer any option to create folders and saving sessions under that directory tree. You can even save username/password to get it logged automatically and there is an option to pass commands to be run soon after login. I can't recommend this since some bug was found with these options. Portaputty is a variant of putty which stores all the Configuration data in text files instead of MS Window

#!/usr/bin/env bash ## Ping all machines in a Network PING="$(which ping) -c 1 -W 1" echo "Enter Subnet(eg:192.168.0)" read Subnet echo "Do you want to PING the entire network or a RANGE of IPs ? Enter your choice" echo 1. Ping Entire Network echo 2. Ping a RANGE read choice if [ $choice = 1 ]; then { echo Pinging..... for((i=1;i<255;i++)); do ${PING} ${Subnet}.${i} > /dev/null 2> /dev/null if [ $? -eq 0 ]; then echo -e "${Subnet}.${i} is up" fi done } fi if [ $choice = 2 ]; then { echo Enter the Starting IP of Range read a echo Enter the Last IP of Range read b echo Pinging..... for((i=$a;i<$b;i++)); do ${PING} ${Subnet}.${i} > /dev/null 2> /dev/null if [ $? -eq 0 ]; then echo -e "${Subnet}.${i} is up" fi done } fi exit 0