Subject: Re: bug#29312: GRUB with multiple partitions with identical bzImage

From: [email-masked] (Ludovic Courtès)
Date: Thu, 16 Nov 2017 15:30:22 +0100

Hey Vagrant,

Vagrant Cascadian <[email-masked]> skribis:

> menuentry "GNU with Linux-Libre 4.13.12 (beta)" {
>     search --file --set /gnu/store/q9q8y9rh3jw1qcx6bic1v18qag80z74a-linux-libre-4.13.12/bzImage
>     linux /gnu/store/q9q8y9rh3jw1qcx6bic1v18qag80z74a-linux-libre-4.13.12/bzImage \
>           --root=/dev/mapper/cryptic \
>           --system=/gnu/store/bsxnm36vvx2wxc9h3q5l8b5286gw75hr-system \
>           --load=/gnu/store/bsxnm36vvx2wxc9h3q5l8b5286gw75hr-system/boot \
>     initrd /gnu/store/7w9dzb6b9vb9gzj61zyqsg4zg6ys4hgb-raw-initrd/initrd
> }
>
> I had two partitions, one on (hd0,msdos4) and one on (crypto0) which
> both contained
> /gnu/store/q9q8y9rh3jw1qcx6bic1v18qag80z74a-linux-libre-4.13.12/bzImage,
> and the search command was returning the one on (hd0,msdos4), and thus
> setting root (hd0,msdos4).

Oh.

> Unfortunately,
> /gnu/store/7w9dzb6b9vb9gzj61zyqsg4zg6ys4hgb-raw-initrd/initrd was only
> present on the (crypto0) partition.
>
> So, when it booted, I would get the confusing error message:
>
>   error: file `/gnu/store/7w9dzb6b9vb9gzj61zyqsg4zg6ys4hgb-raw-initrd/initrd' not found
>
> And then a kernel panic, as there was no initrd...
>
>
> The suggestion from the #grub folks was to use a UUID or some other more
> reliable method of finding the correct device to load the kernel and
> initrd files from.

Indeed.  You can force GuixSD to use a file system label or a UUID by
declaring your file system with a label/UUID.  So you would write:

  (file-system
    ;; …
    (mount-point "/")
    (title 'uuid)
    (device (uuid "f549617a-07b0-430a-9723-36c43b98c748")))

or:

  (file-system
    ;; …
    (mount-point "/")
    (title 'label)
    (device "my-root"))

When you do that, the generated grub.cfg searches the file system by
label/UUID, which should be more reliable as you write.

Would that work for you?

> A quick workaround might be to also add a search line for the initrd
> after loading the kernel:
>
> menuentry "GNU with Linux-Libre 4.13.12 (beta)" {
>     search --file --set /gnu/store/q9q8y9rh3jw1qcx6bic1v18qag80z74a-linux-libre-4.13.12/bzImage
>     linux /gnu/store/q9q8y9rh3jw1qcx6bic1v18qag80z74a-linux-libre-4.13.12/bzImage \
>           --root=/dev/mapper/cryptic \
>           --system=/gnu/store/bsxnm36vvx2wxc9h3q5l8b5286gw75hr-system \
>           --load=/gnu/store/bsxnm36vvx2wxc9h3q5l8b5286gw75hr-system/boot \
>     search --file --set /gnu/store/7w9dzb6b9vb9gzj61zyqsg4zg6ys4hgb-raw-initrd/initrd
>     initrd /gnu/store/7w9dzb6b9vb9gzj61zyqsg4zg6ys4hgb-raw-initrd/initrd
> }

The assumption is that there’s only one /gnu/store that matters and that
it contains both the kernel and the initrd.  So I think the real
solution is for the first ‘search’ command to be appropriate.

Thanks for your report!

Ludo’.