swap – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Fri, 16 Sep 2022 09:44:09 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How To Add Swap Space on Debian 11 https://tecadmin.net/how-to-add-swap-space-on-debian-11/ https://tecadmin.net/how-to-add-swap-space-on-debian-11/#respond Sat, 11 Sep 2021 05:16:47 +0000 https://tecadmin.net/?p=27715 Swap memory is a location on hard disk to be used as Memory by the operating system. When the operating systems detects that main memory is low and required more RAM to run applications properly it check for swap space and transfer files there. In general terms, swap is a part of the hard disk [...]

The post How To Add Swap Space on Debian 11 appeared first on TecAdmin.

]]>
Swap memory is a location on hard disk to be used as Memory by the operating system. When the operating systems detects that main memory is low and required more RAM to run applications properly it check for swap space and transfer files there. In general terms, swap is a part of the hard disk used as RAM on the system.

This tutorial will help you to Add Swap on Debian 11 Bullseye Linux system.

How to Create Swap in Debian 11

Use the below steps to create and enable Swap memory on your Debian 11 system via command line.

  1. First of all, Check that no Swap memory is enabled on your system. You can see the swap memory details by running the following commands.
    sudo swapon -s 
    free -m 
    

    Check Available Swap Memory
    Check Available Swap Memory
  2. Now, create a file to use as swap in your system system. Make sure you have enough free disk available to create new file. Also keep the swap just up to 2x of the memory on your system.

    My Debian system have 2GB of main memory. So we will create a swapfile of 4GB in size.

    sudo fallocate -l 4G /swapfile 
    chmod 600 /swapfile 
    
  3. Now use the mkswap command to convert file to use for swap memory.
    sudo mkswap /swapfile 
    
  4. Then activate the swap memory on your system.
    sudo swapon /swapfile 
    
  5. You have successfully added swap memory to your system. Execute one of the below commands to view current active swap memory on your system:
    sudo swapon -s 
    free -m 
    

    add swap on ubuntu
    Swap is Added to your System

Make Swap Permanent

After running above commands, Swap memory is added to your system and operating system can use when required. But after reboot of system swap will deactivate again.

You can make it permanent by appending the following entry in /etc/fstab file. Edit fstab file in editor:

vim /etc/fstab 

and add below entry to end of file:

/swapfile   none    swap    sw    0   0

Add swap in fatab

Save file and close. Now Swap memory will remain activate after system reboots.

Configure Swappiness

Now change the swappiness kernel parameter as per your requirement. It tells the system how often system utilize this swap area.

Edit /etc/sysctl.conf file:

sudo vim /etc/sysctl.conf 

append following configuration to end of file

vm.swappiness=10

Now reload the sysctl configuration file

sudo sysctl -p 

Conclusion

Now the operating system can use swap memory in case of low physical memory. In this tutorial, you have learned to create and enable Swap memory on Debian 11 Linux system.

The post How To Add Swap Space on Debian 11 appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-add-swap-space-on-debian-11/feed/ 0
How to Add Swap Space In Ubuntu 22.04, 20.04 https://tecadmin.net/how-to-add-swap-memory-on-ubuntu-20-04/ https://tecadmin.net/how-to-add-swap-memory-on-ubuntu-20-04/#respond Fri, 29 May 2020 15:22:01 +0000 https://tecadmin.net/?p=21715 Virtual memory is physical memory that has been marked as available for new data. This is used to increase the amount of data that can be stored in a computer system by temporarily storing data on a storage device, such as a hard drive, rather than in physical memory. For example, if a computer has [...]

The post How to Add Swap Space In Ubuntu 22.04, 20.04 appeared first on TecAdmin.

]]>
Virtual memory is physical memory that has been marked as available for new data. This is used to increase the amount of data that can be stored in a computer system by temporarily storing data on a storage device, such as a hard drive, rather than in physical memory. For example, if a computer has 4 GB of physical memory and the computer is running three applications that each require 2 GB of memory, the computer will not be able to run all three applications at the same time. However, if the computer has 8 GB of virtual memory, it can divide the 8 GB of virtual memory into 4 GB for each application and 2 GB will remain as free physical memory. There is just one very good reason to add a swap on CentOS. And that’s when you’ve run out of physical memory and can’t service any new requests. When this happens, the OS swaps out the least recently used (LRU) processes and pages their data to the disk. With enough swap space, you can avoid reaching this situation.

This article will help you to create swap space on your ubuntu system after installation.

How to Add Swap in Ubuntu

Follow the below steps to create and enable Swap memory on your Ubuntu system.

