The lvconvert command fails to create LVM mirror

This document (7023879) is provided subject to the disclaimer at the end of this document.

Environment

SUSE Linux Enterprise Server 15
SUSE Linux Enterprise Server 12 Service Pack 4 (SLES 12 SP4)
SUSE Linux Enterprise Server 12 Service Pack 3 (SLES 12 SP3)

Situation

When attempting to convert an LVM logical volume (LV) to a mirrored volume, the following errors were observed:
sudo lvconvert -m1 /dev/vg/vol1 /dev/vdb
  Insufficient free space: 1 extents needed, but only 0 available

sudo lvconvert -m1 --type mirror /dev/vg/vol1 /dev/vdb
  Insufficient suitable allocatable extents for logical volume : 2559 more required
  Unable to allocate extents for mirror(s).

The physical volume (PV) and volume group (VG) configuration follows:
sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda
  VG Name               vg
  PV Size               10.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2559
  Free PE               0 <====================================
  Allocated PE          2559
  PV UUID               AOjXRz-FsVF-Mhw2-LHcW-Z2l9-C2U2-jazlAO
  
  --- Physical volume ---
  PV Name               /dev/vdb
  VG Name               vg
  PV Size               10.00 GiB / not usable 4.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              2559
  Free PE               2559
  Allocated PE          0
  PV UUID               7bjW1S-JVW1-8sUc-OISW-NIGq-sbPq-nT6aRB

sudo vgdisplay
  --- Volume group ---
  VG Name               vg
  System ID            
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               19.99 GiB
  PE Size               4.00 MiB
  Total PE              5118
  Alloc PE / Size       2559 / 10.00 GiB
  Free  PE / Size       2559 / 10.00 GiB
  VG UUID               2ZwK4Z-uhc7-U0tW-zxZ1-uMgs-0Utb-7Kjfkd
  
sudo lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  vol1 vg   -wi-a----- 10.00g                                                   

Resolution

There are three possible options to successfully create the LVM mirror.

Option 1 - Free up at least one extent on the originating PV (/dev/vda in this case)
Option 2 - Use the legacy mirror segment type
Option 3 - Backup, remove, create a new mirror and restore

Each option is explored below.

NOTE: Before proceeding, please backup all your data.

Option 1 - Free up at least one extent on the originating PV (/dev/vda in this case)
Advantages:  Continues to use the new raid1 segment type
Disadvantages:  Time consuming. Some filesystems cannot be reduced.

1. Shrink the filesystem
sudo grep vol1 /proc/mounts
/dev/mapper/vg-vol1 /mnt ext4 rw,relatime,data=ordered 0 0

sudo df /mnt
Filesystem          1K-blocks  Used Available Use% Mounted on
/dev/mapper/vg-vol1  10186040 23028   9622548   1% /mnt

sudo umount /dev/vg/vol1

