• CentOS lvm虚拟磁盘管理(vg_centoslv_root扩充和缩小)


    查看磁盘使用情况

    [root@centos6 ~]# df -h
    Filesystem                     Size  Used Avail Use% Mounted on
    /dev/mapper/vg_centos-lv_root  148G   49G   92G  35% /
    tmpfs                          3.9G     0  3.9G   0% /dev/shm
    /dev/sda1                      477M   88M  360M  20% /boot
    /dev/mapper/vg_centos-lv_home   69G   11G   55G  16% /home
    

    查看分区情况

    [root@centos6 ~]# fdisk -l
    
    Disk /dev/sda: 500.1 GB, 500107862016 bytes
    255 heads, 63 sectors/track, 60801 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disk identifier: 0xcad4ebea
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          64      512000   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              64       60802   487873536   8e  Linux LVM
    
    Disk /dev/mapper/vg_centos-lv_root: 161.1 GB, 161061273600 bytes
    255 heads, 63 sectors/track, 19581 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disk identifier: 0x00000000
    
    
    Disk /dev/mapper/vg_centos-lv_swap: 6257 MB, 6257901568 bytes
    255 heads, 63 sectors/track, 760 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disk identifier: 0x00000000
    
    
    Disk /dev/mapper/vg_centos-lv_home: 75.2 GB, 75161927680 bytes
    255 heads, 63 sectors/track, 9137 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disk identifier: 0x00000000
    

    查看已经存在的PV

    [root@centos6 ~]# pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               vg_centos
      PV Size               465.27 GiB / not usable 3.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              119109
      Free PE               61297
      Allocated PE          57812
      PV UUID               MBViEk-fqNP-FUlc-PB3X-gOfi-x0pI-z7Bzbc
    

    查看VG

    [root@centos6 ~]# vgdisplay
      --- Volume group ---
      VG Name               vg_centos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  8
      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               465.27 GiB
      PE Size               4.00 MiB
      Total PE              119109
      Alloc PE / Size       57812 / 225.83 GiB
      Free  PE / Size       61297 / 239.44 GiB
      VG UUID               Xbfben-cWfV-XN6s-3SqM-SQOJ-tXPY-nCCFqC
    

    查看LV

    [root@centos6 ~]# lvdisplay
      --- Logical volume ---
      LV Path                /dev/vg_centos/lv_root
      LV Name                lv_root
      VG Name                vg_centos
      LV UUID                WmZIWz-aiAY-CUPs-bYnH-4iyy-yKeG-b5onvL
      LV Write Access        read/write
      LV Creation host, time centos, 2019-02-24 04:08:00 +0800
      LV Status              available
      # open                 1
      LV Size                150.00 GiB
      Current LE             38400
      Segments               2
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:0
       
      --- Logical volume ---
      LV Path                /dev/vg_centos/lv_home
      LV Name                lv_home
      VG Name                vg_centos
      LV UUID                sA7I2d-44Fm-HUBi-BAbK-F1ST-fSTW-mmBzx0
      LV Write Access        read/write
      LV Creation host, time centos, 2019-02-24 04:08:18 +0800
      LV Status              available
      # open                 1
      LV Size                70.00 GiB
      Current LE             17920
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:2
       
      --- Logical volume ---
      LV Path                /dev/vg_centos/lv_swap
      LV Name                lv_swap
      VG Name                vg_centos
      LV UUID                OBXMGc-pGZK-b66R-i072-Jnfi-t07d-NHMiW0
      LV Write Access        read/write
      LV Creation host, time centos, 2019-02-24 04:12:30 +0800
      LV Status              available
      # open                 2
      LV Size                5.83 GiB
      Current LE             1492
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:1
    

    缩小LV(非root分区)

    lvreduce -L 50G -f -r /dev/vg/lv   # 减少到50G
    lvreduce -L -10G -f -r /dev/vg/lv  # 减10G
    
    #相当于以下3条命令
    e2fsck -f /dev/testvg/testlv
    
    resize2fs /dev/testvg/testlv 50G
    
    lvreduce -L 50G /dev/testvg/testlv
    

    拓展LV

    lvextend -L +10G -f -r /dev/testvg/testlv  #增加10G
    lvextend -L 100G -f -r /dev/testvg/testlv   #空间扩大到100G
    
    # 相当于
    lvextend -L +10G /dev/testvg/testlv
    resize2fs -f /dev/testvg/testlv 30G
    

    root分区拓展和缩小操作,不能在本机一次性完成,操作后不能进行resize

    我们可以进入救援模式或者将硬盘拆下来到其他的centos或者archlinux系统下resize

    e2fsck -f /dev/mapper/vg_host01-lv_root
    resize2fs -p /dev/mapper/vg_host01-lv_root 50G

    查看空闲的空间

    [root@centos6 ~]# vgdisplay|grep "Free  PE"
      Free  PE / Size       61297 / 239.44 GiB
    

      

      

  • 相关阅读:
    全面的学习资料(收藏)
    远程下载文件源码
    【转】c#托管资源和非托管资源区别
    Jquery 限制文本框输入字数
    好用的网站
    交叉表查询
    jquery 和 javascript 清空上传控件 方法总结
    关于java.io.IOException问题
    http 302
    django使用静态文件二
  • 原文地址:https://www.cnblogs.com/jay763190097/p/16060658.html
Copyright © 2020-2023  润新知