#945404 grub2-common: '/boot/grub/.background_cache.png' is not created on LUKS encrypted system

Package:
grub2-common
Source:
grub2
Description:
GRand Unified Bootloader (common files for version 2)
Submitter:
Robert
Date:
2020-11-21 18:21:03 UTC
Severity:
normal
Tags:
#945404#5
Date:
2019-11-24 12:15:25 UTC
From:
To:
Dear Maintainer,

on a newly installed system with full disk encryption, update-grub does not
create '/boot/grub/.background_cache.png'.

It looks like the command 'if is_path_readable_by_grub "${1}"; then' in line
100 in '/etc/grub.d/05_debian_theme' always returns "true", and therefore
'/boot/grub/.background_cache.png' is never created.

Regard,
Robert

#945404#10
Date:
2020-01-13 21:36:15 UTC
From:
To:
Hey!

On a system where it works, I get:

# grub-probe -t abstraction /usr/share/desktop-base/futureprototype-theme/grub/grub-16x9.png
cryptodisk
luks
gcry_rijndael
gcry_rijndael
gcry_sha1
lvm

When it doesn't work:

# grub-probe -t abstraction /usr/share/desktop-base/futureprototype-theme/grub/grub-16x9.png
lvm

As the initial reporter, the systems where it works are installed
since quite some time where the system where it doesn't work is
installed only since a few days.

Adding -vv, I see that in the working case, grub-probe says:

grub-core/kern/disk.c:196: Opening `hostdisk//dev/sda'...

But in the non-working case, I don't have that, but:

grub-core/kern/disk.c:196: Opening `hostdisk//dev/mapper/nvme0n1p3_crypt'...

Maybe Grub doesn't like NVME disks?

When it works, it starts with:

grub-probe: info: cannot open `/boot/grub/device.map': No such file or directory.
grub-probe: info: changing current directory to /dev/mapper.
grub-probe: info: /dev/mapper/zoro--vg-root is not present.
grub-probe: info: /dev/mapper/sda3_crypt is not present.
grub-probe: info: changing current directory to /dev.
grub-probe: info: changing current directory to v4l.
grub-probe: info: changing current directory to by-id.
grub-probe: info: changing current directory to by-path.
grub-probe: info: changing current directory to vboxusb.
grub-probe: info: changing current directory to 003.
grub-probe: info: changing current directory to 002.
grub-probe: info: changing current directory to 001.
grub-probe: info: changing current directory to cpu.
grub-probe: info: changing current directory to 3.
grub-probe: info: changing current directory to 2.
grub-probe: info: changing current directory to 1.
grub-probe: info: changing current directory to 0.
grub-probe: info: changing current directory to snd.
grub-probe: info: changing current directory to by-path.
grub-probe: info: changing current directory to vfio.
grub-probe: info: changing current directory to net.
grub-probe: info: changing current directory to mqueue.
grub-probe: info: changing current directory to hugepages.
grub-probe: info: changing current directory to shm.
grub-probe: info: changing current directory to zoro-vg.
grub-probe: info: changing current directory to mapper.
grub-probe: info: changing current directory to usb.
grub-probe: info: changing current directory to dri.
grub-probe: info: changing current directory to by-path.
grub-probe: info: changing current directory to disk.
grub-probe: info: changing current directory to by-uuid.
grub-probe: info: changing current directory to by-partuuid.
grub-probe: info: changing current directory to by-id.
grub-probe: info: changing current directory to by-path.
grub-probe: info: changing current directory to block.
grub-probe: info: /dev/sda3 is not present.
grub-probe: info: Looking for /dev/sda3.
grub-probe: info: /dev/sda is a parent of /dev/sda3.
grub-probe: info: /dev/sda3 starts from 1499136.
grub-probe: info: opening the device hostdisk//dev/sda.
grub-core/kern/disk.c:196: Opening `hostdisk//dev/sda'...
grub-probe: info: drive = 0.
grub-probe: info: the size of hostdisk//dev/sda is 500118192.
grub-core/kern/disk.c:196: Opening `hostdisk//dev/sda'...
grub-probe: info: drive = 0.
grub-probe: info: the size of hostdisk//dev/sda is 500118192.
grub-core/disk/diskfilter.c:136: Scanning for DISKFILTER devices on disk hostdisk//dev/sda
grub-probe: info: Scanning for DISKFILTER devices on disk hostdisk//dev/sda.
grub-probe: info: Scanning for mdraid1x devices on disk hostdisk//dev/sda.
grub-core/osdep/hostdisk.c:417: opening the device `/dev/sda' in open_device()

When it doesn't work:

