{"id":8694,"date":"2020-06-17T04:59:47","date_gmt":"2020-06-17T08:59:47","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=8694"},"modified":"2021-12-04T08:48:44","modified_gmt":"2021-12-04T08:48:44","slug":"add-swap-space-ubuntu-20-04-lts","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/add-swap-space-ubuntu-20-04-lts\/","title":{"rendered":"How to Add Swap Space in Ubuntu 20.04 LTS"},"content":{"rendered":"\n
Here you will learn how to add swap in Ubuntu<\/a> 20.04 LTS. This will help you out of-memory errors on your server if you find they are occurring. Swap space may not be the best solution above properly optimizing your server<\/a> or increasing RAM.<\/p>\n\n\n\n Swap space is a portion of your hard drive to store persistent data that is not accessed as frequently and to keep RAM free for other apps that are active. Swap is significantly slower than RAM so it is not ideal for the operating system to use it for running programs.<\/p>\n\n\n\n Your server may resort to using swap as a RAM fallback when the latter is depleted and this is why we want to reserve some hard disk space for the server whenever the need arises.<\/p>\n\n\n\n Warning: It is important to note that using swap space on SSDs is not recommended as it can cause degradation of the disk over time. Therefore swap is only recommended on systems with traditional spinning hard disk drives. Again you want to prioritize optimizing your server services to suit the hardware you have otherwise you may benefit more from adding additional RAM onto the server.<\/em><\/p>\n\n\n\n The first thing you will want to do is to check if swap space has already been added to your system. This can be done by running the command below:<\/p>\n\n\n\n If you do not get any output it means your system does not have swap space otherwise you will get something similar to this:<\/p>\n\n\n\n You can also use the free utility to check for active swap space.<\/p>\n\n\n\n The output will look something similar to this:<\/p>\n\n\n\n Swap has to be created on the physical disk so it is important that you make sure the space exists in the first place. Run the following command to check for available space:<\/p>\n\n\n\n Your output will look something similar to this:<\/p>\n\n\n\nAdding Swap Space in Ubuntu 20.04 LTS<\/h2>\n\n\n\n
Step 1: Check if Swap is Already Enabled<\/h2>\n\n\n\n
$ sudo swapon --show<\/code><\/pre>\n\n\n\n
NAME TYPE SIZE USED PRIO\n\/dev\/dm-1 partition 1G \t364M -2<\/code><\/pre>\n\n\n\n
$ free -h<\/code><\/pre>\n\n\n\n
total used free shared buff\/cache available\nMem: 981Mi 129Mi 640Mi 0.0Ki 211Mi 714Mi\nSwap: 1G 364M 0B<\/code><\/pre>\n\n\n\n
Step 2 \u2013 Check for Available Space on the Hard Drive Partition<\/h2>\n\n\n\n
$ df -h<\/code><\/pre>\n\n\n\n
Filesystem Size Used Avail Use% Mounted on\nudev 474M 0 474M 0% \/dev\ntmpfs 99M 932K 98M 1% \/run\n\/dev\/vda1 40G 1.4G 38G 3% \/\ntmpfs 491M 0 491M 0% \/dev\/shm\ntmpfs 5.0M 0 5.0M 0% \/run\/lock\ntmpfs 473M 0 491M 0% \/sys\/fs\/cgroup\n\/dev\/vda15 104M 3.9M 101M 4% \/boot\/efi\n\/dev\/loop0 56M 55M 0 100% \/snap\/core18\/1705\ntmpfs 99M 0 99M 0% \/run\/user\/1000<\/code><\/pre>\n\n\n\n