Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Jul 2024 14:03:16 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        Bryce <678yym@gmail.com>
Cc:        freebsd-fs@freebsd.org
Subject:   Re: Kernel boot process and root fs in minimal systems
Message-ID:  <CANCZdfoDqeOK4Xo=SH50Zok1a2=uqyN7nNbd=q3G3v7dJj_RKA@mail.gmail.com>
In-Reply-To: <CADF3e167z4wtqvZtUEuyu7HVBwsj0aa55FrgyaKCRYMXdfEhVg@mail.gmail.com>
References:  <CADF3e167z4wtqvZtUEuyu7HVBwsj0aa55FrgyaKCRYMXdfEhVg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
--00000000000030953f061e2c013b
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Fri, Jul 26, 2024 at 12:23=E2=80=AFPM Bryce <678yym@gmail.com> wrote:

> Hello list,
>
> Ive been using FreeBSD for a few months now, and have been using Linux fo=
r
> a few years. I've read some man pages and relevant sections of the manual=
.
> I'm not opposed to RTFM, but please point to relevant sections.
>
> So what I've gathered:
>
> BSD has a 3 stage bootloader, stage 0 is obviously just for getting past
> the one sector limit, stage 1 passes kernel configuration options(?) to
> stage 3, which finds the kernel on the rootfs (which may be the network),
> and passes stage 2 config onto the kernel (ie, what modules to load etc?)=
.
>
> Then, what I assume happens is that the kernel takes the config options
> from stage 2 and mounts rootfs and then executes /init.
>
> Is this correct, list? If so, is it possible to use a tmpfs-like
> filesystem to mount rootfs in memory alone?
>

Sorta. For BIOS booting, it's indeed a several step process: boot0 acts as
MBR (though standard MBR also works). boot 1 loads boot2 which reads
boot.conf for kernel command line args (very restricted) and passes them to
/boot/loader of the first UFS partition it finds on that disk. /boot/loader
decodes those args, finds the root filesystem, loads the kernel from it
then boots the kernel. This is only on x86.

For UEFI bootlng, loader.efi runs directly, finds the root, loads the
kernel and jumps to that.

There's some other weird cases that you likely don't care about for niche
hardware.


> I know about md(4), and how it bakes the md image into the kernel. This i=
s
> what I'm looking for, but what about the bootloaders? do they need to be
> configured to not look for rootfs on disk?
>

For BIOS booting, you are stuck reading a ram disk off some disk and then
you can use that to boot in various ways. It's a pain and has been a while
since I've done this, but I recall there being several issues that trial
and error would be needed to solve.

For UEFI, you can either have a ram disk from the ESP or you can bundle it
with the loader.efi program. This is possible, but I'd have to go look at
the sources to refresh my memory on what options you'd need for bundling.


> sorry if my questions are uninformed, I'm quite new. If somebody wants to
> point me to the relevant sources in the source tree I'd be happy to read
> them.
>
> also, if this is the wrong list to be writing to, I apologize, I couldn't
> find a more appropriate list.
>

I'm not sure this is the best place for it, but it isn't the worst place
for it.

Maybe if you could describe what you're doing, I can tailor my answers a
bit better.

Warner

Warner


> thanks list.
>
>

--00000000000030953f061e2c013b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Fri, Jul 26, 2024 at 12:23=E2=80=
=AFPM Bryce &lt;<a href=3D"mailto:678yym@gmail.com">678yym@gmail.com</a>&gt=
; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px=
 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div di=
r=3D"auto">Hello list,<div dir=3D"auto"><br></div><div dir=3D"auto">Ive bee=
n using FreeBSD for a few months now, and have been using Linux for a few y=
ears. I&#39;ve read some man pages and relevant sections of the manual. I&#=
39;m not opposed to RTFM, but please point to relevant sections.</div><div =
dir=3D"auto"><br></div><div dir=3D"auto">So what I&#39;ve gathered:</div><d=
iv dir=3D"auto"><br></div><div dir=3D"auto">BSD has a 3 stage bootloader, s=
tage 0 is obviously just for getting past the one sector limit, stage 1 pas=
ses kernel configuration options(?) to stage 3, which finds the kernel on t=
he rootfs (which may be the network), and passes stage 2 config onto the ke=
rnel (ie, what modules to load etc?).</div><div dir=3D"auto"><br></div><div=
 dir=3D"auto">Then, what I assume happens is that the kernel takes the conf=
ig options from stage 2 and mounts rootfs and then executes /init.</div><di=
v dir=3D"auto"><br></div><div dir=3D"auto">Is this correct, list? If so, is=
 it possible to use a tmpfs-like filesystem to mount rootfs in memory alone=
?</div></div></blockquote><div><br></div><div>Sorta. For BIOS booting, it&#=
39;s indeed a several step process: boot0 acts as MBR (though standard MBR =
also works). boot 1 loads boot2 which reads boot.conf for kernel command li=
ne args (very restricted) and passes them to /boot/loader of the first UFS =
partition it finds on that disk. /boot/loader decodes those args, finds the=
 root filesystem, loads the kernel from it then boots the kernel. This is o=
nly on x86.<br></div><div><br></div><div>For UEFI bootlng, loader.efi runs =
directly, finds the root, loads the kernel and jumps to that.</div><div><br=
></div><div>There&#39;s some other weird cases that you likely don&#39;t ca=
re about for niche hardware.<br></div><div>=C2=A0</div><blockquote class=3D=
"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(2=
04,204,204);padding-left:1ex"><div dir=3D"auto"><div dir=3D"auto">I know ab=
out md(4), and how it bakes the md image into the kernel. This is what I&#3=
9;m looking for, but what about the bootloaders? do they need to be configu=
red to not look for rootfs on disk?</div></div></blockquote><div><br></div>=
<div>For BIOS booting, you are stuck reading a ram disk off some disk and t=
hen you can use that to boot in various ways. It&#39;s a pain and has been =
a while since I&#39;ve done this, but I recall there being several issues t=
hat trial and error would be needed to solve.</div><div><br></div><div>For =
UEFI, you can either have a ram disk from the ESP or you can bundle it with=
 the loader.efi program. This is possible, but I&#39;d have to go look at t=
he sources to refresh my memory on what options you&#39;d need for bundling=
.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0=
px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><=
div dir=3D"auto"><div dir=3D"auto">sorry if my questions are uninformed, I&=
#39;m quite new. If somebody wants to point me to the relevant sources in t=
he source tree I&#39;d be happy to read them.</div><div dir=3D"auto"><br></=
div><div dir=3D"auto">also, if this is the wrong list to be writing to, I a=
pologize, I couldn&#39;t find a more appropriate list.</div></div></blockqu=
ote><div><br></div><div>I&#39;m not sure this is the best place for it, but=
 it isn&#39;t the worst place for it.</div><div><br></div><div>Maybe if you=
 could describe what you&#39;re doing, I can tailor my answers a bit better=
.</div><div><br></div><div>Warner<br></div><div><br></div><div>Warner<br></=
div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px =
0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div=
 dir=3D"auto"><div dir=3D"auto">thanks list.</div><div dir=3D"auto"><br></d=
iv></div>
</blockquote></div></div>

--00000000000030953f061e2c013b--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfoDqeOK4Xo=SH50Zok1a2=uqyN7nNbd=q3G3v7dJj_RKA>