LVM 镜像尝试导致“可用空间不足”

ker*_*att 7 linux lvm

尝试在 CentOS 7 上添加磁盘以镜像 LVM 卷总是失败,并显示“可用空间不足:需要 1 个范围,但只有 0 个可用”。寻找解决方案后,我尝试指定磁盘、多个日志记录选项、添加第三个日志分区,但没有找到解决方案

不确定我是否犯了菜鸟错误,或者有一些更微妙的错误(我更熟悉 ZFS,刚开始使用 LVM):

# lvconvert -m1 centos_bi/home
  Insufficient free space: 1 extents needed, but only 0 available  
# lvconvert -m1 --corelog centos_bi/home
  Insufficient free space: 1 extents needed, but only 0 available
# lvconvert -m1 --corelog --alloc anywhere centos_bi/home
  Insufficient free space: 1 extents needed, but only 0 available
# lvconvert -m1 --mirrorlog mirrored --alloc anywhere centos_bi/home /dev/sda2
  Insufficient free space: 1 extents needed, but only 0 available  
# lvconvert -m1 --corelog --alloc anywhere centos_bi/home /dev/sdi2 /dev/sda2
  Insufficient free space: 1 extents needed, but only 0 available
Run Code Online (Sandbox Code Playgroud)

这两个磁盘大小相同,并且通过“sfdisk -d /dev/sdi > part_table; sfdisk /dev/sda < part_table”具有相同的分区布局。下面详细介绍当前的配置。

# pvs
  PV         VG        Fmt  Attr PSize   PFree
  /dev/sda1  centos_bi lvm2 a--  496.00m 496.00m
  /dev/sda2  centos_bi lvm2 a--  465.27g 465.27g
  /dev/sdi2  centos_bi lvm2 a--  465.27g      0

# vgs
  VG        #PV #LV #SN Attr   VSize   VFree
  centos_bi   3   3   0 wz--n- 931.02g 465.75g 

# lvs -a -o +devices
  LV   VG        Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert Devices
  home centos_bi -wi-ao---- 391.64g                                              /dev/sdi2(6050)
  root centos_bi -wi-ao----  50.00g                                              /dev/sdi2(106309)
  swap centos_bi -wi-ao----  23.63g                                              /dev/sdi2(0)


# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdi2
  VG Name               centos_bi
  PV Size               465.27 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              119109
  Free PE               0
  Allocated PE          119109

  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos_bi
  PV Size               465.27 GiB / not usable 3.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              119109
  Free PE               119109
  Allocated PE          0

  --- Physical volume ---
  PV Name               /dev/sda1
  VG Name               centos_bi
  PV Size               500.00 MiB / not usable 4.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              124
  Free PE               124
  Allocated PE          0

# vgdisplay
  --- Volume group ---
  VG Name               centos_bi
  System ID
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  10
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               931.02 GiB
  PE Size               4.00 MiB
  Total PE              238342
  Alloc PE / Size       119109 / 465.27 GiB
  Free  PE / Size       119233 / 465.75 GiB

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos_bi/swap
  LV Name                swap
  VG Name                centos_bi
  LV Write Access        read/write
  LV Creation host, time localhost, 2014-08-07 16:34:34 -0400
  LV Status              available
  # open                 2
  LV Size                23.63 GiB
  Current LE             6050
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos_bi/home
  LV Name                home
  VG Name                centos_bi
  LV Write Access        read/write
  LV Creation host, time localhost, 2014-08-07 16:34:35 -0400
  LV Status              available
  # open                 1
  LV Size                391.64 GiB
  Current LE             100259
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/centos_bi/root
  LV Name                root
  VG Name                centos_bi
  LV Write Access        read/write
  LV Creation host, time localhost, 2014-08-07 16:34:37 -0400
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
Run Code Online (Sandbox Code Playgroud)

小智 14

从大约 2013 年 9 月开始,lvm2 中的默认镜像段类型一直是“raid1”(不是“mirror”)。这使得--corelog--mirrorlog disk/core/mirroredoptions 在这种默认情况下不适用,因为 raid1 段类型总是将其日志(实际上,元数据子卷)存储在与被镜像的 LV 相同的 PV 上的磁盘上。您不再需要日志的第三个 PV,或将日志存储在内存中。

还有两个进一步的含义。首先,创建镜像的命令简化了,因为只需要指定要镜像的LV,以及要存储镜像段的(通常是一个)PV:# lvconvert -m1 /dev/my_vg/my_lv /dev/my_new_pv

其次,有几个空间方面的考虑。你需要有:

  • 很明显,镜像PV上的空间用来存放原始LV的副本,
  • 而且,镜像 PV 上还有 1 个额外的 LE,用于存储日志,
  • 而且(这是我错过了一段时间),原始PV上的 1 个额外 LE ,用于存储日志(因为日志存储在原始 PV 和新 PV 上)。

通常,这种原始 PV 额外空间要求会导致问题,因为现有 PV 中没有空间可用于为日志分配甚至 1 个新 LE。在这种情况下,您可能会遇到 OP 类型的错误,即1 extents needed, but only 0 available.

正如上面其他人指出的那样,补救措施是调整(在缩小文件系统后缩小)现有 LV 的大小,以便在同一个 PV 上分配日志有空间。如果你不能这样做,你可以使用--type mirror强制传统的“镜像”段类型。

  • 我需要将 FS 和 LV 缩小多少才能为 1 LE 腾出空间? (2认同)