10

Attempting to add a disk to mirror an LVM volume on CentOS 7 always fails with "Insufficient free space: 1 extents needed, but only 0 available". Having searched for a solution, I have tried specifying disks, multiple logging options, adding 3rd log partition, but have not found a solution

Not sure if I am making a rookie mistake, or there is something more subtle wrong (I am more familiar with ZFS, new to using 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

The two disks are of the same size, and have identical partition layouts via "sfdisk -d /dev/sdi > part_table; sfdisk /dev/sda < part_table". The current configuration is detailed below.

# 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
5
  • Um, have you tried the obvious? Shrink one of the LVs. Commented Aug 21, 2014 at 15:34
  • Its not too obvious, as "lvreduce -l 1" warns of potential data destruction on the home and root volumes. Since this is a test machine, I tried it anyway, and the volumes no longer mount.
    – kermatt
    Commented Aug 21, 2014 at 15:51
  • 2
    yeah you should've shrunk the fs first...
    – Petter H
    Commented Aug 21, 2014 at 17:39
  • And the default XFS filesystem in CentOS 7 is not shrinkable. Will have to recreate with some slack space.
    – kermatt
    Commented Aug 21, 2014 at 18:10
  • try with "lvconvert -m1 --corelog centos_bi/home /dev/sda2"
    – c4f4t0r
    Commented Aug 21, 2014 at 21:49

2 Answers 2

17

Since about September 2013, the default mirror segment type in lvm2 has been 'raid1' (not 'mirror'). This makes --corelog and --mirrorlog disk/core/mirrored options inapplicable in this default case, because raid1 segment type always stores its logs (in fact, metadata subvolumes) on-disk on the same PV(s) as the LV being mirrored. You no-longer need a third PV for the log, or to store the log in-memory.

There are two further implications. First, the command to create the mirror is simplified, because there is only a need to specify the LV to be mirrored, and the (usually one) PV on which the mirror segment will be stored: # lvconvert -m1 /dev/my_vg/my_lv /dev/my_new_pv

Second, there are a couple of space considerations. You need to have:

  • obviously, space on the mirror PV to store the copy of the original LV,
  • but also, 1 additional LE on the mirror PV, to store the log,
  • AND ALSO (and this is the point I missed for some time), 1 additional LE on the original PV, to store the log (since the log is stored on BOTH the original PV and the new PV).

Often this original-PV additional space requirement causes a problem because there is no space in the existing PV for even 1 new LE to be allocated for the log. In this case, you might get an error of the kind OP encountered, ie., 1 extents needed, but only 0 available.

The remedy, as indicated above by others, is to resize (shrink, after shrinking the filesystem) the existing LV, so there is room for the log to be allocated on the same PV. If you can't do that, you can use --type mirror to force legacy 'mirror' segment type.

3
  • 2
    How much do I need to shrink the FS and LV to make room for 1 LE?
    – bjarkef
    Commented Nov 3, 2016 at 10:12
  • 1
    @bjarkef 1LE is usually 4MiB. You can confirm this for your particular system/vg with vgs -o vg_name,vg_extent_size
    – Patrick
    Commented Nov 3, 2016 at 22:38
  • 1
    So long as the total size of your VG is at least 2x your LV +1 extent shouldn't it be possible to extend the existing LV by the one necessary extent?
    – Sammitch
    Commented Nov 9, 2016 at 20:24
0

You can actually fix the partition with one command like so:

lvreduce -l -1 --resizefs /dev/centos_bi/home¹

This will:

  1. -l -1² reduce the size of /dev/centos_bi/home by exactly 1 extent as required

  2. --resizefs reduces the file system accordingly (if necessary/possible)

That way, you do not have to worry about whether you're doing it right.

The --resizefs option makes the command fail if there is not enough space which in most cases is very unlikely (i.e. it would mean your partition is already 100% full, or very close to 100%). It may, however, fail if the filesystem you are using does not have a way to be shrunk.

After that command, the extend command works without that error:

lvconvert -m1 centos_bi/home

And now you have a RAID1 system.

IMPORTANT NOTE: the reduce command cannot be used on a partition which is currently mounted, so not on the boot drive (which is often the one you're trying to tweak). One way to tweak your boot drive is to get a live Linux running and from that instance tweak the drive(s) as required.

For this specific case, I like to use the GParted live CD. It still fits on a CD-R and it includes all the necessary commands to tweak your drives (LVM, resize2fs, fdisk, etc.)


¹ I'm not totally sure about the path that you need here in your specific case. Maybe centos_bi/home would work too. I prefer to check my drive with ls /dev/<group-name> and use one of the files there (the one that makes sense).

² Notice the minus (-) sign before the 1 (one). This means get the current size and reduce it by exactly one extent. Similarly you can grow a partition using the + sign or set the size to a specific number when not using a sign.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .