Lvm – lvcreate can’t take a snapshot; “Unable to create new logical volume with no extents” but target volume filesystem has plenty of space

lvm

Long story short: I'm trying to create a snapshot of a volume using lvcreate using the following command:

lvcreate -l 100%FREE -s -n SNAPSHOT /dev/volume-group/data

I get an error saying "Unable to create new logical volume with no extents." After some digging, I discovered that the volume group in question has no free space according to vgdisplay, even though df -h shows plenty of space available.

vgdisplay output:

--- Volume group ---
VG Name               volume-group
System ID             
Format                lvm2
Metadata Areas        2
Metadata Sequence No  8
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               1
Max PV                0
Cur PV                2
Act PV                2
VG Size               39.99 GiB
PE Size               4.00 MiB
Total PE              10238
Alloc PE / Size       10238 / 39.99 GiB
Free  PE / Size       0 / 0   
VG UUID               fP36on-3yzf-c8i2-bOzO-4Htf-txUa-k3y8p9

df -h output:

Filesystem                            Size  Used Avail Use% Mounted on
udev                                  7.5G     0  7.5G   0% /dev
tmpfs                                 1.5G   73M  1.5G   5% /run
/dev/xvda1                             62G  2.2G   60G   4% /
tmpfs                                 7.5G     0  7.5G   0% /dev/shm
tmpfs                                 5.0M     0  5.0M   0% /run/lock
tmpfs                                 7.5G     0  7.5G   0% /sys/fs/cgroup
tmpfs                                 1.5G     0  1.5G   0% /run/user/1000
/dev/mapper/volume--group--data        40G   17G   24G  43% /mnt/mysql

I think what I'd need to do at this point is change the size of the logical volume containing /dev/volume-group/data to something a little bit larger than the current disk usage, take my snapshot, and then set it back to 40GB? But I'm not sure if that's the proper procedure or if I should be doing something else.

This is all happening in an AWS EC2 instance and the volume I'm trying to take a snapshot of is an EBS volume housing MySQL database data, in case those details matter.

Best Answer

LVM extent allocation and filesystems on top of logical volumes have no significant relationship. LVM commands operate on LVM, and don't care what you use logical volumes for.

You're trying to make a snapshot logical volume, which will require free extents in your volume group to create - a snapshot is really just another logical volume that backs up data as changes are made to the original volume.

Looking at this relevant line:

Free PE / Size 0 / 0

This says you don't have any room left over on your volume group to make another logical volume of any kind, which includes snapshots. One approach would be to shrink a logical volume to free up some extents on this VG. Shrinking your LV involves shrinking your filesystem first, as shrinking a logical volume without doing so would truncate the end of your filesystem and trash it. Thankfully, LVM can call out to most filesystem utilities to ensure a shrink happens first for the new target LV size - but make sure this is happening before you run with it.

Alternatively, you can resize an EBS volume and give yourself some additional physical extents. That's the easiest route, especially if you're using XFS which can't ever shrink.