VirtualBox

Ignore:
Timestamp:
Nov 30, 2018 11:07:51 AM (6 years ago)
Author:
vboxsync
Message:

Additions/linux/installer: build new kernel modules on system stop.
bugref:3809: Linux installer maintenance
With this change, we stop trying to use the DKMS hooks to rebuild kernel
modules, as they have proved too unreliable to be useful. Instead we now
simply rebuild for new kernels found at shutdown time, and again on start-up
in case there was a hard shutdown. Also clean up quite a bit of shell script
and improve the udev detection.

Location:
trunk/src/VBox/Additions/linux/installer
Files:
2 edited

Legend:

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

    r70930 r75839  
    6060usage()
    6161{
    62     info ""
    63     info "Usage: $SELF install [<installation directory>]"
    64     info "       [--with-<module>] |"
    65     info "       uninstall"
    66     info "       [--force] [--no-setup]"
    67     info ""
    68     info "Example:"
    69     info "$SELF install"
     62    catinfo << EOF
     63
     64Usage: $SELF install [<installation directory>]
     65       [--with-<module>]
     66       [--package-base <base> |
     67       uninstall
     68       [--force] [--no-setup]
     69
     70Options:
     71  --package-base <base>    For use when building distribution packages.
     72                           Installs relative to <base> instead of to "/",
     73                           does not run setup, installs to "<base>/usr/lib"
     74                           instead of to "/opt" and does not create uninstall.
     75
     76Example:
     77$SELF install
     78EOF
    7079    exit 1
    7180}
     
    159168        fi
    160169    fi
     170    # Inhibit rebuilding of any installed kernels.
     171    for i in /lib/modules/*; do
     172        ver="${i##*/}"
     173        test ! -d "$i"/build || touch /var/lib/VBoxGuestAdditions/skip-"$ver"
     174    done
    161175    # Stop what we can in the way of services and remove them from the
    162176    # system
     
    195209info "$PACKAGE_NAME installer"
    196210
    197 # Check architecture
    198 cpu=`uname -m`;
    199 case "$cpu" in
    200   i[3456789]86|x86)
    201     cpu="x86"
    202     lib_candidates="/usr/lib/i386-linux-gnu /usr/lib /lib"
    203     ;;
    204   x86_64|amd64)
    205     cpu="amd64"
    206     lib_candidates="/usr/lib/x86_64-linux-gnu /usr/lib64 /usr/lib /lib64 /lib"
    207     ;;
    208   *)
    209     cpu="unknown"
    210 esac
    211 ARCH_PACKAGE="$PACKAGE-$cpu.tar.bz2"
    212 if [ ! -r "$ARCH_PACKAGE" ]; then
    213   info "Detected unsupported $cpu machine type."
    214   exit 1
    215 fi
    216 # Find the most appropriate libary folder by seeing which of the candidate paths
    217 # are actually in the shared linker path list and choosing the first.  We look
    218 # for Debian-specific paths first, then LSB ones, then the new RedHat ones.
    219 libs=`ldconfig -v 2>/dev/null | grep -v ^$'\t'`
    220 for i in $lib_candidates; do
    221   if echo $libs | grep -q $i; then
    222     lib_path=$i
    223     break
    224   fi
    225 done
    226 if [ ! -x "$lib_path" ]; then
    227   info "Unable to determine correct library path."
    228   exit 1
    229 fi
    230 
    231211# Sensible default actions
    232212ACTION="install"
     
    234214NO_CLEANUP=""
    235215FORCE_UPGRADE=""
     216PACKAGE_BASE=""
    236217
    237218while [ $# -ge 2 ];
     
    249230            uninstall)
    250231                ACTION="uninstall"
     232                ;;
     233
     234            package)
     235                ACTION="package"
     236                INSTALLATION_DIR=/usr/lib
     237                PACKAGE_BASE="$2"
     238                DO_SETUP=""
     239                shift
     240                if test ! -d "${PACKAGE_BASE}"; then
     241                    info "Package base directory not found."
     242                    usage
     243                fi
    251244                ;;
    252245
     
    315308done
    316309
     310# Check architecture
     311cpu=`uname -m`;
     312case "$cpu" in
     313  i[3456789]86|x86)
     314    cpu="x86"
     315    lib_candidates="/usr/lib/i386-linux-gnu /usr/lib /lib"
     316    ;;
     317  x86_64|amd64)
     318    cpu="amd64"
     319    lib_candidates="/usr/lib/x86_64-linux-gnu /usr/lib64 /usr/lib /lib64 /lib"
     320    ;;
     321  *)
     322    cpu="unknown"
     323esac
     324ARCH_PACKAGE="$PACKAGE-$cpu.tar.bz2"
     325if [ ! -r "$ARCH_PACKAGE" ]; then
     326  info "Detected unsupported $cpu machine type."
     327  exit 1
     328fi
     329# Find the most appropriate libary folder by seeing which of the candidate paths
     330# are actually in the shared linker path list and choosing the first.  We look
     331# for Debian-specific paths first, then LSB ones, then the new RedHat ones.
     332libs=`ldconfig -v 2>/dev/null | grep -v ^$'\t'`
     333for i in $lib_candidates; do
     334  if echo $libs | grep -q $i; then
     335    lib_path=$i
     336    break
     337  fi
     338done
     339if [ ! -x "$lib_path" ]; then
     340  info "Unable to determine correct library path."
     341  exit 1
     342fi
     343
    317344# uninstall any previous installation
    318345# If the currently installed Additions have provided an uninstallation hook, try
     
    387414
    388415# Set symlinks into /usr and /sbin
    389 link_into_fs "bin" "/usr/bin"
    390 link_into_fs "sbin" "/usr/sbin"
     416link_into_fs "bin" "${PACKAGE_BASE}/usr/bin"
     417link_into_fs "sbin" "${PACKAGE_BASE}/usr/sbin"
    391418link_into_fs "lib" "$lib_path"
    392 add_symlink "$INSTALLATION_DIR/lib/$PACKAGE" /usr/lib/"$PACKAGE"
    393 link_into_fs "src" "/usr/src"
     419link_into_fs "src" "${PACKAGE_BASE}/usr/src"
    394420
    395421if [ -d "$INSTALLATION_MODULES_DIR" ]; then
  • trunk/src/VBox/Additions/linux/installer/vboxadd.sh

    r75428 r75839  
    6060## systemd logs information about service status, otherwise do that ourselves.
    6161QUIET=
    62 test -z "${KERN_VER}" && KERN_VER=`uname -r`
     62test -z "${TARGET_VER}" && TARGET_VER=`uname -r`
     63# Marker to ignore a particular kernel version which was already installed.
     64SKIPFILE_BASE=/var/lib/VBoxGuestAdditions/skip
    6365
    6466setup_log()
    6567{
    66     test -n "${LOG}" && return 0
     68    test -z "${LOG}" || return 0
    6769    # Rotate log files
    6870    LOG="/var/log/vboxadd-setup.log"
     
    105107begin()
    106108{
    107     test -z "${QUIET}" && echo "${SERVICE}: ${1}"
     109    test -n "${QUIET}" || echo "${SERVICE}: ${1}"
    108110}
    109111
     
    184186            fi
    185187        fi
    186         test -z "$maj" && {
     188        test -n "$maj" || {
    187189            rmmod vboxguest 2>/dev/null
    188190            fail "Cannot locate the VirtualBox device"
     
    223225{
    224226    begin "Starting."
    225     # If we got this far assume that the slow set-up has been done.
    226     QUICKSETUP=start
    227227    if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
    228         uname -r | grep -q -E '^2\.6|^3|^4' 2>/dev/null &&
     228        setup --quick
     229        test -d /sys &&
    229230            ps -A -o comm | grep -q '/*udevd$' 2>/dev/null ||
    230231            no_udev=1
     
    233234                fail "Cannot remove $dev"
    234235            }
    235 
    236236            rm -f $userdev || {
    237237                fail "Cannot remove $userdev"
    238238            }
    239 
    240             $MODPROBE vboxguest >/dev/null 2>&1 || {
    241                 setup
    242                 $MODPROBE vboxguest >/dev/null 2>&1 ||
    243                     fail "modprobe vboxguest failed"
    244             }
     239            $MODPROBE vboxguest >/dev/null 2>&1 ||
     240                fail "modprobe vboxguest failed"
    245241            case "$no_udev" in 1)
    246242                sleep .5;;
     
    252248
    253249        running_vboxsf || {
    254             $MODPROBE vboxsf > /dev/null 2>&1 || {
    255                 if dmesg | grep "VbglR0SfConnect failed" > /dev/null 2>&1; then
    256                     info "Unable to start shared folders support.  Make sure that your VirtualBox build supports this feature."
    257                 else
    258                     info "modprobe vboxsf failed"
    259                 fi
    260             }
     250            $MODPROBE vboxsf > /dev/null 2>&1 ||
     251                info "modprobe vboxsf failed"
    261252        }
    262253    fi  # INSTALL_NO_MODULE_BUILDS
     
    278269{
    279270    begin "Stopping."
     271    test -n "${INSTALL_NO_MODULE_BUILDS}" || setup --quick
    280272    if test -r /etc/ld.so.conf.d/00vboxvideo.conf; then
    281273        rm /etc/ld.so.conf.d/00vboxvideo.conf
     
    308300    depmod "${version}"
    309301    rm -f "/lib/modules/${version}/initrd/vboxvideo"
    310     test -d "/lib/modules/${version}/initrd" &&
    311         test -f "/lib/modules/${version}/misc/vboxvideo.ko" &&
     302    test ! -d "/lib/modules/${version}/initrd" ||
     303        test ! -f "/lib/modules/${version}/misc/vboxvideo.ko" ||
    312304        touch "/lib/modules/${version}/initrd/vboxvideo"
    313305
     
    328320cleanup_modules()
    329321{
    330     test "x${1}" = x--skip && skip_ver="${2}"
    331322    # Needed for Ubuntu and Debian, see update_initramfs
    332323    rm -f /lib/modules/*/initrd/vboxvideo
    333324    for i in /lib/modules/*/misc; do
    334         kern_ver="${i%/misc}"
    335         kern_ver="${kern_ver#/lib/modules/}"
     325        KERN_VER="${i%/misc}"
     326        KERN_VER="${KERN_VER#/lib/modules/}"
    336327        unset do_update
    337328        for j in ${OLDMODULES}; do
    338329            test -f "${i}/${j}.ko" && do_update=1 && rm -f "${i}/${j}.ko"
    339330        done
    340         test -n "${do_update}" && test "x${kern_ver}" != "x${skip_ver}" &&
    341             update_initramfs "${kern_ver}"
     331        test -z "$do_update" || update_initramfs "$KERN_VER"
    342332        # Remove empty /lib/modules folders which may have been kept around
    343333        rmdir -p "${i}" 2>/dev/null || true
    344334        unset keep
    345         for j in /lib/modules/"${kern_ver}"/*; do
     335        for j in /lib/modules/"${KERN_VER}"/*; do
    346336            name="${j##*/}"
    347337            test -d "${name}" || test "${name%%.*}" != modules && keep=1
    348338        done
    349339        if test -z "${keep}"; then
    350             rm -rf /lib/modules/"${kern_ver}"
    351             rm -f /boot/initrd.img-"${kern_ver}"
     340            rm -rf /lib/modules/"${KERN_VER}"
     341            rm -f /boot/initrd.img-"${KERN_VER}"
    352342        fi
    353343    done
     
    357347    done
    358348    rm -f /etc/depmod.d/vboxvideo-upstream.conf
     349    rm -f "$SKIPFILE_BASE"-*
    359350}
    360351
     
    362353setup_modules()
    363354{
    364     # don't stop the old modules here -- they might be in use
    365     test -z "${QUICKSETUP}" && cleanup_modules --skip "${KERN_VER}"
    366     # This does not work for 2.4 series kernels.  How sad.
    367     test -n "${QUICKSETUP}" && test -f "${MODULE_DIR}/vboxguest.ko" && return 0
    368     info "Building the VirtualBox Guest Additions kernel modules.  This may take a while."
    369 
    370     # If the kernel headers are not there, wait at bit in case they get
    371     # installed.  Package managers have been known to trigger module rebuilds
    372     # before actually installing the headers.
    373     for delay in 60 60 60 60 60 300 30 300 300; do
    374         test "x${QUICKSETUP}" = xyes || break
    375         test -d "/lib/modules/${KERN_VER}/build" && break
    376         printf "Kernel modules not yet installed, waiting %s seconds." "${delay}"
    377         sleep "${delay}"
    378     done
    379 
    380     # Inhibit shutdown for up to ten minutes if possible.
    381     systemd-inhibit 600 2>/dev/null &
    382     log "Building the main Guest Additions module."
     355    KERN_VER="$1"
     356    test -n "$KERN_VER" || return 1
     357    test ! -f /lib/modules/"$KERN_VER"/misc/vboxguest.ko || return 0
     358    test ! -f /lib/modules/"$KERN_VER"/misc/vboxguest.o || return 0
     359    test -d /lib/modules/"$KERN_VER"/build || return 0
     360    test ! -f "$SKIPFILE_BASE"-"$KERN_VER" || return 0
     361    export KERN_VER
     362    info "Building the modules for kernel $KERN_VER."
     363
     364    log "Building the main Guest Additions module for kernel $KERN_VER."
    383365    if ! myerr=`$BUILDINTMP \
    384366        --save-module-symvers /tmp/vboxguest-Module.symvers \
     
    389371        "${INSTALL_DIR}"/other/check_module_dependencies.sh 2>&1 &&
    390372            info "Look at $LOG to find out what went wrong"
    391         kill $! 2>/dev/null
    392373        return 0
    393374    fi
     
    399380        module_build_log "$myerr"
    400381        info  "Look at $LOG to find out what went wrong"
    401         kill $! 2>/dev/null
    402382        return 0
    403383    fi
     
    415395    echo "override vboxvideo * misc" >> /etc/depmod.d/vboxvideo-upstream.conf
    416396    update_initramfs "${KERN_VER}"
    417     depmod
    418     kill $! 2>/dev/null
    419397    return 0
    420398}
     
    458436}
    459437
    460 create_module_rebuild_script()
    461 {
    462     # And a post-installation script for rebuilding modules when a new kernel
    463     # is installed.
    464     mkdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d
    465     cat << EOF > /etc/kernel/postinst.d/vboxadd
    466 #!/bin/sh
    467 # Run in the background so that we can wait in case the package installer has
    468 # not yet installed the kernel headers we need.
    469 KERN_VER="\${1}" /sbin/rcvboxadd quicksetup &
    470 exit 0
    471 EOF
    472     cat << EOF > /etc/kernel/prerm.d/vboxadd
    473 #!/bin/sh
    474 for i in ${OLDMODULES}; do rm -f /lib/modules/"\${1}"/misc/"\${i}".ko; done
    475 rmdir -p /lib/modules/"\$1"/misc 2>/dev/null
    476 exit 0
    477 EOF
    478     chmod 0755 /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
    479 }
    480 
    481438shared_folder_setup()
    482439{
     
    507464    export USERNAME
    508465
     466    test x"$1" != x--quick || QUICKSETUP=true
     467    test -n "$QUICKSETUP" || cleanup
    509468    MODULE_SRC="$INSTALL_DIR/src/vboxguest-$INSTALL_VER"
    510469    BUILDINTMP="$MODULE_SRC/build_in_tmp"
    511     test -e /etc/selinux/config &&
     470    test ! -e /etc/selinux/config ||
    512471        chcon -t bin_t "$BUILDINTMP"
    513472
    514     test -z "${INSTALL_NO_MODULE_BUILDS}" && setup_modules
     473    if test -z "$INSTALL_NO_MODULE_BUILDS"; then
     474        if test -z "$QUICKSETUP"; then
     475            info "Building the VirtualBox Guest Additions kernel modules.  This may take a while."
     476            info "To build modules for other installed kernels, run"
     477            info "  /sbin/rcvboxadd quicksetup <version>"
     478            for setupi in /lib/modules/*; do
     479                KERN_VER="${setupi##*/}"
     480                # For a full setup, mark kernels we do not want to build.
     481                touch "$SKIPFILE_BASE"-"$KERN_VER"
     482            done
     483        fi
     484        # That is, we mark all but the requested kernel.
     485        rm -f "$SKIPFILE_BASE"-"$TARGET_VER"
     486        for setupi in /lib/modules/*; do
     487            KERN_VER="${setupi##*/}"
     488            setup_modules "$KERN_VER"
     489        done
     490        depmod
     491    fi
    515492    create_vbox_user
    516493    create_udev_rule
    517     test -z "${INSTALL_NO_MODULE_BUILDS}" && create_module_rebuild_script
    518     test -n "${QUICKSETUP}" && return 0
     494    test -z "$QUICKSETUP" || return 0
    519495    shared_folder_setup
    520496    if  running_vboxguest || running_vboxadd; then
     
    543519    # Remove other files
    544520    rm /sbin/mount.vboxsf 2>/dev/null
    545     if test -z "${INSTALL_NO_MODULE_BUILDS}"; then
    546         rm -f /etc/kernel/postinst.d/vboxadd /etc/kernel/prerm.d/vboxadd
    547         rmdir -p /etc/kernel/postinst.d /etc/kernel/prerm.d 2>/dev/null
    548     fi
    549521    rm /etc/udev/rules.d/60-vboxadd.rules 2>/dev/null
    550522}
     
    577549    ;;
    578550quicksetup)
    579     QUICKSETUP=yes
    580     setup
     551    test -z "$2" || test ! -d /lib/modules/"$2"/build || TARGET_VER="$2"
     552    setup --quick
    581553    ;;
    582554cleanup)
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