what is LVM.
LVM is a shorthand for Logical Volume Manager (Logical Volume management), a mechanism for managing disk partitions in a Linux environment :
Borrow a picture of someone else's log, thank you http://dreamfire.blog.51cto.com
Basic term:
LVM is a logical layer added between disk partitions and file systems To shield the file system from the lower disk partition layout, provide an abstract storage volume, and establish the file system on the storage volume
physical storage media (physical storage media):
refers to the physical storage device of the system: such as disk,/ DEV/HDA,DEV/SDA
Physical Volume (physical Volume, referred to as PV):
refers to a disk partition or a logical partition with the same functionality as the disk partitions (such as RAID), is an LVM basic storage logic block , but compared to basic physical media such as partitions, disks, and so on, it contains the LVM-related and administrative parameters
Volume Group (Volume group, referred to as VG):
is similar to a physical disk in a non-LVM system. It consists of more than one physical volume PV that creates one or more LV (logical volume)
logical volumes (Logical Volume, referred to as LV) on a volume group:
is similar to a disk partition in a non-LVM system, and logical volumes are established in volume groups ( VG), above the logical volume LV can be established file systems (such as/home or/usr, etc.)
physical block (physical Extent, referred to as PE):
Each physical volume PV is divided into the basic unit called PE, A uniquely numbered PE is the smallest unit that can be addressed by LVM, the size of the PE is configurable and the default is 4MB, so the physical volume consists of a basic unit PE of the same size as the
logical block (logical Extent, abbreviated LE):
The logical volume LV is also divided into addressable basic units, called Le, in the same volume group, le is the same size as PE, and one by one corresponds to the
Installation Management tool:
If the system is installed with LVM, Typically with administrative tools, if there is no check to see if an LVM tool is installed
Rpm-qa |grep LVM
Create management:
1. Create partitions:
Use the partition tool Fdisk to create an LVM partition, as in the case of creating other general partitions, the difference being that the LVM partition type is 8e and the average is 83 (he modifies the type with the T under Fdisk)
Fdisk/dev/sdb
n
e
+5g (select size for this step)
W
#可以重复创建多个
2. Create a physical Volume:
To create the entire physical volume of a disk as a physical volume:
Pvcreate/dev/sdb
To create a single partition as a physical volume:
Pvcreate/dev/sdb5
To create multiple partitions as physical volumes:
pvcreate/dev/sdb{5,6}
Use PVs or Pvdisplay to view, Pvdisplay can also specify only one PV such as: PVDIPLAY/DEV/SDB6
3. Create Volume Group:
Vgcreate myvg/dev/sdb{5,6} #myvg是卷组的逻辑名, all partitions and disks that are later added to the volume group
The default PE is 4MB, but can also be manually specified, the PE size range is 8KB to 16G, and must always be a multiple of 2, specified with-s, the unit can be bbsskkmmggttppee
Vgcreate-s 8M myvg/dev/sdb{5,6}
Note: Because of the kernel reason, the PE size determines the maximum size of the logical volume, 4MB of PE determines the maximum capacity of a single logical volume is 256GB, if you want to use a logical volume greater than 256G, specify a larger PE when you create a volume group
Use VGS or Vgdisplay to view
4. Add a new physical volume to the volume Group:
Pvcreate/dev/sdb7
vgextend myvg/dev/sdb7
5. Remove a physical volume from the volume Group:
To remove a physical volume from a volume group, first make sure that the physical volume you want to delete is not being used by any logical volume, and you must use the Pvdisplay command to view a physical volume information
If a physical volume is being used by a logical volume, you need to back up the data for that physical volume somewhere else, and then delete it, and the command to delete the physical volume is
PVMOVE/DEV/SDB5 #把数据移动其它PV上去
vgreduce myvg/dev/sdb5 #返sdb5这个PV从myvg移除
vgremove/dev/sdb5 # SDB5 This PV delete, the inside of the data are erased, using PVS can not see the
6. Create Logical volumes:
Create a 50M logical volume named TESTLV on the VG named MYVG
Lvcreate-l 50m-n TESTLV MYVG #-l The specified size (supported unit Bbsskkmmggttppee)-N is the name of the logical volume, MYVG is the volume group name
Then format the logical volume
Msfs.ext4/dev/myvg/testlv
Mount to/TESTLV Directory
MOUNT/DEV/MYVG/TESTLV/TESTLV
Note: The path of the Mount reference is/DEV/MAPPER/MYVG-TESTLV,/DEV/MYVG/TESTLV is just a soft link, linked to/dev/mapper/ Myvg-testlv
Use LVS or Lvdisplay to view logical volume related information
7. Create the file system:
Resize2fs-p/DEV/MYVG/TESTLV #或者resize2fs-P/DEV/MAPPER/MYVG-TESTLV
#然后挂载就可以使用了
mount/dev/myvg/ Testlv/testlv
8. Delete a logical Volume:
A. Deleting a logical volume requires that it be uninstalled before deleting
Umount/testlv
B. Deleting logical volumes
Lvremove/dev/myvg/testlv
9. Expand Logical Volume Size:
A. Before you expand, make sure there's enough space in the VG to expand.
B. Extending physical boundaries
Lvextend-l 3G/DEV/MYVG/TESTLV #-l Specifies the size (+3g meaning to extend 3G, not to extend to 3G) to extend the physical boundary, where df-h is not seen to change.
C. Extending logical boundaries
Resize2fs-p/DEV/MYVG/TESTLV #扩展逻辑边界, or write Resize2fs-p/DEV/MAPPER/MYVG-TESTLV
10. Reduce Logical Volume Size:
A. Reduction is risky and cannot be reduced online and needs to be uninstalled first
Umount/testlv
B. Ensure that the reduced size of the space, still can store all the original data
E2fsck-f/DEV/MAPPER/MYVG-TESTLV
C. Before downsizing, you should check the file system first to ensure that the file system card consistency status
RESIZE2FS/DEV/MAPPER/MYVG-TESTLV 3G #缩减到3G
D. Reducing physical boundaries
Lvreduce-l 3G/DEV/MYVG/TESTLV
#会有提示: Do your really want to reduce testlv?[ Y/N]: press y OK
#完成后会提示: reducing logical Volume TESTLV to 3GB Logical volume
TESTLV successfully
11. Snapshot Volume
A. The life cycle is the length of the entire data, in which case the data growth cannot exceed the snapshot volume size
B. The snapshot volume should be read-only
C. In the same volume group as the original volume
Lvcreate
-L: Specify size, the specified size needs to be estimated by itself, if the data growth is greater than the size of the snapshot volume, the data will be corrupted
-S: To create a snapshot volume
-P: Specify Permissions R|w
Create a snapshot volume #对/DEV/MYVG/TESTLV testlv_snap
Use LVS or Lvdisplay to view
To mount a snapshot volume:
Mount/dev/myvg/testlv_snap/testlv_snap
To uninstall a snapshot volume:
Umount/testlv_snap
To remove a snapshot volume:
Lvremove/dev/myvg/tstlv_snap