linux-lv-磁盘扩容

前提:centos7并添加磁盘到服务器或者虚拟机

流程:磁盘->创建pv->扩容vg->扩容lv->刷新挂载目录->查看结果

--查看磁盘

lsblk   #查看扩容的磁盘为sdb

--扩容lv
虚拟机不重启进行磁盘识别-重新扫描scsi总线,添加scsi设备
echo "- - -" > /sys/class/scsi_host/host0/scan

#注 "- - -"中间有空格
--建pv

[root@localhost ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.
[root@localhost ~]# pvs
  PV         VG Fmt  Attr PSize   PFree  
  /dev/sda2  cl lvm2 a--   99.00g   4.00m
  /dev/sdb   cl lvm2 a--  100.00g 100.00g

--扩容vg

vgextend vg_name pv_name

[root@localhost ~]# vgs
  VG #PV #LV #SN Attr   VSize  VFree
  cl   1   3   0 wz--n- 99.00g 4.00m
[root@localhost ~]# vgextend cl /dev/sdb         #cl为vg名称 /dev/sdb是刚刚创建的pv
  Volume group "cl" successfully extended
[root@localhost ~]# vgs
  VG #PV #LV #SN Attr   VSize   VFree  
  cl   2   3   0 wz--n- 198.99g 100.00g

--扩容lv
lvextend -l +100%free /dev/vg_name/lv_name

[root@localhost ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0  100G  0 disk 
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0   99G  0 part 
  ├─cl-root 253:0    0   50G  0 lvm  /                      #需要扩容根目录
  ├─cl-swap 253:1    0  7.9G  0 lvm  [SWAP]
  └─cl-home 253:2    0 41.1G  0 lvm  /home
sdb           8:16   0  100G  0 disk 
sr0          11:0    1  4.1G  0 rom  
[root@localhost ~]# ll /dev/cl/root                          #确定lv设备路径
lrwxrwxrwx 1 root root 7 Jul 24 19:17 /dev/cl/root -> ../dm-0
[root@localhost ~]# lvextend -l +100%free /dev/cl/root
  Size of logical volume cl/root changed from 50.00 GiB (12800 extents) to 150.00 GiB (38400 extents).
  Logical volume cl/root successfully resized.
[root@localhost ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0  100G  0 disk 
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0   99G  0 part 
  ├─cl-root 253:0    0  150G  0 lvm  /                      #已经扩容到150G
  ├─cl-swap 253:1    0  7.9G  0 lvm  [SWAP]
  └─cl-home 253:2    0 41.1G  0 lvm  /home
sdb           8:16   0  100G  0 disk 
└─cl-root   253:0    0  150G  0 lvm  /
sr0          11:0    1  4.1G  0 rom 

--刷新lv磁盘存储(不同格式化不同方式)
resize2fs /dev/vg_name/lv_name      #ext4格式
xfs_growfs /dev/vg_name/lv_name    #xfs格式

[root@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   50G  3.0G   48G   6% /
devtmpfs             3.9G     0  3.9G   0% /dev
tmpfs                3.9G     0  3.9G   0% /dev/shm
tmpfs                3.9G   17M  3.9G   1% /run
tmpfs                3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1           1014M  139M  876M  14% /boot
/dev/mapper/cl-home   42G   33M   42G   1% /home

[root@localhost ~]# lsblk -f
NAME        FSTYPE      LABEL           UUID                                   MOUNTPOINT
sda                                                                            
├─sda1      xfs                         c8e6d619-2c7f-4876-83e8-8e371314518f   /boot
└─sda2      LVM2_member                 hc97wL-RVdX-nbVS-9tub-9Vc5-Dw3F-kZuLOM 
  ├─cl-root xfs                         d0c8731e-5e7a-4cac-bfcd-693c1fce99b0   /             #确定类型      

[root@localhost ~]# xfs_growfs /dev/cl/root                                                  #刷新扩容
meta-data=/dev/mapper/cl-root    isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 39321600
[root@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root  150G  3.0G  148G   2% /

常用实例:
(1)创建一个指定大小的lv,并指定名字为lv_2
lvcreate -L 2G -n lv_2 vg_1
(2)创建一个占全部卷组大小的lv,并指定名字为lv_3(注意前提是vg并没有创建有lv)
lvcreate -l 100%VG -n lv_3 vg_1
(3)创建一个空闲空间80%大小的lv,并指定名字为lv_4(常用)
lvcreate -l 80%Free -n lv_4 vg_1

posted @ 2020-07-04 20:34  苍茫宇宙  阅读(3083)  评论(0编辑  收藏  举报