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

How to add a swap partition to a Linux system

Jan 03, 2024 am 10:18 AM
space swap llinux swap partition

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 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Where is the space key on your computer? Where is the space key on your computer? Feb 22, 2023 am 10:15 AM

The computer space key is at the bottom of the keyboard; the space key is the space bar, or blank key, which is a key on the computer keyboard; the space key is usually a long bar. The main reason for using this design is that it can easily enter spaces, such as in Two words are usually separated by a space, so the space bar is designed to be wider than any other key, allowing the thumbs of both hands to hit the space bar easily.

What is linux swap space What is linux swap space Jul 18, 2023 am 11:58 AM

Linux swap space is a special hard disk space used for memory expansion in the Linux operating system. Its role is to provide additional virtual memory to ensure the normal operation of the system. Proper configuration and management of swap space can help maintain the stability and performance of the system regularly. It is the responsibility of the system administrator to monitor the usage of Swap space and adjust the size of the swap space according to the actual situation.

What is the use of turning off SWAP in Redis? What is the use of turning off SWAP in Redis? May 27, 2023 am 10:30 AM

Turn off SWAPSWAP is a memory swapping technology. Copy the memory to the preset disk space in pages. Memory is fast and expensive. Disks are slow and cheap. Generally, the more SWAP is used, the lower the system performance will be. Redis is an in-memory database, and using SWAP will cause rapid performance degradation. It is recommended to leave enough memory and turn off SWAP.

LEGO bricks constructed from meteorite dust, test run for a moon base LEGO bricks constructed from meteorite dust, test run for a moon base Jun 28, 2024 am 07:25 AM

It is hard to imagine that the building materials for a planned lunar base would first have to be transported to Earth's satellite at great expense. After all, every pound counts when launching from the Earth's surface. The problem is the lunar regol

Steps and methods to add swap partition - Linux System Guide Steps and methods to add swap partition - Linux System Guide Jan 03, 2024 pm 07:10 PM

If you want to add a swap partition in a Linux system, how do you add it? Let’s take a look at the detailed tutorial below. 1. First, click "Launcher" on the dock bar, find "Deepin Terminal" and run it. 2. Then set a password for the root user. Because the installation process is for the administrator user, the root password is not set. sudopasswdroot3. After the setting is completed, execute the su command to switch to the root user. 4. Execute the following command to generate a swap file in the root directory, count sets the number of blocks, and bs sets the block size to generate a 4G swap. ddif=/dev/zeroof=/swapfilecou

How to solve the problem of high Linux Swap space utilization How to solve the problem of high Linux Swap space utilization May 27, 2023 pm 12:37 PM

What is swap? Swapspace is an area on the disk, which can be a partition, a file, or a combination of them. To put it simply, when the system's physical memory is tight, Linux will save infrequently accessed data in the memory to swap, so that the system has more physical memory to serve each process, and when the system needs to access the content stored on swap When, the data on the swap is loaded into the memory. This is what we often call swapout and swapin. Why is swap needed? To answer this question, we need to answer what benefits swap brings to us. For some large applications (such as LibreOffice, videoeditor

How to set up swap virtual memory on Linux cloud server How to set up swap virtual memory on Linux cloud server May 15, 2023 pm 11:52 PM

Swap memory mainly means that when the physical memory is not enough, the system will enable part of the hard disk space to serve as server memory. By default, swap memory has some setting standards, which are also related to the size of physical memory. Check the memory space: free-h Create swap partition file: ddif=/dev/zeroof=/data/swapbs=1Mcount=4096 Code explanation: bs is the size of the block, count is the number of blocks, it is known that bs=1M, count= 4096, 1M*1024=4G swap partition virtual memory, /data/swap is the path where the swap file is created, the above parameters can be modified according to your own needs. m

What should I do if deepin does not have a swap partition? What should I do if deepin does not have a swap partition? What should I do if deepin does not have a swap partition? What should I do if deepin does not have a swap partition? Feb 29, 2024 am 10:10 AM

During the use of deepin, some users find that their system lacks a swap partition and don’t know what to do. In fact, in most cases, it doesn’t matter if we don’t have a swap partition. If necessary, you can also manually create and mount a swap partition. to solve. What to do if deepin does not have a swap partition: 1. During installation 1. If there is no swap when we install the system partition, as shown in the figure. 2. At this time, you can exit the installation program first, then select swap under the file system item, and then install it. 2. Swap1 cannot be found. If we created a swap partition during installation but cannot find it when using it, it may be a resolution problem. 2. At this time we can try to enter the grub interface, in

See all articles