Increasing Swap Space On Linux
Increasing Swap Space On Linux
Increasing Swap Space On Linux
Sometimes the default physical memory is not enough to serve certain tasks or processes. It may happen that the
processes are swapping more memory in and out of the swap space. This post helps to explain how to increase the swap
memory on a Linux system.
There will be 3 different ways explained in this post, it depends on the availability of each case to use any of these options.
2. Once the new disk is presented to the instance and the OS has detected it, run the below commands to create the new
swap space/partition on this new disk. Be aware that the remaining space on the disk can be used for any other file system
as required.
https://www.thegeekdiary.com/3-ways-of-increasing-swap-space-on-linux/ 1/7
8/2/23, 11:13 AM 3 Ways of Increasing Swap Space on Linux – The Geek Diary
p
BSD: not present
APM: not present
GPT: present
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
3. Run the following command to reload the changes on the partition table.
4. Create a new swap area on the new partition that had been just created:
5. Add the swap entry to the /etc/fstab file as indicated below on this step, the best recommendation is to use UUID of the
partition instead the name.
6. Load the new swap space that had been created for the Instance to start using it when needed, the below command
https://www.thegeekdiary.com/3-ways-of-increasing-swap-space-on-linux/ 2/7
8/2/23, 11:13 AM 3 Ways of Increasing Swap Space on Linux – The Geek Diary
6. Load the new swap space that had been created for the Instance to start using it when needed, the below command
needs to be issued.
# sudo swapon -a
# sudo swapon -s
8. Finally, run the below command to add this to the initramfs of the server.
# sudo dracut -f -v
2. If there is free space, create a new partition on the original disk with the following commands.
https://www.thegeekdiary.com/3-ways-of-increasing-swap-space-on-linux/ 3/7
8/2/23, 11:13 AM 3 Ways of Increasing Swap Space on Linux – The Geek Diary
p
BSD: not present
APM: not present
GPT: present
Hex code or GUID (L to show codes, Enter = 8300): 8200 ### Choose Linux Swap type.
Changed type of partition to 'Linux swap'
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
https://www.thegeekdiary.com/3-ways-of-increasing-swap-space-on-linux/ 4/7
8/2/23, 11:13 AM 3 Ways of Increasing Swap Space on Linux – The Geek Diary
3. Run the following command to reload the changes on the partition table.
4. Create a new swap area on the new partition that had been just created on the original disk.
5. Add the swap entry to the /etc/fstab file as indicated below on this step:
6. Load the new swap space that had been created for the Instance.
$ sudo swapon -a
https://www.thegeekdiary.com/3-ways-of-increasing-swap-space-on-linux/ 5/7
8/2/23, 11:13 AM 3 Ways of Increasing Swap Space on Linux – The Geek Diary
# sudo swapon -s
Note: In case this method is used, consider that if more space is needed for partition #3 in future, the last partition
(swap partition) will need to be removed to be able to extend partition #3.
2. Create a new file into this new directory, in this example a new file for 2Gb is create.
3. Create a new swap area on the file that has been created.
5. Add the swap partition to the /etc/fstab file as indicated below on this step:
6. Load the new swap space that had been created for the Instance.
https://www.thegeekdiary.com/3-ways-of-increasing-swap-space-on-linux/ 6/7
8/2/23, 11:13 AM 3 Ways of Increasing Swap Space on Linux – The Geek Diary
6. Load the new swap space that had been created for the Instance.
$ sudo swapon -a
$ sudo swapon -s
The new swap area that the instance will have available can be checked with this command below.
$ sudo free -m
total used free shared buff/cache available
Mem: 14763 256 11898 65 2608 14102
Swap: 12661 0 12661 ### Total Swap area
Copyright (https://www.thegeekdiary.com/copyright-terms-and-privacy-policy/)
https://www.thegeekdiary.com/3-ways-of-increasing-swap-space-on-linux/ 7/7