Create a SWaP file and adjust the SWaP capacity

Source: Internet
Author: User

When we are operating, whether the system reflection speed will be slow, but the operating system can still run. Then we should check whether SWaP space is used up. If so, the system will have an error. Today we will learn how to adjust the SWaP capacity by creating a SWaP file.

Create a SWaP file and adjust the SWaP capacity

When all the hard disk space in the system has been allocated to other partitions, it is not suitable to use the fdisk command to increase the capacity of the SWaP partition. This command will delete the objects in the target space. In this case, the system administrator needs to create a SWaP file to increase the virtual SWaP space. To put it simply, create a virtual SWaP file in the hard disk. This file is used to divide a space in the system hard disk for the SWaP space.

Step 1: Create a SWaP file.

The system administrator can use the "dd bs = count =" command to create a SWaP file. This command mainly uses the bs and count parameters. The bs parameter specifies the number of bytes read and input each time. Because the minimum unit of hard disk access is sector, setting the bs parameter is equivalent to setting the size of each sector.

Generally, this parameter is set to 32 as well. The count parameter is mainly used to set the number of sectors that can be used. Therefore, the space occupied by this file is the product of the above parameters. Note that to increase the SWaP file capacity, you can adjust the count parameter. That is to say, the bs parameter is generally 32 and does not need to be moved.

Step 2 format and start the SWaP file.

After creating a file, you also need to format the file and enable it. This is mainly because the file is still in the original file system format on the hard disk until now, such as ext3. The file system format cannot be used for expansion of SWaP partitions.

For this reason, the system administrator needs to first use the mkSWaP tool to format this file as a SWaP file. Run the SWaPon command to enable the file. This feature is somewhat like the concept of dynamic disks in Microsoft operating systems.

If you need to manually execute the SWaPon command to start the SWaP partition or file after each boot, this is too much trouble. To solve this problem, you need to modify the Linux Startup configuration file. For example, the system administrator can add a line of content to the startup configuration file to enable the SWaP partition and file automatically when the Linux system starts up.

In addition to this Automatic startup, there are also some performance differences. Especially when a SWaP file is used to create a virtual SWaP space, the execution performance of the virtual SWaP space is worse than that of the real SWaP space. However, it does not affect the files in the existing partition.

Therefore, although the Linux official quarantine SWaP space should be 1-2 times the memory capacity. However, some applications have special requirements in actual work. Therefore, after the Linux system is installed, System Engineers sometimes have to adjust the SWaP capacity. We will explain how to use the SWaP file to obtain the SWaP space.

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.