Linux system disk storage zone management principles and skills

Source: Internet
Author: User
Article Title: Linux system disk storage area management principles and skills. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

  Principles

1. What is the swap space?

Swap space in Linux is used when the physical memory (RAM) is full. If the system requires more memory resources and the physical memory is full, the inactive pages in the memory will be moved to the swap space.

Although swap space can help machines with a small amount of memory, this method should not be replaced by memory. The swap space is located on the hard drive, which is slower than the physical memory.

A swap space can be a dedicated swap partition (recommended), swap file, or a combination of the two. The total size of the swap space should be equivalent to two times of your computer's memory and one larger value of 32 MB, but it cannot exceed 2048 MB (2 GB ).

2. Add swap space

Sometimes, it is necessary to add more swap space after installation. For example, you upgrade the system memory from 64 MB to 128 MB, but you only have 128 MB swap memory. If you are executing a large number of memory-intensive operations or running a program that requires a large amount of memory, increasing the swap zone to 256 MB may be advantageous to you.

You have two options: Add a swap partition or add a swap file. We recommend that you add a swap partition. However, it is not easy to create swap partitions if you do not have much free space available.

To add a swap partition (assume/dev/hdb2 is the swap partition you want to add ):

Hard drive cannot be used (partition cannot be attached, and swap partition cannot be enabled ). The easiest way to achieve this is to guide your system in rescue mode. When you are prompted to mount the file system, select "Skip ".

If the drive does not contain any used partitions, You can detach these partitions and use the swapoff command to close all swap spaces on the hard drive.

  Tip

Use parted or fdisk to create swap partitions. Parted is easier to use than fdisk. Therefore, only parted is described here. To use parted to create a swap partition:

Run the command parted/dev/hdb as the root user at the shell prompt. Here/dev/hdb is the name of your device with a free space hard drive.

At the (parted) prompt, type print to view the number of existing partitions and free space. The start and end values are in MB. Determine the number of free space on the hard drive and the amount of space you want to allocate to the new swap partition.

At the (parted) prompt, type mkpartfs part-type linux-swap start end. The part-type here is one of primary, extended, and logical, and start is the start point of the partition, end is the termination point of the partition.

Warning changes occur immediately. Exercise caution when typing.

Type quit to exit parted.

Now you can create swap partitions and use the mkswap command to set swap partitions. In the shell prompt, enter the following command as the root user:

Mkswap/dev/hdb2

To enable swap partition immediately, type the following command:

Swapon/dev/hdb2

To enable it during boot, edit the/etc/fstab file to include the following lines:

/Dev/hdb2 swap defaults 0 0

During the next boot, the new swap partition is enabled.

After a new swap partition is added and enabled, check the output of cat/proc/swaps or the free command to ensure that the swap partition is enabled.

To add a swap file:

Determine the size of the new swap file. Multiply the size by 1024 to determine the size of the block. For example, the block size of a 64 MB swap file is 65536.

In the shell prompt, enter the following command as the root user, where count is equal to the expected block size:

Dd if =/dev/zero of =/swapfile bs = 1024 count = 65536

Run the following command to set the file exchange:

Mkswap/swapfile

To enable the swap file immediately instead of automatically enabling it during boot, run the following command:

Swapon/swapfile

To enable it during boot, edit the/etc/fstab file to include the following lines:

/Swapfile swap defaults 0 0

The new swap file is Enabled Next time the system boots.

After a new swap partition is added and enabled, check the output of cat/proc/swaps or the free command to ensure that the swap partition has been started.

[1] [2] [3] Next page

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.