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 extend swap Partition in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

I believe that many inexperienced people don't know what to do about how to expand the swap partition in Linux. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

What is swap space?

When physical memory (RAM) is full, swap space in Linux is used. When physical memory is full, inactive pages in memory are moved to swap space.

This helps the system run applications continuously, but it cannot be used as a substitute for more memory.

Swap space is on the hard disk, so it cannot handle requests like physical memory.

How to create a swap partition using LVM

Since we already know how to create logical volumes, the same is true of swap partitions. Just follow the procedure below.

Create the logical volume you need. In my case, I want to create a swap partition for 5GB.

Sudo lvcreate-L 5G-n LogVol_swap1 vg00 Logical volume "LogVol_swap1" created.

Format the new swap space.

$sudo mkswap / dev/vg00/LogVol_swap1Setting up swapspace version 1, size = 5 GiB (5368705024 bytes) no label, UUID=d278e9d6-4c37-4cb0-83e5-2745ca708582

Add the following entry to / etc/fstab.

# vi / etc/fstab/dev/mapper/vg00-LogVol_swap1 swap swap defaults 00

Enable extended logical volumes.

$sudo swapon-vaswapon: / swapfile: already active-- ignoredswapon: / dev/mapper/vg00-LogVol_swap1: found signature [pagesize=4096, signature=swap] swapon: / dev/mapper/vg00-LogVol_swap1: pagesize=4096, swapsize=5368709120, devsize=5368709120swapon / dev/mapper/vg00-LogVol_swap1

Test whether the swap space has been added correctly.

$cat / proc/swapsFilename Type Size Used Priority/swapfile file 1459804 526336-1/dev/dm-0 partition 5242876 0-2$ free-g total used free shared buff/cache availableMem: 11 000 0Swap: 6 06 how to use LVM to extend the switching partition

Simply follow the procedure below to expand the LVM exchange logical volume.

Disable swapping of related logical volumes.

$sudo swapoff-v / dev/vg00/LogVol_swap1swapoff / dev/vg00/LogVol_swap1

Resize the logical volume. I will increase the swap space from 5GB to 11GB.

$sudo lvresize / dev/vg00/LogVol_swap1-L + 6G Size of logical volume vg00/LogVol_swap1 changed from 5.00 GiB (1280 extents) to 11.00 GiB (2816 extents). Logical volume vg00/LogVol_swap1 successfully resized.

Format the new swap space.

$sudo mkswap / dev/vg00/LogVol_swap1mkswap: / dev/vg00/LogVol_swap1: warning: wiping old swap signature.Setting up swapspace version 1, size = 11 GiB (11811155968 bytes) no label, UUID=2e3b2ee0-ad0b-402c-bd12-5a9431b73623

Enable extended logical volumes.

$sudo swapon-vaswapon: / swapfile: already active-- ignoredswapon: / dev/mapper/vg00-LogVol_swap1: found signature [pagesize=4096, signature=swap] swapon: / dev/mapper/vg00-LogVol_swap1: pagesize=4096, swapsize=11811160064, devsize=11811160064swapon / dev/mapper/vg00-LogVol_swap1

Test whether the logical volume has been properly extended.

$free-g total used free shared buff/cache availableMem: 11000 0Swap: 12012$ cat / proc/swapsFilename Type Size Used Priority/swapfile file 1459804 237024-1/dev/dm-0 partition 11534332 0-2 after reading the above, have you mastered how to expand the swap partition in Linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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

Servers

Wechat

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

12
Report