@@ -59,7 +59,8 @@ declare version me start_time dialog_title license adrelanos_signify \
5959 transfer_proxy_suffix proxy curl_transfer_proxy curl_opt_ssl \
6060 url_guest_file url_origin signify_key signify_signer url_domain \
6161 url_version download_flag checkhash interface_name \
62- dist_installer_cli_was_sourced APTGETOPT APTGETOPT_SERIALIZED
62+ dist_installer_cli_was_sourced can_boot_virtualbox_guest_vms APTGETOPT \
63+ APTGETOPT_SERIALIZED
6364
6465if [[ -n " ${BASH_SOURCE[0]-} " && " ${BASH_SOURCE[0]} " != " ${0} " ]]; then
6566 # # Script was sourced.
@@ -1098,6 +1099,10 @@ check_guest_boot() {
10981099 return 0
10991100 fi
11001101
1102+ if [ " ${can_boot_virtualbox_guest_vms} " = ' false' ]; then
1103+ log warning " A reboot may be required before the installed virtual machine(s) can be launched."
1104+ fi
1105+
11011106 # # Refresh variables vm_or_vms_already_existing_test_result, gateway_exists and workstation_exists.
11021107 check_vm_exists_general " (check after import)"
11031108
@@ -1547,6 +1552,86 @@ check_installed_debian() {
15471552}
15481553
15491554
1555+ disable_kvm_virt_at_load () {
1556+ local module_list_str kvm_variant kvm_variant_unload_failed \
1557+ kvm_core_unload_failed kvm_reload_failed
1558+
1559+ module_list_str=' '
1560+ kvm_variant=' '
1561+ kvm_variant_unload_failed=' false'
1562+ kvm_core_unload_failed=' false'
1563+ kvm_reload_failed=' false'
1564+
1565+ # # KVM's 'enable_virt_at_load' feature renders VirtualBox unusable on systems
1566+ # # using Linux 6.12 or higher.
1567+ # #
1568+ # # VirtualBox can be fixed by setting 'enable_virt_at_load=0' in the KVM
1569+ # # driver. This does not break KVM, it simply prevents it from conflicting
1570+ # # with VirtualBox (at the expense of making the first KVM VM launch and the
1571+ # # last KVM VM shutdown take slightly longer). This is safe to set even on
1572+ # # kernels older than 6.12, it will act as a no-op there.
1573+ # #
1574+ # # Using modprobe.d for setting this parameter as recommended by
1575+ # # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1082157#29
1576+ # #
1577+ # # Using same method documented at
1578+ # # https://www.kicksecure.com/wiki/Template:VirtualBox_Host_Software_Installation#Ubuntu
1579+ log notice " Disabling KVM virt-at-load feature to enable VirtualBox to function. This will not break the ability to use KVM virtual machines..."
1580+ printf ' %s\n' " \
1581+ ## Prevent VirtualBox and KVM from conflicting. This does not break KVM.
1582+ options kvm enable_virt_at_load=0" \
1583+ | root_cmd tee /etc/modprobe.d/disable-kvm-virt-at-load.conf > /dev/null
1584+ log notice " KVM virt-at-load feature disabled."
1585+
1586+ # # Hot-reloading KVM kernel module if possible. This is necessary for VM
1587+ # # autostart to work later.
1588+ log notice " Attempting hot reload of KVM kernel modules to allow VirtualBox VM auto-start later..."
1589+ module_list_str=" $( lsmod | cut -d' ' -f1) "
1590+
1591+ if grep ' ^kvm_intel$' <<< " ${module_list_str}" ; then
1592+ kvm_variant=' intel'
1593+ elif grep ' ^kvm_amd$' <<< " ${module_list_str}" ; then
1594+ kvm_variant=' amd'
1595+ elif grep ' ^kvm$' <<< " ${module_list_str}" ; then
1596+ # # KVM hot-reload will almost certainly fail if we can't detect the KVM
1597+ # # variant, as the core KVM module requires a helper module for the
1598+ # # specific CPU architecture. Warn, but try to reload anyway.
1599+ log warn " Could not detect KVM variant. KVM hot reload will probably fail."
1600+ kvm_variant=' unknown'
1601+ fi
1602+
1603+ if [ " ${kvm_variant} " != ' unknown' ]; then
1604+ root_cmd modprobe -r " kvm_${kvm_variant} " || kvm_variant_unload_failed=' true'
1605+ fi
1606+ root_cmd modprobe -r ' kvm' || kvm_core_unload_failed=' true'
1607+
1608+ if [ " ${kvm_variant_unload_failed} " = ' true' ]; then
1609+ log warn " Failed to unload KVM kernel modules. A reboot will possibly be required before VirtualBox VMs will function properly."
1610+ can_boot_virtualbox_guest_vms=' false'
1611+ elif [ " ${kvm_core_unload_failed} " = ' true' ]; then
1612+ # # Try to put the variant kernel module back. It is not fatal if this
1613+ # # fails.
1614+ root_cmd modprobe " kvm_${kvm_variant} " || true
1615+ log warn " Failed to unload KVM kernel modules. A reboot will possibly be required before VirtualBox VMs will function properly."
1616+ can_boot_virtualbox_guest_vms=' false'
1617+ fi
1618+
1619+ if [ " ${kvm_variant} " != ' unknown' ]; then
1620+ root_cmd modprobe " kvm_${kvm_variant} " || kvm_reload_failed=' true'
1621+ else
1622+ root_cmd modprobe ' kvm' || kvm_reload_failed=' true'
1623+ fi
1624+
1625+ if [ " ${kvm_reload_failed} " = ' true' ]; then
1626+ log warn " Failed to reload KVM kernel modules. A reboot will possibly be required before either VirtualBox or KVM VMs will function properly."
1627+ can_boot_virtualbox_guest_vms=' false'
1628+ return 0
1629+ fi
1630+
1631+ log notice " Successfully reloaded KVM kernel modules. VirtualBox VMs should be functional."
1632+ }
1633+
1634+
15501635install_package_fedora_common () {
15511636 pkg_mngr=" dnf"
15521637 pkg_mngr_install=( " ${pkg_mngr} " ' install' ' --assumeyes' ' --setopt=install_weak_deps=False' )
@@ -1719,6 +1804,7 @@ install_virtualbox_fedora_common_end() {
17191804 fi
17201805
17211806 add_user_to_vbox_group
1807+ disable_kvm_virt_at_load
17221808}
17231809
17241810
@@ -1733,6 +1819,7 @@ install_virtualbox_debian_common_end() {
17331819 fi
17341820
17351821 add_user_to_vbox_group
1822+ disable_kvm_virt_at_load
17361823}
17371824
17381825
@@ -3925,6 +4012,7 @@ set_default() {
39254012 qubes_template_detected=" "
39264013 install_pkg_fasttrack_extra_args_maybe=()
39274014 user_warned_potential_startup_issue=" "
4015+ can_boot_virtualbox_guest_vms=" true"
39284016 # # 'vboxmanage' locale needs to be "C" (default, English) so output can be grepped.
39294017 vboxmanage_locale_english=( ' env' ' LC_ALL=C.UTF-8' ' LANG=C.UTF-8' ' LANGUAGE=C' ' vboxmanage' )
39304018}
0 commit comments