Home >System Tutorial >LINUX >How to add a swap partition to a Linux system

How to add a swap partition to a Linux system

WBOY
WBOYforward
2024-01-03 10:18:021054browse

Does the swap space feel like the virtual memory of Linux? When the memory is not enough, certain technical means are used to temporarily store some things in the physical memory that have not been used for a long time in this space. Then free up some memory for the program to use.

The method of adding is very simple

First you need superuser identity (add sudo or sudo su - before the command)

First sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576

/dev/zero file represents a device file that always outputs 0. Using it as input can result in a completely empty file. Therefore it can be used to create new files and clear old files by overwriting them.

Here we created an empty file of 1G size (bs means writing 1024bit each time, a total of 1048576 times)

Then let’s set this file as a swap file

sudo mkswap /swapfile

Here are the parameters of the mkswap command. You can add

if needed.

-c Before creating the swap area, check whether there are damaged blocks.

-f When creating a swap area on a SPARC computer, add this parameter.

-v0 creates a legacy swap area, this is the default.

-v1 Create a new swap area.

Then

sudo swapon /swapfile

Just turn on the swap partition.

Use this

sudo swapon -s to check if

appears

/swapfile file10485720-1

Indicates that the setting is successful.

The above is the detailed content of How to add a swap partition to a Linux system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete

Related articles

See more