LVM2 Fixes for Arch Linux

Alright, so I run Xen on Arch Linux, and I use LVM to manage virtual disks, because snapshots take the pain out of life. There's been a longstanding problem in the hand off from initrd to systemd where not every logical volume is activated at boot, and lvmetad1) will end up running twice with both hanging– in an aggravating but also amusing lock race– when there's a large number of logical volumes.

There was a bug on it, but the bug report suggested that fixes had been implemented and I felt like I was on my own. From there I decided that I wouldn't include root in the LVM, and older systems would just have need intervention on boot. Which is fine– the two affected systems are on my desk or in a datacenter, so inadvertent reboots are rare.

Well, today I decided to patch for Intel-horror, and I really looked at the bug report to fix it once and for all.

It turned out to be absurdly simple.

The Fix

Open up /usr/lib/initcpio/hooks/lvm2 in $EDITOR.

Look for this:

# We are suffering a race condition in non-systemd initramfs: If lvmetad is
# killed before pvscan processes finish we have stale processes and
# uninitialized physical volumes. So wait for pvscan processes to finish.
# Break after 10 seconds (50*0.2s) to avaid infinite loop.
run_latehook() {
    local i=50
 
    while pgrep -f pvscan >/dev/null 2>/dev/null && [ $i -gt 0 ]; do
        sleep 0.2
        i=$((i - 1))
    done
}

Change that there i from 50 to 300, and all is well. Booting up currently takes much less than that, so I've got room to grow. I think the max I've ever had was something like 40 logical volumes, so I don't expect to run into that problem again until they update mkinitcpio and I forget to patch it..

So, one number. Awesome. I spoke up on the bug mentioned above, but since I'm a pretty rare case, I don't know that it'll get fixed. So I'm documenting it here for the other person who has this problem. Wherever you are.

1)
needed for snapshots