LVM is short for Logical Volume Manager. It is a mechanism for managing disk partitions in Linux, LVM is a logical layer built on hard disks and partitions to improve the flexibility of disk partition management. As mentioned above, LVM is a logical layer added between the disk partition and the file system to shield the file system from the underlying disk partition layout and provide an abstract disk volume, create a file system on the disk.
Related Concepts:
Physical Volume PV: Refers to a hard disk partition or a device that looks logically similar to a hard disk partition (such as a RAID device ).
Logical Volume LV: one or more physical volumes form one logical volume.
Volume group VG: one or more logical volumes form a volume group. A volume group combines multiple logical volumes to form a manageable unit.
Physical block PE: physical volumes are stored in units of equal size blocks. The block size is the same as the logical volume block size in the volume group.
Logical Block LE: Logical volumes are stored in blocks. The block size of all logical volumes in a volume group is the same.
- Create a physical partition
- Before using LVM, you must first partition the disk, that is, use the fdisk command to partition the disk. You must specify the partition type as linux LVM, the corresponding ID is 8e (in fact, LVM can also identify linux's default partition type 83)
- [Root @ rhel5 ~] # Fdisk-l
- Disk/dev/sda: 21.4 GB, 21474836480 bytes
- 255 heads, 63 sectors/track, 2610 cylinders
- Units = cylinders of 16065*512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /Dev/sda1*1 13 104391 83 Linux
- /Dev/sda2 14 78 522112 + 82 Linux swap/Solaris
- /Dev/sda3 79 1383 10482412 + 8e Linux LVM
- /Dev/sda4 1384 2610 9855877 + 5 Extended
- /Dev/sda5 1384 1994 4907826 83 Linux
- [Root @ rhel5 ~] # Fdisk-t 8e/dev/sda5
- Create a physical volume PV
- The command for creating a physical volume is pvcreate. You can use this command to create all the disk partitions or the entire disk to be added to the volume group (VG) as a physical volume. Format:
- Pvcreate disk partition or entire disk
- [Root @ rhel5 ~] # Pvcreate/dev/sda5
- Physical volume "/dev/sda5" successfully created
- Create/activate volume group VG
- The command for creating a volume group is vgcreate, in the format:
- Vgcreate volume group name physical volume
- [Root @ rhel5 ~] # Vgcreate iscsi/dev/sda5
- Volume group "iscsi" successfully created
- After creating a volume group, you can use the vgchange command to activate the volume group without restarting the system. The format of Vgchange is as follows:
- Vgchange-a y volume group name (activate volume group)
- Vgchange-a n volume group name (Disable volume group)
- The command for creating logical volumes is lvcreate. The common format is:
- Lvcreate [-L logical volume size |-l number of PES]-n volume group name to which the logical volume name belongs
- Where:
- -L: the size of the logical volume that is followed by K, M, and G. Such as 100 M, 10g, etc.
- -L: Use the number of PES to calculate the logical volume size.
- [Root @ rhel5 ~] # Lvcreate-n sharedisk-L 2G iscsi
- Logical volume "sharedisk" created
- Displays PV, VG, and LV attributes.
- [Root @ rhel5 ~] # Pvs
- Pv vg Fmt Attr PSize PFree
- /Dev/sda3 rootvg lvm2 a-9.97G 0
- /Dev/sda5 iscsi lvm2 a-4.68G 4.68G
- [Root @ rhel5 ~] # Vgs
- VG # PV # LV # SN Attr VSize VFree
- Iscsi 1 0 0 wz -- n-4.68G 4.68G
- Rootvg 1 1 0 wz-n-9.97G 0
- [Root @ rhel5 ~] # Lvs
- Lv vg Attr LSize Origin Snap % Move Log Copy % Convert
- Sharedisk iscsi-wi-ao 2.00G
- Rootlv rootvg-wi-ao 9.97G
- You can also view more detailed information through pvdisplay, vgdisplay, and lvdisplay.