Get familiar with the commonly used LVM expansion

Physical Volume (PV, Physical Volume)
Physical volume refers to a disk, a disk partition or a device that has the same function as a disk partition (such as RAID). It is the basic storage logical block of LVM, but it is the same as the basic physical storage medium (such as Partitions, disks, etc.), but it contains management parameters related to LVM. The current LVM allows you to save 0 to 2 metadata copies of this physical volume on each physical volume . The default is 1, which is saved at the beginning of the device. When it is 2, the second backup is saved at the end of the device.

Volume Group (VG, Volume Group)
LVM volume group is similar to the physical hard disk in non-LVM system, which is composed of physical volumes. One or more "LVM partitions" (logical volumes) can be created on the volume group. The LVM volume group is composed of one or more physical volumes.

Logical Volume (LV, Logical Volume)
The logical volume of LVM is similar to the hard disk partition in the non-LVM system, and a file system (such as /home or /usr, etc.) can be established on the logical volume.
*Linear Logical Volumes (Linear Volumes)
A linear logical volume aggregates multiple physical volumes into one logical volume. For example, if you have two 60GB hard drives, you can generate 120GB logical volumes.
*Striped Logical Volumes Volumes)
When you write data to this logical volume, the file system can place the data in multiple physical volumes. For a large number of connected read and write operations, it can improve the efficiency of data I/O.
*Mirrored Logical Volumes (Mirrored Logical Volumes)
images store consistent data on different devices. Data is written to the original device and the image device at the same time. It provides fault tolerance between devices.
*Snapshot Volumes (Snapshot Volumes)
snapshot volume provides a device virtual image at a specific moment, when the snapshot starts, he copies a copy of the changes to the current data area, because he prioritizes these changes, so he can reconstruct the current device status.
Create the logical volume of the image.
#lvcreate -L 52M -m1 -n test lvm_test /dev/sdb1 /dev/sdc1 /dev/sdb2
Logical volume “test” created
-m1 means that only a single image is generated, and the images are placed in /dev/sdb1 and /dev/ On sdc1, the image log is placed on /dev/sdb2.

Create a snapshot volume.
#lvcreate --size 10 --snapshot --name snaptest /dev/lvm_test/test
PE (physical extent)
Each physical volume is divided into a basic unit called PE (Physical Extents), a PE with a unique number can be The smallest unit of LVM addressing. The size of the PE is configurable, and the default is 4MB.
LE (logical extent)
logical volumes are also divided into basic addressable units called LE (Logical Extents). In the same volume group, the size of LE and PE are the same, and there is a one-to-one correspondence.

PV->VG->LV-> File system use (mounting to a directory)
steps:
1. First check
#pvdisplay
#pvs
#lvs
#lvs --segments Check the logical volume type
#vgs
scan block device-can be checked by lvmdiskscan See that those devices become physical volumes.
#lvmdiskscan
scans the disk to generate cache files
#vgscan

