Skip to main content

SETTING SWAP SPACE

There are two methods to increase the swap memory after installation

1.FDISK UTILITY
First check the system for swap information, use swapon -s option
#swapon -s
It will show you no swap space
#free -m (This command will give you information about total swap memory available)
We can see no swap memory available


Now we have to create a partition.our attached harddisk is xvdf.so using fdisk utility
#fdisk /dev/xdvf
Now select primary or extended partition that we want.We go with primary.
Then select partition number.we select 1 which is default.After that we set size as +500M.
Then we want to select type,so type t and then L for listing.Out of it select 82 which is the swap partition
Now save it by typing w



#lsblk
From this we can see that certain space is allocated as swap space


Then refresh the system settings, using the partprobe command
#partprobe /dev/xvdf1
Format the swap partition by using mkswap command
#mkswap /dev/xdvf1
Activate the swap partition by using the following command.
#swapon /dev/xdvf1


Make enteries in /etc/fstab file to make it permanent
Open the /etc/fstab configuration file.
#vi /etc/fstab
And make following enteries
/dev/xvdf1 swap swap defaults 0 0




2.FILE METHOD
If no additional disks is available, create a file and use that file for swap space.
Utilize the following command to create a swap file under /root directory.
#dd if=/dev/zero of=/root/myswap bs=1M count=450
Here count indicates the swap file size
Of indicates location of swap file

Now to view size type
#ls -lh /root/myswap
Then make the file as a swap file using mkswap command
#mkswap /root/myswap
Enable the newly created swap file
#swapon /root/myswap


Now add the entry in the /etc/fstab configuration file.
#vi /etc/fstab
/root/myswap                              swap                    swap    defaults        0 0


Save and exit from the file.
Verify whether the newly created swap area is available or not.
#swapon -s
We can see the 2 swaps we assigned are available


Thus our swap space is set.