Steps for adding swap space for swap in Ubuntu

Source: Internet
Author: User
1. Run the free command to view the Swap partition size in the system. Free-mtotalusedfreesharedbuffers &

1. Run the free command to view the Swap partition size in the system.
Free-m

Total used free shared buffers cached
Mem: 2012 1960 51 0 748 950
-/+ Buffers/cache: 260 1751
Swap: 255 0 255


We can see that Swap is only 255 M. Next we will expand it to 2G.

2. Create a Swap file.
Mkdir/swapfile
Cd/swapfile
Sudo dd if =/dev/zero of = swap bs = 1024 count = 2000000

The following message is displayed. The count in the preceding command indicates the swap file size.

Recorded 2000000 + 0 reads
Records 2000000 + 0 writes
2048000000 bytes (2.0 GB) Copied, 63.3147 seconds, 32.3 MB/second

Convert the generated file to a Swap file
Sudo mkswap-f swap

Setting up swapspace version 1, size = 1999996 KiB
No label, UUID = fee9ab21-9efb-47c9-80f4-57e48142dd69


3. Activate the Swap file.
Sudo swapon swap

View the free-m result again.

Total used free shared buffers cached
Mem: 2012 1971 41 0 572 1156
-/+ Buffers/cache: 241 1770
Swap: 2209 0 2209


Added successfully.

Extension:
If you need to uninstall the swap file, you can enter the created swap file directory. Run the following command.
Sudo swapoff swap

If you need to keep this swap, you can write it into the/etc/fstab file.

/Swapfile none swap defaults 0 0

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.