Centos/linux Adding a swap partition

Source: Internet
Author: User

swap partition is useful: Swap is when the physical memory is not enough to put the data into the swap, so swap plays a role in the virtual memory, in a sense, it is also an increase in memory space. The general swap partition is set when the system is installed, if you forget to swap partition when installing the system, it is OK, there is a remedy. Let's talk about how to add a swap partition after installing the system.

Scenario: After loading the system, the bitterness found no swap partition, and for the production server, this obviously does not work, so you need to add a swap partition.

1. First check the swap size

# free

                    Total used       free     shared    buffers     cachedmem:       3922944     158168    3764776          0       6948      37384-/+ buffers/cache:     113836    3809108Swap:            0          0          0

This is clearly shown as zero.



2. Create a swap partition with the DD command

# dd If=/dev/zero Of=/doiido/swap bs=1024 count=8388608


Calculation formula for count: count=size*1024 (SIZE in megabytes)
This creates a/doiido/swap partition file with a size of 8G


3. Format the newly created partition
# Mkswap /doiido/swap



4. Turn the newly created partition into a swap partition
# swapon /doiido/swap

Note: Closing the Swap partition command is: # Swapoff /doiido/swap


5. First check the swap size
# free
                    Total used       free     shared    buffers     cachedmem:       3922944     158168    3764776          0       6948      37384-/+ buffers/cache:     113836    3809108Swap:      8388608          0    8388608


6. Auto-mount swap on boot
# echo "/doiido/swap Swap swap defaults 0 0" >>/etc/fstab

So the swap partition is created



Centos/linux Adding a swap partition

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.