Page MenuHomeFreeBSD

freebsd-update: Add check for kernel modules
ClosedPublic

Authored by fernape on Apr 19 2023, 4:38 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 14, 6:05 PM
Unknown Object (File)
Sun, Apr 7, 3:07 PM
Unknown Object (File)
Tue, Apr 2, 3:05 AM
Unknown Object (File)
Feb 19 2024, 10:11 PM
Unknown Object (File)
Feb 10 2024, 9:39 PM
Unknown Object (File)
Jan 24 2024, 2:38 PM
Unknown Object (File)
Dec 20 2023, 8:19 AM
Unknown Object (File)
Dec 16 2023, 5:56 AM

Details

Summary

People get confused when some software (VirtualBox, etc) does not work as
expected (or at all) after a major upgrade.

We have a nice way to deal with this when using sources, namely including
PORTS_MODULES in /etc/make.conf, but we lack something similar for binary
updates.

This patch retrieves a list of kernel modules installed from packages and
advises the user to recompile from ports to avoid problems.

Note that AFAIK there is no way to tell if a port needed the base sources at
build time so ports like sysutils/lsof will not be detected since it doesn't
install a kernel module.

Future plans include:

  • Suggest the user to include the src component if it is not selected but there are kernel modules installed from packages.
  • Have a way of record if a port needs the kernel sources (USES=kmod works only for kernel modules and other ports might need sources in base other than the kernel's. USES=basesrc?).
  • Ideally, if the user agrees, bootstrap a ports collection and rebuild/reinstall those ports at the proper stage of the major upgrade.
Test Plan

Apply patch. After that, try to run an upgrade. For instance:

$ sudo sh freebsd-update.sh -r 13.2-RELEASE upgrade
src component not installed, skipped


The following modules have been installed from packages.
As a consequence they might not work when performing a major upgrade.
It is advised to rebuild these ports:

Module                           Package                            Port
------                           -------                            ----
/boot/modules/nvidia-modeset.ko  nvidia-driver-470-470.161.03       x11/nvidia-driver-470
/boot/modules/nvidia.ko          nvidia-driver-470-470.161.03       x11/nvidia-driver-470
/boot/modules/vboxguest.ko       virtualbox-ose-additions-6.1.36_1  emulators/virtualbox-ose-additions
/boot/modules/vboxvfs.ko         virtualbox-ose-additions-6.1.36_1  emulators/virtualbox-ose-additions
/boot/modules/vboxdrv.ko         virtualbox-ose-kmod-6.1.36         emulators/virtualbox-ose-kmod
/boot/modules/vboxnetadp.ko      virtualbox-ose-kmod-6.1.36         emulators/virtualbox-ose-kmod
/boot/modules/vboxnetflt.ko      virtualbox-ose-kmod-6.1.36         emulators/virtualbox-ose-kmod


Looking up update.FreeBSD.org mirrors... 2 mirrors found.
Fetching metadata signature for 13.1-RELEASE from update1.freebsd.org... done.
Fetching metadata index... done.
...
...

Diff Detail

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

Event Timeline

delphij added inline comments.
usr.sbin/freebsd-update/freebsd-update.sh
670

Before proceeding any further, we should check if pkg is present. Something like:

if pkg -N 2>/dev/null ; then
    (code that expects pkg to be present)
else
    return
fi

would do it. Otherwise freebsd-update will attempt to install pkg.

672

I think it's probably a good idea to only match the last module_path= instead of matching all module_path (they may be commented out, or overridden by a later occurrence).

Address delphij feedback.

  • Check for pkg(8) before proceeding any further.
  • Improve module_path parsing
fernape added inline comments.
usr.sbin/freebsd-update/freebsd-update.sh
670

Thanks, that makes sense.

672

Done.

I also added /boot/modules as a fallback case.

Oh that's good point. I think you can avoid hardcoding the value and just grep over two files instead (see suggested edit).

usr.sbin/freebsd-update/freebsd-update.sh
677

I think you can avoid hardcoding the value by simply grep'ing the defaults and the canonical loader.conf in this order...

fernape marked 2 inline comments as done.

Look for module_path in /boot/defaults/loader.conf first.

fernape added inline comments.
usr.sbin/freebsd-update/freebsd-update.sh
677

Nice!

Thank you.

usr.sbin/freebsd-update/freebsd-update.sh
699

It is advised to rebuild these ports:

Or
It is advised to re-install these packages or rebuild these ports: ?

These modules are previously installed from packages, users may prefer to re-install them rather than rebuild from ports.

fernape added inline comments.
usr.sbin/freebsd-update/freebsd-update.sh
699

Reinstalling packages might not work depending on the timing. Packages are built for the minor version of FreeBSD. If someone upgrades from 13.1 to 13.2 today (as I did) and then try to load, for instance, the virtualbox modules , they will get these messages:

kldload: an error occurred while loading module vboxdrv. Please check dmesg(8) for more details.
kldload: an error occurred while loading module vboxnetadp. Please check dmesg(8) for more details.

and in dmesg(8):

KLD vboxdrv.ko: depends on kernel - not available or version mismatch
linker_load_file: /boot/modules/vboxdrv.ko - unsupported file type
KLD vboxnetadp.ko: depends on vboxdrv - not available or version mismatch
linker_load_file: /boot/modules/vboxnetadp.ko - unsupported file type

Reinstalling from packages will only work once the package builders are using 13.2 (in the example) which will presumably be when 13.1 is EOLed.

See this note in the Handbook.

usr.sbin/freebsd-update/freebsd-update.sh
699

I see.

For minor version upgrades (e.g., 13.1 to 13.2), the ABI is guaranteed to be stable, so normal packages ( those built on 13.1 ) will continue to work, but some special packages those providing kernel modules such as virtualbox-ose-kmod may not work.

So can we have different port build policy for those special packages ? Just build them ( on 13.2 ) immediately so that the upgrade will be smooth.

Also CC releng .

usr.sbin/freebsd-update/freebsd-update.sh
699

Yes, that would reduce the problematic window, although I don't know how many resources we have for that.
Another approach would be to trigger the rebuild of the ports containing kernel modules from the freebsd-update upgrade -r ... invocation.
But for that we would need to:

  • Checkout the specific port + build dependencies
  • Rebuild everything in a contained environment (so poudriere, synth or some kind of chroot)

And that might be very expensive. For instance, after upgrading from 13.1 to 13.2 I rebuilt virtualbox-ose-kmod for 13.2 using a poudriere jail. But it took a while because it builds with gcc and it needed to be rebuilt.

Some Linux distros trigger the rebuilding of drivers when upgrading. Because the system is so bloated in the first time, they don't need any extra dependencies, everything is in the system already (git, gcc, binutils, etc.)

Is anyone interested in this?

Is anyone interested in this?

I think it is a useful feature. I planed to test it but I'm currently out of bandwidth .

In D39695#946275, @zlei wrote:

Is anyone interested in this?

I think it is a useful feature. I planed to test it but I'm currently out of bandwidth .

OK!

usr.sbin/freebsd-update/freebsd-update.sh
698

Minor upgrade should also be warned.

699

Explicitly note build from source .

706
usr.sbin/freebsd-update/freebsd-update.sh
678

Shall it be warned if either /boot/defaults/loader.conf or /boot/loader.conf does not exist ?

  • freebsd-update: Add check for kernel modules
  • Address zlei's comments
fernape added inline comments.
usr.sbin/freebsd-update/freebsd-update.sh
699

Aren't ports by definition built always from source?

usr.sbin/freebsd-update/freebsd-update.sh
699

Aren't ports by definition built always from source?

I think YES. So

Explicitly note build from source

is not needed.

This revision is now accepted and ready to land.Sun, Apr 7, 3:14 PM
This revision was automatically updated to reflect the committed changes.