After Linux/centos is installed, add the SWAP partition, centosswap

Source: Internet
Author: User

After Linux/centos is installed, add the SWAP partition, centosswap
Usage of swap partitioning: swap puts data into swap when the physical memory is insufficient. Therefore, swap plays a role in virtual memory, in a sense, memory space is also increased. Generally, the swap partition is set when the system is installed. If you forget to divide the swap partition when installing the system, it will be okay and there is a remedy. The following describes how to add a swap partition after installing the system.

Scenario:
After the system is installed, it is hard to find that SWAP partitions are not divided. For production servers, this obviously does not work. Therefore, you need to add SWAP partitions.


1. First check the swap size
# Free
Total used free shared buffers cached
Mem: 3922944 158168 3764776 0 6948 37384
-/+ Buffers/cache: 113836 3809108
Swap: 0 0 0

Obviously, it is displayed as zero.


2. Run the dd command to create a swap partition.
# Dd if =/dev/zero of =/doiido/swap bs = 1024 count = 8388608

Calculation Formula of count: count = SIZE * 1024 (size in MB)
In this way, create a/doiido/swap partition file with a size of 8 GB.


3. format the new partition.
# Mkswap/main/swap


4. Change the new partition to a swap partition.
# Swapon/main/swap

Note: The command to disable SWAP partitioning is: # swapoff/main/swap


5. view the swap size again
# Free
Total used free shared buffers cached
Mem: 3922944 158168 3764776 0 6948 37384
-/+ Buffers/cache: 113836 3809108
Swap: 8388608 0 8388608


6. automatically mount swap upon startup
# Echo "/main/swap defaults 0 0">/etc/fstab



The SWAP partition is created.
The partition/swap and/home locations change during CentOS installation.

First, I think this is similar to the windows system partition. Why is the system installed on the C drive by default? The C drive should be the first partition. on the periphery of the disk, the line speed is relatively fast and the access speed is also fast.
The system should put the swap priority in the home partition by default. By default, it is considered that home requires faster access than swap, and swap generally does not use it much.
The second question is what you understand.
 
How to Set/change swap partitions on centos

According to Redhat's suggestion, the swap partition in Linux is 1-2 times the physical memory size. however, on Linux, some software requires a large number of swap partitions. For example, to smoothly execute the Oracle database software, the swap partition requires at least MB space or more than 2 times the physical memory. of course, when installing Linux, we can directly talk about setting the swap partition to a sufficient size. However, if Linux is already installed, we want to install Oracle-like software again, but I found that swap partition space is not enough. What should I do? There are two solutions to this problem: creating a new swap partition and creating a swap file. (This section describes how to create a swap file.) create a swap file. If all your hard disk space has been allocated to other partitions, there is no extra budget to purchase a new hard disk, we can use the swap file to increase the virtual swap space, but the execution performance will be worse than the actual swap partition. to generate a swap file, create a swap file and run the dd command to add a MB swap file: # dd if =/dev/zero of =/tmp/myswap bs = 32 k count = 8192 (bs = 32 k indicates that each slice occupies 32 KB and reads 8192 0 segments, output 8192 0 segments) Note: The bs parameter is used to specify the number of bytes read and input each time. Because the minimum disk access unit is sector, therefore, setting bs is equal to setting the size of each slice, while the count is used to specify how many slice can be used. therefore, the available hard disk space is equal to bs * count. the above example shows that the available hard disk space is 32*8192 = 262144 (KB) or MB. after executing the preceding command, a MB myswap file in the/tmp directory will be created, and the swap file will be started. Then run the mkswap command to format the myswap file into the s file system, the system can use it only. Switch to the/tmp directory and run the following command: # mkswap myswap (# format the file as a swap file) setting up swapspace version 1, size = 262144 KB # swapon/tmp/myswap (# Start the swap partition) to stop using the newly created swap file, just run the swapoff/tmp/myswap command. automatically Start the newly added swap partition at startup. If you need to execute the swapon command to start the swap partition or file after each boot, this is too troublesome. you can use the text editor to add a line to the/etc/fstab file so that swap partitions and files can be automatically started at startup: /dec/hdb5 swap defaults 0 0 (start this swap partition at boot)/tmp/myswap swap defaults 0 0 (start this swap file at boot)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.