上篇是lv卷的大小扩容,本篇是怎样给卷组增加容量和对lv在线扩容

增加磁盘(略)

快速分区

[root@aiker01 ~]# fdisk /dev/sdb

Command (m for help): n
All primary partitions are in use
Adding logical partition 8
First sector (25176064-41943039, default 25176064): 
Using default value 25176064
Last sector, +sectors or +size{K,M,G} (25176064-41943039, default 41943039): +2G
Partition 8 of type Linux and of size 2 GiB is set
Command (m for help): t
Partition number (1-8, default 8): 
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!

手动更新分区表

[root@aiker01 ~]# partprobe

列出分区

**[root@aiker01 ~]# parted -l

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system  Flags
 1      1049kB  2149MB  2147MB  primary                lvm
 2      2149MB  4296MB  2147MB  primary                lvm
 3      4296MB  6443MB  2147MB  primary                lvm
 4      6443MB  21.5GB  15.0GB  extended
 5      6445MB  8592MB  2147MB  logical                lvm
 6      8593MB  10.7GB  2147MB  logical                lvm
 7      10.7GB  12.9GB  2147MB  logical                lvm
 8      12.9GB  15.0GB  2147MB  logical                lvm

**

创建PV

[root@aiker01 ~]# pvcreate /dev/sdb8
  Physical volume "/dev/sdb8" successfully created.

    **vg扩展**

[root@aiker01 ~]# vgextend vg1 /dev/sdb8
  Volume group "vg1" successfully extended
[root@aiker01 ~]# vgdisplay vg1
  --- Volume group ---
  VG Name               vg1
  System ID             
  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  26
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                4
  Act PV                4
  VG Size               7.98 GiB
  PE Size               4.00 MiB
  Total PE              2044
  Alloc PE / Size       1152 / 4.50 GiB
  Free  PE / Size       892 / 3.48 GiB
  VG UUID               dx3XD9-rQBV-QtBu-EebN-wgjI-CQcn-36iIbm

lv扩容 
这里是比较简单的扩容,直接把新分区给加了进去

[root@aiker01 ~]# lvextend /dev/vg1/lv1 /dev/sdb8
  Size of logical volume vg1/lv1 changed from 4.50 GiB (1152 extents) to <6.50 GiB (1663 extents).
  Logical volume vg1/lv1 successfully resized.
[root@aiker01 ~]# lvdisplay /dev/vg1/lv1
  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                q6dAzJ-1dbC-2EoY-Fzcp-QqEE-enuU-FS5BLT
  LV Write Access        read/write
  LV Creation host, time aiker01, 2017-12-06 03:02:40 +0800
  LV Status              available
  # open                 1
  LV Size                <6.50 GiB
  Current LE             1663
  Segments               4
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:4  

更新lv挂载卷前

[root@aiker01 ~]# df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl-root xfs       8.6G  5.3G  3.4G  62% /
devtmpfs            devtmpfs  2.4G     0  2.4G   0% /dev
tmpfs               tmpfs     2.4G     0  2.4G   0% /dev/shm
tmpfs               tmpfs     2.4G  8.7M  2.4G   1% /run
tmpfs               tmpfs     2.4G     0  2.4G   0% /sys/fs/cgroup
/dev/mapper/cl-home xfs       4.0G   33M  4.0G   1% /home
/dev/mapper/cl-var  xfs       3.0G  159M  2.8G   6% /var
/dev/sda2           xfs       497M  132M  366M  27% /boot
tmpfs               tmpfs     479M     0  479M   0% /run/user/0
/dev/mapper/vg2-lv2 ext4      3.9G   16M  3.7G   1% /data
/dev/mapper/vg1-lv1 ext4      4.4G   16M  4.2G   1% /mnt

更新lv挂载信息(这步很重要)

[root@aiker01 ~]# resize2fs /dev/mapper/vg1-lv1  #xfs文件系统不适用,xfs文件系统需要执行xfs_growfs /dev/vg1/lv1  xfs
![](http://i2.51cto.com/images/blog/201712/08/f4977ad91fc0c475ced44d60e51dc25a.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/vg1-lv1 is mounted on /mnt; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/vg1-lv1 is now 1702912 blocks long.

更新后

[root@aiker01 ~]# df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl-root xfs       8.6G  5.3G  3.4G  62% /
devtmpfs            devtmpfs  2.4G     0  2.4G   0% /dev
tmpfs               tmpfs     2.4G     0  2.4G   0% /dev/shm
tmpfs               tmpfs     2.4G  8.7M  2.4G   1% /run
tmpfs               tmpfs     2.4G     0  2.4G   0% /sys/fs/cgroup
/dev/mapper/cl-home xfs       4.0G   33M  4.0G   1% /home
/dev/mapper/cl-var  xfs       3.0G  159M  2.8G   6% /var
/dev/sda2           xfs       497M  132M  366M  27% /boot
tmpfs               tmpfs     479M     0  479M   0% /run/user/0
/dev/mapper/vg2-lv2 ext4      3.9G   16M  3.7G   1% /data
/dev/mapper/vg1-lv1 ext4      6.4G   18M  6.1G   1% /mnt

[root@aiker01 ~]# ll /mnt/
total 36
-rw-r--r-- 1 root root     9 Dec  7 02:26 1.txt
-rw-r--r-- 1 root root     9 Dec  7 02:26 2.txt
drwxr-xr-x 2 root root  4096 Dec  7 02:34 6

[root@aiker01 ~]# cat /mnt/1.txt 
12345678