Search This Blog

Monday, 29 May 2017

How to add a Swap Space in RHEL



What is Swap Space?
Swap space in Linux is used when the Physical memory (RAM) is full. If the system needs a more memory resources but the physical memory is full, the system moves the inactive pages in RAM memory to swap space. While swap space can help machines with a small amount of RAM. Swap space is located on hard drives, The swap space will be slower access time than physical memory.
The Swap space size should be equal to twice your computer’s RAM.

Adding Swap Space
sometimes its necessary to add more swap space after installation. For Example, you may upgrade the amount of RAM in your system from 64 MB to 128 MB but there is only 128 MB of swap space. so we need to increase the swap space to 256 MB  if you perform memory-intense operations or run applications  that require a large amount of memory.

To add a swap partition (assuming /dev/hdb2 is the swap partition you want to add)
1.The hard drive can not be in use (partitions can not be mounted, and swap space can not be enabled). The partition table should not be modified while in use because the kernel may not properly recognize the changes. Data could be overwitten by writing to the wrong partition because the partition table and partitions mounted do not match.
The easiest way to achieve this is to boot your system in rescue mode. when prompted to
mount the file system, select skip
if the drive does not contain any partitions in use, you can unmount them and turn off all the swap space on the hard drive with the swapoff command.
2. Creating the Swap partition using Parted
  • At Shell Prompt as root, type the command Parted /dev/hdb, where dev/hdb is the device name for the hard drive with free space.
  • Type Print to view the existing partitions and the amount of free space. Determine how much free space is on the hard drive and how much you want to allocate for a new swap partition.
  • Then type mkpartfs part-type linux-swap start end, where part type is one of primary, extended, or logical, start is the starting point of the partition, and end is the end point of the partition.
  • Exit parted by typing quit

3. Now you have create the swap partition, using the following command mkswap to setup the swap partition. At a shell prompt as root
1
4. Following Command for enable the swap partition immediately
2
5. To enable it at boot time, edit /etc/fstab to include
3
The next time the system boots, it enables the new swap partition.
6. Verify the added swap partition are enabled or not by the following command Cat /proc/swap or free


Thank You…..!

No comments:

Post a Comment