The swap partition in Linux is similar to Windows virtual memory, in the case of insufficient hard disk space, can be created by the swap partition to solve, the following small series to introduce you to the Linux how to create and delete the swap partition.
1.swap Overview
The role of swap partitions, or swap spaces, can be simply described as: when the physical memory of the system is not enough, it is necessary to release some of the space in physical memory for use by the currently running program. The freed space may come from programs that have not been manipulated for a long time, and the freed space is temporarily saved in the swap space until those programs run, recovering the saved data from the swap into memory. In this way, the system always does swap swap when physical memory is not enough. In fact, swap adjustments are critical to the performance of Linux servers, especially Web servers. By adjusting swap, you can sometimes bypass system performance bottlenecks and save on system upgrade costs.
2. Create swap
Because you forgot to create a swap partition when you installed the CentOS 6.0 operating system, an alarm occurs when you use Zabbix to monitor the server. Only then did you find that the swap partition was not created. So you need to create a swap partition that works as follows:
First, a user with root access via SSH remote login or local terminal log in to the system, to create a swap partition
DD If=/dev/zero of=/swapfile bs=1024 count=1024000
DD If=/dev/sda3 of=/swapfile bs=1m count=2048 "or specified units"
If//input
of//Output
BS//block size
Count//Total size
Create a Linux swap file
Mkswap/swapfile "mkswap-f/swapfile"
Activate/swapfile swap files now
Swapon/Swapfile
See if it takes effect
[Email protected] ~]# free-m
Total used free shared buffers Cached
MEM:2007 140 1867 0 8 35
-/+ buffers/cache:96 1911
swap:2048 0 2048
As you can see from the output above, the swap partition has been successfully created.
Set to permanent effect
Although it is now in effect, wait until the next time the server restarts. The swap virtual disk will fail to be valid for permanent use, and you will need to add the following instruction set in the/etc/fstab file:
echo "/swapfile Swap swap defaults 0 0" >>/etc/fstab
So far, the swap partition has finished creating.
2. Delete a swap partition
Sometimes you may need to delete a swap partition, how do you delete the partition correctly?
First stop the Swap partition
Swapoff/Swapfile
Delete a swap partition file
RM-RF/Swapfile
Delete "/etc/swap" specified file
This allows you to manually add and remove swap partitions.
The code is as follows:
Sed-i "/'/swapfile Swap swap defaults 0 0 '//"/etc/fstab
This article is from the "Learning Journey" blog, declined reprint!
How Linux creates and deletes a swap partition