Page MenuHomeFreeBSD

bsdinstall: add pkgbase target
ClosedPublic

Authored by ifreund_freebsdfoundation.org on Apr 14 2025, 10:59 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, May 29, 4:26 AM
Unknown Object (File)
Tue, May 27, 8:52 PM
Unknown Object (File)
Mon, May 26, 7:51 PM
Unknown Object (File)
Mon, May 26, 6:52 PM
Unknown Object (File)
Sat, May 24, 4:09 AM
Unknown Object (File)
Fri, May 23, 5:14 AM
Unknown Object (File)
Mon, May 5, 7:49 AM
Unknown Object (File)
Sun, May 4, 9:20 AM

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

Thanks for the comments on the man pages, I'll push an updated version in a minute.

usr.sbin/bsdinstall/bsdinstall.8
248

Imperative is definitely better, thanks for the catch.

What do you think about "Fetch and install base system packages..."?

It sounds less awkward to me and I think it preserves clarity. Perhaps simply "base packages" would be fine as well though.

339–345

I think it is important to clarify that this directory is only for "repository configuration files" not the main pkg.conf configuration file.

While your suggested wording is much more concise, I think it is important to make that distinction plain.

It would be easier to write this clearly if pkg had a separate man page for "repository configuration files" rather than describing them in a section of pkg.conf(5)

usr.sbin/bsdinstall/bsdinstall.8
248

The latter is probably better. Since this is one of the first manuals mentioning pkgbase in the tree, we should be thoughtful about the precident.

339–345

Would it be clear using "repository configuration" instead of just "configuration" in my suggestion?

Slight race condition, I didn't see your replies before pushing that update.

usr.sbin/bsdinstall/bsdinstall.8
248

Indeed, we've been pretty inconsistent with pkgbase (or should I say PkgBase?) related terminology so far.

I think "base packages" is good, I'll switch to that in my next update.

339–345

Would it be clear using "repository configuration" instead of just "configuration" in my suggestion?

Hmm, I'm not sure. I think if the user was not already aware that there are two types of configuration files described in pkg.conf it could be quite confusing.

I tweak this wording in the latest update to get rid of some of the redundancy you highlighted while also being more accurate and concise. Let me know if you want even more conciseness though, I'll defer to your docs expertise :)

emaste added inline comments.
usr.sbin/bsdinstall/bsdinstall.8
248

Yeah, we haven't had to think about this too hard before, because it's only now that pkgbase is really becoming end-user-facing. This terminology will also appear in the Handbook and other documentation.

"Base system packages" is good. I think it's also fine to shorten it to "base packages" depending on context.

ziaee added inline comments.
usr.sbin/bsdinstall/bsdinstall.8
339

You may want to xr pkg 7 here.

flua LGTM, thanks! Did you happen to run devel/lua-luacheck on this? I don't really see any of the problems it would complain about with a quick eyeball, but always good to confirm.

Make luacheck happy, .Xr pkg 8 in man page

Luacheck doesn't like the fact that all the functions I wrote are globals (the
default in lua) rather than locals. While this may seem needlessly pedantic in
such a short script at first, I realize now that there is real value in avoiding
global functions and performing the necessary reordering of the function
definitions. With these changes luacheck is able to catch a typo in a function
name at a callsite statically and give a warning, which is a nice bit of safety
in such a dynamic language.

Thanks kevans for pointing me towards luacheck!

I believe all review comments so far have now been satisfactorily resolved, thank for the reviews!

usr.sbin/bsdinstall/bsdinstall.8
248

After going back and forth a bit in my head, I've left it as "base system packages" here. It's more clear without being needlessly verbose.

If I were to repeat the phrase multiple times in the same sentence I would surely prefer "base packages" for the repetitions :)

339

Done, thanks.

