Linux Logical Volume Tool LVM Tutorial

Source: Internet
Author: User
Keywords linux linux lvm linux lvm commands
Detailed method of creating logical volume (LVM):

STEP 1: First use the fdisk command to create physical partitions, and then convert each partition type to LVM type, numbered 8e. If you are building PV for the entire disk, this step can be ignored.


STEP 2: Use the pvcreate command to create PV, which is a physical volume. The method to create a disk or partition as a physical volume is pvcreate /dev/sda5. If you want to create more than one, you can pvcreate /dev/sda{5,6,7,8……}.


STEP 3: Use the three commands pvscan, pvdisplay, and pvs to check the current system physical volume information.


STEP 4: Use the vgcreate command to create a volume group. The smallest unit of a volume group is PE, and the default size is 4M. Similarly, vgscan and vgdisplay can check whether the current system has a volume group.


vgcreate -s 8 vg0 /dev/sdb /dev/sdc #Create a volume group, named vg0, PE size is 8M, composed of two PVs /dev/sdb sdc


STEP 5: vgrename can modify the volume group name.


vgrename testvg myvg #Change the name of the volume group testvg to myvg

STEP 6: If the logical volume space is not enough later, you can add a new physical volume to the volume group using the vgextend command.


vgextend vg0 /dev/sda8 #Add the /dev/sda8 physical volume to the vg0 volume group. Then use pvscan to check whether these physical volumes have been added to the volume group.

vgreduce vg0 /dev/sda8 #vgreduce command can delete the physical volume from the volume group


STEP 7: Use lvcreate to create a logical volume, and then format the partition. After formatting, use the mount command to mount it to the directory. The lvdisplay command can view the current system logical volume status.


lvcreate -L 200M -n lv0 vg0 # -L specifies the size of the logical volume. If you use -l, you specify the number of PEs. It is usually convenient to use -L. -n is to set the logical volume name.

mkfs.xfs /dev/vg0/lv0 #The partition here needs to use the name of the logical volume

STEP 8: The lvextend command can dynamically expand the size of the logical volume.


lvextend -L 1G /dev/vg0/lv0 #Note that the size here refers to the expanded size, not the increase in M. If you want to increase, you can change 1G to "+1G".

resize2fs /dev/vg0/lv0 #Update the system space size


STEP 9: The lvreduce command reduces the logical volume. You need to unmount the partition first, then use e2fsck to check the file system, and then use the resize2fs command to inform the system that it needs to be resized. If it is an xfs format system, you cannot use resize2fs, but xfs_growfs


e2fsck -f /dev/vg0/lv0 #-f stands for mandatory check

risize2fs /dev/vg0/lv0 1000M #Inform the system that the size of the logical volume needs to be adjusted to 1000M, but there is no real adjustment at this time, and the last command lvreduce is needed.

lvreduce /dev/vg0/lv0 -L -1000M #Reduce the space of 1000M from the current logical volume.
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.