Manually add a SWAp in a Linux System

Source: Internet
Author: User
The simplest code is Swapon/swap partition, which can be viewed using fdisk-L,
I learned that my swap partition is in/dev/sda12,
Enter Swapon/dev/sda12 in the command line and press Enter.

----------------------------------------------------------------------------------

If swap space is insufficient, how can I manually add swap space? The following operations must be performed under the root user:

First, create a partition and use the DD command, such

Dd If =/dev/Zero of =/home/swap BS = 1024 COUNT = 512000

This will create a partition file such as/home/swap. The file size is 512000 blocks. Generally, 1 block is 1 K, so the space is 512 MB. Then

Into swap partitions.

/Sbin/mkswap/home/swap

Then use the swap partition. Make it valid.

/Sbin/Swapon/home/swap

Now, run the free-M command to check the memory and swap partition size, and we can see that the space is increased by MB. However, after the computer is restarted, it is found that swap is still so large,

The new swap is not automatically started and must be manually started. Modify the/etc/fstab file and add the following line:

/Home/swap defaults 0 0

You will find that swap space increases after your machine is automatically started.

----------------------------------------------------------------------------------

Temporarily increase the swap space. The method is as follows:

Step 1:

# Dd If =/dev/Zero of =/home/swap BS = 1024 COUNT = 500000

Note: Of =/home/swap: place the swap space. The size of count is the size of the added swap space, and the size of 1024 is the block size. Here it is 1 K, so the total space is

BS * COUNT = 500 m

Step 2:

# Mkswap/home/swap

Note: format the space in the previous step into various swap types.

Step 3:

# Swapon/home/swap

Note: Make the created swap space

To close the newly opened swap space, run the following command: # swapoff

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.