Linux系统中物理劵增加、删除;卷组的扩容、缩容;逻辑卷的增加与删除

1、准备三块测试硬盘

 

 

 

[root@PC1linuxprobe dev]# pwd
/dev
[root@PC1linuxprobe dev]# find sd*
sda
sda1
sda2
sdb
sdc
sdd

 

2、将/dev/sdb和/dev/sdc格式化为物理劵

[root@PC1linuxprobe dev]# pvcreate /dev/sdb /dev/sdc
  Physical volume "/dev/sdb" successfully created
  Physical volume "/dev/sdc" successfully created
[root@PC1linuxprobe dev]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               rhel
  PV Size               19.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4994
  Free PE               0
  Allocated PE          4994
  PV UUID               yjrVt7-2jdY-K7hl-x7yf-p5zQ-EeSk-TjDEBo
   
  "/dev/sdb" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               oz6M4H-dXWv-Oig2-WBiL-ZO9y-CwvW-pcpPDw
   
  "/dev/sdc" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               HFL1Xz-r0jh-EWw4-79Ny-SeCJ-cyLf-jBTtBq
   

 

3、删除/dev/sdc物理劵

[root@PC1linuxprobe dev]# pvremove /dev/sdc
  Labels on physical volume "/dev/sdc" successfully wiped
[root@PC1linuxprobe dev]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               rhel
  PV Size               19.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4994
  Free PE               0
  Allocated PE          4994
  PV UUID               yjrVt7-2jdY-K7hl-x7yf-p5zQ-EeSk-TjDEBo
   
  "/dev/sdb" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               oz6M4H-dXWv-Oig2-WBiL-ZO9y-CwvW-pcpPDw
   

 

4、将/dev/sdc和/dev/sdd添加为物理劵

[root@PC1linuxprobe dev]# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created
[root@PC1linuxprobe dev]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               rhel
  PV Size               19.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4994
  Free PE               0
  Allocated PE          4994
  PV UUID               yjrVt7-2jdY-K7hl-x7yf-p5zQ-EeSk-TjDEBo
   
  "/dev/sdb" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               oz6M4H-dXWv-Oig2-WBiL-ZO9y-CwvW-pcpPDw
   
  "/dev/sdc" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               0ys3mD-KMOU-6d7y-5fyc-Z5Ls-IIKX-3N9OTc
   
[root@PC1linuxprobe dev]# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created
[root@PC1linuxprobe dev]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               rhel
  PV Size               19.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4994
  Free PE               0
  Allocated PE          4994
  PV UUID               yjrVt7-2jdY-K7hl-x7yf-p5zQ-EeSk-TjDEBo
   
  "/dev/sdb" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               oz6M4H-dXWv-Oig2-WBiL-ZO9y-CwvW-pcpPDw
   
  "/dev/sdc" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               0ys3mD-KMOU-6d7y-5fyc-Z5Ls-IIKX-3N9OTc
   
  "/dev/sdd" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdd
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               Z3R2Ek-xwNp-nRiC-47jq-fCa5-jxO6-Wf0LWS

查看此时的物理劵:

[root@PC1linuxprobe dev]# pvscan
  PV /dev/sda2   VG rhel   lvm2 [19.51 GiB / 0    free]
  PV /dev/sdb    VG vg1    lvm2 [20.00 GiB / 19.41 GiB free]
  PV /dev/sdd    VG vg1    lvm2 [20.00 GiB / 20.00 GiB free]
  PV /dev/sdc    VG vg1    lvm2 [20.00 GiB / 20.00 GiB free]

 

5、将/dev/sdb、/dev/sdc、/dev/sdd创建为卷组vg1

[root@PC1linuxprobe dev]# vgcreate vg1 /dev/sdb /dev/sdc /dev/sdd
Volume group "vg1" successfully created
[root@PC1linuxprobe dev]# vgdisplay 
  --- Volume group ---
  VG Name               rhel
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               19.51 GiB
  PE Size               4.00 MiB
  Total PE              4994
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               UWd4dl-0vSA-zern-l7on-XLj0-e3cR-AHmckC
   
  --- Volume group ---
  VG Name               vg1
  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               59.99 GiB
  PE Size               4.00 MiB
  Total PE              15357
  Alloc PE / Size       0 / 0   
  Free  PE / Size       15357 / 59.99 GiB
  VG UUID               jZeTak-WfBZ-f0K6-57wM-cT5y-BxYJ-8AzNvO

 

6、从卷组vg1中删除/dev/sdb

[root@PC1linuxprobe dev]# vgreduce vg1 /dev/sdc
  Removed "/dev/sdc" from volume group "vg1"
[root@PC1linuxprobe dev]# vgdisplay 
  --- Volume group ---
  VG Name               rhel
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               19.51 GiB
  PE Size               4.00 MiB
  Total PE              4994
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               UWd4dl-0vSA-zern-l7on-XLj0-e3cR-AHmckC
   
  --- Volume group ---
  VG Name               vg1
  System ID             
  Format                lvm2
  Metadata Areas        2
  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                2
  Act PV                2
  VG Size               39.99 GiB
  PE Size               4.00 MiB
  Total PE              10238
  Alloc PE / Size       0 / 0   
  Free  PE / Size       10238 / 39.99 GiB
  VG UUID               Bjeykx-Lulw-rdC5-s1MV-9MSE-5G1y-hbYaHl
   

 

7、将/dev/sdc增加到卷组vg1

[root@PC1linuxprobe dev]# vgextend vg1 /dev/sdc
  Volume group "vg1" successfully extended
[root@PC1linuxprobe dev]# vgdisplay 
  --- Volume group ---
  VG Name               rhel
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               19.51 GiB
  PE Size               4.00 MiB
  Total PE              4994
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               UWd4dl-0vSA-zern-l7on-XLj0-e3cR-AHmckC
   
  --- Volume group ---
  VG Name               vg1
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  3
  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               59.99 GiB
  PE Size               4.00 MiB
  Total PE              15357
  Alloc PE / Size       0 / 0   
  Free  PE / Size       15357 / 59.99 GiB
  VG UUID               Bjeykx-Lulw-rdC5-s1MV-9MSE-5G1y-hbYaHl
   

查看此时的卷组:

[root@PC1linuxprobe dev]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "rhel" using metadata type lvm2
  Found volume group "vg1" using metadata type lvm2

 

8、从卷组vg1中切割出逻辑卷lv1、lv2、lv3

[root@PC1linuxprobe dev]# lvcreate -n lv1 -L 100M vg1 
Logical volume "lv1" created
[root@PC1linuxprobe dev]# lvdisplay 
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID 1vqFco-Lxys-ZwR7-1M05-4E22-QQ1G-txfgUg
LV Write Access read/write
LV Creation host, time localhost, 2020-11-05 23:23:01 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID 9I3kQe-7tJ4-H61H-ppmA-admB-WKqD-20F6oa
LV Write Access read/write
LV Creation host, time localhost, 2020-11-05 23:23:01 +0800
LV Status available
# open 1
LV Size 17.51 GiB
Current LE 4482
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Path /dev/vg1/lv1
LV Name lv1
VG Name vg1
LV UUID 9EoISr-VUde-Ow95-MVhd-b0ka-ba5e-C7NMfF
LV Write Access read/write
LV Creation host, time PC1linuxprobe, 2020-11-08 16:40:22 +0800
LV Status available
# open 0
LV Size 100.00 MiB
Current LE 25
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2

[root@PC1linuxprobe dev]# lvcreate -n lv2 -L 200M vg1 
  Logical volume "lv2" created
[root@PC1linuxprobe dev]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/rhel/swap
  LV Name                swap
  VG Name                rhel
  LV UUID                1vqFco-Lxys-ZwR7-1M05-4E22-QQ1G-txfgUg
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-11-05 23:23:01 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/rhel/root
  LV Name                root
  VG Name                rhel
  LV UUID                9I3kQe-7tJ4-H61H-ppmA-admB-WKqD-20F6oa
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-11-05 23:23:01 +0800
  LV Status              available
  # open                 1
  LV Size                17.51 GiB
  Current LE             4482
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                9EoISr-VUde-Ow95-MVhd-b0ka-ba5e-C7NMfF
  LV Write Access        read/write
  LV Creation host, time PC1linuxprobe, 2020-11-08 16:40:22 +0800
  LV Status              available
  # open                 0
  LV Size                100.00 MiB
  Current LE             25
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/vg1/lv2
  LV Name                lv2
  VG Name                vg1
  LV UUID                jOwGw7-7PUW-e6GC-cIpG-WGm2-8gc7-Bf3t92
  LV Write Access        read/write
  LV Creation host, time PC1linuxprobe, 2020-11-08 16:41:05 +0800
  LV Status              available
  # open                 0
  LV Size                200.00 MiB
  Current LE             50
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3
   
