VirtualBox

Ignore:
Timestamp:
Mar 18, 2022 6:52:14 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
150592
Message:

Additions: Linux: Prevent kernel modules rebuild on system boot if they already been built, bugref:9138.

This is the same approach as we have for host drivers. Before attempting to build
modules, we try to detect if modinfo can already see them and check versions. Modules
rebuilding skipped in positive case.

This change only affects 'rcvboxadd start' action which is used on system boot. Having this
change will speed up boot process a bit. Actions 'rcvboxadd setup' and 'rcvboxadd quicksetup'
not affected.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/linux/installer/vboxadd.sh

    r93374 r94308  
    135135MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
    136136BUILDINTMP="$MODULE_SRC/build_in_tmp"
     137
     138# Attempt to detect VirtualBox Guest Additions version and revision information.
     139VBOXCLIENT="${INSTALL_DIR}/bin/VBoxClient"
     140VBOX_VERSION="`"$VBOXCLIENT" --version | cut -d r -f1`"
     141[ -n "$VBOX_VERSION" ] || VBOX_VERSION='unknown'
     142VBOX_REVISION="r`"$VBOXCLIENT" --version | cut -d r -f2`"
     143[ "$VBOX_REVISION" != "r" ] || VBOX_REVISION='unknown'
    137144
    138145running_vboxguest()
     
    404411}
    405412
     413# Returns path to module file as seen by modinfo(8) or empty string.
     414module_path()
     415{
     416    mod="$1"
     417    [ -n "$mod" ] || return
     418
     419    modinfo "$mod" 2>/dev/null | grep -e "^filename:" | tr -s ' ' | cut -d " " -f2
     420}
     421
     422# Returns module version if module is available or empty string.
     423module_version()
     424{
     425    mod="$1"
     426    [ -n "$mod" ] || return
     427
     428    modinfo "$mod" 2>/dev/null | grep -e "^version:" | tr -s ' ' | cut -d " " -f2
     429}
     430
     431# Returns module revision if module is available in the system or empty string.
     432module_revision()
     433{
     434    mod="$1"
     435    [ -n "$mod" ] || return
     436
     437    modinfo "$mod" 2>/dev/null | grep -e "^version:" | tr -s ' ' | cut -d " " -f3
     438}
     439
     440# Returns "1" if externally built module is available in the system and its
     441# version and revision number do match to current VirtualBox installation.
     442# Or empty string otherwise.
     443module_available()
     444{
     445    mod="$1"
     446    [ -n "$mod" ] || return
     447
     448    [ "$VBOX_VERSION" = "$(module_version "$mod")" ] || return
     449    [ "$VBOX_REVISION" = "$(module_revision "$mod")" ] || return
     450
     451    # Check if module belongs to VirtualBox installation.
     452    #
     453    # We have a convention that only modules from /lib/modules/*/misc
     454    # belong to us. Modules from other locations are treated as
     455    # externally built.
     456    mod_path="$(module_path "$mod")"
     457
     458    # If module path points to a symbolic link, resolve actual file location.
     459    [ -L "$mod_path" ] && mod_path="$(readlink -e -- "$mod_path")"
     460
     461    # File exists?
     462    [ -f "$mod_path" ] || return
     463
     464    # Extract last component of module path and check whether it is located
     465    # outside of /lib/modules/*/misc.
     466    mod_dir="$(dirname "$mod_path" | sed 's;^.*/;;')"
     467    [ "$mod_dir" = "misc" ] || return
     468
     469    echo "1"
     470}
     471
     472# Check if required modules are installed in the system and versions match.
     473setup_complete()
     474{
     475    [ "$(module_available vboxguest)"   = "1" ] || return
     476    [ "$(module_available vboxsf)"      = "1" ] || return
     477
     478    # All modules are in place.
     479    echo "1"
     480}
     481
    406482# setup_script
    407483setup()
     
    412488
    413489    if test -z "$INSTALL_NO_MODULE_BUILDS"; then
    414         info "Building the VirtualBox Guest Additions kernel modules.  This may take a while."
    415         info "To build modules for other installed kernels, run"
    416         info "  /sbin/rcvboxadd quicksetup <version>"
    417         info "or"
    418         info "  /sbin/rcvboxadd quicksetup all"
    419         if test -d /lib/modules/"$TARGET_VER"/build; then
    420             setup_modules "$TARGET_VER"
    421             depmod
     490        # Check whether modules setup is already complete for currently running kernel.
     491        # Prevent unnecessary rebuilding in order to speed up booting process.
     492        if test "$(setup_complete)" = "1"; then
     493            info "VirtualBox Guest Additions kernel modules $VBOX_VERSION $VBOX_REVISION are"
     494            info "already available for kernel $TARGET_VER and do not require to be rebuilt."
    422495        else
    423             info "Kernel headers not found for target kernel $TARGET_VER. \
     496            info "Building the VirtualBox Guest Additions kernel modules.  This may take a while."
     497            info "To build modules for other installed kernels, run"
     498            info "  /sbin/rcvboxadd quicksetup <version>"
     499            info "or"
     500            info "  /sbin/rcvboxadd quicksetup all"
     501            if test -d /lib/modules/"$TARGET_VER"/build; then
     502                setup_modules "$TARGET_VER"
     503                depmod
     504            else
     505                info "Kernel headers not found for target kernel $TARGET_VER. \
    424506Please install them and execute
    425507  /sbin/rcvboxadd setup"
     508            fi
    426509        fi
    427510    fi
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette