Home > System Tutorial > LINUX > body text

How to add a swap partition to a Linux system

WBOY
Release: 2024-01-03 10:18:02
forward
1011 people have browsed it

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!