System Hacks for Noob's 2 : Boost your Linux VM Performance

Add Swap File to your Linux VM's if not present


Swap is a space on a disk that is used when the amount of physical RAM is full .When any system having Linux Distribution installed on it consumes all the RAM space during task processing on these systems if Swap id defined then all the inactive pages are moved from the RAM to Swap Space to optimize system performance.

In general we can understand this concept as it acts as your system's assistant in terms of processing so that your system can focus on all the necessary and priority tasks.Swap area can be configured as dedicated partition or in the form of swap file.

In most cases when having Linux installed on Virtual Machine a Swap Partition is not present so the only option we are left with is to configure swap file.Swap should be equal to your RAM size or double of that not more than that,if done beyond description it will not add to processing but will reduce Hard Disk space.

Remember on thing Swap is not your RAM or any RAM upgrade as it is not that much fast as RAM. It is introduced to handle all the background tasks.

To add 2GB Swap to your machines follow these steps in Linux Terminal:


STEP1:
Create a file which will be used for swap.Execute this command:

    sudo fallocate -l 2G /swapfile



If faillocate is not installed or if you get an error message saying fallocate failed: Operation not supported then you can use the following command to create the swap file:

    sudo dd if=/dev/zero of=/swapfile bs=2048 count=1048576



STEP 2:
Set the correct permissions.Only the root user should be able to write and read the swap file. To set the right permissions type:

    sudo chmod 600 /swapfile



STEP 3:
Set up a Linux swap area.Use the mkswap utility to set up the file as Linux swap area:

    sudo mkswap /swapfile



STEP 4:
Enable the swap.Activate the swap file with the following command:

    sudo swapon /swapfile



To make the change permanent open the /etc/fstab file and append using following line:

    sudo nano /etc/fstab



At end of the file add following line:

    /swapfile swap swap defaults 0 0

Press Ctrl + O and Enter to write and Ctrl + X to exit


STEP 5:
Verify the swap status.

To verify that the swap is active we can use either the swapon or the free command as shown below:

    sudo swapon --show 



or
    sudo free -h

How to remove Swap File:

If for any reason you want to deactivate and remove the swap file, follow these steps:

STEP 1:
First, deactivate the swap using the following command:

    sudo swapoff -v /swapfile

STEP 2:
Remove the swap file entry /swapfile swap swap defaults 0 0 from the /etc/fstab file.

STEP 3:
Finally delete the actual swapfile file:

sudo rm /swapfile

For many more trick and hacks for you system and smartphones stay connected with us and share this to all your near and dears to make them aware about the devices they use daily.

To get regular updates from us Subscribe to our blog by providing your email in SUBSCRIBE section.

Don't Forget to Subscribe and Share and provide us your valuable feedback in comments.

- TEAM COMPUTEMONSTER

Comments

Popular Posts