How to manage disk buckets in Linux

Source: Internet
Author: User

This is a tip for managing disk storage zones in Linux. Many friends often ask me about this. Today I will summarize this, starting from the principle of Linux-specific swap partitions, this article introduces how to manage disk technology in Linux: Windows partitions that we are familiar)
Principles
1. What is the swap space?
Swap space in Linux is used when 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.
Swap space can be a dedicated swap partition recommended method), swap files, 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 MB2 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, suppose/dev/hdb2 is the swap partition you want to add ):
Hard drive cannot be mounted in the used partition, and swap partition cannot be enabled ). The easiest way to achieve this is to guide your system in rescue mode. See Chapter 9th for instructions on booting the system into 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 is enabled.
3. delete a swap space
To delete a swap partition:
Hard drive cannot be mounted in the used partition, and swap partition cannot be enabled ). The easiest way to achieve this is to guide your system in rescue mode. See Chapter 9th for instructions on booting the system into 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.
At the shell prompt, enter the following command as the root user to confirm that the swap partition has been disabled. Here,/dev/hdb2 is the swap partition ):
Swapoff/dev/hdb2
Delete the project from the/etc/fstab file.
Use parted or fdisk to delete partitions. Only parted is described here. To use parted to delete a 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 swap space hard drive.
At the (parted) prompt, type print to view the existing partition and determine the secondary number of the SWAp partition you want to delete.
At the (parted) prompt, type rm MINOR. Here, MINOR is the secondary number of the partition you want to delete.
Warning the change will happen immediately. You must enter the correct secondary number.
Type quit to exit parted.
To delete the swap file:
Run the following command as the root user to disable/swapfile in the shell prompt ):
Swapoff/swapfile
Delete the project from/etc/fstab.
Delete an actual file:
Rm/swapfile
4. Mobile Exchange Space
To move a swap space from one place to another, first follow the instructions for deleting the swap space and then add the swap space.
After you install Red Hat Linux, you may want to view existing partition tables, change the partition size, delete partitions, or add partitions from idle space or attached hard drive. The parted tool allows you to execute these tasks. This chapter describes how to use the parted command to execute file system tasks. In addition, you can also use fdisk to execute most of these tasks in addition to re-partitioning ). For more information about fdisk, read the manual man or info ).
You must install the parted package to use the parted tool. To start parted, enter the command parted/dev/hdb as the root user at the shell prompt.
Here/dev/hdb is the name of the device you want to configure. You will see a (parted) prompt. Type help to view the list of available commands.
If you want to create, delete, or re-partition the partition size, the device where the partition is located cannot be used or mounted, and the swap space cannot be enabled ). The simplest way to achieve this is to guide the system in the rescue mode.
If the drive does not contain any partitions in use, you can run the umount command to detach the partition and run the swapoff command to disable swap space on the hard drive.
Commands
The following table contains the most common parted commands.
Print
A table similar to the following will appear:
Disk geometry for/dev/hda: 0.000-9765.492 megabytes
Disk label type: msdos
MinorStart End Type Filesystem Flags
1 0.031101.975 primary ext3boot
2101.975611.850 primary linux-swap
3611.851760.891 primary ext3
4760.891 9758.232 extended lba
5760.922 9758.232 logical ext3
The first line shows the disk size, the second line shows the disk tag type, and the remaining output shows the partition table.
In a partition table, Minor secondary) labels are partition numbers. For example, the partition with the secondary number 1 is opposite to/dev/hda1.
Start) and End) are measured in MB.
Type) is one of primary, extended, and logical.
Filesystem) is a file system type, it can be one of ext2, ext3, FAT, hfs, jfs, linux-swap, ntfs, reiserfs, hp-ufs, sun-ufs, or xfs.
Flags) column lists the criteria set for partitions. Available logos include boot, root, swap, hidden, raid, lvm, or lba.
TIPS:
Do not restart parted to select different devices, use the select command, followed by the device name, such as/dev/hdb. Then, you can view or configure its partition table.

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.