1、準備
在虛拟機中新增1-2塊硬碟
2、建立邏輯卷
1)檢視新增的硬碟
fdisk -l 檢視到有新增的兩塊硬碟
[root@test ~]# fdisk -l
***
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track,1305 cylinders
Units = cylinders of 16065 *512 = 8225280 bytes
Sector size (logical/physical):512 bytes / 512 bytes
I/O size (minimum/optimal): 512bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdc: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track,1958 cylinders
2)整塊硬碟做邏輯卷
建立并檢視PV
[root@test ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb"successfully created
[root@test ~]# pvscan
PV /dev/sdb lvm2 [10.00 GiB]
Total: 1 [10.00 GiB] / in use: 0 [0 ] / in no VG: 1 [10.00 GiB]
[root@test ~]# pvdisplay
"/dev/sdb" is a new physical volumeof "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID AZDLi9-EJfs-rfNr-aDK3-uhis-aKej-li1bWQ
建立并檢視VG
[root@test ~]# vgcreate -s 16M testvg001 /dev/sdb
Volume group "testvg001"successfully created
[root@test ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "testvg001"using metadata type lvm2
[root@test ~]# vgdisplay
--- Volume group ---
VG Name testvg001
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VGSize 9.98 GiB
PE Size 16.00 MiB
Total PE 639
Alloc PE / Size 0 / 0
Free PE / Size 639 / 9.98 GiB
VG UUID acZzA4-QK2R-wC2w-W47W-TSzo-7c77-zVOOZN
建立并檢視LV
[root@test ~]# lvcreate -l 639 -n testlv001 testvg001
Logical volume "testlv001" created.
[root@test ~]# lvscan
ACTIVE '/dev/testvg001/testlv001' [9.98GiB] inherit
[root@test ~]# lvdisplay
--- Logical volume ---
LV Path /dev/testvg001/testlv001
LV Name testlv001
VG Name testvg001
LV UUID WT7Evl-VQ2O-fWB3-k2wU-k5JF-D2Cb-HOCAQZ
LV Write Access read/write
LV Creation host, time test, 2017-08-0123:00:26 +0800
LV Status available
# open 0
LV Size 9.98 GiB
Current LE 639
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
3)測試挂載讀寫
格式化、挂載與檢視 LV
[root@test ~]# mkfs.ext3/dev/testvg001/testlv001
[root@test ~]# mkdir/mnt/test_lvm
[root@test ~]# mount/dev/testvg001/testlv001 /mnt/test_lvm/
[root@test~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 18G 2.4G 15G 15% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/sda1 190M 33M 147M 19% /boot
/dev/sda2 9.8G 23M 9.2G 1% /home
/dev/mapper/testvg001-testlv001
9.9G 151M 9.2G 2% /mnt/test_lvm
[root@test ~]# echo test1234> /mnt/test_lvm/test001
[root@test ~]# cat/mnt/test_lvm/test001
test1234
3、擴充LV
1)硬碟分區
fdisk /dev/sdc
[root@test ~]# fdisk –l
Disk /dev/sdc: 16.1 GB,16106127360 bytes
Units = cylinders of 16065 * 512= 8225280 bytes
Disk identifier: 0x000b271d
Device Boot Start End Blocks Id System
/dev/sdc1 1 654 5253223+ 83 Linux
/dev/sdc2 655 1308 5253255 83 Linux
/dev/sdc3 1309 1958 5221125 83 Linux
2)建立PV
[root@test ~]# pvcreate/dev/sdc{1,2,3}
Physical volume "/dev/sdc1"successfully created
Physical volume "/dev/sdc2"successfully created
Physical volume "/dev/sdc3"successfully created
PV /dev/sdb VG testvg001 lvm2 [9.98 GiB/ 0 free]
PV /dev/sdc1 lvm2 [5.01 GiB]
PV /dev/sdc2 lvm2 [5.01 GiB]
PV /dev/sdc3 lvm2 [4.98 GiB]
Total: 4 [24.98 GiB] / in use: 1 [9.98 GiB] /in no VG: 3 [15.00 GiB]
System ID
Metadata Sequence No 2
Cur LV 1
Open LV 1
VG Size 9.98 GiB
Alloc PE / Size 639 / 9.98 GiB
Free PE / Size 0 / 0
VG UUID acZzA4-QK2R-wC2w-W47W-TSzo-7c77-zVOOZN
3)擴充VG
[root@test ~]# vgextendtestvg001 /dev/sdc1
Volume group "testvg001"successfully extended
Metadata Areas 2
Metadata Sequence No 3
Cur PV 2
Act PV 2
VG Size 14.98 GiB
Total PE 959
Free PE / Size 320 / 5.00 GiB
擴充LV
[root@test ~]# lvresize -l +320/dev/testvg001/testlv001
Size of logical volume testvg001/testlv001changed from 9.98 GiB (639 extents) to 14.98 GiB (959 extents).
Logical volume testlv001 successfullyresized.
LV Name testlv001
LV Size 14.98 GiB
Current LE 959
Segments 2
附:
VG操作相關指令:
vgreate:建立VG
vgscan:檢視系統VG
vgdisplay:顯示系統VG狀态
vgextend:在VG上增加額外的PV
vgreduce:在VG内删除PV
vgchange:設定VG是否啟動
vgremove:移除一個VG