grub-probe: info: cannot open `/boot/grub/device.map': No such file or directory.
grub-probe: info: changing current directory to /dev/mapper.
grub-probe: info: /dev/mapper/guybrush--vg-root is not present.
grub-probe: info: /dev/mapper/nvme0n1p3_crypt is not present.
grub-probe: info: Looking for /dev/mapper/nvme0n1p3_crypt.
grub-probe: info: /dev/mapper/nvme0n1p3_crypt is a parent of /dev/mapper/nvme0n1p3_crypt.
grub-probe: info: changing current directory to /dev.
grub-probe: info: changing current directory to v4l.
grub-probe: info: changing current directory to by-path.
grub-probe: info: changing current directory to by-id.
grub-probe: info: changing current directory to snd.
grub-probe: info: changing current directory to by-path.
grub-probe: info: changing current directory to vfio.
grub-probe: info: changing current directory to net.
grub-probe: info: changing current directory to mqueue.
grub-probe: info: changing current directory to hugepages.
grub-probe: info: changing current directory to shm.
grub-probe: info: changing current directory to guybrush-vg.
grub-probe: info: changing current directory to mapper.
grub-probe: info: /dev/mapper/nvme0n1p3_crypt is present.
grub-probe: info: Looking for /dev/mapper/nvme0n1p3_crypt.
grub-probe: info: /dev/mapper/nvme0n1p3_crypt is a parent of /dev/mapper/nvme0n1p3_crypt.
grub-probe: info: /dev/mapper/guybrush--vg-root is not present.
grub-probe: info: /dev/mapper/nvme0n1p3_crypt is present.
grub-probe: info: Looking for /dev/mapper/nvme0n1p3_crypt.
grub-probe: info: /dev/mapper/nvme0n1p3_crypt is a parent of /dev/mapper/nvme0n1p3_crypt.
grub-probe: info: changing current directory to /dev.
grub-probe: info: changing current directory to v4l.
grub-probe: info: changing current directory to by-path.
grub-probe: info: changing current directory to by-id.
grub-probe: info: changing current directory to snd.
grub-probe: info: changing current directory to by-path.
grub-probe: info: changing current directory to vfio.
grub-probe: info: changing current directory to net.
grub-probe: info: changing current directory to mqueue.
grub-probe: info: changing current directory to hugepages.
grub-probe: info: changing current directory to shm.
grub-probe: info: changing current directory to guybrush-vg.
grub-probe: info: changing current directory to mapper.
grub-probe: info: /dev/mapper/nvme0n1p3_crypt is present.
grub-probe: info: Looking for /dev/mapper/nvme0n1p3_crypt.
grub-probe: info: /dev/mapper/nvme0n1p3_crypt is a parent of /dev/mapper/nvme0n1p3_crypt.
grub-probe: info: /dev/mapper/guybrush--vg-root is not present.
grub-probe: info: opening lvmid/dtT4tK-J3GP-nQVE-od5h-kDg8-3IRn-Jik70g/VnZ8kl-b0s1-EG6T-6Ypt-tCZP-zPg9-Rz9MrF.
grub-core/kern/disk.c:196: Opening `lvmid/dtT4tK-J3GP-nQVE-od5h-kDg8-3IRn-Jik70g/VnZ8kl-b0s1-EG6T-6Ypt-tCZP-zPg9-Rz9MrF'...
grub-core/kern/disk.c:196: Opening `proc'...
grub-core/disk/diskfilter.c:136: Scanning for DISKFILTER devices on disk proc
grub-probe: info: Scanning for DISKFILTER devices on disk proc.
grub-probe: info: Scanning for mdraid1x devices on disk proc.
grub-core/kern/disk.c:420: Read out of range: sector 0xfffffffffffffff0 (attempt to read or write outside of disk `proc').
-----BEGIN PGP SIGNATURE-----

iQJGBAEBCAAwFiEErvI0h2bzccaJpzYAlaQv6DU1JfkFAl4c4swSHGJlcm5hdEBk
ZWJpYW4ub3JnAAoJEJWkL+g1NSX5wWYP/Rldo+F91m9TfSxc8tz9H+LP0Dbfmtj3
5Xs00StBXJ92oz64YRaUzStdIGofaB6y/MXB6AwBwRw8oATmZFIdLzOXCuWCNZf+
3l9PY/etgSpf3RqJpjrjX1SfOCuo1spGXge3r+wAZFVfSEPlKewkTtXrARkD8IIF
5itDZ6Q5VnWBbJo5iFde0HqPRtIGIlr831Ber/WdgWrBzRywacsJoyyckhG4NGM4
kjpqeuc2QmpAJmtqXv21AUFsIIXCLWUmPODEWHOd6lpFyloYcfQznPsyh4jMcUpZ
OSGOX1MSyJnYi/oxeB4a/xB1H6V9PLa+KuGlZvkokgnbpxGLp23gk3hE1pO6+OqF
ejrKV2qLfCSLQ8dErRbWPbXGWH3HkqSfJiYWn6n97Z4V9QOUzsFINtWGw54DTrwl
eROract47Ln0s3AUYPyC1nh/gqdaj1absRqsc/HseoLLEKhFb4+/n+ZQun5/2vFf
fSfBO/NkcZ7d3QDtI4PExEQw9wMyDCAvCaiGBLJ6BMWJzLsLjS0+3Dda553dEgzf
pJJhRubzuj4XdwgbKkGhUfcwGfFgSPX1CqI3A4R1vrHRyVwzgC0D9bLBO+B36b93
pLghjh3XQXQ0w1ksX2s68frfsYU3rExq4Wfc2CSOmTunvs6YnJqXjsoaymjd2nAx
Rk1qvRJqccni
=TpS3
-----END PGP SIGNATURE-----

