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

简单来说就是:
PV:等同磁盘分区的物理卷
VG:VG由PV组成
LV:从VG中划分的逻辑卷
如下图所示PV、VG、LV三者关系:

-----------------------------------------------------------------------

特别注意的是:
resize2fs命令            针对的是ext2、ext3、ext4文件系统
xfs_growfs命令         针对的是xfs文件系统

-----------------------------------------------------------------------

  一、LVM在线扩容

  0.查看/home大小为96G

[root@PT233v184 ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   50G  1.7G   49G   4% /
devtmpfs             3.9G     0  3.9G   0% /dev
tmpfs                3.9G   12K  3.9G   1% /dev/shm
tmpfs                3.9G  8.4M  3.9G   1% /run
tmpfs                3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda1           1014M  139M  876M  14% /boot
/dev/mapper/cl-home   96G   32G   64G  34% /home
tmpfs                783M     0  783M   0% /run/user/1000

  1.假设新增的磁盘为/dev/vdb,对磁盘分区。这一步不分区也可行,后文另有说明。

[root@PT233v184 ~]# fdisk /dev/vdb 
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x304ff336.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-629145599, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599): 
Using default value 629145599
Partition 1 of type Linux and of size 300 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

  2.创建PV

[root@PT233v184 ~]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created

  3.加入VG,vgdisplay查看已存在的VG Name

[root@PT233v184 ~]# vgdisplay 
  --- Volume group ---
  VG Name               cl
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  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               149.00 GiB
  PE Size               4.00 MiB
  Total PE              38143
  Alloc PE / Size       38142 / 148.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               dGSxPy-2MJ2-TgiB-n3f8-tRCb-NAco-ZCcoSo
   
[root@PT233v184 ~]# vgextend cl /dev/vdb1
  Volume group "cl" successfully extended

  4.扩容LV分区,lvdisplay查看要扩容的LV Path

[root@PT233v184 ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                NCfBQB-hUSM-ISL0-GUL0-KNru-2qsC-qqoBuE
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-10-13 09:24:40 +0800
  LV Status              available
  # open                 2
  LV Size                3.88 GiB
  Current LE             992
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/cl/home
  LV Name                home
  VG Name                cl
  LV UUID                KUyFmw-TeAX-EcBd-fOX3-vJ00-ceCQ-tHcL4I
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-10-13 09:24:40 +0800
  LV Status              available
  # open                 1
  LV Size                95.12 GiB
  Current LE             24350
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                7u7ZgM-Zn2l-n2ET-y3Ec-EFHx-bzyP-sNVsJK
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-10-13 09:24:41 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
#vgdisplay查看可用空间"Free PE / Size",76800
[root@PT233v184 ~]# vgdisplay 
  --- Volume group ---
  VG Name               cl
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               448.99 GiB
  PE Size               4.00 MiB
  Total PE              114942
  Alloc PE / Size       38142 / 148.99 GiB
  Free  PE / Size       76800 / 300.00 GiB
  VG UUID               dGSxPy-2MJ2-TgiB-n3f8-tRCb-NAco-ZCcoSo
   
[root@PT233v184 ~]# lvextend -l +76800 /dev/cl/home
  Size of logical volume cl/home changed from 95.12 GiB (24350 extents) to 395.12 GiB (101150 extents).
  Logical volume cl/home successfully resized.

  4.a.多种lvextend扩容参数

lvextend -L 390G /dev/cl/home      #增大至390G
lvextend -L +300G /dev/cl/home     #增加300G
lvextend -l 100126 /dev/cl/home    #增加至100126个PE
lvextend -l +76800 /dev/cl/home    #增加76800个PE
lvextend -l +100%FREE /dev/cl/home #剩余的空间全部增加给LV

  5.执行重设大小

ext2/ext3/ext4文件系统的调整命令是resize2fs
resize2fs /dev/cl/home
xfs文件系统的调整命令是xfs_growfs
xfs_growfs /dev/cl/home
[root@PT233v184 ~]# xfs_growfs /dev/cl/home
meta-data=/dev/mapper/cl-home    isize=512    agcount=4, agsize=6233600 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=24934400, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=12175, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 24934400 to 103577600

  6.再次查看/home大小

[root@PT233v184 ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   50G  1.7G   49G   4% /
devtmpfs             3.9G     0  3.9G   0% /dev
tmpfs                3.9G   12K  3.9G   1% /dev/shm
tmpfs                3.9G  8.4M  3.9G   1% /run
tmpfs                3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda1           1014M  139M  876M  14% /boot
/dev/mapper/cl-home  396G   34G  362G   9% /home
tmpfs                783M     0  783M   0% /run/user/1000

  二、LVM初次增加

#磁盘分区
无论新挂载点或者现有挂载点在线扩容,不需要分区,直接pvcreate走起,我也不知道磁盘分区的目的是什么了,可能是不想把整块磁盘的空间全部扩容给lv吧。

# 创建PV、VG、LV
pvcreate /dev/vdb
vgcreate vg_data /dev/vdb
lvcreate -l 25599 -n lv_data vg_data
lvcreate -l +100%FREE -n lv_data vg_data

# 格式化磁盘
mkfs.xfs /dev/vg_data/lv_data

# 修改/etc/fstab,挂载磁盘
echo "/dev/vg_data/lv_data                      /data                   xfs     defaults        0 0" >> /etc/fstab
mkdir -p /data
mount -a
df -h

 

posted @ 2017-11-07 16:50  金枪语  阅读(4337)  评论(0编辑  收藏  举报