返回
软件
分类

LVM将一个或多个磁盘分区(PV)虚拟为一个卷组(VG),无法继续扩容

日期: 2020-01-02 07:57 浏览次数 : 136

CentOS7 根目录扩容

virtualbox 下添加新的虚拟硬盘

环境:CentOS 7,分区使用的是默认分区。
一台机器共有4块2T的硬盘,在sda上已经安装有系统,想要扩容。参考网页内容必赢备用网址 ,。
仍然存在的问题是,vg扩展到6T以后,vl只能扩展到4T,无法继续扩容,待解决。
结果!!!!居然分次extend就可以继续extend了!!如下所示!!!简直给跪!所以造成这个结果的原因是我这个+后面的数字算错了!!!太弱智了!

一、LVM简介

LVM将一个或多个磁盘分区(PV)虚拟为一个卷组(VG),无法继续扩容。一.创建LVM逻辑分区

fdisk -l 查看分区

必赢备用网址 1

1:分区类型 sdb或sda

2,3:接下来要使用的内容

[root@localhost ~]# lvextend -L +360558 /dev/centos/home
  Rounding size to boundary between physical extents: 352.11 GiB
  Size of logical volume centos/home changed from 4.03 TiB (1056286 extents) to 4.37 TiB (1146426 extents).
  Logical volume home successfully resized.
[root@localhost ~]# lvextend -L +360558 /dev/centos/home
  Rounding size to boundary between physical extents: 352.11 GiB
  Insufficient free space: 90140 extents needed, but only 90138 available
[root@localhost ~]# lvextend -L +90138 /dev/centos/home 
  Rounding size to boundary between physical extents: 88.03 GiB
  Size of logical volume centos/home changed from 5.06 TiB (1326706 extents) to 5.15 TiB (1349241 extents).
  Logical volume home successfully resized.

    LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制。LVM将一个或多个磁盘分区(PV)虚拟为一个卷组(VG),相当于一个大的硬盘,我们可以在上面划分一些逻辑卷(LV)。当卷组的空间不够使用时,可以将新的磁盘分区加入进来。我们还可以从卷组剩余空间上划分一些空间给空间不够用的逻辑卷使用。

二.增加分区

必赢备用网址 2

1. 查看当前lvm的情况(/dev/sda2)

首先fdisk -l查看当前的分区情况如下所示,sda,sdb,sdc,sdd四块硬盘均已分区,sdbcd各自分为了一个大区,其中sda已有lvm分区/dev/sda2。

[root@localhost ~]# fdisk -l

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes, 3907029168 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: 0x0007dc9b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048  3907028991  1953001472   8e  Linux LVM

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes, 3907029168 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: 0xc3897539

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048  3907029167  1953513560   83  Linux

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes, 3907029168 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: 0xc3897517

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048  3907029167  1953513560   83  Linux

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes, 3907029168 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: 0xc389752b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  3907029167  1953513560   83  Linux

Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/centos-swap: 4294 MB, 4294967296 bytes, 8388608 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 /dev/mapper/centos-home: 1941.8 GB, 1941824339968 bytes, 3792625664 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    

使用命令vgdisplay和lvdisplay查看当前的卷组(Volume group)和逻辑卷(Logical volumes)情况。