2. Partition the new disk /dev/sdb
#parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted!
Type'help ' to view a list of commands. (parted) mklabel
New disk label type? gpt
(parted) mkpart
Partition name? []?
File system type? [ext2]? xfs
Start? 1
End? 10G
(parted) q
Information: You may need to update /etc/fstab.
Create physical volume pvcreate /dev/sdb1
Create a volume group and add physical volumes to it vgcreate data /dev/sdb1 (data is the volume group name)
Create a logical volume group and allocate the size lvcreate -l +100%FREE -n lvdata data

  ***可以创建条块化的逻辑卷(必须大于两个物理卷)***
  #lvcreate -l +100%FREE -i2 -n lvdata data
   Using default stripesize 64.00 KB
	Rounding size (125 extents) up to stripe boundary size (126 extents)
	Logical volume “data” created
	-i2指此逻辑卷在两个物理卷中条块化存放数据,默认一块大小为64KB.
	
	[root@centos7 ~]# lvcreate --help</p> <p> lvcreate: Create a logical volume(创建逻辑卷)
	lvcreate
	[-A|--autobackup {y|n}](自动备份)
	[-a|--activate [a|e|l]{y|n}]
	[--addtag Tag](增加标签)
	[--alloc AllocationPolicy](分配策略)
	[--cachemode CacheMode](Cache模式)
	[-C|--contiguous {y|n}]
	[-d|--debug]
	[-h|-?|--help]
	[--ignoremonitoring](忽略监控)
	[--monitor {y|n}](监控)
	[-i|--stripes Stripes [-I|--stripesize StripeSize]]
	[-k|--setactivationskip {y|n}]
	[-K|--ignoreactivationskip]
	{-l|--extents LogicalExtentsNumber[%{VG|PVS|FREE}] |(逻辑扩展数)
	-L|--size LogicalVolumeSize[bBsSkKmMgGtTpPeE]}(逻辑卷大小)
	[-M|--persistent {y|n}] [--major major] [--minor minor]
	[-m|--mirrors Mirrors [--nosync] [{--mirrorlog {disk|core|mirrored}|--corelog}]](镜像)
	[-n|--name LogicalVolumeName](逻辑卷名字)
	[--noudevsync]
	[-p|--permission {r|rw}]
	[--[raid]minrecoveryrate Rate]
	[--[raid]maxrecoveryrate Rate]
	[-r|--readahead ReadAheadSectors|auto|none](读取头扇区)
	[-R|--regionsize MirrorLogRegionSize](镜像逻辑区域尺寸)
	[-T|--thin [-c|--chunksize ChunkSize](块大小)
	[--discards {ignore|nopassdown|passdown}]
	[--poolmetadatasize MetadataSize[bBsSkKmMgG]]]
	[--poolmetadataspare {y|n}]
	[--thinpool ThinPoolLogicalVolume{Name|Path}] (精简池逻辑卷)
	[-t|--test]
	[--type VolumeType](卷类型)
	[-v|--verbose]
	[-W|--wipesignatures {y|n}]
	[-Z|--zero {y|n}]
	[--version]
	VolumeGroupName [PhysicalVolumePath...]

Format mkfs.xfs /dev/mappper/data-lvdata,
boot and mount the new hard disk vi /etc/fstab
mount mount -a (build the data directory mkdir /data first)
view df -lh
unmount the mount point umount /dev/mapper/ data-lvdata

3. Expansion The
disk /dev/sdb is only divided into 10 Gs. . There is still no allocation of 10G. . So continue to partition
parted /dev/sdb and
print the partition information table, you can see that there are two partitions.
Create a physical volume pvcreat /dev/sdb2 to
view the volume group information to be expanded vgdisplay It can be seen that the expandable size is 0 to
extend the physical volume to the volume group #vgextend data /dev/sdb2 (where'data' is the volume group name)
View the volume again Group information vgdisplay The expandable space becomes 10G.
Generally, it is best to unmount the file system, adjust the size, and then load
. Extend the free space in the volume group to /data #lvextend -l +100%FREE /dev/mapper/data-lvdata
Refreshing the file system is the expansion effect #xfs_growfs /dev/mapper/data-lvdata (xfs file system uses this command)
                #resize2fs /dev/mapper/data-lvdata (ext4 file system uses this command)
                #ext2online /dev/lvm_test/test (Use this command for ext2 file system)
View the result: df -lh expansion is successful

以下为建立条带型卷:
#apt-get install lvm2 xfsprogs bwm-ng bonnie++
#pvdisplay
#pvcreate /dev/xvd[bcdefghi]
Physical volume “/dev/xvdb” successfully created
Physical volume “/dev/xvdc” successfully created
Physical volume “/dev/xvdd” successfully created
Physical volume “/dev/xvde” successfully created
Physical volume “/dev/xvdf” successfully created
Physical volume “/dev/xvdg” successfully created
Physical volume “/dev/xvdh” successfully created
Physical volume “/dev/xvdi” successfully created
#vgcreate vol_e27 /dev/xvd[bcdefghi]
Volume group “vol_e27” successfully created
#vgdisplay
— Volume group —
VG Name vol_e27
System ID
Format lvm2
Metadata Areas 8
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 8
Act PV 8
VG Size 5.82 TiB
PE Size 4.00 MiB
Total PE 1526184
Alloc PE / Size 0 / 0
Free PE / Size 1526184 / 5.82 TiB
VG UUID yn3lAL-HqxB-ZpiH-o4Zt-Z4EQ-8Wxx-M9kkaw
#lvcreate --extents 100%FREE --name root vol_e27
Logical volume “root” created
#lvdisplay
— Logical volume —
LV Path /dev/vol_e27/root
LV Name root
VG Name vol_e27
LV UUID 5F3dSX-CbHC-j3m6-oY1c-bIN8-6mJC-RrZO3h
LV Write Access read/write
LV Creation host, time ip-10-237-150-222, 2014-06-09 03:49:45 +0000
LV Status available
#open 0
LV Size 5.82 TiB
Current LE 1526184
Segments 8
Allocation inherit
Read ahead sectors auto

  • currently set to 256
    Block device 252:0

