「ORACLE-VIRTUALBOX」-

认识

官网:https://www.virtualbox.org/
文档:https://www.virtualbox.org/wiki/Documentation
仓库:https://github.com/VirtualBox/virtualbox

组成

命令程序 and 配置文件

VBoxBugReport/vboxbugreport:Bug 反馈工具;
VBoxDTrace/vboxdtrace:软连接到 VBox.sh
vbox-img:磁盘工具,用于格式转化、修复等功能;
vboxsdl/VBoxSDL:VBoxSDL 是个简单的图形用户界面(GUI),缺少良好的交互支持。VBoxSDL 目前主要用于内部调试 VirtualBox,因此没有正式支持;
vboxconfig:软连接,指向 /opt/VirtualBox/postinst-common.sh。用于安装公共部分;
VBoxHeadless/vboxheadless:vboxheadless 在主机上根本不产生可见的输出,但仍然可以提供 VRDP 数据。vboxheadless 也不依赖于 Linux 和 Solaris 主机上的 X Window 系统;
vboxwebsrv:它提供 web 服务;
VBoxAutostart:用于自动启动或者自动保存虚拟机。但是只能和 systemd 一起使用;
VBoxBalloonCtrl:watchdog
VBoxVRDP
VBoxSysInfo.sh
VBoxNetNAT
VBoxTestOGL
vboxautostart-service.sh
VBoxNetDHCP
VBoxBalloonCtrl
routines.sh
VBoxCreateUSBNode.sh
rdesktop-vrdp
vboxballoonctrl-service.sh
VBoxNetAdpCtl
VirtualBox
VBoxVolInfo
VBoxTunctl
VBoxAutostart
vboxweb-service.sh
VBoxSDL
VBoxHeadless
VBoxDTrace
vboxshell.py
vboxwebsrv
VBox.sh
VBoxSVC
prerm-common.sh
vbox-img
VBoxExtPackHelperApp
check_module_dependencies.sh
VBoxXPCOMIPCD
vboxdrv.sh

性质

提供多种客户操作系统

Guest Operating Systems https://www.virtualbox.org/manual/topics/Introduction.html#guestossupport

提供界面配置 | GUI Configuration

qt – How do I set default font for all Qt5 applications? – Unix & Linux Stack Exchange

目前(VirtualBox 7)并未提供 GUI 的更多精细化配置,诸如字体配置等等;

但是,某些 GUI 框架支持通过环境变量控制应用配置。而 VirutalBox 基于 Qt 开发,我们或许可以针对 Qt 环境进行配置;

针对 Qt5 应用,可以使用 Qt5ct 进行全局应用配置。目前(11/21/2022),我们只想调整 GUI 字体;

提供 Hyper-V 兼容模式(Windows 10/11 1903 及以上版本)

Using Hyper-V with Oracle VirtualBox

从 VirtualBox 6.0 开始,VirtualBox 支持在启用 Hyper-V 的系统中运行,但需要切换到 Hyper-V 兼容模式。

针对该模式,VirtualBox 会利用 Hyper-V 的虚拟化技术(称为 Windows Hypervisor Platform),而不是自己的虚拟化技术。

针对该模式,其性能通常不如 VirtualBox 的默认模式。

提供虚拟机嵌套功能 | 在虚拟机中,运行虚拟机 | Nested Virtualization

virtualization – Virtualbox enable nested vtx/amd-v greyed out – Stack Overflow
How To Enable Nested Virtualization In VirtualBox – OSTechNix

Nested Virtualization

开启嵌套特性:

# 如果 System => Processer => Enable Nested VT-x/AMD-V 灰色,则执行:
VBoxManage modifyvm "Virtual Machine Name" --nested-hw-virt on

验证开启成功:

# Linux
egrep --color -i "svm|vmx" /proc/cpuinfo

# Windows
# 通过 Sysinternals 的 Coreinfo 命令,显示 SVM 与 VMX 标识;

Q:VirtualBox on Linux, Guest Windows 10,通过虚拟机嵌套,在 Windows 10 中启动 VirtualBox 导致 Windows 10 卡住不动;
A:(1)配置 System / Acceleration Paravirtualization Interface: None 即可;(2)我们同时在 Guest Windows 10 中执行 bcdedit /set hypervisorlaunchtype off 命令,但并不能确定与此相关;

构建

安装 | Linux | Windows | macOS

on Ubuntu 24.04 LTS

Linux_Downloads – Oracle VM VirtualBox

# 安装全家桶
apt-get install -y $(
    apt-cache search virtualbox | grep -E '^virtualbox' | grep -v -- '-hwe' | awk '{printf("%s ", $1)}'
)

VBoxManage --version # virtualbox --help

针对 7.0.20_Ubuntur163906 版本,启动虚拟机提示 KVM 冲突,需要禁用 kvm 相关的内核模块:

modprobe -r kvm_intel # Intel CPU
modprobe -r kvm_amd   # AMD CPU
modprobe -r kvm

cat > /etc/modprobe.d/blacklist-virtualbox-ours.conf <<EOF
blacklist kvm_intel
blacklist kvm_amd
blacklist kvm
EOF

通过官方源安装

# 02/19/2022 与官方相比,通过仓库安装的 VirtualBox 缺少如干组件,比如自动启动虚拟机的管理服务;

echo 'deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian focal contrib' \
    > /etc/apt/source.list.d/virtualbox-offical.list

wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | apt-key add -
apt-get update

apt-get install virtualbox-6.1

