Kernel module DM can achieve the following functions
Snapshot: Preserves data at that time state, providing additional access to the data path. If the data in the access snapshot does not change, the original path is used and the snapshot data is accessed if a change occurs. Can be used for backup.
Multipath: Each path, the operating system will be considered to be a physical disk, but it is actually a different path to the same physical disk
LVM2:
Physical Volume (PV):
Physical Disk Area (PE): Logical storage unit
Logical Volume Group (VG): Provides a uniform interface container for the LV. Mirroring: Storing one copy of the same data on different physical volumes
Logical Volume (LV): Dynamically scaled-down file system
Logical Partitioning (LE): Specify multiple PE as one Le
Snapshot Volume: Create a snapshot for a logical volume reserve space
LVM Operations:
Pv:pvcreate,pvremove,pvscan,pvdisplay,pvmove
Vg:vgcreate,vgremove,vgextend,vgreduce,vgs,vgscan
Lv:lvcreate,lvremove,lvextend,lvreduce,lvresize,lvs,lvdisplay
[[email protected] ~]# pvcreate/dev/sdd{1,2} Physical volume "/DEV/SDD1" successfully created. Physical volume "/DEV/SDD2" successfully created. [Email protected] ~]# PVs PV VG Fmt Attr PSize pfree /dev/sda2 Rhel lvm2 a--<93.82g 4.00m /DEV/SDD1 lvm2---1.41g 1.41g /DEV/SDD2 lvm2---599.00m 599.00m More Information View Pvdisplay [Email protected] ~]# Pvscan Pv/dev/sda2 VG Rhel lvm2 [<93.82 gib/4.00 MiB Free] Pv/dev/sde2 lvm2 [699.00 MiB] PV/DEV/SDF1 lvm2 [600.00 MiB] PV/DEV/SDD2 lvm2 [599.00 MiB] PV/DEV/SDF2 lvm2 [1.41 GiB] Pv/dev/sde1 lvm2 [<1.32 GiB] PV/DEV/SDD1 lvm2 [1.41 GiB] Total:7 [99.81 Gib]/in use:1 [<93.82 GIB]/in no vg:6 [<6.00 GIB] |
VG Operation:
Vgcreate vgname path_to_pv-s Specify PE size default 4M [[email protected] ~]# VGs-------------------View VG VG #PV #LV #SN Attr vsize vfree Rhel 1 2 0 wz--n-<93.82g 4.00m [[email protected] ~]# vgcreate yellow/dev/sd{d,e,f}{1,2}-------------------Create VG Volume Group "Yellow" successfully created [Email protected] ~]# VGS VG #PV #LV #SN Attr vsize vfree Rhel 1 2 0 wz--n-<93.82g 4.00m Yellow 6 0 0 wz--n-<5.98g <5.98g [Email protected] ~]# Vgdisplay Yellow ---Volume Group--- VG Name Yellow System ID Format lvm2 Metadata Areas 6 Metadata Sequence No 1 VG Access Read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 6 ACT PV 6 VG Size <5.98 GiB PE Size 4.00 MiB Total PE 1530 Alloc pe/size 0/0 Free pe/size 1530/<5.98 GiB VG UUID u5fzzk-bwln-rtst-kvl9-cyfr-ojuw-f0e52l [[email protected] ~]# vgremove Yellow--------------Delete VG Volume Group "Yellow" successfully removed To remove PV from the VG: [Email protected] ~]# PVs PV VG Fmt Attr PSize pfree /dev/sda2 Rhel lvm2 a--<93.82g 4.00m /DEV/SDD1 Yellow lvm2 a--1.41g 1.41g /DEV/SDD2 Yellow lvm2 a--596.00m 596.00m /DEV/SDE1 Yellow lvm2 a--1.31g 1.31g /DEV/SDE2 Yellow lvm2 a--696.00m 696.00m /DEV/SDF1 Yellow lvm2 a--596.00m 596.00m /DEV/SDF2 Yellow lvm2 a--1.41g 1.41g [[email protected] ~]# pvmove/dev/sdf2-----------------first move PV data to other VG No data to move for yellow. [[email protected] ~]# vgreduce yellow/dev/sdf2-----------------Delete VG from VG Removed "/DEV/SDF2" from volume Group "yellow" [Email protected] ~]# VGS VG #PV #LV #SN Attr vsize vfree Rhel 1 2 0 wz--n-<93.82g 4.00m Yellow 5 0 0 wz--n-<4.57g <4.57g [Email protected] ~]# PVs PV VG Fmt Attr PSize pfree /dev/sda2 Rhel lvm2 a--<93.82g 4.00m /DEV/SDD1 Yellow lvm2 a--1.41g 1.41g /DEV/SDD2 Yellow lvm2 a--596.00m 596.00m /DEV/SDE1 Yellow lvm2 a--1.31g 1.31g /DEV/SDE2 Yellow lvm2 a--696.00m 696.00m /DEV/SDF1 Yellow lvm2 a--596.00m 596.00m /DEV/SDF2 lvm2---1.41g 1.41g [[email protected] ~]# pvremove/dev/sdf2--------------------Remove PV Labels on physical volume "/DEV/SDF2" successfully wiped. [Email protected] ~]# PVs PV VG Fmt Attr PSize pfree /dev/sda2 Rhel lvm2 a--<93.82g 4.00m /DEV/SDD1 Yellow lvm2 a--1.41g 1.41g /DEV/SDD2 Yellow lvm2 a--596.00m 596.00m /DEV/SDE1 Yellow lvm2 a--1.31g 1.31g /DEV/SDE2 Yellow lvm2 a--696.00m 696.00m /DEV/SDF1 Yellow lvm2 a--596.00m 596.00m Add a VG [Email protected] ~]# PVCREATE/DEV/SDF2 Physical volume "/DEV/SDF2" successfully created. [Email protected] ~]# vgextend YELLOW/DEV/SDF2 Volume Group "Yellow" successfully extended [Email protected] ~]# VGS VG #PV #LV #SN Attr vsize vfree Rhel 1 2 0 wz--n-<93.82g 4.00m Yellow 6 0 0 wz--n-<5.98g <5.98g |
LV Operation:
Create LV: Lvcreate-n lv_name-l (Size KMG) [-L number of extents] Vg_name [Email protected] ~]# lvcreate-l 80m-n TESTLV Yellow Logical volume "TESTLV" created. [Email protected] ~]# LVDISPLAY/DEV/YELLOW/TESTLV ---Logical volume--- LV PATH/DEV/YELLOW/TESTLV LV Name TESTLV VG Name Yellow LV UUID 1zcsl4-yezt-nh1p-rtaw-dh7r-lg7b-1cvx5d LV Write Access Read/write LV Creation Host, Time Localhost.localdomain, 2018-05-30 23:47:15 +0800 LV Status Available # Open 0 LV Size 80.00 MiB Current LE 20 Segments 1 Allocation inherit Read ahead Sectors Auto -Currently set to 8192 Block Device 253:2 [[email protected] ~]# mkfs.ext4-j/DEV/YELLOW/TESTLV-------------Create file system MKE2FS 1.42.9 (28-dec-2013) File System label = OS Type:linux Block size =1024 (log=0) Chunked size =1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 20480 inodes, 81920 blocks 4096 Blocks (5.00%) reserved for the Super user First block of data =1 Maximum filesystem blocks=33685504 Block groups 8192 blocks per group, 8192 fragments per group 2048 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Allocating group tables: complete Writing Inode table: complete Creating Journal (4096 blocks): complete Writing Superblocks and FileSystem accounting information: Complete [[email protected] ~]# mount/dev/yellow/testlv/mnt/--------hanging in the relevant directory Logical Volume Removal: Confirm Mount point is umount before removal [Email protected] ~]# LVREMOVE/DEV/MAPPER/YELLOW-TESTLV Logical Volume YELLOW/TESTLV contains a filesystem in use. [Email protected] ~]# umount/mnt/ [Email protected] ~]# LVREMOVE/DEV/MAPPER/YELLOW-TESTLV Do you really want to remove active logical volume YELLOW/TESTLV? [y/n]: Y Logical volume "TESTLV" successfully removed |
To extend a logical volume:
Lvextend-l [+]# (plus sign indicates how much to extend, #表示扩展到多少) [Email protected] mapper]# df-h File system capacity has been used with available% mount points /dev/mapper/rhel-root 90G 33G 58G 37%/ Devtmpfs 1.4G 0 1.4G 0%/dev Tmpfs 1.5G 0 1.5G 0%/dev/shm Tmpfs 1.5G 9.4M 1.4G 1%/run Tmpfs 1.5G 0 1.5G 0%/sys/fs/cgroup /DEV/SDA1 1014M 170M 845M 17%/boot Tmpfs 287M 28K 287M 1%/run/user/0 /DEV/MAPPER/YELLOW-QQ 477M 2.3M 445M 1%/uuu [[email protected] mapper]# VGs---------------------to view the VG free before expansion is sufficient size VG #PV #LV #SN Attr vsize vfree Rhel 1 2 0 wz--n-<93.82g 4.00m Yellow 6 1 0 wz--n-<5.98g <5.49g [Email protected] mapper]# lvextend-l 2G/DEV/YELLOW/QQ Size of logical Volume YELLOW/QQ changed from 500.00 MiB (extents) to 2.00 GiB (extents). Logical volume yellow/qq successfully resized. [Email protected] mapper]# df-h File system capacity has been used with available% mount points /dev/mapper/rhel-root 90G 33G 58G 37%/ Devtmpfs 1.4G 0 1.4G 0%/dev Tmpfs 1.5G 0 1.5G 0%/dev/shm Tmpfs 1.5G 9.4M 1.4G 1%/run Tmpfs 1.5G 0 1.5G 0%/sys/fs/cgroup /DEV/SDA1 1014M 170M 845M 17%/boot Tmpfs 287M 28K 287M 1%/run/user/0 /DEV/MAPPER/YELLOW-QQ 477M 2.3M 445M 1%/uuu |
To shrink a logical volume:
1, can not be reduced online, you have to uninstall first. 2, to ensure that the size can be reduced to carry the original data 3. Forcibly check the file before shrinking to ensure the file system is in consistency check [[email protected] mapper]# umount/uuu [[email protected] mapper]# e2fsck-f/dev/mapper/ YELLOW-QQ&NBSP E2fsck 1.42.9 (28-dec-2013) First step: Check Inode, block, and size Step two: Check directory structure Step 3rd: Check directory Connectivity Pass 4: Checking reference counts 5th step: Check cluster profile /dev/mapper/yellow-qq:11/128016 files (0.0% non-contiguous), 26684/ 512000 blocks [Email protected] mapper]# lvreduce-l 1G/DEV/YELLOW/QQ Warning:reducing Active Logical Volume to 1.00 GiB. This May DESTROY YOUR DATA (filesystem etc) Does really want to reduce yellow/qq? [y/n]: Y Size of logical Volume YELLOW/QQ changed from 2.00 gib (+ extents) to 1.00 GIB (extents). Logical volume yellow/qq successfully resized.
[Email protected] mapper]# mount/dev/yellow/qq/uuu [Email protected] mapper]# df-h File system capacity has been used with available% mount points /dev/mapper/rhel-root 90G 33G 58G 37%/ Devtmpfs 1.4G 0 1.4G 0%/dev Tmpfs 1.5G 0 1.5G 0%/dev/shm Tmpfs 1.5G 9.4M 1.4G 1%/run Tmpfs 1.5G 0 1.5G 0%/sys/fs/cgroup /DEV/SDA1 1014M 170M 845M 17%/boot Tmpfs 287M 28K 287M 1%/run/user/0 /DEV/MAPPER/YELLOW-QQ 477M 2.3M 445M 1%/uuu |
Snapshot Volume:
1. Data growth in the life cycle cannot exceed the size of the snapshot volume (you can specify the amount of data in the LV) 2. The snapshot volume is read-only 3, with the original volume in the same volume group Lvcreate-l (size)-s (snapshot volume)-P r|w lv_name [Email protected] mapper]# lvcreate-l 10m-n testlv_snap-s/dev/yellow/qq-p R Rounding up size to full physical extent 12.00 MiB Logical volume "Testlv_snap" created. |
Mirrored volumes:
[[email protected] mapper]# lvcreate-l 1g-m1-n BBQ yellow/dev/sdf1/dev/sdf2/dev/sde1 Logical Volume "BBQ "Created. [[email protected] mapper]# lvs-a-o +devices LV VG Attr lsize Pool Origin data% meta% Move Log cpy%sync Con Vert Devices Root Rhel-wi-ao----90.00g/dev/sda2 (976) Swap rhel-wi-ao----3.81g/dev/sda2 (0) BBQ Yellow Rwi-a-r---1.00g 100.00 bbq_rimage_0 (0), bbq_rimage_1 (0) [bbq_rimage_0] Yellow iwi-aor---1.00g/dev/sdf2 (1) [ Bbq_rimage_1] Yellow iwi-aor---1.00g/dev/sde1 (1) [bbq_rmeta_0] Yellow ewi-aor---4.00m/dev/sdf2 (0) [bbq_rmeta _1] Yellow ewi-aor---4.00m/dev/sde1 (0) QQ YELLOW Owi-aos---1.00g/dev/sdd1 (0) TESTLV_SNAP Yellow Sri-aos---1 2.00m QQ 0.10/DEV/SDD1 (+) [Email protected] mapper]# LVDISPLAY/DEV/YELLOW/BBQ ---Logical volume--- LV PATH/DEV/YELLOW/BBQ LV Name BBQ VG Name Yellow LV UUID MVWHVG-DJHJ-0JDM-6MLR-T4IG-0VNX-PHZ8S4 LV Write Access Read/write LV Creation Host, Time Localhost.localdomain, 2018-05-31 01:25:13 +0800 LV Status Available # Open 0 LV Size 1.00 GiB Current LE 256 Mirrored volumes 2 Segments 1 Allocation inherit Read ahead Sectors Auto -Currently set to 8192 Block Device 253:10 [Email protected] ~]# lvextend bbq/dev/sde1 [Email protected] ~]# LVCONVERT-M1/DEV/YELLOW/BBQ/DEV/SDE1/DEV/SDF1/DEV/SDF2 |
Reference:
7623356
48676347
LINUX--LVM2 Learning