Skip to content

Commit eae99cf

Browse files
committed
Merge remote-tracking branch 'ArrayBolt3/arraybolt3/trixie'
2 parents 291d77c + 8acc388 commit eae99cf

File tree

3 files changed

+185
-2
lines changed

3 files changed

+185
-2
lines changed

usr/bin/dist-installer-cli

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

6465
if [[ -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+
15501635
install_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
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <[email protected]>
2+
## See the file COPYING for copying conditions.
3+
4+
## Prevent KVM and VirtualBox from conflicting. This does not break the
5+
## ability to use KVM virtual machines, it simply keeps KVM from being active
6+
## when unneeded so that VirtualBox can run.
7+
options kvm enable_virt_at_load=0

usr/share/usability-misc/dist-installer-cli-standalone

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ declare version me start_time dialog_title license adrelanos_signify \
6060
transfer_proxy_suffix proxy curl_transfer_proxy curl_opt_ssl \
6161
url_guest_file url_origin signify_key signify_signer url_domain \
6262
url_version download_flag checkhash interface_name \
63-
dist_installer_cli_was_sourced APTGETOPT APTGETOPT_SERIALIZED
63+
dist_installer_cli_was_sourced can_boot_virtualbox_guest_vms APTGETOPT \
64+
APTGETOPT_SERIALIZED
6465

6566
if [[ -n "${BASH_SOURCE[0]-}" && "${BASH_SOURCE[0]}" != "${0}" ]]; then
6667
## Script was sourced.
@@ -1847,6 +1848,10 @@ check_guest_boot() {
18471848
return 0
18481849
fi
18491850

1851+
if [ "${can_boot_virtualbox_guest_vms}" = 'false' ]; then
1852+
log warning "A reboot may be required before the installed virtual machine(s) can be launched."
1853+
fi
1854+
18501855
## Refresh variables vm_or_vms_already_existing_test_result, gateway_exists and workstation_exists.
18511856
check_vm_exists_general "(check after import)"
18521857

@@ -2296,6 +2301,86 @@ check_installed_debian() {
22962301
}
22972302

22982303

2304+
disable_kvm_virt_at_load() {
2305+
local module_list_str kvm_variant kvm_variant_unload_failed \
2306+
kvm_core_unload_failed kvm_reload_failed
2307+
2308+
module_list_str=''
2309+
kvm_variant=''
2310+
kvm_variant_unload_failed='false'
2311+
kvm_core_unload_failed='false'
2312+
kvm_reload_failed='false'
2313+
2314+
## KVM's 'enable_virt_at_load' feature renders VirtualBox unusable on systems
2315+
## using Linux 6.12 or higher.
2316+
##
2317+
## VirtualBox can be fixed by setting 'enable_virt_at_load=0' in the KVM
2318+
## driver. This does not break KVM, it simply prevents it from conflicting
2319+
## with VirtualBox (at the expense of making the first KVM VM launch and the
2320+
## last KVM VM shutdown take slightly longer). This is safe to set even on
2321+
## kernels older than 6.12, it will act as a no-op there.
2322+
##
2323+
## Using modprobe.d for setting this parameter as recommended by
2324+
## https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1082157#29
2325+
##
2326+
## Using same method documented at
2327+
## https://www.kicksecure.com/wiki/Template:VirtualBox_Host_Software_Installation#Ubuntu
2328+
log notice "Disabling KVM virt-at-load feature to enable VirtualBox to function. This will not break the ability to use KVM virtual machines..."
2329+
printf '%s\n' "\
2330+
## Prevent VirtualBox and KVM from conflicting. This does not break KVM.
2331+
options kvm enable_virt_at_load=0" \
2332+
| root_cmd tee /etc/modprobe.d/disable-kvm-virt-at-load.conf >/dev/null
2333+
log notice "KVM virt-at-load feature disabled."
2334+
2335+
## Hot-reloading KVM kernel module if possible. This is necessary for VM
2336+
## autostart to work later.
2337+
log notice "Attempting hot reload of KVM kernel modules to allow VirtualBox VM auto-start later..."
2338+
module_list_str="$(lsmod | cut -d' ' -f1)"
2339+
2340+
if grep '^kvm_intel$' <<< "${module_list_str}" ; then
2341+
kvm_variant='intel'
2342+
elif grep '^kvm_amd$' <<< "${module_list_str}" ; then
2343+
kvm_variant='amd'
2344+
elif grep '^kvm$' <<< "${module_list_str}" ; then
2345+
## KVM hot-reload will almost certainly fail if we can't detect the KVM
2346+
## variant, as the core KVM module requires a helper module for the
2347+
## specific CPU architecture. Warn, but try to reload anyway.
2348+
log warn "Could not detect KVM variant. KVM hot reload will probably fail."
2349+
kvm_variant='unknown'
2350+
fi
2351+
2352+
if [ "${kvm_variant}" != 'unknown' ]; then
2353+
root_cmd modprobe -r "kvm_${kvm_variant}" || kvm_variant_unload_failed='true'
2354+
fi
2355+
root_cmd modprobe -r 'kvm' || kvm_core_unload_failed='true'
2356+
2357+
if [ "${kvm_variant_unload_failed}" = 'true' ]; then
2358+
log warn "Failed to unload KVM kernel modules. A reboot will possibly be required before VirtualBox VMs will function properly."
2359+
can_boot_virtualbox_guest_vms='false'
2360+
elif [ "${kvm_core_unload_failed}" = 'true' ]; then
2361+
## Try to put the variant kernel module back. It is not fatal if this
2362+
## fails.
2363+
root_cmd modprobe "kvm_${kvm_variant}" || true
2364+
log warn "Failed to unload KVM kernel modules. A reboot will possibly be required before VirtualBox VMs will function properly."
2365+
can_boot_virtualbox_guest_vms='false'
2366+
fi
2367+
2368+
if [ "${kvm_variant}" != 'unknown' ]; then
2369+
root_cmd modprobe "kvm_${kvm_variant}" || kvm_reload_failed='true'
2370+
else
2371+
root_cmd modprobe 'kvm' || kvm_reload_failed='true'
2372+
fi
2373+
2374+
if [ "${kvm_reload_failed}" = 'true' ]; then
2375+
log warn "Failed to reload KVM kernel modules. A reboot will possibly be required before either VirtualBox or KVM VMs will function properly."
2376+
can_boot_virtualbox_guest_vms='false'
2377+
return 0
2378+
fi
2379+
2380+
log notice "Successfully reloaded KVM kernel modules. VirtualBox VMs should be functional."
2381+
}
2382+
2383+
22992384
install_package_fedora_common() {
23002385
pkg_mngr="dnf"
23012386
pkg_mngr_install=( "${pkg_mngr}" 'install' '--assumeyes' '--setopt=install_weak_deps=False' )
@@ -2468,6 +2553,7 @@ install_virtualbox_fedora_common_end() {
24682553
fi
24692554

24702555
add_user_to_vbox_group
2556+
disable_kvm_virt_at_load
24712557
}
24722558

24732559

@@ -2482,6 +2568,7 @@ install_virtualbox_debian_common_end() {
24822568
fi
24832569

24842570
add_user_to_vbox_group
2571+
disable_kvm_virt_at_load
24852572
}
24862573

24872574

@@ -4674,6 +4761,7 @@ set_default() {
46744761
qubes_template_detected=""
46754762
install_pkg_fasttrack_extra_args_maybe=()
46764763
user_warned_potential_startup_issue=""
4764+
can_boot_virtualbox_guest_vms="true"
46774765
## 'vboxmanage' locale needs to be "C" (default, English) so output can be grepped.
46784766
vboxmanage_locale_english=( 'env' 'LC_ALL=C.UTF-8' 'LANG=C.UTF-8' 'LANGUAGE=C' 'vboxmanage' )
46794767
}

0 commit comments

Comments
 (0)