Bug 1: GRUB2 parser bug with lvmcache

⚠️ WARNING: It’s known that my patch does not handle escape character (\\) correctly. Be careful!


bug reproduction:


set -xe

dd if=/dev/zero of=raw1 bs=100M count=1
dd if=/dev/zero of=raw2 bs=100M count=1
dd if=/dev/zero of=raw3 bs=100M count=1

losetup /dev/loop1 raw1
losetup /dev/loop2 raw2
losetup /dev/loop3 raw3

# mirror
pvcreate /dev/loop1 /dev/loop2
vgcreate vgtest /dev/loop1 /dev/loop2

lvcreate -n lvmirror -L 50M --type mirror vgtest
mkfs.ext4 /dev/vgtest/lvmirror

# now grub-probe works properly
grub-probe --device /dev/mapper/vgtest-lvmirror

# cache
pvcreate /dev/loop3
vgcreate vgcache /dev/loop3

lvcreate -L 20M -n mcache_meta vgcache
lvcreate -L 40M -n mcache vgcache
lvconvert --type cache-pool --poolmetadata vgcache/mcache_meta --cachemode writethrough -c 1M vgcache/mcache

# merge and set policy
vgmerge vgtest vgcache
lvchange --cachepolicy mq --cachesettings 'migration_threshold=2048 random_threshold=4' vgtest/mcache

# now grub-probe fails with "error: unknown node 'lvmirror_mimage_0'."
grub-probe --device /dev/mapper/vgtest-lvmirror || true

# cleanup
vgremove vgtest
pvremove /dev/loop1 /dev/loop2 /dev/loop3
losetup -d /dev/loop1 /dev/loop2 /dev/loop3
rm -f raw1 raw2 raw3
sudo apt build-dep grub2

# Update debian changelog
[email protected] dch --local taoky
# Build
dpkg-buildpackage -b -rfakeroot -us -uc
apt-mark hold grub-common

Bug 2: Debian bug #987008

Grub fails to find LVM volume after previous LV rename”

bug reproduction (modified from


set -e
losetup -d /dev/loop1 || dmsetup remove_all

rm -f raw1
dd if=/dev/zero of=raw1 bs=1 count=0 seek=100G
losetup /dev/loop1 raw1
pvcreate /dev/loop1
vgcreate vgtest /dev/loop1
for ((n=0;n<100;n++)); do
  lvcreate -L 100m -n lv$n vgtest


mkfs.ext4 $path

for ((n=0;n<100;n++)); do
  for p in r rw; do
    lvchange -p $p $path >& /dev/null
    if grub-probe -d $path -t fs |& grep -q 'disk.*not found'; then
      set -x
      grub-probe -d $path -t fs || true

# cleanup
pvremove --force --force /dev/loop1 || true
dmsetup remove_all
rm -f raw1

Note: This bug exists when there are enough LVs.

patch applied in 2.04-20taoky2_amd64