[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name               centos
System ID             
Format                lvm2
Metadata Areas        1
Metadata Sequence No  4
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                3
Open LV               3
Max PV                0
Cur PV                1
Act PV                1
VG Size               1.82 TiB
PE Size               4.00 MiB
Total PE              476806
Alloc PE / Size       476791 / 1.82 TiB
Free  PE / Size       15 / 60.00 MiB
VG UUID               o56Jrx-kGgK-bfPO-fROL-5UB1-m21V-K3vi9Z

lv情况如下,分为/dev/centos/swap、/dev/centos/home、 /dev/centos/root三个lv:

[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                H7KpXK-YjfS-ssLE-7gbx-xNnt-QJsQ-hEWcu0
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-01-02 20:26:29 +0800
  LV Status              available
  # open                 2
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/home
  LV Name                home
  VG Name                centos
  LV UUID                kveGiy-O6Y2-OMqN-2Ec2-76Ls-TdDh-1Rl3uu
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-01-02 20:26:29 +0800
  LV Status              available
  # open                 1
  LV Size                1.77 TiB
  Current LE             462967
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                lOLgfM-Jw1f-zH5e-IOld-kVok-Jr0f-IhNfAK
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-01-02 20:27:08 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0    

 

三.创建物理卷加入组

pvcreate /dev/sdb1(默认为sdb1)vgextend centos(图1的2)/dev/sdb1vgdisplay 查看是否成功必赢备用网址 3成功后显示的可用空间为你加入的空间大小

2.向当前VG增加一块磁盘sdb的容量

  1. 创建一个新的linux lvm格式的分区/dev/sdb1。如果/dev/sdb没有分区,则先分区。而我们的/dev/sdb已经分区为/dev/sdb1一个分区,所以可以直接转换为lvm分区:

    fdisk /dev/sdb
    t #修改分区格式
    8e #指定为LVM分区
    w #写入分区表
    partprobe #重读分区表

  2. 给新分区创建PV,加入VG,LV

    pvcreate /dev/sdb1

    加入VG

    vgextend centos /dev/sdb1

    扩展LV

    lvdisplay

    lvextend -L xxxxx /dev/centos/home (增大到xxxxx)

    或者# lvextend -L +xxxx /dev/centos/home (比原来增加xxxx)
    重设LV大小

    resize2fs /dev/centos/home

    如果文件系统为xfs则使用xfs_growfs /dev/centos/home

    df -h

    LVM模型如下图:

四.扩容

lvextend -L +90G /dev/centos(图1的2)/root(图1的3)fdisk -l查看是否成功扩容

物理硬盘(虚拟硬盘)---创建物理卷PV--多个PV合成一个组VG---在VG基础上创建逻辑卷LV

五.操作生效

xfs_growfs /dev/centos/root参考内容:1.

根目录扩容 virtualbox 下添加新的虚拟硬盘 一.创建LVM逻辑分区 fdisk -l 查看分区 1:分区类型 sdb或sda 2,3:接下来要使用的内容 二.增加分区...

扩展主要步骤:

  1. 1. 添加新的物理磁盘
  2. 2.创建新的分区,最多可分配【3个主分区,1个扩展分区】 或 【4个主分区】,扩展分区又可以有多个分区;
  3. window常见的分配方式:
  4. 方式1:[1个主分区(C盘)+1个扩展分区(包括3个分区,D,E,F盘)]
  5. 方式2:[4个主分区,分别作为:C、D、E、F盘]
  6. 若是使用LVM方式分区,分区时最好选择LVM分区方式;
  7. 3. 创建PV;
  8. 4. 创建VG;
  9. 5. 创建LV;
  10. 6. 格式化LV,ext3,ext4等格式;
  11. 7. 挂载LV到指定目录;
  12. 8. 将挂载信息写入:/etc/fstab;
  13. 9. LVM扩容操作
  14. 9.1 LV的扩容;
  15. (1) 使用VG的Free空间,对LV扩容;
  16. (2) 完成后需要在对文件系统扩容;
  17. 9.2 VG的扩容
  18. 方式1: 通过增加PV来实现
  19. 方式2: 通过扩展raid(磁盘阵列)设备的容量来间接对VG扩容
  20. 10. LVM缩减操作
  21. 10.1 LV的缩减
  22. 10.2 VG的缩减
  23. 11. 删除LVM

必赢备用网址 4

二、LVM添加硬盘和扩容

    测试环境:CentOS7 64位(KVM虚拟机)

    LVM版本:lvm2-2.02.105-14.el7.x86_64

   1、使用 fdisk -l 查看到这块新盘为/dev/sda:

   2、对新盘分区

    使用 fdisk 命令对新盘进行分区,这里建立了一个主分区/dev/sda,大小25GB,最后使用 partprobe 命令重新读取分区表:

   输入:n,1,回车,回车,t,8e,w

   再输入:partprobe

    在分区的过程中,注意设置格式为8e,这是LVM的分区格式。

    3、创建物理卷(PV)

    使用 pvcreate 命令创建物理卷,pvdisplay 查看物理卷信息:

    

[root@iotApp&iagri-44 ~]# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created
[root@iotApp&iagri-44 ~]# pvscan
PV /dev/sda2 VG centos lvm2 [49.80 GiB / 0 free]
PV /dev/sda3 VG centos lvm2 [5.00 GiB / 5.00 GiB free]
PV /dev/sda4 lvm2 [25.00 GiB]
Total: 3 [79.80 GiB] / in use: 2 [54.80 GiB] / in no VG: 1 [25.00 GiB]

 

    4、将PV加入卷组(VG)

    使用 vgdisplay 查看卷组信息,下图显示卷组名为centos,空闲大小为0:

[root@iotApp&iagri-44 ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 54.80 GiB
PE Size 4.00 MiB
Total PE 14028
Alloc PE / Size 12749 / 49.80 GiB
Free PE / Size 1279 / 5.00 GiB
VG UUID mMcfc3-2mj2-cFk6-uMNY-FWQl-cXZ5-ENEEXX

    使用 vgextend 命令把/dev/vdb1加入到centos:

[root@iotApp&iagri-44 ~]# vgextend centos /dev/sda4
Volume group "centos" successfully extended

  

[root@iotApp&iagri-44 ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size 79.79 GiB
PE Size 4.00 MiB
Total PE 20427
Alloc PE / Size 12749 / 49.80 GiB
Free PE / Size 7678 / 29.99 GiB
VG UUID mMcfc3-2mj2-cFk6-uMNY-FWQl-cXZ5-ENEEXX

    5、创建逻辑卷(LV)&扩容

    创建逻辑卷用lvcreate

    使用 lvextend 命令进行逻辑卷扩容。我把所有剩余空间都分配给了newlv,增大到了25GB,

[root@iotApp&iagri-44 ~]# lvextend -l +7678 /dev/centos/root

Size of logical volume centos/root changed from 47.94 GiB (12272 extents) to 77.93 GiB (19950 extents).
Logical volume root successfully resized
[root@iotApp&iagri-44 ~]# lvdisplay

--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID Zep8rM-0AR5-RE0m-zj2n-Nc8S-VrL5-W2Zjzx
LV Write Access read/write
LV Creation host, time localhost, 2016-10-12 03:54:21 -0400
LV Status available
# open 1
LV Size 77.93 GiB
Current LE 19950
Segments 3
Allocation inherit
Read ahead sectors auto

  • currently set to 8192
    Block device 253:0

    使用 xfs_growfs 命令在线调整xfs格式文件系统大小(CentOS6使用resize2fs):

[root@iotApp&iagri-44 ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=3141632 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=12566528, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=6136, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 12566528 to 20428800

最后我们看到逻辑卷分区已经动态扩容了25GB:

[root@iotApp&iagri-44 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 78G 924M 78G 2% /
devtmpfs 2.9G 0 2.9G 0% /dev
tmpfs 2.9G 0 2.9G 0% /dev/shm
tmpfs 2.9G 8.4M 2.9G 1% /run
tmpfs 2.9G 0 2.9G 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot