Linux LVM Logical Volume configuration process detailed

Source: Internet
Author: User

Linux LVM Logical Volume configuration process detailed

Many Linux users encounter the dilemma of installing the operating system: how to accurately evaluate and allocate the capacity of each hard disk partition, if the initial evaluation is not accurate, once the system partition is not enough, you may have to back up, 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, a logical layer that is built on top of hard disks and partitions and under a file system to improve the flexibility of disk partition management. RHEL5 the default installed partition format is the format of the LVM logical volume, it is important to note that the/boot partition cannot be created based on LVM and must be independent.

LVM configuration process is also very simple, not difficult, for this reason, I drew an illustrated diagram of an illustration, the entire process of LVM creation. For more detailed theoretical knowledge please refer to some tutorials or go to Google Oh!

Lab Environment:

First create two partitions from an empty hard disk SDB sdb1 1g,sdb2 2G. Prepare for the next LVM.

In order to facilitate the maintenance of management, remember to label the partition, so that even if you are not in the case, others see the mark will not easily move the area. The LVM logo is 8e, after the setup is done, remember to press W to save

First, create a logical volume

Convert the newly created two partition/DEV/SDB1/DEV/SDB2 into physical volumes, mainly by adding LVM attribute information and dividing the PE storage unit.

Create the volume group Vgdata and add the two physical volumes you just created to the volume group. You can see that the default PE size is 4mb,pe is the smallest storage unit for the volume group. You can modify the size by –s parameter.

Split 500M from the physical volume Vgdata to the new logical volume LVDATA1.

Use the MKFS.EXT4 command to create a EXT4 file system on the logical volume LVDATA1.

Mount the created file system/data1 on the/data1. (after creation, a soft connection named "Volume Group-Logical Volume" will be generated in/dev/mapper/.)

It is convenient for the server to restart the automatic mount, need to add the created file system mount information to/etc/fstab inside. The UUID can be queried by the Blkid command.

To see if the/etc/fstab is set correctly, you can unload the logical volume DATA1 and then use Mount–a to make the kernel reread/etc/fstab to see if it can be mounted automatically.

second, logical volume lvdata1 not enough, how to expand.

Adding space to a logical volume does not affect the use of the previous space, so there is no need to unmount the file system, directly via the command lvextend–l +500m/dev/vgdata/lvdata1 or lvextend–l 2.5g/dev/vgdata/lvdata1 To lvdata1 add 500M space (Lvdata1 is currently 2G space) after the setup is complete, remember to use the RESIZE2FS command to synchronize the file system.

Third, how to expand the volume group when the volume group is not enough

Re-create a partition from the second hard disk SDB3, the specific steps omitted. and add the created partition to the existing volume group Vgdata. See if it is successful through the PVS command.

Four, if the hard disk space is not enough, if the space to reduce the logical volume is freed to other logical volumes to use.

To reduce logical volume space, proceed as follows

1. First unload the logical volume DATA1

2. Then the free space on the logical volume is detected by the E2FSCK command.

3. Use RESIZE2FS to reduce the file system to 700M.

4, then use the lvreduce command to reduce the logical volume to 700M.

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 as file systems. If the logical volume is smaller than the file system, there is a problem with the data.

Once you are done, you can use the Mount command to mount it again.

Mount/dev/vgdata/lvdata1/data1

Mount | grep data1

V. If a piece of disk or partition fails, how to quickly transfer data to the same volume group other space.

1. Transfer spatial data via Pvmove command

2, by Vgreduce command will be bad disk or partition from the volume group Vgdata inside remove removed.

3. Remove the bad disk or partition from the system by Pvremove command.

4. Manually remove the hard drive or repair the partition with some tools.

Vi. deleting the entire logical volume

1. Remove the logical volume by Umount command first lvdata1

2, modify the/etc/fstab inside the logical volume mount information, or the system may not start up.

3. Delete the logical volume by Lvremove lvdata1

4. Delete the volume group by Vgremove Vgdata

5. Convert physical volumes to normal partitions via Pvremove.

After the deletion, do not forget to modify the ID identifier of the partition. Modify it to a normal Linux partition.

Summary: LVM logical volumes are a great space-use mechanism in Linux because partitions are not available to be enlarged or smaller without formatting. With LVM, you can make your disk space flexible.

Linux LVM Logical Volume configuration process detailed

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.