[linux] LVM 非根挂载点扩容(原磁盘扩容)

阿里云机器,ECS运行时磁盘由300G扩容到500G,重启机器生效后登录。可以看到/data目录总大小300G,/dev/vdb已经扩容到500G。

[root@HD1g-elasticsearch2 ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/vda1                     40G  5.6G   32G  15% /
devtmpfs                     3.9G     0  3.9G   0% /dev
tmpfs                        3.9G   12K  3.9G   1% /dev/shm
tmpfs                        3.9G  380K  3.9G   1% /run
tmpfs                        3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/vg_data-lv_data  300G  218G   83G  73% /data
tmpfs                        783M     0  783M   0% /run/user/1000
[root@HD1g-elasticsearch2 ~]# fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x0008d73a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83884031    41940992   83  Linux

Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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/vg_data-lv_data: 322.1 GB, 322118352896 bytes, 629137408 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

1.pvs先查看已有的pv,再resize

[root@HD1g-elasticsearch2 ~]# pvs
  PV         VG      Fmt  Attr PSize    PFree
  /dev/vdb   vg_data lvm2 a--  <300.00g    0 
[root@HD1g-elasticsearch2 ~]# pvresize /dev/vdb
  Physical volume "/dev/vdb" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
[root@HD1g-elasticsearch2 ~]# pvs
  PV         VG      Fmt  Attr PSize    PFree  
  /dev/vdb   vg_data lvm2 a--  <500.00g 200.00g

2.vg大小随pvresize而变

vgs原大小在pvresize之前才能看到
[root@HD1g-elasticsearch2 ~]# vgs
  VG      #PV #LV #SN Attr   VSize    VFree
  vg_data   1   1   0 wz--n- <300.00g    0

pvresize后vg自动扩容了
[root@HD1g-elasticsearch2 ~]# vgs
  VG      #PV #LV #SN Attr   VSize    VFree  
  vg_data   1   1   0 wz--n- <500.00g 200.00g

3.查看要扩容的lv,获取要扩容的LV Path

[root@HD1g-elasticsearch2 ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/vg_data/lv_data
  LV Name                lv_data
  VG Name                vg_data
  LV UUID                4Ncz4O-016I-Vh8u-vmOT-BZ7W-ARiy-fCHO4s
  LV Write Access        read/write
  LV Creation host, time HD1g-elk-elastic2, 2018-09-06 14:34:31 +0800
  LV Status              available
  # open                 1
  LV Size                <300.00 GiB
  Current LE             76799
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           252:0
   
[root@HD1g-elasticsearch2 ~]# lvextend -l +100%FREE /dev/vg_data/lv_data
  Size of logical volume vg_data/lv_data changed from <300.00 GiB (76799 extents) to <500.00 GiB (127999 extents).
  Logical volume vg_data/lv_data successfully resized.
[root@HD1g-elasticsearch2 ~]# lvs
  LV      VG      Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_data vg_data -wi-ao---- <500.00g

4.查看原挂载节点文件系统格式,选用命令resize挂载点大小,xfs文件系统用xfs_growfs,ext*文件系统用resize2fs

[root@HD1g-elasticsearch2 ~]# df -hT
Filesystem                  Type      Size  Used Avail Use% Mounted on
/dev/vda1                   ext4       40G  5.6G   32G  15% /
devtmpfs                    devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                       tmpfs     3.9G   12K  3.9G   1% /dev/shm
tmpfs                       tmpfs     3.9G  380K  3.9G   1% /run
tmpfs                       tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/vg_data-lv_data xfs       300G  218G   83G  73% /data
tmpfs                       tmpfs     783M     0  783M   0% /run/user/1000
[root@HD1g-elasticsearch2 ~]# xfs_growfs /dev/vg_data/lv_data
meta-data=/dev/mapper/vg_data-lv_data isize=512    agcount=7, agsize=13106944 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=78642176, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=25599, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 78642176 to 131070976
[root@HD1g-elasticsearch2 ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/vda1                     40G  5.6G   32G  15% /
devtmpfs                     3.9G     0  3.9G   0% /dev
tmpfs                        3.9G   12K  3.9G   1% /dev/shm
tmpfs                        3.9G  380K  3.9G   1% /run
tmpfs                        3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/vg_data-lv_data  500G  218G  283G  44% /data
tmpfs                        783M     0  783M   0% /run/user/1000

 

posted @ 2019-04-12 10:45  金枪语  阅读(2429)  评论(0编辑  收藏  举报