1. Check Current Swap

Before working make sure that the system has already swap enabled. If there is no swap, you will get the output header only.

sudo swapon -s 

check swap ubuntu

2. Create Swap File

Let’s create a file to use for swapping in the system of the required size. Before making a file make sure you have enough free space on the disk. Generally, it recommends that the swap should be equal to double of installed physical memory.

My Digital Ocean droplet has 2GB of memory. So creating the swapfile of 4GB in size.

sudo fallocate -l 4G /swapfile 
chmod 600 /swapfile 

Then, make it to swap format and activate it on your system by running the following commands:

sudo mkswap /swapfile 
sudo swapon /swapfile 

3. Make Swap Permanent

After running the above commands, Swap memory is added to your system and the operating system can use it when required. But after a reboot of the system swap will deactivate again.

You can make it permanent by appending the following entry in /etc/fstab file. Edit /etc/fstab file in the editor:

sudo vim /etc/fstab 

Append the below entry to the end of the file:

/swapfile   none    swap    sw    0   0

Add swap in fatab

Save the file and close. Now Swap memory will remain activated after the system reboots.

4. Check System Swap Memory

You have successfully added swap memory to your system. Execute one of the below commands to view the current active swap memory on your system:

sudo swapon -s 
free -m 

add swap on ubuntu

5. Update Swappiness Parameter

Now change the swappiness kernel parameter as per your requirement. It tells the system how often the system utilizes this swap area.

Edit /etc/sysctl.conf file:

sudo vim /etc/sysctl.conf 

Append the following configuration to the end of the file

vm.swappiness=10

Now reload the sysctl configuration file

sudo sysctl -p 

Conclusion

When a system runs out of memory, the operating system will begin to swap or page out memory pages to persistent storage such as a disk drive. When you have more free disk space, you can add additional swap space so your OS has an additional location to store temporary data when necessary. In this tutorial, you have learned to add Swap space on the Ubuntu systems.

The post How to Add Swap Space In Ubuntu 22.04, 20.04 appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-add-swap-memory-on-ubuntu-20-04/feed/ 0
How To Add Swap Space on Debian 10 https://tecadmin.net/create-swap-in-debian-10/ https://tecadmin.net/create-swap-in-debian-10/#comments Fri, 29 May 2020 15:20:09 +0000 https://tecadmin.net/?p=21724 Swap memory is a location on harddisk is used as Memory by the operating system. When the operating systems detects that main memory is getting full and required more RAM to run applications properly it check for swap space and transfer files there. In general terms, swap is a part of the hard disk used [...]

The post How To Add Swap Space on Debian 10 appeared first on TecAdmin.

]]>
Swap memory is a location on harddisk is used as Memory by the operating system. When the operating systems detects that main memory is getting full and required more RAM to run applications properly it check for swap space and transfer files there. In general terms, swap is a part of the hard disk used as RAM on the system.

This tutorial will help you to ADD Swap memory on Debian 10 Buster Linux system.

Add Swap in Debian 10

Use the below steps to create and enable Swap memory on your Debian system via command line.

1. Check Current Swap

First of all, Make sure your system have no Swap memory configured on your system. You can check if by running one of the below commands.

sudo swapon -s
free -m

check swap Debian 10

2. Create Swap file on Debian

Lets create a file to use for swap in system of required size. Before making file make sure you have enough free space on disk. Generally, it recommends that swap should be equal to double of installed physical memory.

My Debian system have 2GB of main memory. So we will create a swapfile of 4GB in size.

sudo fallocate -l 4G /swapfile
chmod 600 /swapfile

The, make it to swap format and activate on your system by running following commands:

sudo mkswap /swapfile
sudo swapon /swapfile

3. Make Swap Permanent

After running above commands, Swap memory is added to your system and operating system can use when required. But after reboot of system swap will deactivate again.

You can make it permanent by appending the following entry in /etc/fstab file. Edit fstab file in editor:

vim /etc/fstab

and add below entry to end of file:

/swapfile   none    swap    sw    0   0

Add swap in fatab

Save file and close. Now Swap memory will remain activate after system reboots.

4. Verify Swap Memory

You have successfully added swap memory to your system. Execute one of the below commands to view current active swap memory on your system:

sudo swapon -s
free -m

add swap on Debian

5. Update Swappiness Parameter

Now change the swappiness kernel parameter as per your requirement. It tells the system how often system utilize this swap area.

Edit /etc/sysctl.conf file:

sudo vim /etc/sysctl.conf

append following configuration to end of file

vm.swappiness=10

