Linux LVM逻辑卷管理及扩容(二)

四、LVM扩展逻辑卷

我们当如何对lvm扩容呢,在vg组有空余的空间时,可以lvextend增加空间;在vg组无空间时,可以通过先增加pv,再lvextend实现扩容

点击(此处)折叠或打开

  1. [root@localhost ~]# lvextend -L +300m /dev/libo/X
  2. Size of logical volume libo/X changed from 1.50 GiB (384 extents) to 1.79 GiB (459 extents).
  3. Logical volume X successfully resized.
  4. [root@localhost ~]# vgextend libo /dev/sdb3
  5. Volume group "libo" successfully extended
我们把LVM逻辑卷管理及扩容(一)中创建的四个分区全部都添加给lvm X,大小为4G

点击(此处)折叠或打开

  1. [root@localhost ~]# lvextend -L +2g /dev/libo/X
  2. Size of logical volume libo/X changed from 1.79 GiB (459 extents) to 3.79 GiB (971 extents).
  3. Logical volume X successfully resized.
  4. [root@localhost ~]# lvdisplay x
  5. Volume group "x" not found
  6. Cannot process volume group x
  7. [root@localhost ~]# lvdisplay /dev/libo/X
  8. --- Logical volume ---
  9. LV Path /dev/libo/X
  10. LV Name X
  11. VG Name libo
  12. LV UUID fpyvTb-f1Wd-OVek-5h05-3U19-gLmQ-2sBMF8
  13. LV Write Access read/write
  14. LV Creation host, time localhost.localdomain, 2016-04-26 12:33:53 +0800
  15. LV Status available
  16. # open 1
  17. LV Size 3.79 GiB
  18. Current LE 971
  19. Segments 4
  20. Allocation inherit
  21. Read ahead sectors auto
  22. - currently set to 8192
  23. Block device 253:2

通过xfs_growfs对lvm进行扩容 xfs_growfs -d /dev/libo/X

点击(此处)折叠或打开

  1. [root@localhost ~]# xfs_growfs -d /dev/libo/X
  2. meta-data=/dev/mapper/libo-X isize=256 agcount=4, agsize=98304 blks
  3. = sectsz=512 attr=2, projid32bit=1
  4. = crc=0 finobt=0
  5. data = bsize=4096 blocks=393216, imaxpct=25
  6. = sunit=0 swidth=0 blks
  7. naming =version 2 bsize=4096 ascii-ci=0 ftype=0
  8. log =internal bsize=4096 blocks=2560, version=2
  9. = sectsz=512 sunit=0 blks, lazy-count=1
  10. realtime =none extsz=4096 blocks=0, rtextents=0
  11. data blocks changed from 393216 to 996352
  12. [root@localhost ~]# df -h
  13. Filesystem Size Used Avail Use% Mounted on
  14. /dev/mapper/rhel-root 20G 3.7G 17G 19% /
  15. devtmpfs 898M 0 898M 0% /dev
  16. tmpfs 913M 84K 913M 1% /dev/shm
  17. tmpfs 913M 9.1M 904M 1% /run
  18. tmpfs 913M 0 913M 0% /sys/fs/cgroup
  19. /dev/sda3 1014M 33M 982M 4% /163
  20. /dev/sr0 3.8G 3.8G 0 100% /mnt
  21. /dev/md5 2.0G 33M 2.0G 2% /md5
  22. /dev/sda1 797M 165M 633M 21% /boot
  23. tmpfs 183M 16K 183M 1% /run/user/42
  24. tmpfs 183M 0 183M 0% /run/user/0
  25. /dev/mapper/libo-X 3.8G 33M 3.8G 1% /lvm

五、LVM缩减逻辑卷

当硬盘空间在某种情况下,如果减少逻辑卷的空间释放给其他逻辑卷使用。我们可以通过lvreduce 缩减或是vgreduce缩减
点击(此处)折叠或打开

  1. [root@localhost ~]# lvs
  2. LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
  3. x libo -wi-a----- 3.90g
  4. root rhel -wi-ao---- 20.00g
  5. swap rhel -wi-ao---- 2.00g
  6. [root@localhost ~]# lvreduce -L 2g /dev/libo/x              #-L 2g 表示把lvm缩减到2g,不是减少2g
  7. WARNING: Reducing active logical volume to 2.00 GiB
  8. THIS MAY DESTROY YOUR DATA (filesystem etc.)
  9. Do you really want to reduce x? [y/n]: y
  10. Size of logical volume libo/x changed from 3.90 GiB (999 extents) to 2.00 GiB (512 extents).
  11. Logical volume x successfully resized.
  12. [root@localhost ~]# lvs
  13. LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
  14. x libo -wi-a----- 2.00g
  15. root rhel -wi-ao---- 20.00g
  16. swap rhel -wi-ao---- 2.00g
  17. [root@localhost ~]# vgreduce libo /dev/sdb4
    Removed "/dev/sdb4" from volume group "libo"
  18. [root@localhost ~]# pvs
      PV         VG   Fmt  Attr PSize    PFree   
      /dev/sda2  rhel lvm2 a--    22.00g    4.00m
      /dev/sdb1  libo lvm2 a--  1020.00m       0 
      /dev/sdb2  libo lvm2 a--  1020.00m       0 
      /dev/sdb3  libo lvm2 a--  1020.00m 1012.00m
      /dev/sdb4       lvm2 ---     1.00g    1.00g


六、lvm删除、vg删除、pv删除

在删除lvm前,需要卸载挂载的分区
点击(此处)折叠或打开

  1. [root@localhost ~]# lvremove /dev/libo/x
  2. Do you really want to remove active logical volume x? [y/n]: y
  3. Logical volume "x" successfully removed
  4. [root@localhost ~]# lvs
  5. LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
  6. root rhel -wi-ao---- 20.00g
  7. swap rhel -wi-ao---- 2.00g
  8. [root@localhost ~]# vgremove libo
  9. Volume group "libo" successfully removed
  10. [root@localhost ~]# vgs
  11. VG #PV #LV #SN Attr VSize VFree
  12. rhel 1 2 0 wz--n- 22.00g 4.00m
  13. [root@localhost ~]# pvremove /dev/sdb{1..4}
  14. Labels on physical volume "/dev/sdb1" successfully wiped
  15. Labels on physical volume "/dev/sdb2" successfully wiped
  16. Labels on physical volume "/dev/sdb3" successfully wiped
  17. Labels on physical volume "/dev/sdb4" successfully wiped
  18. [root@localhost ~]# pvs
  19. PV VG Fmt Attr PSize PFree
  20. /dev/sda2 rhel lvm2 a-- 22.00g 4.00m
  21. [root@localhost ~]#




来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27039319/viewspace-2088624/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27039319/viewspace-2088624/

你可能感兴趣的:(Linux LVM逻辑卷管理及扩容(二))