#945404#15
Date:
2020-03-04 18:26:35 UTC
From:
To:
I don't believe this is a problem specific to NVMe, as my working machine has an NVMe drive.

The working installation is quite old as is the case with the reporter. The working machine was
upgraded in place from stretch. The original installation medium was:

```
# cat /var/log/installer/lsb-release
DISTRIB_ID=Debian
DISTRIB_DESCRIPTION="Debian GNU/Linux installer"
DISTRIB_RELEASE="9 (stretch) - installer build 20170112"
X_INSTALLATION_MEDIUM=cdrom
```

I am able to reproduce the breakage with two other machines which have HDD. These machines were
installed more recently (most recent was two days ago), using the same netinst image over USB:

```
# cat /var/log/installer/lsb-release
DISTRIB_ID=Debian
DISTRIB_DESCRIPTION="Debian GNU/Linux installer"
DISTRIB_RELEASE="10 (buster) - installer build 20190702+deb10u2"
X_INSTALLATION_MEDIUM=cdrom
```

All three machines are now on buster and have grub-common=2.04-5. All three machines are laptops.

Below are the lines from `grub-probe -vv -t abstraction` which are only present on the working
machine:

```
grub-probe: info: changing current directory to block.
grub-probe: info: changing current directory to by-partuuid.
grub-probe: info: changing current directory to by-uuid.
grub-probe: info: changing current directory to disk.
grub-probe: info: cheatmounted hostdisk//dev/nvme0n1,msdos5 (luks) at /dev/mapper/nvme0n1p5_crypt.
grub-probe: info: no LVM signature found.
grub-probe: info: opening the device hostdisk//dev/nvme0n1.
grub-probe: info: Partition 0 starts from 2048.
grub-probe: info: Partition 4 starts from 501760.
grub-probe: info: scanning crypto0 for LDM.
grub-probe: info: Scanning for dmraid_nv devices on disk crypto0.
grub-probe: info: Scanning for ldm devices on disk crypto0.
grub-probe: info: Scanning for ldm devices on disk hostdisk//dev/nvme0n1.
```

To summarize, it seems that grub-probe is scanning a few more /dev paths, "cheatmounted" one of the
devices, and did not find an LVM signature on one of the devices. There are also several references
to a crypto0 device.

I've reinstalled one of the machines with RC3 of the buster installation media and had the same
issue. Partitioned as "Guided full disk LVM encrypted volume" -- accepted all defaults.

#945404#20
Date:
2020-04-05 02:11:03 UTC
From:
To:

#945404#25
Date:
2020-08-12 10:53:46 UTC
From:
To:
The reason is lack of LUKS2 support. Specifically, in
grub-core/osdep/devmapper/getroot.c, grub_util_get_dm_abstraction() has:

  if (strncmp (uuid, "CRYPT-LUKS1-", 12) == 0)
    {
      grub_free (uuid);
      return GRUB_DEV_ABSTRACTION_LUKS;
    }

That will not match LUKS2-encrypted volumes, so grub-probe thinks the
filesystem will be readable.

Although grub upstream has some LUKS2 support now (see
https://savannah.gnu.org/bugs/?55093), that does not seem to cover this
part of the code yet.

#945404#30
Date:
2020-08-17 10:21:20 UTC
From:
To:
Hi,

As a nasty workaround I created /etc/grub.d/06_debian_theme_fix[0] with
hard coded content. I've got a separate LUKS1 crypted /boot, hence
"(crypto0)", update with appropriate grub device name for /boot (eg
hd0,1) and remember to delete this when a proper fix appears. If
/boot/grub/.background_cache.png resides on a LUKS2 this will not work.

Kind Regards
--
Tom

[0]
"""
#!/bin/sh
set -e

cp /usr/share/images/desktop-base/desktop-grub.png /boot/grub/.background_cache.png

cat << EOF
background_image (crypto0)/grub/.background_cache.png
set color_normal=white/black
set color_highlight=black/white
set menu_color_normal=white/black
set menu_color_highlight=black/white
EOF
"""

#945404#35
Date:
2020-11-21 18:16:17 UTC
From:
To:
Control: tags -1 +patch

ACK, you've worked out the cause of the problem here. I have a system
that shows exactly the same issue here.

Looking at the wider picture, at boot grub will not be able to read
the background graphic on lots of systems where the user has an
unencrypted /boot and so has has not configured grub to unencrypt
anything. This is the default setup for encrypted systems created
using debian-installer, so it's going to be quite common. (It's how I
found this!)

To be honest, I'm thinking we should just change the Debian theme
setup here to *always* copy the background image to
/boot/grub/.background_cache.png and use it from there. Not all users
need it, but it makes the logic simpler and more consistent here. It's
only a single graphic that's copied into /boot, after all...

@Colin: thoughts?

Patch attached for review.