Now reload the sysctl configuration file

sudo sysctl -p

Conclusion

In this tutorial, you have learned to create and enable Swap memory on Debian system.

The post How To Add Swap Space on Debian 10 appeared first on TecAdmin.

]]>
https://tecadmin.net/create-swap-in-debian-10/feed/ 2
How to Create Swap in Linux https://tecadmin.net/linux-create-swap/ https://tecadmin.net/linux-create-swap/#respond Wed, 22 Jan 2020 18:00:45 +0000 https://tecadmin.net/?p=20298 Swap memory is a part of system permanent storage (harddisk). When the system found the physical memory of the system is full, then it automatically starts the utilization of Swap memory available on the system. In simple terms, swap memory is a part of the hard disk used as RAM on the system. If your [...]

The post How to Create Swap in Linux appeared first on TecAdmin.

]]>
Swap memory is a part of system permanent storage (harddisk). When the system found the physical memory of the system is full, then it automatically starts the utilization of Swap memory available on the system. In simple terms, swap memory is a part of the hard disk used as RAM on the system.

If your system is facing issues like system running out of memory frequently and you don’t want to increase physical memory. Then this is the best idea to add Swap memory on your system. Remember, swap memory is good but much slower than physical memory. This tutorial will help you to create a swap file on the Linux system and use it as swap memory.

How to Create Swap in Linux

Here is the step by step tutorial to create a swap file on the Linux machine and configure in the system.

  1. Check System Swap

    Before start working, check if the system has already swap enabled. If there is no swap, you will get an output header only.

    sudo swapon -s
    

    Alternatively use free or top command to view swap memory status.

  2. Create Swap File

    Let’s create a file to use for swap in the system of the required size. Before making a file make sure you have enough free space on the disk. Generally, it recommends that swap should be equal to double of installed physical memory.

    My system have 2 GB physical memory installed. So I am creating a swap file of 4 GB using following command. Then set the proper permission on file:

    sudo fallocate -l 4G /swapfile
    chmod 600 /swapfile
    
  3. Make It Swap

    Now make this file as swap usable file using mkswap command.

    sudo mkswap /swapfile
    
  4. Enable Swap

    After that, enable the swap memory on your system using swapon command.

    sudo swapon /swapfile
    

    Now, again check that swap is enabled or not. You will see results something like below.

    sudo swapon -s
    
    Filename                Type        Size    Used    Priority
    /swapfile               file        4194300 0       -1
    
  5. Setup Swap Permanent

    Append the following entry in /etc/fstab file to enable swap on system reboot. Its a good idea to make a copy of this file before changes:

    cp /etc/fstab /etc/fstab.backup
    vim /etc/fstab
    
    /swapfile   none    swap    sw    0   0
    
  6. Setup Kernel Parameter

    Now change the swappiness kernel parameter as per your requirement. It tells the system how often the system utilizes this swap area.

    Edit /etc/sysctl.conf file and append following configuration in file.

    sudo vim /etc/sysctl.conf
    
    vm.swappiness=10
    

    Now reload the sysctl configuration file

    sudo sysctl -p
    

Disable Swap

If you don’t need a swap file or need to increase swap file. You can disable an already active swap file on the system using the following command.

swapoff /swapfile

You can create a new larger swap file using the above steps or to disable permanently remove the entry from /etc/fstab file.

Conclusion

You have successfully created a swap file on your Linux machine and configured it as swap memory.

The post How to Create Swap in Linux appeared first on TecAdmin.

]]>
https://tecadmin.net/linux-create-swap/feed/ 0
How to Add Swap on CentOS, RHEL and Scientific Linux https://tecadmin.net/enable-swap-on-centos-and-rhel/ https://tecadmin.net/enable-swap-on-centos-and-rhel/#comments Thu, 23 Jul 2015 03:08:53 +0000 https://tecadmin.net/?p=8002 When a system runs out of memory, the operating system will begin to swap or page out memory pages to persistent storage such as a disk drive. This is because virtual memory is faster than physical memory and it’s cheaper to store data on disk rather than RAM. When you have more free disk space, [...]

The post How to Add Swap on CentOS, RHEL and Scientific Linux appeared first on TecAdmin.

]]>
When a system runs out of memory, the operating system will begin to swap or page out memory pages to persistent storage such as a disk drive. This is because virtual memory is faster than physical memory and it’s cheaper to store data on disk rather than RAM. When you have more free disk space, you can add additional swap space so your OS has an additional location to store temporary data when necessary. If your server does not have enough physical memory for all the processes that need it, some of them may be forced to use virtual memory rather than physical memory. This means that they are going to be slower and use disk storage as a “scratchpad” for their operational data. Where possible, this should be avoided as it is a less efficient use of resources. But if it becomes necessary, then you can add swap space on CentOS (or any other Linux system).

