From nobody Fri Jul 26 20:03:16 2024 X-Original-To: freebsd-fs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WVzG92twDz5RG8g for ; Fri, 26 Jul 2024 20:03:29 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WVzG90z6bz4c6r for ; Fri, 26 Jul 2024 20:03:29 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2c964f5a037so985704a91.0 for ; Fri, 26 Jul 2024 13:03:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1722024208; x=1722629008; darn=freebsd.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nvmWyL9xcClR56hIrk1myy9BQGZXPSNN0MmlLJiWlOE=; b=Y9juCSLXF1H1/H55ThbcsC7Hye6jji9fVer2SxJafYpCmkilL/kM5or+vvyJih1Ca7 GbjmtQO+T6DFNr/B949qQEb//gdMU7zcRJNP/sXTHScuHrMYdpPS8SvIDl8xbnfnEaar LjeidV1fHZOZHhPE+SHR3jFhX7I7JkrXaKEZ7uoJrGITSe0BnH3flkNABIRtlo3s0fxP FfbGTkv9EMY1kKkF09FUIBU+aI+mJXlEy1c/cCE0I/FTEO6IolxRqFcs9X9gmp9Kl9rN x1p2fN+i09DhX/riGechqwPP5upmGdMayviWaB7Iw7vTc9xhDIdPQg5q0Vvz+1/d70sb 40EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722024208; x=1722629008; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nvmWyL9xcClR56hIrk1myy9BQGZXPSNN0MmlLJiWlOE=; b=hzoZ/T+TgOpjS7BXoJquWTtv4rDpWII5hDyCf11jvWxmCpBpNV1rqkEZE7Kheq+Y3F INPAMZvOW2MF5LDSO89wfGc1wfZFublvk5xEPix+AjWDmd2hzXnOd/La5bD+/aWCX6SN ToRNguliCQ3qPnINH/K29eYuFnbsaXtJ3O4zGdJ3OTWLurKU0H32cL2tNYuZt4Ofpgvu qsQcnyyOIFhIQs0aABmrKNNMfK0yvJZGlTTiSmWek4CiLRokGEpEvK4ENM71eOVU9XvQ irDR2wuLRvt6iOv1ctD/s9ypx56z1K53OQjBKCbNRP/ilIJIxPuFHy8PbuAdBvGriBie mZCQ== X-Gm-Message-State: AOJu0Yz/iRltXaL3DdH4vfdsDLbB4SxAN8EYtBLcro/LvNgeYJgBjcwI 9y9iiqVGcz4HeENXW5vdPvwuQEPqSAjIlnFSAab6cjMTuGpGtVHf4f5W3VY4zj2Cz9TrN6Y8hvp tn3I7q7KD2mrqGQftgstk+gLAQXswcor0sFe9ZIlyW9AHmidpigg= X-Google-Smtp-Source: AGHT+IGvRWjBjJaPBJBBuBq57mMBoXgXM1XDeywREi8WqKmoOSbA8IAEOJMhYOKZD1/7T+GvBFgkXQPSekM2N4Apbqk= X-Received: by 2002:a17:90b:4b12:b0:2cd:b9a0:67dc with SMTP id 98e67ed59e1d1-2cf7e831dacmr652382a91.31.1722024207611; Fri, 26 Jul 2024 13:03:27 -0700 (PDT) List-Id: Filesystems List-Archive: https://lists.freebsd.org/archives/freebsd-fs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-fs@FreeBSD.org MIME-Version: 1.0 References: In-Reply-To: From: Warner Losh Date: Fri, 26 Jul 2024 14:03:16 -0600 Message-ID: Subject: Re: Kernel boot process and root fs in minimal systems To: Bryce <678yym@gmail.com> Cc: freebsd-fs@freebsd.org Content-Type: multipart/alternative; boundary="00000000000030953f061e2c013b" X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] X-Rspamd-Queue-Id: 4WVzG90z6bz4c6r --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


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

Ive bee= n using FreeBSD for a few months now, and have been using Linux for a few y= ears. I've read some man pages and relevant sections of the manual. I&#= 39;m not opposed to RTFM, but please point to relevant sections.

So what I've gathered:

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?).

Then, what I assume happens is that the kernel takes the conf= ig 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&#= 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.

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 ca= re about for niche hardware.
=C2=A0
I know ab= out md(4), and how it bakes the md image into the kernel. This is what I= 9;m looking for, but what about the bootloaders? do they need to be configu= red to not look for rootfs on disk?

=
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's a pain and has been = a while since I've done this, but I recall there being several issues t= hat 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 t= he sources to refresh my memory on what options you'd need for bundling= .
=C2=A0
<= 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'd be happy to read them.

also, if this is the wrong list to be writing to, I a= pologize, 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
=C2=A0
thanks list.

--00000000000030953f061e2c013b--