在 CentOS/RHEL 中无法扩展带有关联快照的 LVM 文件系统

问题

用户无法扩展具有快照的 LVM 文件系统,错误“快照源卷只能在不活动时调整大小:尝试 lvchange -an”。
用户在非根 LVM 卷上创建了一个快照,如下所示。

# lvcreate --size 100M --snapshot --name testsnap /dev/testVG/testLV 
  Logical volume "testsnap" created
# lvs -a -o+devices
  LV       VG         Attr   LSize   Oroirn Snap%  Move Log Copy%  Convert Devices       
  LogVol00 VolGroup00 -wi-ao   7.91G                                       /dev/vda2(0)  
  LogVol01 VolGroup00 -wi-ao   1.97G                                       /dev/vda2(253)
  testLV   testVG     owi-a-   1.00G                                       /dev/vdb1(0)  
  testsnap testVG     swi-a- 100.00M testLV   0.01                         /dev/vdb1(256)
# vgs -a
  VG         #PV #LV #SN Attr   VSize VFree
  VolGroup00   1   2   0 wz--n- 9.88G    0 
  testVG       2   2   1 wz--n- 3.99G 2.89G

如果用户尝试使用关联的快照扩展文件系统,则会引发如下所示的错误。

# lvextend -L +1G /dev/testVG/testLV 
  Snapshot oroirn volumes can be resized only while inactive: try lvchange -an
欢迎来到之路教程(on itroad-com)

解决方案

在扩展/调整大小之前,需要停用带有快照的 LV,因为无法在线调整带有快照的 LVM 分区的大小。
请按照以下步骤操作:

  1. 先去激活LVM分区,验证LV的当前大小。
# lvchange -an /dev/testVG/testLV
# lvs -a -o+devices
  LV       VG         Attr   LSize   Oroirn Snap%  Move Log Copy%  Convert Devices       
  LogVol00 VolGroup00 -wi-ao   7.91G                                       /dev/vda2(0)  
  LogVol01 VolGroup00 -wi-ao   1.97G                                       /dev/vda2(253)
  testLV   testVG     owi---   1.00G                                       /dev/vdb1(0)  
  testsnap testVG     swi--- 100.00M testLV                                /dev/vdb1(256)
  1. 现在执行调整大小操作并再次验证 LV 大小。
# lvextend -L +1G /dev/testVG/testLV 
  Extending logical volume testLV to 2.00 GB
  Logical volume testLV successfully resized
# lvs -a -o+devices
  LV       VG         Attr   LSize   Oroirn Snap%  Move Log Copy%  Convert Devices       
  LogVol00 VolGroup00 -wi-ao   7.91G                                       /dev/vda2(0)  
  LogVol01 VolGroup00 -wi-ao   1.97G                                       /dev/vda2(253)
  testLV   testVG     owi---   2.00G                                       /dev/vdb1(0)  
  testLV   testVG     owi---   2.00G                                       /dev/vdb1(281)
  testLV   testVG     owi---   2.00G                                       /dev/vdc1(0)  
  testsnap testVG     swi--- 100.00M testLV                                /dev/vdb1(256)
  1. 下一步是调整与 LV 关联的 LVM 快照的大小。
# lvextend -L +100M /dev/testVG/testsnap
Extending logical volume testsnap to 200.00 MB
  Logical volume testsnap successfully resized
日期:2020-09-17 00:12:44 来源:oir作者:oir