欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

linux动态增加LV空间的方法

程序员文章站 2022-04-19 20:34:51
今天小编要为大家带来得是linux动态增加LV空间的方法!希望对大家会有帮助!有需要的朋友一起去看看吧... 17-03-22...

一直都说lvm可以在线增加空间,一直都没有试过

下面小试一下:

1.增加硬盘

2.创建pv

3.添加pv到vg

4.扩展lv

1.增加硬盘

该干嘛干嘛

添加后需要重启(有知道不用重启的办法吗)

--这个是新添加的硬盘  
[root@localhost ~]# fdisk -l /dev/sdb  
disk /dev/sdb: 5368 mb, 5368709120 bytes  
255 heads, 63 sectors/track, 652 cylinders  
units = cylinders of 16065 * 512 = 8225280 bytes  
disk /dev/sdb doesn't contain a valid partition table

2.创建pv

--命令很简单

--命令很简单  
[root@localhost ~]# pvcreate /dev/sdb  
  physical volume "/dev/sdb" successfully created  
  
--可以看到新的pv了  
[root@localhost ~]# pvdisplay  
  /dev/hdc: open failed: no medium found  
  --- physical volume ---  
  pv name               /dev/sda2  
  vg name               volgroup00  
  pv size               9.90 gb / not usable 22.76 mb  
  allocatable           yes (but full)  
  pe size (kbyte)       32768  
  total pe              316  
  free pe               0  
  allocated pe          316  
  pv uuid               n5fs6m-jbih-n9vu-pbtd-iocv-bbte-buenzo  
     
  "/dev/sdb" is a new physical volume of "5.00 gb"  
  --- new physical volume ---  
  pv name               /dev/sdb  
  vg name                 
  pv size               5.00 gb  
  allocatable           no  
  pe size (kbyte)       0  
  total pe              0  
  free pe               0  
  allocated pe          0  
  pv uuid               tds3mn-3on3-ehbl-cohr-7hr3-8608-jillxg  

3.添加pv到vg

--指定对应的vg和pv  
[root@localhost ~]# vgextend volgroup00 /dev/sdb  
  volume group "volgroup00" successfully extended  
  
--看到新的5g添加到vg里面了,状态是没有分配  
[root@localhost ~]# vgdisplay   
  --- volume group ---  
  vg name               volgroup00  
  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               14.84 gb  
  pe size               32.00 mb  
  total pe              475  
  alloc pe / size       316 / 9.88 gb  
  free  pe / size       159 / 4.97 gb  
  vg uuid               x1uypd-qbge-2yqv-t1cb-igiz-e4lb-fghf1w  

4.扩展lv

--先添加2g练手  
[root@localhost ~]# lvextend -l +2g /dev/volgroup00/logvol00  
  extending logical volume logvol00 to 10.88 gb  
  logical volume logvol00 successfully resized  
--成功后还未看到新的空间  
[root@localhost ~]# df -m  
filesystem           1m-blocks      used available use% mounted on  
/dev/mapper/volgroup00-logvol00  
                          8804      7362       988  89% /  
--需要手动刷新  
[root@localhost ~]# resize2fs /dev/volgroup00/logvol00  
resize2fs 1.39 (29-may-2006)  
filesystem at /dev/volgroup00/logvol00 is mounted on /; on-line resizing required  
performing an on-line resize of /dev/volgroup00/logvol00 to 2850816 (4k) blocks.  
the filesystem on /dev/volgroup00/logvol00 is now 2850816 blocks long.  
  
--现在就完成了  
[root@localhost ~]# df -m  
filesystem           1m-blocks      used available use% mounted on  
/dev/mapper/volgroup00-logvol00  
                         10788      7365      2867  72% / 

若需要先缩小则使用以下命令:

lvreduce -l -20g /dev/mapper/vg_mysvr-lv_home

resize2fs /dev/mapper/vg_my-lv_home

lvextend -l +20g /dev/mapper/vg_mysvr-lv_root

resize2fs /dev/mapper/vg_mysvr-lv_root