LVM創建與擴容


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

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

 

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

255 heads, 63 sectors/track,1958 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: 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

[root@test ~]# pvscan

  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]

 

[root@test ~]# vgdisplay

  --- Volume group ---

  VG Name               testvg001

  System ID             

  Format                lvm2

  Metadata Areas        1

  Metadata Sequence No  2

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                1

  Open LV               1

  Max PV                0

  Cur PV                1

  Act PV                1

  VG Size               9.98 GiB

  PE Size               16.00 MiB

  Total PE              639

  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

[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        2

  Metadata Sequence No  3

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                1

  Open LV               1

  Max PV                0

  Cur PV                2

  Act PV                2

  VG Size               14.98 GiB

  PE Size               16.00 MiB

  Total PE              959

  Alloc PE / Size       639 / 9.98 GiB

  Free PE / Size       320 / 5.00 GiB

  VG UUID              acZzA4-QK2R-wC2w-W47W-TSzo-7c77-zVOOZN

 

擴展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.

[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                14.98 GiB

  Current LE             959

  Segments               2

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:0

 

附:

VG操作相關命令:

vgreate:新建VG

vgscan:查看系統VG

vgdisplay:顯示系統VG狀態

vgextend:在VG上增加額外的PV

vgreduce:在VG內刪除PV

vgchange:設置VG是否啓動

vgremove:移除一個VG

 

 

 

 

 

 

 

 

 

 

 

 

 

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章