Get the App
SLTechnology News&Howtos  ›  Development  › 

How Linux expands swap Space

Shulou Source: shulou.com Published: 2022-06-01 14:08:40 09月29日 Update

This article mainly shows you "Linux how to expand swap space", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "Linux how to expand swap space" this article.

We have already established the swap partition when we installed the system. Swap partition is usually called swap partition, which is a special hard disk space, that is, when the actual memory is insufficient, the operating system will take part of the temporarily unused data from memory and put it in the swap partition, thus freeing up enough memory space for the currently running program.

Let's first check the size of the existing swap space / partition, using the command free-m or swapon-s

Expand swap Space on Linux system expand swap Space on Linux system

My swap partition size is 2 GB, and we will extend the swap space to 1GB.

Step 1: use the following dd command to create an exchange file with the size of 1GB

The code is as follows:

[root@linuxtechi] # dd if= http://www.3lian.com/dev/zero of= http://www.3lian.com/swap_file bs=1G count=11+0 records in1+0 records out1073741824 bytes (1.1GB) copied, 414.898 s, 2.6MB/s [root@linuxtechi] #

Replace the size of bs and count according to your needs.

Step 2: set the swap file permissions to 600

The code is as follows:

[root@linuxtechi ~] # chmod 600 / swap_file

Step 3: open the exchange area (swap_file) with a file

Open the exchange area with the mkswap command

The code is as follows:

[root@linuxtechi ~] # mkswap / swap_fileSetting up swapspace version 1, size = 1048572 KiBno label, UUID=f7b3ae59-c09a-4dc2-ba4d-c02abb7db33b [root@linuxtechi ~] #

Step 4: add an exchange file entry to the fstab file

Add the following entry to the fstab file so that the exchange file can continue to use each other after each restart.

The code is as follows:

/ swap_file swap swap defaults 0 expand swap space on Linux system expand swap space on Linux system

Step 5: enable swap files with the command 'mkswap on'.

Copy the code

The code is as follows:

[root@linuxtechi ~] # swapon / swap_file

Step 6: check the swap space now

Expand swap Space on Linux system expand swap Space on Linux system

Note: to avoid unexpected situations, turn it off using the swapoff command as shown below, and re-enable the swap file using the swapon command shown in step 5 only if you need it.

The code is as follows:

[root@linuxtechi] # swapoff / swap_file above is all the content of this article "how Linux expands swap space". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Space file system code command size memory content article time entry learning help special unexpected operating system insufficient not used actual situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MariaDB Shulou Information Xiaomi Apple