[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 906
  • Last Modified:

freebsd loader chain loading through grub2. how to tell the loader where the kernel is

hi guys

i have a pretty specific setup : i load the same freebsd system both physically and virtually, and when virtually the disk where freebsd is installed is not always the first one

for now, i have a grub config that does a good job with this by booting the kernel directly and setting vfs.root.mountfrom appropriately (actually it autodetects freebsd systems and boots them wherever they are)

my goal is the following : i want the above to be compatible with systems that have settings in loader.conf, and this is where things get complicated

problem

if i boot the loader instead of the kernel, the currdev and bootdev are both set to wherever the grub config file resides, so the loader cannot load the kernel. booting the proper kernel from the loader's command line works fine.

i'm not interested in solutions involving to set stuff in loader.rc or loader.conf because this does not fit the autodetect goal, and it would not work anyway since the loader cannot find either of those files fior the same reason it cannot find the kernel

i naively tried to set kFreeBSD.currdev to no avail (boots but currdev is not changed)
i tried to chainload boot2 and ended up with "Invalid signature" (grub2 message when it cannot chainload something... no idea what it actually means)

i did not try chain.b (yet) because for some reason it does not happen to exist in my /boot (regular freebsd 10 install using the new installer)... ideas welcome while i'm looking for a copy, but i'd rather not rely on something that may or may not be there
i tried to chainload boot0 but (at least in qemu, it only displays "F1" with no system facing it and F6 for pxe boot. whatever key i press just prints a '#'. anyway i did not really expected it to do anything useful, i just though it might give a useful hint)

as a side note (or perhaps side question), i'd like to find a way to tell the loader where the root partiton is so it in turn can tell the kernel

any ideas ?

thanks for your input
0
skullnobrains
Asked:
skullnobrains
  • 3
1 Solution
 
skullnobrainsAuthor Commented:
sorry all, this is idiotic : i figured it out the second i posted the question : the currdev is set to wherever root is set in grub

basically if $file contains the location of the loader

menuentry "freebsd loader $file" "$file"{
                  regexp -s root '^([^)][^)]*\))' "$file"
                  kfreebsd "$2"
            }

does the trick

i missed the regexp line
0
 
skullnobrainsAuthor Commented:
i'm leaving the question open in case anyone has a hint about the side question :

is there a way to instruct the loader the location of the root partition ?

my test system does not have a separate partition for /boot

if i set kFreeBSD.vfs.root.mountfrom=disk1p45 (which does not exist), freebsd still boots fine so i assume the option is ignored

if i boot from the second drive, with the root properly detected and set, the loader finds the kernel, but the kernel does not find the root filesystem any more.

setting mountfrom does not help

hacking loader.rc would likely be feasible but would only work assuming there was a proper initial freebsd install, on the same drive, and the emulated hardware controller was the same which does not really fit my need.

---

if i script something that reads loader.conf in grub-shell and set all those variables as kfreebsd.varnam=varval (assuming i manage to do it), does anybody know if that would work for some or all variables that may be set in loader ?
0
 
skullnobrainsAuthor Commented:
no real solution
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now