参考https://blog.csdn.net/wk022/article/details/50543922

新增磁盘/dev/sdb

fdisk /dev/sdb  分两个分区  (n p 1 /n /n  n e 2 /n /n w)

[root@localhost ~]# fdisk -l /dev/sdb

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0xf648972d

   设备 Boot      Start         End      Blocks   Id  System /dev/sdb1            2048    20973567    10485760   83  Linux /dev/sdb2        20973568    41943039    10484736    5  Extended

创建物理卷

/dev/sdb1

 [root@localhost ~]# pvcreate /dev/sdb1

 Physical volume “/dev/sdb1” successfully created.

[root@localhost ~]# pvdisplay /dev/sdb1  

— Physical volume —   PV Name               /dev/sdb1   VG Name               vg01   PV Size               10.00 GiB / not usable 16.00 MiB   Allocatable           yes   PE Size               16.00 MiB   Total PE              639   Free PE               319   Allocated PE          320   PV UUID               rZAmXt-S4E4-3S1s-dzs9-Xzda-PbJN-ZQ0EsY

创建卷组

vg01 [root@localhost ~]# vgcreate -s 16M vg01 /dev/sdb1  

Volume group “vg01” successfully created

[root@localhost ~]# vgdisplay vg01

  — Volume group —   VG Name               vg01   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               0   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       320 / 5.00 GiB   Free  PE / Size       319 / 4.98 GiB   VG UUID               kCljZC-WILb-v3uX-jEkf-0Wbt-9q1o-UqXJkw

创建逻辑卷

lv01 [root@localhost ~]# lvcreate -L 5G -n lv01 vg01  

Logical volume “lv01” created.

[root@localhost ~]# lvdisplay /dev/vg01/lv01  

— Logical volume —   LV Path                /dev/vg01/lv01   LV Name                lv01   VG Name                vg01   LV UUID                WJvIar-IJ7H-yjzB-7jlt-UkHM-EE4E-04yzpY   LV Write Access        read/write   LV Creation host, time localhost.localdomain, 2019-02-27 23:36:35 +0800   LV Status              available   # open                 0   LV Size                5.00 GiB   Current LE             320   Segments               1   Allocation             inherit   Read ahead sectors     auto   – currently set to     8192   Block device           253:2

卷组内有剩余空间时直接扩容

[root@localhost ~]# lvextend -L +5000M  /dev/vg01/lv01  

Rounding size to boundary between physical extents: 4.89 GiB.   Size of logical volume vg01/lv01 changed from 5.00 GiB (320 extents) to 9.89 GiB (633 extents).   Logical volume vg01/lv01 successfully resized.

resize2fs /dev/vgtest/lvtest  #更新文件系统的大小,即激活

卷组内没有空余空间时,先扩容vg 再扩容lv

[root@localhost ~]# pvcreate /dev/sdb2

WARNING: dos signature detected on /dev/sdb2 at offset 510. Wipe it? [y/n]: y   Wiping dos signature on /dev/sdb2.   Physical volume “/dev/sdb2” successfully created.

[root@localhost ~]# vgextend vg01 /dev/sdb2  

Volume group “vg01” successfully extended

[root@localhost ~]# vgdisplay vg01

  — Volume group —   VG Name               vg01   System ID               Format                lvm2   Metadata Areas        2   Metadata Sequence No  8   VG Access             read/write   VG Status             resizable   MAX LV                0   Cur LV                1   Open LV               0   Max PV                0   Cur PV                2   Act PV                2   VG Size               <19.97 GiB   PE Size               16.00 MiB   Total PE              1278   Alloc PE / Size       633 / 9.89 GiB   Free  PE / Size       645 / <10.08 GiB   VG UUID               kCljZC-WILb-v3uX-jEkf-0Wbt-9q1o-UqXJkw

[root@localhost ~]# lvextend -L +5G /dev/vg01/lv01  

Size of logical volume vg01/lv01 changed from 9.89 GiB (633 extents) to 14.89 GiB (953 extents).   Logical volume vg01/lv01 successfully resized.

[root@localhost ~]# lvdisplay /dev/vg01/lv01  

— Logical volume —   LV Path                /dev/vg01/lv01   LV Name                lv01   VG Name                vg01   LV UUID                WJvIar-IJ7H-yjzB-7jlt-UkHM-EE4E-04yzpY   LV Write Access        read/write   LV Creation host, time localhost.localdomain, 2019-02-27 23:36:35 +0800   LV Status              available   # open                 0   LV Size                14.89 GiB   Current LE             953   Segments               2   Allocation             inherit   Read ahead sectors     auto   – currently set to     8192   Block device           253:2

减容到5G 挂载的话取消挂载  umount /dev/vg01/lv01

[root@localhost ~]# lvreduce -L 5G /dev/vg01/lv01

  WARNING: Reducing active logical volume to 5.00 GiB.   THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vg01/lv01? [y/n]: y   Size of logical volume vg01/lv01 changed from 14.89 GiB (953 extents) to 5.00 GiB (320 extents).   Logical volume vg01/lv01 successfully resized.

删除lvm逻辑卷 删除 顺序 lv>vg>pv

[root@localhost ~]# lvremove /dev/vg01/lv01

Do you really want to remove active logical volume vg01/lv01? [y/n]: y   Logical volume “lv01” successfully removed

[root@localhost ~]# vgremove vg01  

Volume group “vg01” successfully removed

[root@localhost ~]# pvremove /dev/sdb1

  Labels on physical volume “/dev/sdb1” successfully wiped. [root@localhost ~]# pvremove /dev/sdb2   Labels on physical volume “/dev/sdb2” successfully wiped.

 

版权声明:本文为hzk-bk-原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/hzk-bk-/p/10445208.html