How to add swap partitions in linux

Source: Internet
Author: User
Currently, VM instances are more and more widely used. System images of some VM instances do not automatically mount swap partitions, which will definitely affect the performance of the machines,

 

The solution is as follows:

 

1. Some VM instance vendors allocate swap partitions for VM instances, but do not enable automatic system mounting. Run the fdisk-l command to check whether a swap partition is created.

 

Swap partitions, as shown in the following figure:

 

As shown in the figure above, the system has created a swap partition. In this case, you only need to write the swap partition to/etc/fstab and enable the system to automatically mount it.

 

2. If the system does not create a swap partition, we need to create a space by ourselves. The specific steps are as follows:

A. Use the dd command to create a swap partition file
# Dd if =/dev/zero of =/opt/swap bs = 1024 count = 4096000
# Create a 4G swap partition file
B. Format the new partition.
# Mkswap/opt/swap
C. Convert the new partition into a swap partition
# Swapon/opt/swap
Note: the command to disable SWAP partitioning is: # swapoff/opt/swap
D. Run the free command to check the swap partition. If it is a 4G swap partition, it indicates no problem.
E. Automatically mount swap upon startup
# Echo "/opt/swap defaults 0 0">/etc/fstab
F. Restart the system and check whether the swap partition is automatically mounted.

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.