Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Linux

How to Add Swap Space on Ubuntu 22.04

by Cloudbooklet
1 year ago
in Linux
How To Add Swap Space On Ubuntu 22.04
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

How to Add Swap Space on Ubuntu 22.04. Swap Space is a space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, swap space let you store additional information. Swap space can help machines with a small amount of […]

ADVERTISEMENT

How to Add Swap Space on Ubuntu 22.04. Swap Space is a space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, swap space let you store additional information.

Swap space can help machines with a small amount of RAM. In case you have a server with 1GB RAM, then your memory will get exhausted and you will get an error because your server cannot allocate sufficient memory.

In this guide you are going to learn how to add swap space and also remove the swap space that is created already.

ADVERTISEMENT

Check Swap Space

First you need to check whether your server already has a swap space configured. More often virtual machines don’t have a swap space enabled by default. Check swap space with the following command.

You might also like

&Quot; Systemd Service On Linux

How to Create a New systemd Service on Linux: A Step-by-Step Guide

3 months ago
List Groups In Linux

How to List Groups in Linux: A Guide for Beginners

3 months ago
sudo swapon --show

If you don’t get any output, then your server don’t have any swap space. It’s time to add swap memory.

01. Creating a Swap File

Now you can create a swap file to add 1 GB (1G) space. You can also increase the amount of space you need.

ADVERTISEMENT
sudo fallocate -l 1G /swapfile

02. Set up Swap File Permissions

Now you have a swap file of correct size and can be enabled as swap space.

Proceed by setting up correct permissions.

ADVERTISEMENT
sudo chmod 600 /swapfile

03. Set up a Swap Space

You can now mark the file as swap space with the mkswap command.

sudo mkswap /swapfile

You will receive the output similar to this.

ADVERTISEMENT
Output
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=f59595fb-754b-47ae-af6b-8dd6e98654d8

04. Enable Swap Space

Enable the swap space and allow the system to utilise the space.

sudo swapon /swapfile

Verify that the swap is available by typing:

ADVERTISEMENT
sudo swapon --show
Output
NAME TYPE SIZE USED PRIO
/swapfile file 1024M 0B -2

You can check the output of the free utility again.

free -h
Output
              total        used        free      shared  buff/cache   available
Mem:          0.9Gi       334Mi       466Mi       54Mi       0.5Gi       0.5Gi
Swap:          1.0G          0B        1.0G

05. Making the Swap File Permanent

Now swap space is only created for the current session. If you reboot the server the current changes will be gone. So you can make this setting permanent by adding the swap file to our /etc/fstab file.

Back up the /etc/fstab file in case anything goes wrong.

sudo cp /etc/fstab /etc/fstab.bak

Add the swap file information to the end of your /etc/fstab file with the following command.

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

06. Configure Swappiness Value

The swappiness parameter allow to configure how often your system swaps data out of RAM to the swap space.

This value will be between 0 to 100 in percentage. The values close to zero, the kernel will not swap data to the disk unless absolutely necessary. The higher the value that are closer to 100 will try to put more data into swap in an effort to keep more RAM space free.

So, telling the system not to rely on the swap much will generally make your system faster.

You can see the current swappiness value by typing:

cat /proc/sys/vm/swappiness
Output
60

Now set the value to 10 with the following command.

sudo sysctl vm.swappiness=10
Output
vm.swappiness = 10

You can make this value permanent by adding the line to your /etc/sysctl.conf file.

sudo nano /etc/sysctl.conf

At the bottom, add the following line.

vm.swappiness=10

Hit Ctrl+X followed by Y and Enter to save and close the file.

Removing Swap Space

To remove a swap space you need to swapoff the space, remove the entry from the /etc/fstab file and finally delete the swap file.

sudo swapoff -v /swapfile

Edit the /etc/fstab file and remove the swap file entry /swapfile swap swap defaults 0 0

Finally, delete the swap file.

sudo rm /swapfile

Conclusion

Now you have learned how to create a swap file, activate, configure swap space and remove the swap space on your Ubuntu 22.04 server.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Tags: Ubuntu 22.04
Share3Tweet2SendShare
Cloudbooklet

Cloudbooklet

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Hostname In Linux

How to Modify the Hostname in Linux

3 months ago
Linux Systems

Linux systems Hacked with OpenSSH Malware

3 months ago
Install Iptables On Ubuntu

How to Install Iptables on Linux

3 months ago
Open Port In Linux

How to Open Port in Linux: Simple Step-by-Step Guide

3 months ago

Follow Us

Trending Articles

Covers Ai

Create High Quality AI Cover Song with Covers AI

September 18, 2023

How to Delete Netflix Account Permanently

5 Best TikTok Private Account Viewer in 2023

HeyGen AI: Free AI Video Generator to Create Amazing Videos

7 Best AI Girl Generators for Creating Realistic and Beautiful AI Girls

5 Best Laptop for Minecraft in 2023: Top Picks for All Budgets

Popular Articles

Ai Song Generator

10 Best AI Song Generator in 2023 (Free and Paid)

September 19, 2023

3 Ways to Use Stable Diffusion AI Art Generator for Free

How to Use ChatGPT to Translate Your Website or Blog

How to Block YouTube Ads on Android TV in 2023 (6 Easy Methods)

Bigjpg AI: Best AI Image Upscaler for Super Resolution

Top 10 AI Writing Assistant Tools: Detailed Review and Comparison

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.