How Linux adds a swap partition

Source: Internet
Author: User

1. Create a new disk partition as a swap partition
2. Use the file as a swap partition (easier to operate, I'm more used)

A. Create a new disk partition as a swap partition

1. # swapoff-a #停止所有的swap分区

2. Use the Fdisk command (example: # FDISK/DEV/SDB) to partition the disk, add a swap partition, create a new partition, and use the "T" command in Fdisk to change the newly added partition ID to ". Linux swap Type". Finally, the operation is actually written to the hard disk with W (the operation is not valid until W is useless).

3. # mkswap/dev/sdb2 #格式化swap分区, the sdb2 here depends on the actual partition device name displayed after you add the P command

4. # SWAPON/DEV/SDB2 #启动新的swap分区

5. In order for the system to start automatically enable this swap partition, you can edit/etc/fstab, add the following line
/DEV/SDB2 swap swap defaults 0 0


Second, use the file as a swap partition

1. Create a file to be a swap partition: increase the 10GB size of the swap partition (the principle of the swap partition is not changed), then the command is written as follows, where count equals the number of blocks (bs*count= file size) you want.
# dd If=/dev/zero of=/root/swapfile bs=1m count=10240

2. Format the swap partition file:
# mkswap/root/swapfile #建立swap的文件系统

3. Enable the Swap partition file:
# swapon/root/swapfile #启用swap文件

4. Make the system self-enabled when booting, add a line in file/etc/fstab:
/root/swapfile swap swap defaults 0 0

The commands for new and added swap partitions are: Mkswap, Swapon, and so on, and a command like "SWAPON/DEV/SDB2" is used to shut down a swap partition.

How Linux increases the swap partition

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.