Linux logical volume management

First, the logical presentation

        The logical volume is a hard disk or a plurality of multiple logical partitions are grouped together, and from this perspective is the raid like multiple logical disk partitions or more groups together to form a logical unit is the unit volume group , with a total volume capacity of the volume group is set by a plurality of partitions, or a plurality of hard disks are combined, the difference between the logical volume and in that the raid raid requires that each member must be the same size, logical volumes not required, nor does it require the logical volume after the hard disk on the same hard disk partition can also be different, different hard drives or different partitions of different hard drives will do, no less stringent requirements in addition to create a complete logical volume group, and that the volume group is a logical unit can of it as a logical large hard disk, then the volume group has, in the upper small memory division, the logical volume is small storage units, a small space is allocated from logical volume group are combined, the volume group is a hard disk or a plurality of partitions are combined, of course, the logical volume in the volume group from the space and the space volume from the group of multiple hard drives, and It means the logical volume space may also come from multiple hard drives, but a logical volume after creating a logical volume space is not enough, there is space on the volume group free space from the logical volume expansion in the use of space in the volume group

Second, the logical volume management tools

PV: physical volume, refers to a hard disk partition or device (e.g., Raid) having the same function from a logical disk partition, is the basic storage LVM logical blocks. But the force storage media and basic comparison, it has its own management command; 
	the pvcreate: ordinary disk production physical volume, you can specify multiple physical disks once; 
	pvdisplay: Displays information on the current logical system; 
	pvscan: scanning system has a logical volume of the disk; 
	the pvremove: delete logical volumes, so that the disk does not have the attributes of the logical volume; 

VG: volume group, the physical volumes, you can create one or more LVM logical volumes on the volume group, LVM volume group by one or more physical volumes; 
	the vgcreate: create a volume group; 
	the vgdisplay: displaying information on the system volume group; 
	the vgextend: adding physical volume to the volume group; 
	the vgreduce: remove physical volume from the volume group; 
	the vgremove: delete a volume group; 
	vgchange: configure whether to activate the volume group; 
	vgscan: has a disk volume group properties of the scanning system; 

LV: logical volume, similar to the hard disk partition, you can create a file system on the logical volume. 
	lvcreate: Create a logical volume; 
		-n: Specifies when creating a logical volume name; 
		-L: Specifies the size of the logical volume created when; 
		-s: designated snapshot volume; 
		-p: specify permissions, ro read-only, read-write RW or the like; 
	lvdisplay: display information of the logical volume; 
	the lvextend: extension for the logical volume capacity, no unmounted;
		-L: When the specified size expansion, + # G G indicates how much capacity is added based on the original;
		-r: directly adding new space and the original space is formatted the same when expansion of the file system; 
			popular formats: the lvextend G -R & lt -L + # / dev / vg_name / lv_name 
	the lvreduce: logical volume capacity reduction; 
		-L : Specifies the time to reduce the size, ext series supports cut, xfs does not support the reduction; 
	lvremove: delete a logical volume; 
	lvresize: adjust the size of the logical volume capacity; 
	lvscan: logical volumes on the scanning system;

Third, to achieve a LVM logical volume

Requirements: lvm disk management to complete the requirements below, and write a detailed process:

 

  1) Create a size of the at least two PV VG is composed of named testvg of 20G; PE claim size 16MB, then the size of 5G created logical volume in the volume group testlv; to mount / users directory

 

  2) extend testlv to 7G, archlinux requires the user's file can not be lost

 

  3) testlv to shrink 3G, archlinux requires the user's file can not be lost

 

  4) Create a snapshot of the testlv, and try to function-based snapshot backup data validation snapshot

Fourth, the implementation process

  1. Create a logical volume for the size of 5g testlv

First, prepare two free disk using fdisk partition, and change it to a partition type id lvm

View disk information, / dev / sdc and / dev / sdd as an experimental disk

image.png

Use fdisk to change the partition type and where to / dev / sdc sdc and sdd, for example the same practice

image.png

Type t to change the type, L to see what type of partition

image.pngType w to save and exit the partition
/ dev / sdd is the same zoning!
Pv create physical volume and use pvdisplay View

image.png

Creating vg volume group, specify the size of PE 16M, the volume group name testvg and view the volume group information using vgdisplay

image.png

Create a logical volume rate testlv, size is 5G, and view the logical volume information by lvdisplay

image.png

对逻辑卷testlv创建文件系统类型为ext4,并挂载至/users/目录

image.png

2.对testlv的逻辑卷进行扩容

首先vgdisplay查看卷组是否还有空间,如果没有可再添加新磁盘并做为物理卷从而实现VG的增大,然后再为逻辑卷扩容;

实现在线扩展testlv至7G,使用df查看

image.png3.对testlv进行空间的缩减(缩减需要5个步骤)缩容testlv至3G,前提是要保证缩容后逻辑卷中原有文件小于testlv

1)首先使用umount 取消所有挂载关系


2)e2fsck -f /dev/testvg/testlv:强制进行磁盘检测


3)resize2fs /dev/testvg/testlv 3G:定义逻辑卷缩减为多少G,必须与下面lvreduce指定的大小一致,不然报错


4)lvreduce -L 3G /dev/testvg/testlv:定义逻辑卷缩减为多少G,必须与上面resize2fs指定的大小一致,不然报错


5)然后挂载,使用df -h 就可以看到逻辑卷已经缩减容量了

image.png

4.对逻辑卷testlv创建快照,对testlv创建快照,并尝试基于快照备份数据,验证快照的功能

1)快照的作用:

将当时的系统数据记录下来,在未来如若有数据变动,则会将变更前的数据放在快照区进行保存,进行备份时使用,快照只备份变更过的文件,而没有变更过的文件还再原位置上,当你修改数据时,快照会自动将最初始的文件cp一份放到快照区,即使你将来文件修改错了,有最初的文件还可以恢复,如果有人删除文件,也会cp一份到快照区,而且原文件的原属性不变,快照也可以创建多个,创建快照的时间就是它认为原文件的最初始状态时间。

2)快照的缺点:

Because in the same logical volume, so when the logical volume is damaged, the backup data is naturally not be used, so no effect snapshot full backup, when we create if not used immediately delete the snapshot of a snapshot, because the presence of snapshots can affect the performance of the server

Definition 3 capacity) snapshot: a snapshot of the volume size requires only 15% to 20% of the original logical volume is sufficient, can be used to enlarge the snapshot lvextend

image.png5. Implement a snapshot backup, snapshot testlv_snap create and mount it to / mnt / snap

image.png

6. Verify snapshot effect:

Existed before the next logical volume to create a snapshot of a logical volume mount directory data, if there is no data to create a snapshot does not make sense, and now the role of demonstration snapshots, snapshot into default now mount the directory can see these files and do not panic, just to prove a snapshot is already created, the file is now still in the original position, when we modify f1, f2 and deletion, automatic snapshot volume f1 and f2 of the original copy to the directory of the snapshot volume under. So that played a backup.

image.png

7. Restore Snapshot

First unmount a logical volume and the snapshot volume , snapshot volumes are automatically deleted after the snapshot recovery is complete.

image.png

8. Delete Logical Volume

1) first unmounting umount

2) in order to delete the logical volume

3) lvremove / dev / testvg / testlv: Removing a Logical Volume

4) vgremove testvg: Delete volume group

5) pvremove / dev / sdb / dev / sdc: Remove the physical volume

This time using pvdisplay, vgdisplay, lvdisplay not have any information about the logical view of the testlv;

image.png


Guess you like

Origin blog.51cto.com/13406057/2438222