How to Add Swap Space in linux

The following steps will help you to create swap space on your CentOS, RHEL, and Scientific Linux systems.

  1. Check System Swap:
  2. First of all, check if any swap space is already configured on your system. If there is no swap, you will get the output header only.

    sudo swapon -s 
    

  3. Create a Swap File:
  4. The general rule of thumb is to add about twice the amount of physical memory. But this is a very rough estimate and does not account for the varied workloads of different systems. A more accurate formula is to multiply the amount of RAM by 2, then add 10% for good measure. For example, if you have a server with 16 GB of RAM, you should add 32 GB of swap. That’s because 4 GB * 2 = 32 GB + 10% = 34 GB.

    fallocate -l 8G /swapfile 
    

    Set the proper permissions on the file.

    chmod 600 /swapfile 
    

  5. Make It Swap:
  6. Now, use the mkswap to create the swap area on the above-created file. Once you did it, the Swap file is ready to work as Swap space on your system.

    mkswap /swapfile 
    

  7. Enable Swap Space:
  8. As of now, you have created a swap space in a file. Next is to use the swapon command to enable devices and files for paging and swapping.

    swapon /swapfile 
    

    Your system will start using the swap space now. You can verify this by running the following command:

    sudo swapon -s 
    
    Filename                Type        Size     Used    Priority
    /swapfile               file        1043340  881068       -2
    

  9. Setup Swap Permanent:
  10. The above instructions enabled the Swap temporarily, which will be lost after a system reboot. To enable this permanently, append the below-given entry in /etc/fstab file.

    sudo vim /etc/fstab 
    

    Append the below line to the file:

    /swapfile   none    swap    sw    0   0
    

    Save the file and close it.

  11. Setup Kernel Parameter:
  12. Now change the swappiness kernel parameter as per your requirement. It tells the system how often the system utilizes this swap area.

    Edit /etc/sysctl.conf file and append following configuration in file.

    sudo vim /etc/sysctl.conf 
    

    Set the vm.swappiness paramenter as below:

    vm.swappiness=10
    

    Now reload the sysctl configuration file

    sudo sysctl -p 
    

Conclusion

When a system runs out of memory, the operating system will begin to swap or page out memory pages to persistent storage such as a disk drive. When you have more free disk space, you can add additional swap space so your OS has an additional location to store temporary data when necessary. The general rule of thumb is to add about twice the amount of physical memory. But this is a very rough estimate and does not account for the varied workloads of different systems.

A more accurate formula is to multiply the amount of RAM by 2, then add 10% for good measure. And that’s when you’ve run out of physical memory and can’t service any new requests. When this happens, the OS swaps out the least recently used (LRU) processes and pages their data to the disk. With enough swap space, you can avoid reaching this situation.

The post How to Add Swap on CentOS, RHEL and Scientific Linux appeared first on TecAdmin.

]]>
https://tecadmin.net/enable-swap-on-centos-and-rhel/feed/ 1
How to Add Swap Space in Ubuntu 18.04 https://tecadmin.net/add-swap-on-ubuntu-18-04/ https://tecadmin.net/add-swap-on-ubuntu-18-04/#comments Thu, 23 Jul 2015 02:44:28 +0000 https://tecadmin.net/?p=7990 Swap is very useful for that system which required more RAM that physical available. If memory is full and system required more RAM to run applications properly it check for swap space and transfer files there. In general terms, swap is a part of the hard disk used as RAM on the system. I have [...]

The post How to Add Swap Space in Ubuntu 18.04 appeared first on TecAdmin.

]]>
Swap is very useful for that system which required more RAM that physical available. If memory is full and system required more RAM to run applications properly it check for swap space and transfer files there. In general terms, swap is a part of the hard disk used as RAM on the system.

