8.Linux of LVM usage
Command Overview: Commands used (#代表是数字)
pvcreate/dev/sd[ XX]
Vgcreate-s # vgname/dev/sd[]
-s Specifies the size of the PE default size is 4M
Vgextend vgname/dev/sd[xx]
Lvcreate-n Lvname-l #/dev/vgname
Capacity
LVs
Lvextend-l #/dev/vgname/lvname
Resize2fs/dev/vgname/lvname
LVs
Reduced
Umount/dev/vgname/lvname
E2fsck/dev/vgname/lvname
Resize2fs/dev/vgname/lvname #
Lvreduce-l #/dev/ Vgname/lvname
Mount
Snapshot
lvcreate-l #-s-n Snapshot/dev/vgname/lvname
Unload Logical Volume
Umount/dev/vgname/lvname
Lvremove/dev/vgname/lvname
Vgremove/dev/vgname
Pvremove/dev/sd[xx]
-
Use of LVM
The LVM (Logical Volume Manager) is called the logical Volume Manager, with two versions, early LVM1 (now rarely used), LVM2.
PV (physical Volume) physical volume, you need to adjust the system ID to 8e (the LVM identifier) when partitioning, and use pvcreate to create the physical volume. The
VG (Volume Group) volume group, which combines one or more PV into a single VG, can be implemented by Vgcreate. The
LV (Logical Volume) logical volume, which divides the VG into one or more LVS, can be implemented by Lvcreate.
LVM2 uses a DM module to implement a tool that organizes one or more underlying block devices into a logical device. It can map one or more of the underlying block devices to a logical device by attaching a logical layer above it to make the upper layer look like a device, and on top of it, it can also partition logical partitions. The underlying block device (VG) is further separated into a block (PE) that can store the data space, also known as PE (physical Extend), and then combine multiple PE on the VG into one or more
Lv. That is, the size of the LV is determined by the number of PE, LVM default to use 4M PE block, and LVM VG can only contain up to 65,534 PE, so the default LVM VG will have 4m*65534 (1024m/g) =256g, it is the entire LVM the smallest storage block, that is, File
Data is processed by writing to PE. The following is a simple framework for LVM:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/34/wKiom1Sr2Yjweji8AAI4WXREEzY908.jpg "title=" Qq20150106204705.png "alt=" Wkiom1sr2yjweji8aai4wxreezy908.jpg "/>
LVM is implemented in two ways when data is written to the LV:
A. Linear mode (liner) when one of the hard drives is exhausted, use another hard drive
B. Interleaved mode (triped) blocks the data to be stored, the first block is written to the first hard disk in the LV, the second block is written to the LV
The second hard drive in this way, storage in turn, can improve read and write performance, but note that at this time as long as a hard disk corruption, then the data will be lost, if you want to improve read and write performance or use RAID better.
LVM can also achieve dynamic capacity adjustment, when the space is not enough, can add capacity online, when the capacity is too large, can also reduce capacity. It also provides a snapshot feature that enables easy backup. The following is a detailed explanation of their implementation process.
Use of 3.LVM
In fact, the device used by LVM is placed in the/dev/mapper/directory.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/31/wKioL1Sr4jHDvPy6AAINCe-vbhA655.jpg "title=" Qq20150106212043.png "alt=" Wkiol1sr4jhdvpy6aaince-vbha655.jpg "/>
Pv,vg,lv They each have a set of orders.
Enter PV Press two times tab to see the command starting with PV
[Email protected]_basic scripts] #pv
Pvchange pvck pvcreate pvdisplay pvmove pvremove pvresize PVs Pvscan
The other vg,lv are the same.
[Email protected]_basic scripts] #vg
Vgcfgbackup vgck vgdisplay vgimport vgmknodes vgrename vgsplit
Vgcfgrestore vgconvert vgexport vgimportclone vgreduce VGS
Vgchange vgcreate vgextend vgmerge vgremove Vgscan
[Email protected]_basic scripts] #lv
Lvchange lvdisplay lvmchange lvmdump Lvmsar lvrename Lvscan
Lvconvert lvextend lvmconf Lvmetad lvreduce lvresize
Lvcreate LVM lvmdiskscan LVMSADC lvremove LVs
Here we'll show you the format of using Pvcreate,vgcreata
Create a physical volume
Pvcreate-initialize a disk or partition for usage by LVM initializes the disks or partitions using LVM
Pvcreate/dev/sd[a-z]|/dev/sd[a-z][1-9] ... You can follow multiple disks or partitions, note that the disk partition used here should adjust its system identifier to 8e, via the fdisk command
Create a volume group
Vgcreate-create a volume group create a volume group
vgcreate [-S pesize (PE size)] Volumegroupname (the name of the volume group) physicaldevicepath [Physicaldevicepath ...] (Specify the physical volume you just created)
-S,--physicalextentsize Physicalextentsize[bbsskkmmggttppee]
Sets the physical extent size on physical volumes of this volume group.
Creating a logical Volume
Lvcreate-create a logical volume in an existing volume group
Lvcreate-n Lvname-l #/dev/vgname
-N,--name logicalvolume{name| Path}
Sets the name for the new logical volume. Set this logical volume name
-L,--size Logicalvolumesize[bbsskkmmggttppee] Specifies the size of the logical volume, which can be k,m,g,t, etc.
Gives the size to allocate for the new logical volume. A size suffix of B for bytes, S for sectors as to bytes, K for kilobytes, M for megabytes, G for gigabytes, T for Terab Ytes, Pfor petabytes or E for exabytes is optional.
The Default unit is megabytes. Default units
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/58/31/wKioL1Sr6Dvwj5PFAASCDhS_8Kk040.jpg "title=" Qq20150106214636.png "alt=" Wkiol1sr6dvwj5pfaascdhs_8kk040.jpg "/>
Expansion of logical volumes requires expansion of physical volumes and expansion of logical volumes for online expansion
How to extend a logical volume:
A, first determine the target size of the expansion, and ensure that the corresponding volume group has enough free space available;
B, extended physical boundaries can only be extended in the current volume group
Lvextend-l #/dev/vgname/lvname
C. Extending logical boundaries
Resize2fs/dev/vgname/lvname
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/35/wKiom1Sr6Z7QJJl-AAOuIE1X-_I051.jpg "title=" Qq20150106215533.png "alt=" Wkiom1sr6z7qjjl-aaouie1x-_i051.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/58/31/wKioL1Sr68HAThjAAAfZWdIv35w648.jpg "title=" Qq20150106220118.png "alt=" Wkiol1sr68hathjaaafzwdiv35w648.jpg "/>
[Email protected]_basic test] #df-hp/mnt/test
Filesystem Size used Avail use% mounted on
/dev/mapper/vg_lvm-test 4.9G 6.6M 4.7G 1%/mnt/test expanded successfully
[Email protected]_basic test] #du-sh/mnt/test
2.6m/mnt/test expanded content for change
Reducing logical volumes requires that the logical volume be reduced before the physical volume is reduced
Reduction is dangerous!!!
Reduction requires offline
A, determine the reduced target size, and ensure that the corresponding target logical volume size has enough space to accommodate all the original data;
b, uninstall the file system first, and to perform mandatory detection
E2fsck-f
C. Reduce logical boundaries
RESIZE2FS DEVICE #
[Email protected]_basic ~] #resize2fs-help
RESIZE2FS 1.41.12 (17-may-2010)
USAGE:RESIZE2FS [-D debug_flags] [-f] [-f] [-m] [-p] [-p] device [new_size]
D. Reduce physical boundaries
Lvreduce-l #/dev/vg_xx/xxx
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/35/wKiom1Sr7OCik2TAAATzhcMJr5I332.jpg "title=" Qq20150106220905.png "alt=" Wkiom1sr7ocik2taaatzhcmjr5i332.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/58/35/wKiom1Sr7V-TXlZ2AAL8cinA82Q949.jpg "title=" Qq20150106221146.png "alt=" Wkiom1sr7v-txlz2aal8cina82q949.jpg "/>
To create a snapshot volume:
Lvcreate
-L #指定快照卷大小
-n Specifies the snapshot volume name
-s Specifies the snapshot volume
-P R Read-only
Note: The snapshot volume is for a logical volume, so it must be in the same volume group as the target logical volume, without specifying the volume group;
It only backs up and changes the data, and the data that is not changed in the filesystem remains in the original chunk, but the LVM snapshot
function will know where the data is placed, so the "snapshot" file system is "backed up" and the snapshot takes up
The capacity is also very small.
Since the snapshot area shares a lot of PE chunks with the original LV, the snapshot area and the snapshot's LV must be above the same VG.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/35/wKiom1Sr7qaSaBXoAAPrJx2AVDE307.jpg "title=" Qq20150106221647.png "alt=" Wkiom1sr7qasabxoaaprjx2avde307.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/58/35/wKiom1Sr7x2xkMfZAARsyFnJr1g754.jpg "title=" Qq20150106221902.png "alt=" Wkiom1sr7x2xkmfzaarsyfnjr1g754.jpg "/>
LV Snapshot status Active destination for test
LV Status Available
# open 1
LV Size 2.00 GiB
Current LE 64
Cow-table size 512.00 MiB
Cow-table LE 16
Allocated to Snapshot 0.07%
The snapshot area has been used for 0.07% because the original data has changed
Snapshot Chunk Size 4.00 KiB
Segments 1
Allocation inherit
Read ahead Sectors Auto
-Currently set to 256
Block Device 253:5
Recovering the original system using the snapshot area
The amount of system data recovered cannot be higher than the actual capacity of the snapshot area. Since the raw data will be
Move to the snapshot area, if the snapshot area is not large enough, if the original data is changed to the actual amount of data than the snapshot area,
Then of course the snapshot area can not accommodate, this time the snapshot function will be invalidated.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/58/35/wKiom1Sr78KT_XGvAAQqdHTeZiA499.jpg "title=" Qq20150106222145.png "alt=" Wkiom1sr78kt_xgvaaqqdhtezia499.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/35/wKiom1Sr8GfQt868AARWmU5i-4M248.jpg "title=" Qq20150106222434.png "alt=" Wkiom1sr8gfqt868aarwmu5i-4m248.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/58/35/wKiom1Sr8K2CvPi_AANCkZZKgrU182.jpg "title=" Qq20150106222548.png "alt=" Wkiom1sr8k2cvpi_aanckzzkgru182.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/35/wKiom1Sr8aCR9gIvAAYC5xOx3Hc755.jpg "title=" Qq20150106222953.png "alt=" Wkiom1sr8acr9givaayc5xox3hc755.jpg "/>
This article is from the "Happy is good" blog, please be sure to keep this source http://wdllife.blog.51cto.com/6615958/1599979
8.Linux of LVM usage