How to Set/modify swap partitions on centos

Source: Internet
Author: User

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 and there is no extra budget to purchase a new hard disk, we can use the swap file to increase the virtual swap space, however, the execution performance is worse than the actual swap partition.

Generate a swap file
To create a swap file, 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, reads 8192 0 segments, and outputs 8192 0 segments)

Note: The goal of the BS parameter is to specify the number of bytes read and input each time. Because the minimum unit of disk access is sector, setting BS is equal to setting the size of each sector; the purpose of count is to specify how many sectors 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 256 MB.

After the preceding command is executed, a MB myswap file is created in the/tmp directory.

Format and start swap files
Next, run the mkswap command to format the myswap file into the s file system. The system can use the command. 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, run the swapoff/tmp/myswap command.

The newly added swap partition is automatically started 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 startup)
/Tmp/myswap swap defaults 0 0 (start this swap file at startup)

The above text and electronic version, Chen wenchao luckisme, was revised and followed by GPL release. The source of the original article is "Red Hat Linux9 practical application", and the copyright is owned by Qi Biao Publishing Co., Ltd.

This article is from the csdn blog. For more information, see the source:Http://blog.csdn.net/rufeng18/archive/2008/11/01/3202023.aspx

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.