[root@PC1linuxprobe dev]# lvcreate -n lv3 -L 300M vg1 
  Logical volume "lv3" created
[root@PC1linuxprobe dev]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/rhel/swap
  LV Name                swap
  VG Name                rhel
  LV UUID                1vqFco-Lxys-ZwR7-1M05-4E22-QQ1G-txfgUg
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-11-05 23:23:01 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/rhel/root
  LV Name                root
  VG Name                rhel
  LV UUID                9I3kQe-7tJ4-H61H-ppmA-admB-WKqD-20F6oa
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-11-05 23:23:01 +0800
  LV Status              available
  # open                 1
  LV Size                17.51 GiB
  Current LE             4482
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                9EoISr-VUde-Ow95-MVhd-b0ka-ba5e-C7NMfF
  LV Write Access        read/write
  LV Creation host, time PC1linuxprobe, 2020-11-08 16:40:22 +0800
  LV Status              available
  # open                 0
  LV Size                100.00 MiB
  Current LE             25
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/vg1/lv2
  LV Name                lv2
  VG Name                vg1
  LV UUID                jOwGw7-7PUW-e6GC-cIpG-WGm2-8gc7-Bf3t92
  LV Write Access        read/write
  LV Creation host, time PC1linuxprobe, 2020-11-08 16:41:05 +0800
  LV Status              available
  # open                 0
  LV Size                200.00 MiB
  Current LE             50
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3
   
  --- Logical volume ---
  LV Path                /dev/vg1/lv3
  LV Name                lv3
  VG Name                vg1
  LV UUID                10tpyT-5z2e-to8J-6Y9U-gOED-Ogz7-7lTJ8l
  LV Write Access        read/write
  LV Creation host, time PC1linuxprobe, 2020-11-08 16:41:17 +0800
  LV Status              available
  # open                 0
  LV Size                300.00 MiB
  Current LE             75
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:4

查询此时的逻辑卷

[root@PC1linuxprobe dev]# lvscan 
  ACTIVE            '/dev/rhel/swap' [2.00 GiB] inherit
  ACTIVE            '/dev/rhel/root' [17.51 GiB] inherit
  ACTIVE            '/dev/vg1/lv1' [100.00 MiB] inherit
  ACTIVE            '/dev/vg1/lv2' [200.00 MiB] inherit
  ACTIVE            '/dev/vg1/lv3' [300.00 MiB] inherit

 

9、删除逻辑卷lv3

[root@PC1linuxprobe dev]# lvremove /dev/vg1/lv3
Do you really want to remove active logical volume lv3? [y/n]: y
  Logical volume "lv3" successfully removed
[root@PC1linuxprobe dev]# lvscan 
  ACTIVE            '/dev/rhel/swap' [2.00 GiB] inherit
  ACTIVE            '/dev/rhel/root' [17.51 GiB] inherit
  ACTIVE            '/dev/vg1/lv1' [100.00 MiB] inherit
  ACTIVE            '/dev/vg1/lv2' [200.00 MiB] inherit

 

总结:

  • 增加物理劵,pvcreate /dev/disk*
  • 删除物理劵,pvremove /dev/disk*

 

  • 卷组扩容,vgextend vg1 /dev/disk*
  • 卷组缩容,vgreduce vg1 /dev/disk*

 

  • 增加逻辑卷,lvcreate -n lvname -L xxM vgname
  • 删除逻辑卷,lvremove /dev/vgname/lvname

 

posted @ 2020-11-08 17:01  小鲨鱼2018  阅读(1103)  评论(0编辑  收藏  举报