#fdisk -l /dev/mapper/vol_e27-root
Disk /dev/mapper/vol_e27-root: 6401.3 GB, 6401279655936 bytes
255 heads, 63 sectors/track, 778244 cylinders, total 12502499328 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vol_e27-root doesn’t contain a valid partition table
#mkfs.xfs /dev/mapper/vol_e27-root
meta-data=/dev/mapper/vol_e27-root isize=256 agcount=6, agsize=268435455 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=1562812416, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal log bsize=4096 blocks=521728, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

#mkdir /vol_e27
#mount /dev/mapper/vol_e27-root /vol_e27/

#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.8G 774M 6.6G 11% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 121G 12K 121G 1% /dev
tmpfs 25G 360K 25G 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 121G 0 121G 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/mapper/vol_e27-root 5.9T 33M 5.9T 1% /vol_e27
#bwm-ng -i disk -I xvdb,xvdc,xvdd,xvde,xvdf,xvdg,xvdh,xvdi
bwm-ng v0.6 (probing every 0.500s), press ‘h’ for help
input: disk IO type: rate
| iface Rx Tx Total

         xvdb:           0.00 KB/s       449924.16 KB/s       449924.16 KB/s
         xvdc:           0.00 KB/s            0.00 KB/s            0.00 KB/s
         xvdd:           0.00 KB/s            0.00 KB/s            0.00 KB/s
         xvde:           0.00 KB/s            0.00 KB/s            0.00 KB/s
         xvdf:           0.00 KB/s            0.00 KB/s            0.00 KB/s
         xvdg:           0.00 KB/s            0.00 KB/s            0.00 KB/s
         xvdh:           0.00 KB/s            0.00 KB/s            0.00 KB/s
         xvdi:           0.00 KB/s            0.00 KB/s            0.00 KB/s

        total:           0.00 KB/s       449924.16 KB/s       449924.16 KB/s

#bonnie++ -n 0 -u 0 -r free -m | grep 'Mem:' | awk '{print $2}' -s $(echo “scale=0;free -m | grep 'Mem:' | awk '{print $2}'*2” | bc -l) -f -b -d /vol_e27/
Using uid:0, gid:0.
Writing intelligently…done
Rewriting…done
Reading intelligently…done
start 'em…done…done…done…done…done…
Version 1.97 ------Sequential Output------ --Sequential Input- --Random-
Concurrency 1 -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks–
Machine Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP /sec %CP
ip-10-237-1 491996M 455205 38 239391 22 510353 25 322.0 103
Latency 12847us 29639us 10133us 3411us

1.97,1.97,ip-10-237-150-222,1,1402297390,491996M,455205,38,239391,22,510353,25,322.0,103,
,12847us,29639us,10133us,3411us,
#umount /vol_e27
#lvdisplay
— Logical volume —
LV Path /dev/vol_e27/root
LV Name root
VG Name vol_e27
LV UUID 5F3dSX-CbHC-j3m6-oY1c-bIN8-6mJC-RrZO3h
LV Write Access read/write
LV Creation host, time ip-10-237-150-222, 2014-06-09 03:49:45 +0000
LV Status available

open 0

LV Size 5.82 TiB
Current LE 1526184
Segments 8
Allocation inherit
Read ahead sectors auto

  • currently set to 256
    Block device 252:0

Guess you like

Origin blog.csdn.net/seaship/article/details/114023579