on macOS 10.15.6

1)下载:官方下载安装包
2)运行:双击 VirtualBox.pkg 图标,进行程序的安装
3)启动:在 Applications 中,启动应用程序

on Windows 11

华为 Ensp 启动报错 40,Win11 安装 VirtualBox 不兼容问题,VirtualBox-5.2.44 安装_virtualbox5.2.44-CSDN 博客
How to Fix Windows Security’s “This Setting is Managed by Your Administrator” Error

在安装 Ensp 后启动路由器测试时报错 40,根据官网文档操作发现 VirtualBox 因兼容问题根本启动不了,在官网下载 5.2.44 版本后此问题解决。

一定要 Windows 安全中心中关闭内存完整性。

我们尝试卸载 360 应用,但是并没有解决问题。

最后,通过修改注册表,问题得以解决:

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity

Enabled = 0

Exit Registry Editor and click the Power > Restart Start menu options.

卸载

VirtualBox 7.0,Windows 11,在安装目录中,我们未找到卸载程序,需要通过 Seetings/Apps/Installed apps 来卸载。

应用

常见问题处理

改进

常见错误汇总

Cannot register the hard disk … UUID … already exists

Copying VMDK to VDI in VirtualBox
How to Fix VirtualBox UUID already exists Errors

问题描述:当添加磁盘时,提示无法注册磁盘,因为 UUID 已存在:

Cannot register the hard disk ‘E:\VirtualBox VMs\Windows 8 \Windows 8 Enterprise
2.vhd’ {ca2bdc6a-a487-4e57-9fcd-509d0c31d86d} because a hard disk ‘E:\VirtualBox
VMs\Windows 8 Enterprise\Windows 8 Enterprise2.vhd’ with UUID {ca2bdc6a-a487-4e5
7-9fcd-509d0c31d86d} already exists.

原因分析:使用 cp 命令直接复制,导致虚拟磁盘文件的 UUID 相同

解决方案:

# 正确的复制方法
vboxmanage" clonehd original.vmdk new.vdi --format VDI

# 修改 UUID(不一定适用)
vboxmanage internalcommands sethduuid "C:\_VMs\SC9u1\sc9u1.vdi"

#1

Unable to insert the virtual optical disk /opt/VirtualBox/additions/VBoxGuestAdditions.iso into the machine Centos_6.8_x86-64_Local.

在创建虚拟机时,操作系统没有 64 位选项

Why does virtualbox only have 32-bit option, no 64-bit option on Windows 7?
virtualbox Raw-mode is unavailable courtesy of Hyper-V windows 10
VirtualBox only allowing 32 bit OS

参考文章:https://forums.virtualbox.org/viewtopic.php?f=1&t=62339

原因分析:问题原因由很多,在我们的场景里是没有开启虚拟化技术。

For Intel x64: 需要在 BIOS 中开启选项;VT-x (Intel Virtualization Technology) and VT-d are both enabled
For AMD x64: AMD SVM (Secure Virtual Machine) is enabled

在 Windows 中,关闭 Hyper-V 虚拟化:

Windows 功能禁用 Hyper-V 功能。

注意,禁用 Hyper-V 功能只是移除了 Hyper-V 的相关组件和服务,但不会修改启动配置数据(BCD)。因此,bcdedit 中的 hypervisorlaunchtype 仍然保持为 auto,表示 Hypervisor 在启动时仍然可以加载。hypervisorlaunchtype 是启动配置数据(BCD)中的一个参数,用于控制是否在系统启动时加载 Hypervisor。即使 Hyper-V 功能被禁用,如果 hypervisorlaunchtype 仍为 auto,系统仍会尝试加载 Hypervisor,这可能会影响其他虚拟化软件(如 VirtualBox)的正常运行。

所以,还需要 bcdedit /set hypervisorlaunchtype off 来禁用 Hypervisor 服务。

在启动虚拟机后,立刻显示退出,显示 Aborted 状态

virtualbox.org • View topic – VirtualBox 6.1.10 on macOS Catalina 10.15.5 aborting

问题描述:在启动虚拟机后,立刻显示退出,显示 Aborted 状态

环境信息:macOS 10.15.6, VirtualBox 6.1, CentOS Linux release 7.5.1804 (Core)

问题原因:If the last line of the guest’s vbox.log cuts out at “checking audio input permissions”, that is a known issue with Mac OS for now.

解决方法:Disable audio in the guest’s Audio settings to get the guest to run. I think the devs are working on it or waiting for Apple to fix something

补充说明:我们没有深入,音频对于我们来说无关紧要,直接关闭即可。如果需要使用音频功能时,我们再研究;

Bridged networking fails to reconnect when cable unplugged and plugged back in

Bridged networking fails to reconnect when cable unplugged and plugged back in
guest does not regain network connectivity if cable unplugged for for 5+ secs

问题描述:
1)当物理网线插拔时,虚拟机的桥接网络没有随着变化。当再次插入网线之后,虚拟机无法访问网络;
2)Windows 10 IoT Enterprise 21H1,VirtualBox 5.2.44;

… Can’t enumerate USB devices …

Failed to enumerate host USB devices.

VirtualBox is not currently allowed to access USB devices. You can change this by adding your user to the ‘vboxusers’ group. Please see the user manual for a more detailed explanation.

sudo adduser $(whoami) vboxusers

参考

Timeline: https://www.virtualbox.org/timeline?daysback=10
Changelog: https://www.virtualbox.org/wiki/Changelog