Subject: Re: bug#29662: 'guix gc' as user makes system unbootable

From: Martin Castillo <[email-masked]>
Date: Mon, 18 Dec 2017 15:18:20 +0100

Hi,

On 18.12.2017 10:54, Ludovic Courtès wrote:
> Hi Martin,
> 
> Martin Castillo <[email-masked]> skribis:
> 
>> I had a similar situation today. guix gc removed the grub background png
>> from the store. the one, that was used by /boot/grub/grub.cfg. the boot
>> menu then had a black and blue background. rebuilding the configuration
>> refetched the background image, but guix gc removed it again.
> 
> Normally the current ‘grub.cfg’ is a GC root, which prevents the
> background image and other items from being deleted:
> 
> --8<---------------cut here---------------start------------->8---
> $ ls -l /var/guix/gcroots/bootcfg 
> lrwxrwxrwx 1 root root 52 Dec  7 23:21 /var/guix/gcroots/bootcfg -> /gnu/store/2bnr3z8q0rpvdc9zrshhyq4znx7jpzq6-grub.cfg
> $ guix gc --references /var/guix/gcroots/bootcfg 
> /gnu/store/i3l4cv1mz30l4jafbghmbgmafc0xb38h-grub-image.png
> /gnu/store/j5x3dfappv9fdp7h46kgm8wxjbcqv5r6-system
> /gnu/store/qkhhqqkr0lkczwqwbp95gx4s8v0pjj41-raw-initrd
> /gnu/store/xqfpwxbghvi3h85pfji6kdzw7db2sgxz-grub-2.02
> /gnu/store/zi4awdcvrlj0fp74yb0y4ngah4qmcri0-linux-libre-4.14.4
> $ sudo diff /var/guix/gcroots/bootcfg /boot/grub/grub.cfg 
> $ echo $?
> 0
> --8<---------------cut here---------------end--------------->8---
> 
> Could you check if this is the case on your machine?
> 
> Thanks,
> Ludo’.

Like I said, I cannot reproduce currently. guix gc --list-dead doesn't
mention grub files anymore.

below you see what I wrote while doing stuff. it starts with a missing
bootcfg, then doing stuff and at '--- end' I start again with a bootcfg.

--- start missing bootcfg

$ ls /var/guix/gcroots
auto/  booted-system  current-system  profiles

I don't have bootcfg in there.

$ guix --version
guix (GNU Guix) 02345c963e1e8a45afcdf5acb80fca4538244b36

I remember something strange: when I reconfigured my system, the 'old
generations' menu in grub kept having 11 entrys. It overwrote e.g. entry
7 and entry 8 then was the oldest one. I don't _remember_ switching to
an older entry, which would explain that, but that seems to be the only
explanation. Maybe the overwriting of an older generation made the grub
files dead? I often, but not always, use --no-bootloader.

While writing, I try to switch to an older generation, reconfigure (to
overwrite one generation) and see what happens.
the switching did something surprising:
$ sudo guix system switch-generation 5
substitute: updating list of substitutes from
'https://berlin.guixsd.org'... 100.0%
substitute: updating list of substitutes from
'https://mirror.hydra.gnu.org'... 100.0%
The following derivation will be built:
   /gnu/store/7x9dz7vfzpkvinl5h8bwh0p6x3shcwmy-grub.cfg.drv
14,1 MB will be downloaded:
   /gnu/store/d8gkn84yqacjr80pzicz1ka3y2s1f2x0-guile-2.2.2
   /gnu/store/1jcq4fc07bngc5q1cy44j0glv1vrjz52-libffi-3.2.1
   /gnu/store/akc3nsnksgv6256jm1ariljb1c7zh8x2-libgc-7.6.0
   /gnu/store/kpxi8h3669afr9r1bgvaf9ij3y4wdyyn-bash-minimal-4.4.12
   /gnu/store/lh1hwa0i061lwzyvk9brcsjb6h1gyhrg-ncurses-6.0
....
# error about grub-install failing, because ext2 doesn't support embedding
$ sudo grub-install --force /dev/sda3

why does guix need to download something to get to an old configuration?
those things should still be in the store!

then reconfiguring using my config from the latest generation downloadad
again things. This might be because updated guix since I build that
generation. but switching to an older generation should not need to do
that. that makes rollbacks not real rollbacks, right?

guix-gc still looks fine.
the youngest generation is now 6. (side note: in grub.cfg, the date of
the 6th generation is still the same. I remembered something different
above. is this wanted behaviour? I just realized, that a system
configuration, that depends on grub.cfg. is not deterministic from the
config.scm. It depends on prior entries in grub.cfg. is that the reason
there is (or should be) bootcfg in /var/guix/gcroots ?)

reboot. guix gc --list-dead looks good.

--- end

somehow, the grub.cfg now has the dates updated.

$ ls -l /var/guix/gcroots/bootcfg
lrwxrwxrwx 1 root root 52 18. Dez 13:36 /var/guix/gcroots/bootcfg ->
/gnu/store/d3izafd91x81w0bpksyy8s3y09kvy463-grub.cfg
$ guix gc --references /var/guix/gcroots/bootcfg
/gnu/store/i3l4cv1mz30l4jafbghmbgmafc0xb38h-grub-image.png
/gnu/store/xqfpwxbghvi3h85pfji6kdzw7db2sgxz-grub-2.02
$ diff /var/guix/gcroots/bootcfg /boot/grub/grub.cfg
see diff [1] below