I have a virtual machine running which don’t have swap on it. Many times services got crashed due to insufficient memory. In this situation creation of Swap file is better to keep them up. This article will help you to create a swap file on Linux system after installation.

  • Check System Swap – Before working make sure that system has already swap enabled. If there is no swap, you will get output header only.
    sudo swapon -s
    
  • Create Swap File – Lets create a file to use for swap in system of required size. Before making file make sure you have enough free space on disk. Generally, it recommends that swap should be equal to double of installed physical memory.

    I have 2GB memory in my system. So I am creating swap of 4GB in size.

    sudo fallocate -l 4G /swapfile
    chmod 600 /swapfile
    
  • Make It Swap – Now make is swap usable file using mkswap command.
    sudo mkswap /swapfile
    
  • Enable Swap – Now setup the swap for system using swapon command.
    sudo swapon /swapfile
    

    Now again check that swap is enabled or not. You will see results something like below.

    sudo swapon -s
    
    Filename                Type        Size    Used    Priority
    /swapfile               file        4194300 0       -1
    
  • Setup Swap Permanent – Append the following entry in /etc/fstab file to enable swap on system reboot.
    vim /etc/fstab
    
    /swapfile   none    swap    sw    0   0
    
  • Setup Kernel Parameter – Now change the swappiness kernel parameter as per your requirement. It tells the system how often system utilize this swap area.

    Edit /etc/sysctl.conf file and append following configuration in file.

    sudo vim /etc/sysctl.conf
    
    vm.swappiness=10
    

    Now reload the sysctl configuration file

    sudo sysctl -p
    

At this point, you have successfully enabled swap on your Ubuntu system.

The post How to Add Swap Space in Ubuntu 18.04 appeared first on TecAdmin.

]]>
https://tecadmin.net/add-swap-on-ubuntu-18-04/feed/ 5
How to Add Swap on AWS/EC2 Linux Instance https://tecadmin.net/add-swap-partition-on-ec2-linux-instance/ https://tecadmin.net/add-swap-partition-on-ec2-linux-instance/#comments Fri, 13 Jun 2014 10:02:43 +0000 https://tecadmin.net/?p=5715 Swap space is useful for systems having less memory (RAM). If your system facing the problem of lack of memory continuously and you don’t want to increase memory on the server, Then it can be helpful to enable swap in your system. Swap is comparatively much slower than physical memory but the operating system uses [...]

The post How to Add Swap on AWS/EC2 Linux Instance appeared first on TecAdmin.

]]>
Swap space is useful for systems having less memory (RAM). If your system facing the problem of lack of memory continuously and you don’t want to increase memory on the server, Then it can be helpful to enable swap in your system. Swap is comparatively much slower than physical memory but the operating system uses swap space in case system goes out of memory. To know more about working of swap visit here.

This article will help you to enable swap filesystem in your running instance. There are two methods to add swap in Amazon ec2 Linux instances. This article has been tested with CentOS 6.9, but it will work on most of Linux distributions.

Method 1 – Using Swap File

This option is helpful if we don’t want to add extra disks in our systems, In this, we simply create a file in our current file system and make it type swap, which can be used as swap in our system. Use the following commands to create and enable swap on our system.

sudo dd if=/dev/zero of=/var/myswap bs=1M count=4096
sudo mkswap /var/myswap
sudo swapon /var/myswap

bs=1M count=4096 means it will create 4 GB of swap file, You may change as per you need. After enabling swap we can see that our system has swap enabled by running “free -m” command.

To make it enable on system boot, simply edit /etc/fstab file and add following entry at end of file. My fstab file looks like below after adding the swap entry.

 cat /etc/fstab

LABEL=/        /           ext4    defaults,relatime  1   1
tmpfs          /dev/shm    tmpfs   defaults        0 0
devpts         /dev/pts    devpts  gid=5,mode=620  0 0
sysfs          /sys        sysfs   defaults        0 0
proc           /proc       proc    defaults        0 0
/var/myswap    swap        swap    defaults        0 0

Method 2 – Using Additional Disk for Swap

This option is helpful if you do not have enough space in our current drives mounted in the system. In this option, first, we need to add extra disk in our system first. In my case new disk mounted as /dev/xvdd (It may change in your case)

sudo mkswap -f /dev/xvdd
sudo swapon /dev/xvdd

To make it enable on system boot, simply edit /etc/fstab file and add following entry at end of file. After adding swap entry, the

 cat /etc/fstab

LABEL=/        /           ext4    defaults,relatime  1   1
tmpfs          /dev/shm    tmpfs   defaults        0 0
devpts         /dev/pts    devpts  gid=5,mode=620  0 0
sysfs          /sys        sysfs   defaults        0 0
proc           /proc       proc    defaults        0 0
/dev/xvdd      swap        swap    defaults        0 0

Conclusion

In this tutorial you have learned to create and enable Swap memory on EC2 Linux instance.

The post How to Add Swap on AWS/EC2 Linux Instance appeared first on TecAdmin.

]]>
https://tecadmin.net/add-swap-partition-on-ec2-linux-instance/feed/ 7