Setting up a Linux swap partition

Source: Internet
Author: User

Under Linux You can create two types of swap space, one swap partition and one swap file. The former is suitable for free partition can be used, the latter is suitable for the non-empty hard disk partition, the hard disk space has been allocated. For example: When installing Redhat, you can divide the hard disk space by default, the size of the Swap area system default configuration, when you install the system need to install an Oracle database, suddenly issued a warning, swap space is not enough. What should I do now?
1. How to view swap partitions
You can view the current swap partition by using the command Top,free command. You can also use Cat/proc/swaps to view swap partitions
2. How to expand the size of swap space through swap files
For example: increase the swap space of 1G
2.1, DD If=/dev/zone of=/myswap bs=2k count=524288//Partition space
2.2. Format of MKSWAP/MYSWAP//format into swap partition
2.3. Swapon/myswap//Make format swap effective
After setting, you can check the above command to see if it takes effect. When you start the system, you need to automatically load the interactive partition, which can be added in the/etc/fstab file:/myswap swap default 0 0
3, how to increase the swap space through the Swap partition method
3.1. If you want to add a swap partition (assuming you want to add/DEV/HDB5 as a swap partition), the hard drive cannot be used (that is, the partition cannot be loaded and the swap space is not activated). The partition table cannot be modified when it is used because the kernel may not correctly recognize changes in the partition table. This data may be written to the wrong partition, causing the data to be overwritten and lost because the partition table maintained by the kernel is inconsistent with the partition table on the hard disk.
The simplest way to solve this problem is to take the system boot into first Aid (rescue) mode for operation. When prompted to scan and load the file system, select Skip. If no partition on the hard disk is used, you can unmount the partition and use the Swapoff command to turn off all swap partitions on the hard disk.
3.2. Create a swap partition using parted
Run as Root: parted/dev/hdb
At the prompt of the parted command, enter print to view the current partition table, as well as the free space. The start and end values are in megabytes, then calculate how much free space you have and how much space you want to divide into the swap partition.
At the parted prompt, enter Mkpartfs part-tyep linux-swap start end, where Part-type is primary, extend, or logical. Start is the partition start point and end is the partition end point.
Enter Exit Exit parted
3.3. You have now created a swap partition, using the Mkswap command to set the swap partition:
Mkswap/dev/hdb2
3.4. In order to activate the swap partition immediately, enter the following command:
Swapon/dev/hdb2
3.5, in order to activate it at startup, add the following in/etc/fstab:
/DEV/HDB2 swap swap defaults 0 0
The swap partition will be activated automatically the next time you start the system.
3.6. After adding a new partition and activating it, you can see whether the swap partition is working by cat/proc/swaps or free.

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.