sudo e2fsck -f /dev/vg/vol1
e2fsck 1.42.11 (09-Jul-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg/vol1: 11/655360 files (0.0% non-contiguous), 79663/2620416 blocks

sudo resize2fs -M /dev/vg/vol1
resize2fs 1.42.11 (09-Jul-2014)
Resizing the filesystem on /dev/vg/vol1 to 46096 (4k) blocks.
The filesystem on /dev/vg/vol1 is now 46096 blocks long.

sudo mount /dev/vg/vol1 /mnt

sudo df /mnt
Filesystem          1K-blocks  Used Available Use% Mounted on
/dev/mapper/vg-vol1     49184  5136     31148  15% /mnt

2. Reduce the LV size by 1 extent, so it can be used for the mirror log
sudo lvreduce -l-1 /dev/vg/vol1
  WARNING: Reducing active and open logical volume to 9.99 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vol1? [y/n]: n
  Logical volume vol1 NOT reduced

sudo umount /dev/vg/vol1

sudo vgchange -an vg
  0 logical volume(s) in volume group "vg" now active

sudo lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  vol1 vg   -wi------- 10.00g                                                   

sudo lvreduce -l-1 /dev/vg/vol1
  Size of logical volume vg/vol1 changed from 10.00 GiB (2559 extents) to 9.99 GiB (2558 extents).
  Logical volume vol1 successfully resized

NOTE: There is now one "Free PE" available on /dev/vda.
sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda
  VG Name               vg
  PV Size               10.00 GiB / not usable 4.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              2559
  Free PE               1 <===================================
  Allocated PE          2558
  PV UUID               AOjXRz-FsVF-Mhw2-LHcW-Z2l9-C2U2-jazlAO
  
  --- Physical volume ---
  PV Name               /dev/vdb
  VG Name               vg
  PV Size               10.00 GiB / not usable 4.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              2559
  Free PE               2559
  Allocated PE          0
  PV UUID               7bjW1S-JVW1-8sUc-OISW-NIGq-sbPq-nT6aRB

3. Convert the LV to a mirrored logical volume
sudo lvconvert -m1 /dev/vg/vol1 /dev/vdb

sudo vgchange -ay vg
  1 logical volume(s) in volume group "vg" now active

sudo lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  vol1 vg   rwi-a-r--- 9.99g                                    100.00          

4. Resize the filesystem to use all available /dev/vg/vol1 device space
sudo e2fsck -f /dev/vg/vol1
e2fsck 1.42.11 (09-Jul-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg/vol1: 11/16384 files (0.0% non-contiguous), 35084/46096 blocks

sudo resize2fs /dev/vg/vol1
resize2fs 1.42.11 (09-Jul-2014)
Resizing the filesystem on /dev/vg/vol1 to 2619392 (4k) blocks.
The filesystem on /dev/vg/vol1 is now 2619392 blocks long.

sudo mount /dev/vg/vol1 /mnt
sudo df /mnt
Filesystem          1K-blocks  Used Available Use% Mounted on
/dev/mapper/vg-vol1  10181944 23028   9618836   1% /mnt


Option 2 - Use the legacy mirror segment type
Advantages:  You can immediately mirror your existing LV. The mirror segment type allows you to store the mirror log in memory (core), on a third disk or mirrored on both PVs.
Disadvantages:  Raid1 is the default mirror segment type for LVM. You are no longer using the default.

Since the LV uses all the VG space, there is no room on a VG disk for the mirror log. In this example, you can use system memory for the mirror log using the option --corelog, which is the same as --mirrorlog core.

1. Create the mirror using system memory for the mirror log
sudo lvconvert -m1 --type mirror --corelog /dev/vg/vol1 /dev/vdb
  vg/vol1: Converted: 25.0%
  vg/vol1: Converted: 50.0%
  vg/vol1: Converted: 75.0%
  vg/vol1: Converted: 100.0%

sudo lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  vol1 vg   mwi-a-m--- 10.00g                                    100.00         
If you want a persistent mirror log, you need to add an additional device to the VG to store the mirror log. In this case, /dev/vdc has been added for the mirror log.

1. Add a third PV device for the persistent mirror log
sudo pvs
  PV         VG   Fmt  Attr PSize    PFree  
  /dev/vda   vg   lvm2 a--    10.00g       0
  /dev/vdb   vg   lvm2 a--    10.00g   10.00g
  /dev/vdc   vg   lvm2 a--  1020.00m 1020.00m

sudo vgs
  VG   #PV #LV #SN Attr   VSize  VFree
  vg     3   1   0 wz--n- 20.99g 10.99g

sudo lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  vol1 vg   -wi-a----- 10.00g                                                   
2. Create the mirror using the third PV
sudo lvconvert -m1 -b --type mirror --mirrorlog disk /dev/vg/vol1 /dev/vdb /dev/vdc
  Logical volume vol1 converted.

sudo lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log       Cpy%Sync Convert
  vol1 vg   mwi-a-m--- 10.00g                                vol1_mlog 100.00           


Option 3 - Backup, remove, create a new mirror and restore
Advantages:  You can use the default raid1 segment type. You have one extent on each PV that stores the mirror metadata and logs.
Disadvantages:  Time consuming

1. Backup /dev/vg/vol1
2. Remove the LV
sudo lvremove /dev/vg/vol1
Do you really want to remove active logical volume vol1? [y/n]: y
  Logical volume "vol1" successfully removed

sudo pvs
  PV         VG   Fmt  Attr PSize  PFree
  /dev/vda   vg   lvm2 a--  10.00g 10.00g
  /dev/vdb   vg   lvm2 a--  10.00g 10.00g
3. Create the new mirrored LV that uses all available VG space
sudo lvcreate -n vol1 -m1 -l+100%FREE vg
  Logical volume "vol1" created.

sudo lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  vol1 vg   rwi-a-r--- 9.99g                                    100.00         
4. Format /dev/vg/vol1 with the desired filesystem
5. Restore backed up files to /dev/vg/vol1

Cause

The default mirror segment type for lvm2 is raid1. The raid1 type stores its logs on the same disk PV(s) as the LV being mirrored. This makes --corelog and --mirrorlog [disk|core|mirrored] options irrelevant, but they are relevant with the legacy mirror segment type. In this case the originating PV lacked 1 extent, as shown in the "Free PE" line of pvdisplay.
sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda
  VG Name               vg
  PV Size               10.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2559
  Free PE               0 <==================================
  Allocated PE          2559
  PV UUID               AOjXRz-FsVF-Mhw2-LHcW-Z2l9-C2U2-jazlAO

Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.

  • Document ID:7023879
  • Creation Date: 14-May-2019
  • Modified Date:03-Mar-2020
    • SUSE Linux Enterprise Server

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

Join Our Community

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.


SUSE Customer Support Quick Reference Guide SUSE Technical Support Handbook Update Advisories
Support FAQ

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.

Go to Customer Center