The MD and DM modules under Linux:
MD (Multiple devices):
A Btrfs filesystem can be created on top of many devices, and more devices can is added after the FS have been created.
By default, metadata'll be mirrored across-devices and data would be striped across all of the devices present.
If only one device is present, metadata'll be duplicated on the that one device.
DM (device Mapper):
Device Mapper is a universal device mapping mechanism in the Linux2.6 kernel that supports logical volume management, which provides a highly modular kernel architecture for implementing block device drivers for storage resource management, 1.
650) this.width=650; "src=" Http://www.ibm.com/developerworks/cn/linux/l-devmapper/images/image002.gif "alt=" Image002.gif "/>
MD Many functional DM can be implemented, such as linear module can realize the JBOD function in MD, Mirror can achieve RAID 1, and DM Many modules are not available in Md. Like what:
Snapshot (snapshot):
Snapshot essence is to provide another path for all files in a point-in-time file system to be stored in the snapshot, when the file is to be changed, the file is copied a copy in the snapshot, and the unchanged is not changed, so when a snapshot is accessed, if the file is changed is directly found in the snapshot, Otherwise, the location of the original file is accessed through the snapshot.
The use of a lot of snapshots: for example, for virtual machines, another useful use is in the real-time requirements of high-demand scenarios for data backup, because the server can not be interrupted, when we use other methods of backup, because each time period of the data are different, resulting in the backup of the data can not be used, The use of snapshots can achieve our requirements.
Multipath (Multi-Path):
Sometimes we have high safety requirements for production environments, and this time we can provide redundant links, and using this module, we can control the use of the link.
LVM:LVM uses the function of DM to realize the mapping frame mechanism from logical device to physical device, under which the user can make the management strategy of storage resource conveniently according to his own needs.
LVM Model:
650) this.width=650; "Src=" http://g.hiphotos.baidu.com/baike/c0%3Dbaike72%2C5%2C5%2C72%2C24/sign= A40ab540cb95d143ce7bec711299e967/d52a2834349b033bbd18a59916ce36d3d439bde5.jpg "alt=" D52a2834349b033bbd18a59916ce36d3d439bde5 "/> 650) this.width=650; src=" http://a.hiphotos.baidu.com/baike/s% 3d220/sign=0b4099b7b44543a9f11bfdce2e168a7b/8b13632762d0f70329d6d29f0bfa513d2697c509.jpg "alt=" 8b13632762d0f70329d6d29f0bfa513d2697c509 "/>
Basic concepts:
PV (Physical volume physical volume): The/DEV/SDA1,/DEV/SDB1,/DEV/SDC1,/DEV/SDD1 in the diagram, the real physical storage device.
VG (Volume Group): The logical set in the diagram, the set of PV, provides an interface to the upper layer
LV (logic volume Logical volume): The logical partition in the diagram, built on top of the volume group, can create a file system
PE (physical Extent Physical Disk area): Each physical volume PV is divided into a basic unit called PE (physical extents) , with a unique number of PE is the smallest unit that can be addressed by LVM. The size of the PE is configurable and defaults to 4MB. So the physical volume (PV) is made up of basic unit PE of equal size.
LE (logic extent logical extents) is the same as the physical disk area, just stand in the logical volume perspective
The mechanism of LVM is that the function of the physical device through the DM module virtualization, DM to create a volume group, when the need for a physical device, the physical device as a PV added to the volume group, and up to the logical volume, in a logical volume, the volume group is similar to a large disk, can use its provided LE, You can also return the unused Le to it, so that other logical volumes to use, and the use of the underlying physical devices do not care, by the volume group to implement its functions. All of the same volume group of logical volume disk size sum cannot be larger than the volume group itself, volume group can be expanded by adding and removing PV, logical volume can be expanded by adding and removing le.
When a volume group is created, its PE is fixed, and when a PV is added to a volume group, it is formatted into the same PE as the volume group.
Example:
To install the LVM tool:
[email protected] ~]# Yum install Lvm-common lvm2 evms-y
Create PV:
[Email protected] ~]# PVCREATE/DEV/SDB1/DEV/SDB2
Physical volume "/DEV/SDB1" successfully created
Physical volume "/DEV/SDB2" successfully created
[Email protected] ~]# PVs
PV VG Fmt Attr PSize pfree
/DEV/SDB1 lvm2---2.01g 2.01g
/DEV/SDB2 lvm2---3.01g 3.01g
Create VG:
[[email protected] ~]# vgcreate myvg/dev/sdb1/dev/sdb2-s 8M (-s Specify PE size, can not add default 4M)
Volume Group "MYVG" successfully created
[Email protected] ~]# Vgdisplay
---Volume Group---
VG Name MYVG
System ID
Format lvm2
Metadata Areas 2
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 2
ACT PV 2
VG Size 5.01 GiB
PE Size 8.00 MiB
Total PE 641
Alloc pe/size 0/0
Free Pe/size 641/5.01 GiB
VG UUID 2EPSCI-0YXX-HAYV-ZOIN-H4CP-JMLQ-DRSVBQ
Create LV:
[Email protected] ~]# lvcreate-l 5G MYVG
Logical volume "lvol0" created.
[Email protected] ~]# Lvdisplay
---Logical volume---
LV path/dev/myvg/lvol0
LV Name lvol0
VG Name MYVG
LV UUID 2uwnl6-4p0m-ursb-bhm7-1w1j-9gnw-paarov
LV Write Access Read/write
LV Creation Host, Time Logstash, 2016-03-09 16:30:10 +0800
LV Status Available
# Open 0
LV Size 5.00 GiB
Current LE 640
Segments 2
Allocation inherit
Read ahead Sectors Auto
-Currently set to 256
Block Device 253:0
Format the LV and mount it
[Email protected] ~]# mke2fs-j/dev/myvg/lvol0
MKE2FS 1.41.12 (17-may-2010)
Filesystem label=
OS Type:linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the Super user
First Data block=0
Maximum filesystem blocks=1342177280
Groups block
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing Inode Tables:done
Creating Journal (32768 blocks): Done
Writing superblocks and filesystem accounting Information:done
This filesystem would be automatically checked every mounts or
Whichever comes first. Use Tune2fs-c or-i to override.
[Email protected] ~]# Mount/dev/myvg/lvol0/data
[Email protected] ~]# df-h
Filesystem Size used Avail use% mounted on
/dev/sda2 20G 4.0G 15G 22%/
Tmpfs 234M 0 234M 0%/dev/shm
/DEV/SDA1 190M 41M 140M 23%/boot
/dev/mapper/myvg-lvol0
5.0G 139M 4.6G 3%/data
The expansion of LV:
To view the remaining capacity of the VG:
[Email protected] ~]# VGS
VG #PV #LV #SN Attr vsize vfree
MYVG 2 1 0 wz--n-5.01g 8.00m
Expansion of the VG
[[email protected] ~]# vgextend MYVG/DEV/{SDB3,SDB4}
Volume Group "MYVG" successfully extended
[Email protected] ~]# VGS
VG #PV #LV #SN Attr vsize vfree
MYVG 4 1 0 wz--n-9.01g 4.01g
Scaling LV
[Email protected] ~]# lvextend-l +3g/dev/mapper/myvg-lvol0
Size of logical Volume MYVG/LVOL0 changed from 5.00 GIB (640 extents) to 8.00 Gib (1024x768 extents).
Logical Volume lvol0 successfully resized
[Email protected]/]# umount/data/
[[email protected]/]# e2fsck-f/dev/mapper/myvg-lvol0 (check disk)
E2fsck 1.41.12 (17-may-2010)
Pass 1:checking inodes, blocks, and sizes
Pass 2:checking directory structure
Pass 3:checking Directory Connectivity
Pass 4:checking Reference counts
Pass 5:checking Group summary Information
/dev/mapper/myvg-lvol0:12/327680 files (0.0% non-contiguous), 55936/1310720 blocks
[[email protected]/]# resize2fs/dev/mapper/myvg-lvol0 (re-read size)
RESIZE2FS 1.41.12 (17-may-2010)
Resizing the filesystem on/dev/mapper/myvg-lvol0 to 2359296 (4k) blocks.
The filesystem on/dev/mapper/myvg-lvol0 is now 2359296 blocks long.
[[email protected]/]# mount/dev/mapper/myvg-lvol0/data/(re-mount)
[Email protected]/]# df-h
Filesystem Size used Avail use% mounted on
/dev/sda2 20G 4.0G 15G 22%/
Tmpfs 234M 0 234M 0%/dev/shm
/DEV/SDA1 190M 41M 140M 23%/boot
/dev/mapper/myvg-lvol0
8.9G 140M 8.3G 2%/data
Reduction of LV and VG and removal of PV
Note: the difference between reduce and remove is reduced, and remove is removed! the data on the disk is deleted, so be aware that Lvreduce,lvremove also has the use of VG and PV-related commands.
Reduction of LV:
[Email protected]/]# umount/data/
[Email protected]/]# resize2fs/dev/mapper/myvg-lvol0 2G
[Email protected]/]# lvreduce-l 2g/dev/mapper/myvg-lvol0
Warning:reducing Active and open logical volume to 2.00 GiB
This May DESTROY YOUR DATA (filesystem etc)
Does really want to reduce lvol0? [y/n]: Y
Size of logical Volume MYVG/LVOL0 changed from 9.00 Gib (1152 extents) to 2.00 gib (extents).
Logical Volume lvol0 successfully resized
You can also use lvreduce-l 2g-f-r/dev/mapper/myvg-lvol0 a command to complete, reduce risk, pay attention to the data backup.
The reduction of VG:
[Email protected]/]# VGS
VG #PV #LV #SN Attr vsize vfree
MYVG 4 1 0 wz--n- 9.01g 7.01g
[Email protected]/]# vgreduce MYVG/DEV/SDB3
Removed "/DEV/SDB3" from volume Group "MYVG"
[Email protected]/]# VGS
VG #PV #LV #SN Attr vsize vfree
MYVG 3 1 0 wz--n- 7.01g 5.01g
Removal of PV:
[[email protected]/]# PVMOVE/DEV/SDB4 (You must use this command to transfer data from PV to other PV before removing PV)
No data to move for MYVG
[Email protected]/]# PVREMOVE/DEV/SDB4
PV/DEV/SDB4 belongs to Volume Group MYVG so, use Vgreduce first.
(If you were certain need pvremove, then confirm by using--force twice.)
[Email protected]/]# vgreduce MYVG/DEV/SDB4
Removed "/DEV/SDB4" from volume Group "MYVG"
[[email protected]/]# pvremove/dev/sdb4 (This command will erase the data, use with caution!!) )
Labels on physical volume "/DEV/SDB4" successfully wiped
This article is from the "single Season rice" blog, please be sure to keep this source http://linzb.blog.51cto.com/5192423/1748848
One of the LVM