Bug 229770 - loader.efi: 'rootdev' environment variable ignored
Summary: loader.efi: 'rootdev' environment variable ignored
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
Keywords: patch
Depends on:
Reported: 2018-07-14 13:03 UTC by Masachika ISHIZUKA
Modified: 2022-05-10 17:42 UTC (History)
5 users (show)

See Also:

patch for loader.efi 'rootdev' environment variable (506 bytes, patch)
2018-07-16 12:40 UTC, Masachika ISHIZUKA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Masachika ISHIZUKA 2018-07-14 13:03:48 UTC
When I set 'rootdev' environment variable in loader prompt, loader ignores the 'rootdev' environment variable and boots the OS according to the 'currdev' environment variable.
I want to use rEFInd as follows.

menuentry FreeBSD-release {
        loader /EFI/freebsd/loader.efi
        options "rootdev=disk0p5"
        icon /EFI/refind/icons/os_freebsd-release.png

menuentry FreeBSD-current {
        loader /EFI/freebsd/loader.efi
        options "rootdev=disk0p13"
        icon /EFI/refind/icons/os_freebsd-current.png
Comment 1 Warner Losh freebsd_committer 2018-07-14 19:21:23 UTC
loader.efi assumes rootdev is never set and always generates its own. That's bogus, as you point out.
Comment 2 Masachika ISHIZUKA 2018-07-16 12:40:37 UTC
Created attachment 195171 [details]
patch  for loader.efi 'rootdev' environment variable

After applying this patch, setting the 'rootdev' environment variable starts OS from the 'rootdev' disk.
And rEFInd works well with this loader.efi.
Comment 3 Masachika ISHIZUKA 2018-07-17 07:31:23 UTC
(In reply to Masachika ISHIZUKA from comment #2)

And I confirmed that I can start zfs as follows using rEFInd.

menuentry FreeBSD-zfs {
        loader /EFI/freebsd/loader.efi
        options "rootdev=zfs:tank/ROOT/default:"
        icon /EFI/refind/icons/os_freebsd-zfs.png
Comment 4 Warner Losh freebsd_committer 2018-07-18 15:29:12 UTC
I don't think your patch is quite right.


is better. It overrides our location of the default currdev if rootdev is in the env.

Does this work for you?
Comment 5 commit-hook freebsd_committer 2018-07-18 22:45:32 UTC
A commit references this bug:

Author: imp
Date: Wed Jul 18 22:45:27 UTC 2018
New revision: 336463
URL: https://svnweb.freebsd.org/changeset/base/336463

  If rootdev is set, use it as currdev.

  Setting rootdev in the enviornment should specify things
  completely. If it is set, then have it override everything else.

  PR: 229770
  Differential Review: https://reviews.freebsd.org/D16322

Comment 6 Masachika ISHIZUKA 2018-07-19 00:04:30 UTC
(In reply to Warner Losh from comment #4)

Thank you very much.
It works perfect for me and I agree this patch is better.
Comment 7 Juan 2019-11-16 14:18:01 UTC
Are there plans to include this patch with any FreeBSD release?

I just tested the following:

   menuentry FreeBSD-11.3{
      loader /efi/boot/fbsd_11.3.efi
      options "rootdev=disk0p13"


   menuentry FreeBSD-12.1{
      loader  /efi/boot/fbsd_12.1.efi
      options "rootdev=disk0p13:"

to no avail.

fbsd_11.3.efi and fbsd_12.1.efi are the boot1.efi files included in 11.3-RELEASE and 12.1-RELEASE respectively.  Tested with the file included with 12.0-RELEASE), did not work either.

'currdev' enviornmanet variable ends up being set to a default value in all cases: currdev=disk0p10:

By the way, also tested with:

menuentry FreeBSD-12.1{
   loader  /efi/boot/fbsd_12.1.efi
   options "currdev=disk0p13:"

same results.

Setting currdev manually indeed does the trick.
Comment 8 Torfinn Ingolfsen 2022-05-10 17:42:01 UTC
Doesn't work in FreeBSD 13.0-release-p11 either. Tested with entries like these
menuentry "FreeBSD 12" {
    icon /EFI/refind/icons/os_freebsd.png
    loader /EFI/freebsd/loader.efi
    options "rootdev=disk0p7"
in /boot/efi/EFI/refind/refind.conf. The entries show up in rEFInd, and I have verified that rEFInd picks up the rootdev variable (it does). Also tried with "rootdev=disk0p7:" doesn't change anything.

A cursory check seems to indicate that loader should have support for rootdev

root@kg-quiet:~ # strings /boot/efi/EFI/freebsd/loader.efi | grep rootdev
    Setting currdev to configured rootdev %s
root@kg-quiet:~ # strings /boot/loader.efi | grep rootdev
    Setting currdev to configured rootdev %s
root@kg-quiet:~ # strings /boot/loader_lua.efi | grep rootdev
    Setting currdev to configured rootdev %s

but it doesn't work. Setting currdev manually works of course.

root@kg-quiet:~ # freebsd-version -ku
root@kg-quiet:~ # uname -a
FreeBSD kg-quiet.kg4.no 13.0-RELEASE-p11 FreeBSD 13.0-RELEASE-p11 #0: Tue Apr  5 18:54:35 UTC 2022     root@amd64-builder.daemonology.net:/usr/obj/usr/src/amd64.amd64/sys/GENERIC  amd64

root@kg-quiet:~ # ll /boot/efi/EFI/freebsd/loader.efi /boot/*.efi
-r-xr-xr-x  1 root  wheel  114176 Apr  9  2021 /boot/boot1.efi*
-rwxr-xr-x  1 root  wheel  896000 May  8 11:24 /boot/efi/EFI/freebsd/loader.efi*
-r-xr-xr-x  1 root  wheel  109056 Apr  9  2021 /boot/gptboot.efi*
-r-xr-xr-x  2 root  wheel  896000 Apr  9  2021 /boot/loader.efi*
-r-xr-xr-x  1 root  wheel  809984 Apr  9  2021 /boot/loader_4th.efi*
-r-xr-xr-x  2 root  wheel  896000 Apr  9  2021 /boot/loader_lua.efi*
-r-xr-xr-x  1 root  wheel  750080 Apr  9  2021 /boot/loader_simp.efi*