Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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 label type: dos
Disk identifier: 0x141c2b15
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 8e Linux LVM
/dev/sdb2 10487808 20973567 5242880 8e Linux LVM
/dev/sdb3 20973568 31459327 5242880 8e Linux LVM
/dev/sdb4 31459328 41943039 5241856 8e Linux LVM
五、创建PV
命令介绍:
#pvs 查看pv状态
# pvcreate 将物理分区新建成为PV
# pvscan 查询目前系统里面任何具有PV的磁盘
# pvdisplay 显示出目前系统上面的PV状态
# pvremove 将PV属性移除,让该分区不具有PV属性
1、将/dev/sdb1 - /dev/sdb4新建成为PV格式
[iyunv@bash test]# pvcreate /dev/sdb{1..4}
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdb3" successfully created
Physical volume "/dev/sdb4" successfully created
[iyunv@bash test]# vgdisplay
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 3
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 3
Act PV 3
VG Size 14.99 GiB
PE Size 15.00 MiB
Total PE 1023
Alloc PE / Size 0 / 0
Free PE / Size 1023 / 14.99 GiB
VG UUID CT1KmC-upAS-0r1t-5KQV-MR7z-2jfj-ufOc8Q
4、新增PV给myvg
[iyunv@bash test]# vgextend "myvg" /dev/sdb4
Volume group "myvg" successfully extended
5、显示出目前系统上面的VG状态
[iyunv@bash test]# vgdisplay
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 4
Act PV 4
VG Size 19.98 GiB
PE Size 15.00 MiB
Total PE 1364
Alloc PE / Size 0 / 0
Free PE / Size 1364 / 19.98 GiB
VG UUID CT1KmC-upAS-0r1t-5KQV-MR7z-2jfj-ufOc8Q
[iyunv@bash test]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID crtMed-duu9-Nrfc-tCJR-wzby-wFP0-v1P9pT
LV Write Access read/write
LV Creation host, time bash, 2017-02-07 17:01:23 +0800
LV Status available
# open 0
LV Size 19.98 GiB
Current LE 1364
Segments 4
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[iyunv@bash test]# ll /dev/myvg/mylv
lrwxrwxrwx 1 root root 7 Feb 7 17:01 /dev/myvg/mylv -> ../dm-0
[iyunv@bash test]# ll /dev/dm-0
brw-rw---- 1 root disk 253, 0 Feb 7 17:01 /dev/dm-0
[iyunv@bash lvm]# vgextend myvg /dev/sdc
Volume group "myvg" successfully extended
[iyunv@bash lvm]# vgdisplay #查看
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 5
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 5
Act PV 5
VG Size 39.98 GiB
PE Size 15.00 MiB
Total PE 2729
Alloc PE / Size 1364 / 19.98 GiB
Free PE / Size 1365 / 20.00 GiB
VG UUID CT1KmC-upAS-0r1t-5KQV-MR7z-2jfj-ufOc8Q
4.增加LV容量
[iyunv@bash lvm]# lvresize -l +200 /dev/myvg/mylv #无单位表示增减PE个数,
+表示增加,无+号代表增加到
Size of logical volume myvg/mylv changed from 19.98 GiB (1364 extents) to 22.91 GiB (1564 extents).
Logical volume mylv successfully resized.
[iyunv@bash lvm]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID crtMed-duu9-Nrfc-tCJR-wzby-wFP0-v1P9pT
LV Write Access read/write
LV Creation host, time bash, 2017-02-07 17:01:23 +0800
LV Status available
# open 1
LV Size 22.91 GiB
Current LE 1564
Segments 5
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[iyunv@bash lvm]# resize2fs /dev/myvg/mylv
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/myvg/mylv is mounted on /mnt/lvm; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 3
The filesystem on /dev/myvg/mylv is now 6005760 blocks long.
[iyunv@bash ~]# resize2fs /dev/myvg/mylv 5000M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/myvg/mylv to 1280000 (4k) blocks.
The filesystem on /dev/myvg/mylv is now 1280000 blocks long.
[iyunv@bash ~]# lvresize -L 5000M /dev/myvg/mylv #降低lv到5000M,-号表示减少多少
Rounding size to boundary between physical extents: 4.89 GiB
WARNING: Reducing active and open logical volume to 4.89 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv? [y/n]: y
Size of logical volume myvg/mylv changed from 22.91 GiB (1564 extents) to 4.89 GiB (334 extents).
Logical volume mylv successfully resized.
6、查看容量大小
[iyunv@bash ~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID crtMed-duu9-Nrfc-tCJR-wzby-wFP0-v1P9pT
LV Write Access read/write
LV Creation host, time bash, 2017-02-07 17:01:23 +0800
LV Status available
# open 1
LV Size 4.89 GiB
Current LE 334
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[iyunv@bash snapshot]# lvdisplay /dev/myvg/lvsnap
--- Logical volume ---
LV Path /dev/myvg/lvsnap
LV Name lvsnap
VG Name myvg
LV UUID CcICLA-SV2u-ojuv-ZWnX-3JBg-h1Bg-NJNieO
LV Write Access read/write
LV Creation host, time bash, 2017-02-08 01:36:53 +0800
LV snapshot status active destination for mylv
LV Status available
# open 1
LV Size 3.00 GiB
Current LE 768
COW-table size 80.00 MiB
COW-table LE 20
Allocated to snapshot 0.00% #快照卷为空
Snapshot chunk size 4.00 KiB
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3