動かざることバグの如し

近づきたいよ 君の理想に

UbuntuでVirtualBox can't operate in VMX root modeエラーでVirtualBox起動しない

環境

問題

母艦がUbuntuで、VirtualBoxの起動に失敗してしまうようになってしまった。vagrant経由だが以下の様なログ

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/ubuntu-24.04' version '202510.26.0' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Configuring storage mediums...
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "2cac2f5a-f62b-4cc9-9799-5d3036899b40", "--type", "headless"]

Stderr: VBoxManage: error: VirtualBox can't operate in VMX root mode. Please disable the KVM kernel extension, recompile your kernel and reboot (VERR_VMX_IN_VMX_ROOT_MODE)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component ConsoleWrap, interface IConsole

VirtualBox can't operate in VMX root mode. Please disable the KVM kernel extension … (VERR_VMX_IN_VMX_ROOT_MODE)」が該当のエラーっぽい

原因

VirtualBox can't operate in VMX root mode. Please disable the KVM kernel extension … (VERR_VMX_IN_VMX_ROOT_MODE)」だが、 Linux側でKVMモジュールが先に VT-x/AMD‑V を占有している状態で VirtualBox を起動したときに出るエラーらしい。

Ubuntu 24.04 以降+新しめのカーネルでは、KVM モジュールがロードされた時点で自動的に仮想化機能をつかみに行く仕様になっていて、VirtualBox と競合してしまった、というわけ。

KVM モジュールをアンロードして起動できるか確認

sudo rmmod kvm_intel

を実行して起動できればKVM モジュールが問題と言って間違いない。

対応

とはいえ母艦起動時に毎回rmmodするわけにはいかないので恒久的な設定がしたい。

/etc/modprobe.d/VBox-NoKVM.confを新規作成して以下

# Prevent KVM from grabbing virtualization on load for VirtualBox
options kvm enable_virt_at_load=0

initramfsを再生成

sudo update-initramfs -u

これで母艦を再起動すれば起動時にKVM が VT-x/AMD‑V を握らないようになって、VirtualBox が VMX root mode に入れるようになるはず。

補足

kvm_intel / kvm_amd を完全ブラックリストにしてしまう例もあるけれど、 その場合 KVM/QEMU を使えなくなるから、まずはこの「enable_virt_at_load=0」方式のほうが無難

# /etc/modprobe.d/blacklist.conf
blacklist kvm_intel

参考リンク