Detailed explanation of CentOS LVM logical volume configuration process

Source: Internet
Author: User

Many Linux users encounter the following dilemma when installing the operating system: How to accurately evaluate and allocate the capacity of each hard disk partition? If the original evaluation is inaccurate, once the system partition is insufficient, you may have to back up or delete the relevant data, or even be forced to re-plan the partition and reinstall the operating system to meet the needs of the application system.

LVM is a mechanism for managing Disk Partitions In a Linux environment. It is a logical layer built on top of hard disks and partitions and under the file system, which can improve the flexibility of disk partition management. RHEL5 is installed in the format of LVM logical volume by default. Note that/boot partitions cannot be created based on LVM and must be independent.

The LVM configuration process is also very simple and not very difficult. Therefore, I drew a graphic parsing diagram to parse the entire LVM creation process. For more detailed theoretical knowledge, please refer to some tutorials or go to Google!


Lab environment:

First, create two partitions sdb1 1G and sdb2 2G from the empty hard disk sdb. Prepare for LVM.

In order to facilitate maintenance and management in the future, remember to add tags to the partitions so that even if you are not there, others will not easily move the area if they see the labels. the lvm id is 8e. Remember to save it by w after setting.

1. Create a logical volume

The two newly created shards/dev/sdb1/dev/sdb2 are converted into physical volumes. The LVM attribute information is added and PE storage units are divided.

Create a volume group vgdata and add the two physical volumes you just created to the volume group. it can be seen that the default PE size is 4 MB, and PE is the minimum storage unit of the volume group. you can use the-s parameter to modify the size.

Divides MB from the physical volume vgdata to the new logical volume lvdata1.

Use the mkfs. ext4 command to create an ext4 File System on the logical volume lvdata1.

Mount the created File System/data1 to/data1. (After the creation, a soft connection named "volume group-logical volume" will be generated in/dev/mapper ")

To enable automatic mounting after the server is restarted, you need to add the mounting information of the created File System to/etc/fstab. UUID can be queried using the blkid command.

To check whether/etc/fstab is set correctly, you can first uninstall the logical volume data1 and then use mount-a to re-read the/etc/fstab kernel to check whether automatic mounting is possible.

Ii. How to expand the logical volume lvdata1 is insufficient.

Adding space to the logical volume does not affect the usage of the previous space, so you do not need to uninstall the file system, run the command lvextend-L + 500 M/dev/vgdata/lvdata1 or lvextend-l 2.5G/dev/vgdata/lvdata1 to increase the space of lvdata1 by MB (lvdata1 is currently 2 GB) after setting, remember to use the resize2fs command to synchronize the file system.

Iii. How to expand a volume group when the volume group is insufficient

Create a new sdb3 partition from the second hard disk. The operation steps are omitted. Add the created partitions to the existing volume group vgdata. Run the pvs command to check whether the operation is successful.

4. If the hard disk space is insufficient, release the logical volume space to other logical volumes.

To reduce logical volume space, follow these steps:

1. unmount the logical volume data1 first

2. Run the e2fsck command to check the free space on the logical volume.

3. Use resize2fs to reduce the file system to 700 mb.

4. Use the lvreduce command to reduce the logical volume to 700 mb.

Note: The file system size and logical volume size must be consistent. If the logical volume is larger than the file system, space is wasted because some areas are not formatted into a file system. If the logical volume is smaller than the file system, the data may be faulty.

After that, you can mount and re-use the mount command.

5. If a disk or partition fails, how can we quickly transfer data to another space in the same volume group.

1. Use the pvmove command to transfer Spatial Data

2. Run the vgreduce command to remove the damaged disk or partition from the vgdata of the volume group.

3. Run the pvremove command to delete the damaged disk or partition from the system.

4. Manually remove the hard disk or use some tools to repair the partition.

6. Delete the entire logical volume

1. Run the umount command to uninstall the logical volume lvdata1.

2. Modify the mounting information of the logical volume in/etc/fstab. Otherwise, the system may fail to start up.

3. Use lvremove to delete the logical volume lvdata1

4. Delete the volume group vgdata through vgremove

5. Use pvremove to convert a physical volume to a common partition.

After deleting the partition, do not forget to modify the id of the partition. Change it to a common Linux partition.

Summary: The LVM logical volume is a great space usage mechanism in Linux, because partitions cannot be increased or decreased without formatting. With LVM, You can flexibly use your disk space.

This article is from the blog of "the Linux open source technology blog", please be sure to keep this source http://dreamfire.blog.51cto.com/418026/1084729


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.