Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add and remove Swap switching Partition in Centos7

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the Centos7 how to add and delete Swap exchange partition related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Centos7 how to add and delete Swap exchange partition article will have a harvest, let's take a look.

Swap introduction:

Linux divides physical memory into memory segments, called pages. Swapping is the process in which memory pages are copied to a predetermined hard disk space (called swap space) in order to free up memory for the pages. The total size of physical memory and swap space is the total amount of virtual memory available.

Swap: swap partitions, similar to the virtual memory of windows, but when there is insufficient physical memory, part of the hard disk space is used as virtual memory, thus solving the shortage of physical memory.

Advantages: cost savings.

Disadvantages: insufficient performance.

This method is not limited to centos 7 Linux systems.

Operation user: root.

1. Add swap swap Partition Space

Use the dd command to create a swap swap partition file / dev/mapper/centos-swap with a size of 2g:

$dd if=/dev/zero of=/dev/mapper/centos-swap bs=1024 count=2048000

Format the swap partition:

$mkswap / dev/mapper/centos-swap

Set up the swap partition:

$mkswap-f / dev/mapper/centos-swap

Activate the swap partition:

$swapon / dev/mapper/centos-swap

Set to enable automatically when powered on:

$vim / etc/fstab

Add the following at the bottom of the file:

/ dev/mapper/centos-swap swap swap default 0 0

two。 Delete swap swap partition

Stop the swap partition that is in use:

$swapoff / dev/mapper/centos-swap

Delete the swap partition file:

$rm / dev/mapper/centos-swap

Delete or comment the following boot auto-mount content in the / etc/fstab file:

/ dev/mapper/centos-swap swap swap default 0 0

The great task has been completed!

Increase swap partition size under centos7

If the system runs out of physical memory, the system will run slowly but still run; if the swap space is used up, the system will have an error. For example, when the swap space is used up, the service process cannot be started, and a "application is out of memory" error usually occurs, which in serious cases will cause a deadlock of the service process. Therefore, the allocation of swap space is very important, usually the size of swap space should be 2-2.5 times the size of physical memory.

This method is not limited to centos,linux.

The following commands need to be operated under the root account

1. First use free-m to check the size of swap

two。 Use the dd command to create a partition file like / home/swap. The size of the file is 512000 block, and normally 1 block is 1k, so the space here is 512m.

# dd if=/dev/zero of=/home/swap bs=1024 count=512000

3. Then change this partition to the swap partition.

# / sbin/mkswap / home/swap

4. Then use this swap partition. Make it a valid state.

# / sbin/swapon / home/swap

Now look at the memory and swap partition size with the free-m command, and you can see that there is an increase of 512m of space.

Note that when the computer restarts, it is found that the swap is still as big as before, and the new swap does not start automatically, but manually. Then we need to modify the / etc/fstab file by adding the following line

# vi / etc/fstab / home/swap swap swap defaults 0 0

This is the end of the article on "how to add and remove Swap swap partitions in Centos7". Thank you for reading! I believe you all have a certain understanding of "how to add and delete Swap exchange zones in Centos7". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report