let's switch to the newest generation and try from there:

# guix system switch-generation 14
substitute: updating list of substitutes from
'https://berlin.guixsd.org'... 100.0%
substitute: updating list of substitutes from
'https://mirror.hydra.gnu.org'... 100.0%
The following derivation will be built:
   /gnu/store/31bxx2nwp3lxzdkcy8bmybabfl1pi0af-grub.cfg.drv
Von Generation »10« zu »14« gewechselt
$ diff /var/guix/gcroots/bootcfg /boot/grub/grub.cfg
## no-output, grub.cfg has still the same content->
/var/guix/gcroots/bootcfg changed
# guix system reconfigure confs/config.scm
## mentions expected grub error
$ diff /var/guix/gcroots/bootcfg /boot/grub/grub.cfg
see diff [2]

it does not seem to update /var/guix/gcroots/bootcfg.
and bootcfg somehow lists the generation number in the default entry.

what's going on here?

Martin

diff [1]:
44c44
< menuentry "GNU with Linux-Libre 4.14.6 (beta) (#5, 2017-12-16 23:35)" {
---
> menuentry "GNU with Linux-Libre 4.14.6 (beta)" {
46c46
<   linux
/gnu/store/qyp42kaw836b5z5j5zaw9sgqw4q05zw4-linux-libre-4.14.6/bzImage
--root=guix-root --system=/var/guix/profiles/system-5-link
--load=/var/guix/profiles/system-5-link/boot
---
>   linux
/gnu/store/qyp42kaw836b5z5j5zaw9sgqw4q05zw4-linux-libre-4.14.6/bzImage
--root=guix-root
--system=/gnu/store/qhd80larmjzlbg3i7xrcls808bhk9ixi-system
--load=/gnu/store/qhd80larmjzlbg3i7xrcls808bhk9ixi-system/boot
71c71,76
< menuentry "GNU with Linux-Libre 4.14.6 (beta) (#6, 2017-12-17 01:18)" {
---
> menuentry "GNU with Linux-Libre 4.14.6 (beta) (#5, 2017-12-16 23:35)" {
>   search --label --set guix-root
>   linux
/gnu/store/qyp42kaw836b5z5j5zaw9sgqw4q05zw4-linux-libre-4.14.6/bzImage
--root=guix-root --system=/var/guix/profiles/system-5-link
--load=/var/guix/profiles/system-5-link/boot
>   initrd /gnu/store/3ls7xa16y2pghn64vw92wyns83vz1fl6-raw-initrd/initrd
> }
> menuentry "GNU with Linux-Libre 4.14.6 (beta) (#6, 2017-12-18 13:56)" {
76c81
< menuentry "GNU with Linux-Libre 4.14.6 (beta) (#7, 2017-12-17 01:25)" {
---
> menuentry "GNU with Linux-Libre 4.14.6 (beta) (#7, 2017-12-18 14:12)" {

diff [2]:
44c44
< menuentry "GNU with Linux-Libre 4.14.6 (beta) (#14, 2017-12-17 22:24)" {
---
> menuentry "GNU with Linux-Libre 4.14.6 (beta)" {
46c46
<   linux
/gnu/store/qyp42kaw836b5z5j5zaw9sgqw4q05zw4-linux-libre-4.14.6/bzImage
--root=guix-root --system=/var/guix/profiles/system-14-link
--load=/var/guix/profiles/system-14-link/boot
---
>   linux
/gnu/store/qyp42kaw836b5z5j5zaw9sgqw4q05zw4-linux-libre-4.14.6/bzImage
--root=guix-root
--system=/gnu/store/pcmbb1xk3gc0qk68k5kgxch89yy9ac50-system
--load=/gnu/store/pcmbb1xk3gc0qk68k5kgxch89yy9ac50-system/boot
113a114,123
>   initrd /gnu/store/3ls7xa16y2pghn64vw92wyns83vz1fl6-raw-initrd/initrd
> }
> menuentry "GNU with Linux-Libre 4.14.6 (beta) (#14, 2017-12-17 22:24)" {
>   search --label --set guix-root
>   linux
/gnu/store/qyp42kaw836b5z5j5zaw9sgqw4q05zw4-linux-libre-4.14.6/bzImage
--root=guix-root --system=/var/guix/profiles/system-14-link
--load=/var/guix/profiles/system-14-link/boot
>   initrd /gnu/store/3ls7xa16y2pghn64vw92wyns83vz1fl6-raw-initrd/initrd
> }
> menuentry "GNU with Linux-Libre 4.14.6 (beta) (#15, 2017-12-18 14:58)" {
>   search --label --set guix-root
>   linux
/gnu/store/qyp42kaw836b5z5j5zaw9sgqw4q05zw4-linux-libre-4.14.6/bzImage
--root=guix-root --system=/var/guix/profiles/system-15-link
--load=/var/guix/profiles/system-15-link/boot

-- 
GPG: 7FDE 7190 2F73 2C50 236E  403D CC13 48F1 E644 08EC