Re: loader.conf and rootdev option for memory disk

From: Warner Losh <imp_at_bsdimp.com>
Date: Sun, 20 Nov 2022 03:37:58 UTC
On Sat, Nov 19, 2022 at 8:32 PM Warner Losh <imp@bsdimp.com> wrote:

>
>
> On Sat, Nov 19, 2022 at 6:01 PM Tomoaki AOKI <junchoon@dec.sakura.ne.jp>
> wrote:
>
>> But your previous post shows rootdev= there didn't work, and needed
>> setting vfs.root.mountfrom=.
>>
>> OTOH, rootdev= is reported to work in efi/boot/freebsd/loader.env (with
>> efi loader) on freebsd-users-jp ML (as it's Japanese ML, in Japanese)
>> this year.
>>
>> So /boot/defaults/loader.conf (/usr/src/stand/defaults/loader.conf)
>> should be fixed, and what should be set in loader.env should be
>> documented.
>>
>>  *Dedicated brand-new manpage or in boot.8 (or in loader.8 describing
>>   rootdev, or loader.conf.8 in contrast with itself).
>>
>
> Reading the code it's complicated.
>
> rootdev looks like it overrides the default root... unless
> vfs.root.mountfrom
> has already been set.
>

It's also a name in the 'boot loader' device namespace, not in the FreeBSD
device namespace, so it shouldn't be 'ufs:/dev/foo' but rather 'disk1p3:'
or similar. It's only when it's 'zfs:' that the boot loader device name
space
and the FreeBSD device name space overlap (also zfs: is special cased).

It's also a bit complicated because it's not used as 'currdev' either. It's
strictly a hint for where to mount FreeBSD's root front, but it's not used
to find boot scripts and config files. That's always done with 'currdev'
if no device is specified.

It's also a little more complex with OpenFirmware is involved, but
that's rare these days, so I'll not go into that.

Warner


>
>> On Sat, 19 Nov 2022 22:31:42 +0100
>> Chlasták Miroslav <mira@chlastak.cz> wrote:
>>
>> > Look at the file /boot/defaults/loader.conf:
>> >
>> > …
>> > ###  Initial memory disk settings  ###########################
>> > #mdroot_load="YES"              # The "mdroot" prefix is arbitrary.
>> > #mdroot_type="md_image"         # Create md(4) disk at boot.
>> > #mdroot_name="/boot/root.img"   # Path to a file containing the image.
>> > #rootdev="ufs:/dev/md0"         # Set the root filesystem to md(4)
>> device.
>> > …
>> >
>> > —
>> > Mira
>> >
>> > > On 19 Nov 2022, at 21:58, Tomoaki AOKI <junchoon@dec.sakura.ne.jp>
>> wrote:
>> > >
>> > > IIUC, rootdev should be set in loader.env, if needed.
>> > > `man 5 loader.conf` has nothing about rootdev variable.
>> > >
>> > > (It's undocumented, IIRC.)
>> > >
>> > >
>> > > On Sat, 19 Nov 2022 19:57:47 +0100
>> > > Chlasták Miroslav <mira@chlastak.cz <mailto:mira@chlastak.cz>> wrote:
>> > >
>> > >> I have my device working for now - but the question is - Is the
>> documentation and example for “rootdev” right or not?
>> > >>
>> > >> —
>> > >> Mira
>> > >>
>> > >>> On 18 Nov 2022, at 21:13, Warner Losh <imp@bsdimp.com <mailto:
>> imp@bsdimp.com>> wrote:
>> > >>>
>> > >>>
>> > >>>
>> > >>> On Fri, Nov 18, 2022 at 12:57 PM Chlasták Miroslav <
>> mira@chlastak.cz <mailto:mira@chlastak.cz> <mailto:mira@chlastak.cz
>> <mailto:mira@chlastak.cz>>> wrote:
>> > >>> Hi all,
>> > >>>
>> > >>> In the /boot/defaults/loader.conf are these options for memory disk
>> settings:
>> > >>>
>> > >>> #mdroot_load="YES"              # The "mdroot" prefix is arbitrary.
>> > >>> #mdroot_type="md_image"         # Create md(4) disk at boot.
>> > >>> #mdroot_name="/boot/root.img"   # Path to a file containing the
>> image.
>> > >>> #rootdev="ufs:/dev/md0"         # Set the root filesystem to md(4)
>> device.
>> > >>>
>> > >>>
>> > >>> But - is this example for rootdev option still right? Because
>> “ufs:/dev/md0” works fine on freebsd 12.1, but on freebsd 12.3 this does
>> not work and generates error message:
>> > >>>
>> > >>> Can’t determine root device
>> > >>>
>> > >>>
>> > >>> When I use this option with value “/dev/md0” or “md0” (even with
>> this option commented out), so the machine boots correctly without any
>> error.
>> > >>>
>> > >>> I think you want vfs.root.mountfrom= instead of rootdev= here.
>> > >>>
>> > >>> Warner
>> > >>>
>> > >>> —
>> > >>> Mira
>> > >>
>> > >
>> > >
>> > > --
>> > > 青木 知明  [Tomoaki AOKI]    <junchoon@dec.sakura.ne.jp <mailto:
>> junchoon@dec.sakura.ne.jp>>
>> >
>>
>>
>> --
>> 青木 知明  [Tomoaki AOKI]    <junchoon@dec.sakura.ne.jp>
>>
>>