Solved

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

Posted on 2014-03-15
3
804 Views
Last Modified: 2016-02-11
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
Comment
Question by:skullnobrains
  • 3
3 Comments
 
LVL 26

Author Comment

by:skullnobrains
ID: 39931266
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
 
LVL 26

Accepted Solution

by:
skullnobrains earned 0 total points
ID: 39931278
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
 
LVL 26

Author Closing Comment

by:skullnobrains
ID: 39980322
no real solution
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Windows 7 does not have the best desktop search built in. This is something Windows 7 users have struggled with. You type something in, and your search results don’t always match what you are looking for, or it doesn’t actually work at all. There ar…
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now