Using swap files to expand swap space on Linux

Source: Internet
Author: User

Imagine a scenario where our Linux system runs out of swap space, in which case we want to expand the swap space with the swap partition, but in some cases there is no free partition available on the disk, so we can't expand it.

Therefore, in this case, we can use the swap file to increase the swap space.

Here are the steps:

1. Check the size of the existing swap partition

650) this.width=650; "src=" Http:// "title=" Swapsize. PNG "alt=" Wkiom1ztb7vzwqajaaahvamsspy066.png "/>

We can see that the size of our existing swap partition is 2G, and now we extend it to 1G.

2. Create a 1G size normal file 650) this.width=650; "Src=" Wkiol1ztcgaazyz0aaa9wflgtfa242.png "title=" DD. PNG "alt=" Wkiol1ztcgaazyz0aaa9wflgtfa242.png "/>

We used the DD command to create a swapfile file.

If indicates from which location to read

of where to export

BS indicates how large one reads

Count indicates how many times read writes

3. Set the swap file permission to 600 to prevent ordinary users from deleting this file.

650) this.width=650; "src=" Http:// "title=" chmod. PNG "alt=" Wkiol1ztcs_xigeoaaaod96u1-0080.png "/>

4. Format Swap

650) this.width=650; "src=" Http:// "title=" Mkswap . PNG "alt=" Wkiom1ztcwtseybfaaad1s5fsic999.png "/>

5. Turn on swap

650) this.width=650; "src=" Http:// "title=" Swapon . PNG "alt=" Wkiol1ztczqcblv2aaamt-t13xy914.png "/>

6. Set up a new swap file to boot

Edit File/etc/fstab

650) this.width=650; "src=" Http:// "title=" fstab. PNG "alt=" Wkiol1ztcpdgoahaaabqf54esye421.png "/>

Specifically because my swapfile file is under Root's home directory, so I added a line

/root/swapfile swap swap defaults 0 0

5. Check the size of the swap partition again

650) this.width=650; "src=" Http:// "title=" Swapsize. PNG "alt=" Wkiom1ztcymwqpciaaahhbeyup8237.png "/>

Complete the extension!

This article is from the "focus on Java,linux Technology" blog, please be sure to keep this source

Using swap files to expand swap space on Linux

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: 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.