Subject: bug#36942: Reconfigure broke GRUB

From: [email-masked] (Jakob L. Kreuze)
Date: Wed, 14 Aug 2019 15:50:00 -0400

Hi ison,

ison <[email-masked]> writes:

> On Wed, Aug 07, 2019, Jakob L. Kreuze wrote:
>> I'll continue to investigate; perhaps I'll be able to reproduce if I
>> copy your exact partition scheme in the virtual machine. I'm sorry that
>> you had to go through that whole 'guix init' spiel again.
>
> No problem, it's a backup machine anyway, I've held off on updating
> my main (but it doesn't use efi so maybe I can). If this is a
> problem that only I'm having and nobody else then I wonder if a
> fresh install would fix it. Although I'm surprised nobody else seems to be experiencing it.
>
> The only unusual thing I did before it broke is that I tried to consolidate my configs from 2 machines into a single one by adding case statements.
> For example at the top I had (define local-profile 'laptop)
> and then my bootloader was something like:
> (bootloader (bootloader-configuration
>              (case local-profile
>               ((desktop)
>                (bootloader grub-bootloader)
>                ...)
>               ((laptop)
>                (bootloader grub-efi-bootloader)
>                ...))))
>
> But I've since reverted back to my old config for all the subsequent
> "guix init" and reconfigures I've done, so it seems unlikely to be the
> cause but I thought I'd mention it anyway.
> Maybe having a BIOS boot partition on /dev/sda1 even though I'm using
> efi is somehow messing it up?

After some further research, I was able to create a virtual machine with
the partition scheme and bootloader configuration that you described.

;; This is an operating system configuration template
;; for a "bare bones" setup, with no X11 display server.

(use-modules (gnu))
(use-service-modules networking ssh)
(use-package-modules screen)

(operating-system
  (host-name "komputilo")
  (timezone "Europe/Berlin")
  (locale "en_US.utf8")

  ;; Boot in "legacy" BIOS mode, assuming /dev/sdX is the
  ;; target hard disk, and "my-root" is the label of the target
  ;; root file system.
  (bootloader (bootloader-configuration
                (bootloader grub-efi-bootloader)
                (target "/boot/efi")))
  (file-systems (cons* (file-system
                         (device "/dev/sda2")
                         (mount-point "/boot/efi")
                         (type "vfat"))
                       (file-system
                         (device (file-system-label "my-root"))
                         (mount-point "/")
                         (type "ext4"))
                       %base-file-systems))

  ;; This is where user accounts are specified.  The "root"
  ;; account is implicit, and is initially created with the
  ;; empty password.
  (users (cons (user-account
                (name "alice")
                (comment "Bob's sister")
                (group "users")

                ;; Adding the account to the "wheel" group
                ;; makes it a sudoer.  Adding it to "audio"
                ;; and "video" allows the user to play sound
                ;; and access the webcam.
                (supplementary-groups '("wheel"
                                        "audio" "video")))
               %base-user-accounts))

  ;; Globally-installed packages.
  (packages (cons screen %base-packages))

  ;; Add services to the baseline: a DHCP client and
  ;; an SSH server.
  (services (append (list (service dhcp-client-service-type)
                          (service openssh-service-type
                                   (openssh-configuration
                                    (port-number 2222))))
                    %base-services)))

However, I still cannot seem to reproduce this issue with the most
recent master. Everything boots fine. I've extracted the bootloader
installation "script", and everything appears to be normal to me.

(begin
  (use-modules (gnu build bootloader)
               (gnu build install)
               (guix build utils)
               (guix store)
               (guix utils)
               (ice-9 binary-ports)
               (srfi srfi-34)
               (srfi srfi-35))
  (let* ((gc-root (string-append "/" %gc-roots-directory "/bootcfg"))
         (temp-gc-root (string-append gc-root ".new")))
    (switch-symlinks temp-gc-root "/gnu/store/xlb81742i5sb4cdmidfhabprc17ijwck-grub.cfg")
    (install-boot-config "/gnu/store/xlb81742i5sb4cdmidfhabprc17ijwck-grub.cfg" "/boot/grub/grub.cfg" "/")
    (when #t
      (catch #t
        (lambda ()
          ((lambda (bootloader efi-dir mount-point)
             (let ((grub-install (string-append bootloader "/sbin/grub-install"))
                   (install-dir (string-append mount-point "/boot"))
                   (target-esp (if (file-exists? (string-append mount-point efi-dir))
                                   (string-append mount-point efi-dir)
                                   efi-dir)))
               (setenv "GRUB_ENABLE_CRYPTODISK" "y")
               (invoke/quiet grub-install "--boot-directory" install-dir "--bootloader-id=Guix" "--efi-directory" target-esp)))
           "/gnu/store/8hbf54vl9hfgbnfigbqcf0di1agajr88-grub-efi-2.04" "/boot/efi" "/"))
        (lambda args
          (delete-file temp-gc-root)
          (apply throw args))))
    (rename-file temp-gc-root gc-root)))

To the rest of guix -- I would really appreciate some help here. I'm not
sure what else I can do for working on this bug report.

Regards,
Jakob