美文网首页
CentOS使用lvm扩容

CentOS使用lvm扩容

作者: 丁不想被任何狗咬 | 来源:发表于2016-02-25 12:55 被阅读1344次

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

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

    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    
    

    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

    相关文章

      网友评论

          本文标题:CentOS使用lvm扩容

          本文链接:https://www.haomeiwen.com/subject/sriikttx.html