不用gui界面,在Ubuntu命令行运行VirtualBox 虚拟机
2026/5/25 4:06:54 网站建设 项目流程

在 Ubuntu 命令行中启动 VirtualBox 虚拟机,主要通过VBoxManage命令实现。以下是详细步骤:


1. 首先确认虚拟机名称

VBoxManage list vmsCopy
  • 会列出所有已创建的虚拟机(格式如"Ubuntu_Server" {uuid})。
  • 注意:名称需用双引号包裹(尤其当名称含空格时)。

2. 启动虚拟机的命令

推荐方式:无界面模式(Headless)
VBoxManage startvm "虚拟机名称" --type headlessCopy
  • --type headless:关键参数!表示后台运行(无 GUI 界面),适合服务器或纯命令行环境。
  • 示例:
    VBoxManage startvm "My_Ubuntu_VM" --type headlessCopy
其他模式(不推荐用于纯命令行):
# GUI 模式(需图形界面支持,本地桌面环境可用) VBoxManage startvm "虚拟机名称" # 简易窗口模式(类似 headless,但有基础窗口) VBoxManage startvm "虚拟机名称" --type sdlCopy

3. 验证是否启动成功

VBoxManage list runningvmsCopy
  • 若返回虚拟机名称,表示已运行。

4. 常见问题解决

问题 1:权限错误
  • 错误提示RTR3InitEx failed with rc=-1912
  • 解决:将用户加入vboxusers组并重启:
    sudo usermod -aG vboxusers $USER rebootCopy
问题 2:虚拟机卡在启动状态
  • 原因:可能因 Guest Additions 未安装或配置冲突。
  • 解决:强制关闭后重启:
    VBoxManage controlvm "虚拟机名称" poweroff # 强制关机 VBoxManage startvm "虚拟机名称" --type headless # 重新启动Copy
问题 3:Headless 模式下无法连接
  • 解决:通过 SSH 或 RDP 连接(需提前配置):
    • SSH:确保虚拟机内安装openssh-server,并使用ssh user@虚拟机IP
    • RDP:在 VirtualBox 设置中启用远程显示设置 > 显示 > 远程显示),然后用rdesktop连接:
      rdesktop localhost:3389 # 默认端口 3389Copy

附:常用管理命令

功能命令
关机VBoxManage controlvm "虚拟机名称" poweroff
暂停VBoxManage controlvm "虚拟机名称" pause
恢复VBoxManage controlvm "虚拟机名称" resume
查看状态VBoxManage showvminfo "虚拟机名称"

💡提示

  • 所有命令需在安装了 VirtualBox 的主机上执行(非虚拟机内部)。
  • 若未安装 VirtualBox CLI 工具,请先安装:
    sudo apt update && sudo apt install virtualboxCopy

(321 words, 2133 chars, 1351 tokens)

实践

列表

VBoxManage list vms

启动

虚拟机的名字叫ub

VBoxManage startvm ub --type headless

启动完成

VBoxManage startvm ub --type headless
Waiting for VM "ub" to power on...
VM "ub" has been successfully started.

验证已经启动

VBoxManage list runningvms

显示:

VBoxManage list runningvms
"ub" {c270148f-77f8-4488-8c40-84fea93f3893}

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询