Linux how to create and delete swap partitions

  

Linux swap partitions similar to Windows virtual memory, in the case of insufficient hard disk space, can be solved by creating a swap partition, the following small series will introduce you how to create and Delete the swap partition.

1.swap Overview

Swap partition, i.e. exchange zone Swap space action may be simply described as: when the system's physical memory is not enough, it is necessary to physical memory A portion of the space is freed for use by the currently running program. The freed space may come from programs that haven't been manipulated for a long time. These freed spaces are temporarily saved to the Swap space, and when those programs are running, the saved data is restored from Swap to memory. In this way, the system always performs Swap exchange when the physical memory is insufficient. In fact, Swap's tuning is critical to the performance of Linux servers, especially Web servers. By adjusting Swap, you can sometimes overcome system performance bottlenecks and save system upgrade costs.

2.Create a swap

An error occurred when monitoring the server using zabbix because of the forgotten creation of the swap partition when installing the Centos 6.0 operating system. At this time, I found that the swap partition was not created. So you need to create a swap partition, the operation is as follows:

First, use the user with ROOT permission to log in remotely via SSH or the local terminal to log in to the system to create a swap partition

dd if=/dev /zero of=/swap/swap bs=1024 count=1024000

if //input

of //output

bs //block size

count //total size

Create Linux swap file

mkswap /swap/swap

Activate /swap/swap swap file now

swapon /Swap/swap

See if it works

[root@webserver ~]# free -m

total used free shared buffers cached

Mem: 2007 140 1867 0 8 35

-/+ buffers/cache: 96 1911

Swap: 972 0 972

As you can see from the above output, the swap partition has been successfully created.

Set to permanent effect

Although it is now in effect, wait for the next server restart. The swap virtual disk will be invalid. To ensure permanent validity, you need to add the following command set to the /etc/fstab file:

echo “/swap/swap swap swap defaults 0 0” 》” /etc/fstab< Br>

So far, the swap partition has been created.

2. Delete the swap partition

Sometimes you may need to delete the swap partition, how to delete the partition correctly?

Stop the swap partition first

swapoff /swap/swap

Delete the swap partition file

rm -rf /swap/swap

Delete “/etc/swap”specify files

This allows you to manually add and remove swap partitions.

The code is as follows:

sed -i “/‘\\/swa\\/swap swap swap defaults 0 0’//” /etc/fstab

Is the way to create and delete the swap partition in Linux introduced, if you just want to delete a file in the swap, see how the system home Linux deletes the specified file in the swap, I hope to help you.

Copyright © Windows knowledge All Rights Reserved