Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to resize swap in Linux system

Shulou Source: shulou.com Published: 2022-06-01 02:42:44 09月21日 Update

Today, I will talk to you about how the Linux system adjusts the size of swap. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

When deploying services, such as the installation of the Oracle database, the Linux swap partition swap size will be required. Some Linux systems are installed without configuring the swap partition, resulting in a swap partition of 0, or the swap partition is small, which does not meet the service deployment requirements, so you need to manually adjust the Linux swap partition.

1. Swap partition is 0

1. Create a swap partition file (using the root user action):

There are two ways:

(1) use the dd command to create:

# 4G swap partition dd if=/dev/zero of=/usr/swapfile bs=1G count=4

(2) use the fallocate command to create:

# 4G swap partition fallocate-l 4G / usr/swapfile

The first way is common, the disadvantage is slow, and the second is fast.

two。 Enable swap partition files:

First, modify the permissions of the swapfile file:

Chmod 600 / usr/swapfile

Initialize swapfile as a swap file:

Mkswap / usr/swapfile

Then open swap.

Swapon / usr/swapfile

Check to see if the configuration is successful:

Free-g

3. Configure system restart to automatically hang on:

Hang the swap partition in the information write / etc/fstab file

[root@local ~] # vim / etc/fstab/usr/swapfile swap swap defaults 0 0

II. Swap partition resizing

1. Create a swap partition file that meets the required size

(dd method is used this time):

# 8 gigabyte swap partition dd if=/dev/zero of=/usr/swapfile bs=1G count=8

two。 Configure the new swap file:

First, modify the permissions of the swapfile file:

Chmod 600 / usr/swapfile

Initialize swapfile as a swap file:

Mkswap / usr/swapfile

Uninstall the original swap:

Swapoff-a

Then open the newly created swap.

Swapon / usr/swapfile

Check to see if the configuration is successful:

Free-g

You also need to hang the swap partition in the information write / etc/fstab file

[root@local] # vim / etc/fstab/usr/swapfile swap swap defaults 00 after reading the above, do you have any further understanding of how the Linux system resizes swap? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: File size configuration system adjustment content method success information command permission speed service common manual data database more user knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Information Huawei NVidia Docker