usr.sbin/bsdinstall/scripts/pkgbase
56 ↗(On Diff #153644)

I find it odd that minor doesn't feature in these URLs, it means if you're tracking 14.1-STABLE then you are forcefully upgraded to 14.2-STABLE the moment that exists, no?

66 ↗(On Diff #153644)

I don't love splatting config files into the middle of the code. Is there a reason we can't just have it be a file that's built during buildworld that we then install? We already do that in usr.sbin/pkg/Makefile with _BRANCH to decide latest vs quarterly, I don't see why we can't do similar things for base_release_$MINOR vs base_latest.

82 ↗(On Diff #153644)

Putting keys in the Lua is particularly bad, it's a bit shady and makes it hard for people to audit what keys are in the repo. Besides, why can't we just point pkg at the install media's copy of the key for the initial install step? Or at least if we really have to manually bootstrap things by putting a key in the chroot, do so by copying the install media's copy. But it would really be preferable if the key made it into the chroot by virtue of installing FreeBSD-pkg-bootstrap.

92 ↗(On Diff #153644)

How do I get a non-default set?

110 ↗(On Diff #153644)

People want things other than that to be supported in bsdinstall

116 ↗(On Diff #153644)

Can we please not add more hard-coding of lib32 being the only supported libcompat? Very few places in base do that now. _ALL_libcompats from bsd.compat.pre.mk gives you the list of ones that exist, please use that somehow to automatically determine the sets of compatibility libraries the build system knows about.

130 ↗(On Diff #153644)

This won't be true for architectures without lib32

153 ↗(On Diff #153644)

Surely this should be done with normal lua APIs rather than os.execute?

185 ↗(On Diff #153644)

Or just let this continue on, return from the function and exit the script?

Thanks for the in-depth review @jrtc27! I'll get to work on a revised version of this patch shortly.

usr.sbin/bsdinstall/scripts/pkgbase
56 ↗(On Diff #153644)

As I understand it, the repo URLs map directly to the git branches of src from which the packages are continuously built. base_latest here maps to either the main or stable/14 branch depending on the version, and there are no stable/14.0, stable/14.1, etc branches.

66 ↗(On Diff #153644)

Sure, I don't see a reason we couldn't install this to /usr/share/bsdinstall/FreeBSD-base.conf and then copy it from there.

I'll switch to that approach.

82 ↗(On Diff #153644)

Unfortunately pkg always interprets the fingerprints path relative to the --rootdir (in this case the chroot path). This makes it necessary to have a copy of the key inside the chroot path in order to install packages there.

Copying the key from the install media would definitely be better than hardcoding it here though, I'll switch to that. We already rely on the install media's key to bootstrap pkg in any case.

Installing the FreeBSD-pkg-bootstrap package will overwrite this file during the pkg install for what it's worth.

92 ↗(On Diff #153644)

With the current version of this patch, the answer is to manually invoke pkg during the "Manual Configuration" installer step or after installation is complete.

If I understand @bapt's plans correctly, pkg will gain first class support for "groups" of packages, making the pattern matching on package names done by this function obsolete. My intent was to wait for that proper solution to replace this adhoc filtering and then implement a prompt to select package groups directly.

It would certainly be possible however to create a component selection dialog based on this package name pattern matching which offers the same base-dbg, kernel-dbg, lib32, lib32-dbg, etc. options as the existing standard installation path. I'd be happy to implement that in this patch if you like.

110 ↗(On Diff #153644)

Indeed, and it would be straightforward to add a kernel selection dialog in a follow up patch.

My intent was to limit the scope of this initial patch in order to simplify review, perhaps that was misguided though. Would you like me to add that to this patch?

This comment made me realize a related issue with the current design however: we always install a kernel even if targeting a jail. I'm not sure of the best way to fix that. The most straightforward option would be a BSDINSTALL_NO_KERNEL environment variable which is set by the jail target but not the auto target.

116 ↗(On Diff #153644)

Good point, I'll just need to figure out how best to way to embed the value of that variable in this script.

130 ↗(On Diff #153644)

Thanks for the catch, will fix

153 ↗(On Diff #153644)

Unfortunately there is no mkdir available in the lua standard library. In fact, there are no functions that deal with directories at all, only files.

185 ↗(On Diff #153644)

Sure, I don't have a strong opinion about this.

usr.sbin/bsdinstall/scripts/pkgbase
153 ↗(On Diff #153644)

flua has at least some subset of lfs functionality available, see ^/libexec/flua/modules/lfs.c: attirbutes, dir, mkdir, rmdir

usr.sbin/bsdinstall/scripts/pkgbase
153 ↗(On Diff #153644)

Aha! I stand corrected, thanks. Are there docs on the full set of flua extensions somewhere that I have missed?

usr.sbin/bsdinstall/scripts/pkgbase
153 ↗(On Diff #153644)

Nope =(. Some of the newer ones have 3lua section manpages, but a lot of the ones we hacked out earlier on aren't documented outside of their existence in libexec/flua and use in the earlier sys/tools/makesyscalls.lua (or stand/lua).

usr.sbin/bsdinstall/scripts/pkgbase
153 ↗(On Diff #153644)

I'm not sure it would really be better to use lfs.mkdir() here though, implementing the equivalent of -p manually is cumbersome and feels out of place in this script.

usr.sbin/bsdinstall/scripts/pkgbase
56 ↗(On Diff #153644)
92 ↗(On Diff #153644)

IMO we should bias strongly towards having minimal functionality sooner, to facilitate wider testing of pkgbase. Regardless of whether we get pkg groups or implement a selection dialog I'm fine with that coming in a subsequent update.

116 ↗(On Diff #153644)

We have in the past done something along the lines of naming this file pkgbase.in, putting %%LIBCOMPATS%% in it, and using sed to expand the placeholder, but I think that approach is a bit awkward. What about just reading the list of compats from a file?

usr.sbin/bsdinstall/scripts/pkgbase
56 ↗(On Diff #153644)

That is correct.

usr.sbin/bsdinstall/scripts/pkgbase
82 ↗(On Diff #153644)

Unfortunately pkg always interprets the fingerprints path relative to the --rootdir (in this case the chroot path). This makes it necessary to have a copy of the key inside the chroot path in order to install packages there.

This is by choice.

Copying the key from the install media would definitely be better than hardcoding it here though, I'll switch to that. We already rely on the install media's key to bootstrap pkg in any case.

Yup, it's the way to go :)

Installing the FreeBSD-pkg-bootstrap package will overwrite this file during the pkg install for what it's worth.

92 ↗(On Diff #153644)

Having a way to select packages after is easier, it's better to soon have install media offering pkgbase (even if it's full install or all packages) so people can test without doing the bootstrap phase on a live system.

Rework based on review feedback

Major changes:

  1. The FreeBSD-base.conf file is now installed to /usr/share/bsdinstall/ and the correct URL is selected at build time.
  1. The pkgbase target now copies /usr/share/keys/pkg from the host system into the chroot rather than embedding the required key in the script.
  1. The existence of arbitrary libcompats is handled correctly
  1. The pkgbase target has a new --no-kernel option for use by the jail target
ifreund_freebsdfoundation.org added inline comments.
usr.sbin/bsdinstall/scripts/pkgbase
116 ↗(On Diff #153644)

I ended up just doing the`pkgbase.in` + sed thing, I have to do it for FreeBSD-base.conf now as well.

usr.sbin/bsdinstall/bsdinstall.8
254

Roff does not permit starting a new sentence on an existing line. You can check for these kind of issues with mandoc -Tlint here/is/the/file

ifreund_freebsdfoundation.org marked an inline comment as done.

Fix formatting in bsdinstall.8

ifreund_freebsdfoundation.org added inline comments.
usr.sbin/bsdinstall/bsdinstall.8
254

Fixed, thanks for the catch.

I built a disc1.iso with these changes and the installation failed after the root password prompt:
{F115016404}

I built a disc1.iso with these changes and the installation failed after the root password prompt.

The error is misleading here since I forgot to add a || error "Installation of base system packages failed" after bsdinstall pkgbase in the later patches in this series. I'll fix that.

I was not able to reproduce any errors while running bsdinstall directly from my main FreeBSD installation (Which is how I've been testing these patches thus far).
However, building a disc1.iso and running that in a VM makes it clear what the problem is: bootstrapping pkg on the read-only file system of the install media fails (of course):

pkg: failed to extract pkg-static: Failed to create dir '/usr/local/sbin'

I'm not yet sure what the correct fix for this is. The options I see are:

  1. Include a fully bootstrapped pkg in the install media. We will want this anyway eventually for fully offline install media. There are potential forwards compatibility concerns however if we do not also include all packages to be installed in the install media.
  2. Add a feature to pkg(7) which fetches and extracts pkg-static to an arbitrary location without installing it. Use this feature to fetch pkg-static to /tmp and run it from there.
  3. Bootstrap pkg directly in the chroot, adding features to pkg(7) as needed.
  1. Include a fully bootstrapped pkg in the install media. We will want this anyway eventually for fully offline install media. There are potential forwards compatibility concerns however if we do not also include all packages to be installed in the install media.
  2. Add a feature to pkg(7) which fetches and extracts pkg-static to an arbitrary location without installing it. Use this feature to fetch pkg-static to /tmp and run it from there.
  3. Bootstrap pkg directly in the chroot, adding features to pkg(7) as needed.

We are going to need pkg available to install pkgbase from release media, indeed. I'm not sure that implies #1 is necessary though -- 2 and 3 would work just as well installing from an on-disc repo I believe.

That said, at least some install media variants are going to need a set of installed packages for the installer to work (e.g. for graphical installers), so perhaps it's not any effort unique to this.

  1. Include a fully bootstrapped pkg in the install media. We will want this anyway eventually for fully offline install media. There are potential forwards compatibility concerns however if we do not also include all packages to be installed in the install media.
  2. Add a feature to pkg(7) which fetches and extracts pkg-static to an arbitrary location without installing it. Use this feature to fetch pkg-static to /tmp and run it from there.
  3. Bootstrap pkg directly in the chroot, adding features to pkg(7) as needed.

We are going to need pkg available to install pkgbase from release media, indeed. I'm not sure that implies #1 is necessary though -- 2 and 3 would work just as well installing from an on-disc repo I believe.

That said, at least some install media variants are going to need a set of installed packages for the installer to work (e.g. for graphical installers), so perhaps it's not any effort unique to this.

For graphical installer and wifi/drm firmwares we will need full pkg and the pkgs on media, maybe @bz started something on this ?

For graphical installer and wifi/drm firmwares we will need full pkg and the pkgs on media, maybe @bz started something on this ?

Yes, see e.g. 7e2996c1f5b4e.

I took a look at my WIP tree and seems like I tried this out:

# Install packages onto release media.
        ${PKG_INSTALL} wifi-firmware-kmod-release || true
# Install pkg for installing pkgbase
#       ${PKG_INSTALL} pkg || true
        ${PKG_CLEAN} || true

Maybe it's sufficient

For graphical installer and wifi/drm firmwares we will need full pkg and the pkgs on media, maybe @bz started something on this ?

It looks like there is already some prior art here:

  1. release/Makefile installs wifi-firmware-kmod-release into the disc1 and dvd1 install media.
  2. release/scripts/pkg-stage.sh creates a local package repository on the dvd1 install media which includes a copy of pkg.pkg.

I took a look at my WIP tree and seems like I tried this out:

# Install packages onto release media.
        ${PKG_INSTALL} wifi-firmware-kmod-release || true
# Install pkg for installing pkgbase
#       ${PKG_INSTALL} pkg || true
        ${PKG_CLEAN} || true

Maybe it's sufficient

Indeed, installing pkg alongside the wifi firmware in release/Makefile allowed me to perform a successful installation of a pkgbase system using disc1.iso.

A solution that fetches pkg at installation time just before it fetches the base packages from remote repositories would make me feel a bit better about forwards compatibility with potential new pkg/repository formats however. Maybe that's not an issue in practice though.

It would also keep the installation media a tad smaller, though that probably shouldn't be the deciding factor here.

emaste added inline comments.
usr.sbin/bsdinstall/scripts/pkgbase.in
16–22

Aside, I may have some small improvements to make in tools/tools/git/mfc-candidates.sh::exec_command based on this function.

42–43

We'll want some reusable/general functionality for this eventually, but it's perfectly fine only here for now.

This revision is now accepted and ready to land.Apr 28 2025, 1:13 PM
usr.sbin/bsdinstall/scripts/pkgbase.in
126

This may not be correct for the installer -- I'm not sure we have a proper pkg db in the context that it runs. But I was able to successfully install a pkgbase system with this series of patches, so much prefer to get it in the tree asap and start producing snapshots with this support.

Thanks for the review!

usr.sbin/bsdinstall/scripts/pkgbase.in
16–22

Hah, I was wondering if someone had already written this function somewhere in the src tree!

It's not too much code to copy and paste between our various lua scripts but I do wonder if it would make sense to collect this kind of thing in a module under libexec/flua.

126

Hmm, I'm fairly confident we have readonly access to the pkg db created when pkg was installed to the install media while the installer is running. I'm not sure how this check could be passing and allowing the installation to continue otherwise.

This revision was automatically updated to reflect the committed changes.
OSZAR »