怎么用VirtualBox后台运行?~

本文介绍了如何在VirtualBox中实现虚拟机的后台静默启动,通过使用VBoxManage及VBoxHeadless命令行工具,并结合VBS脚本实现完全无界面启动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

VirtualBox 这个虚拟机我第一次使用!~

对他不是很熟悉,配置完成后发现不能后台运行 每次启动都会有界面,对于想要模拟集群的我来说很麻烦~!

我经过查阅资料发现 可以只用 VBoxManage来启动!~

查看help


VBoxManage startvm          <uuid>|<name>
                            [--type gui|sdl|headless]

 

可见他有三个启动模式 分别是  gui  界面

 

 sdl 是什么?,启动就报错

资料说  headless启动没有界面

 

于是 试着运行headless模式,果然没有界面,只不过有个黑色的框框,恶心呀!~

以前有过VBS后台运行程序的经验

 

DIM objShell
set objShell=wscript.createObject("wscript.shell")
iReturn=objShell.Run("pldev.bat /start", 0, TRUE)

 

这样就 可以后台运行

 

那么我试着这样执行

DIM objShell
set objShell=wscript.createObject("wscript.shell")
iReturn=objShell.Run("VBoxManage startvm hadoop -type headless", 0, TRUE)

 

结果呢还是有个黑框框,为什么不能隐藏呢?

我多次实验发现原来VBoxManage 在使用headless模式启动的时候实际上是弹出了另一个程序,是弹出!~

所以我的VBS隐藏了VBoxManage 没有隐藏他的弹出程序!~

我试着直接调用他的弹出程序VBoxHeadless.exe,然后我运行help

C:/Users/IXR>VBoxHeadless
Oracle VM VirtualBox Headless Interface 4.0.8
(C) 2008-2011 Oracle Corporation
All rights reserved.

Usage:
   -s, -startvm, --startvm <name|uuid>   Start given VM (required argument)
   -v, -vrde, --vrde on|off|config       Enable (default) or disable the VRDE
                                         server or don't change the setting
   -e, -vrdeproperty, --vrdeproperty <name=[value]> Set a VRDE property:
                                         "TCP/Ports" - comma-separated list of p
orts
                                         the VRDE server can bind to. Use a dash
 between
                                         two port numbers to specify a range
                                         "TCP/Address" - interface IP the VRDE s
erver
                                         will bind to
   -c, -capture, --capture               Record the VM screen output to a file
   -w, --width                           Frame width when recording
   -h, --height                          Frame height when recording
   -r, --bitrate                         Recording bit rate when recording
   -f, --filename                        File name when recording.  The codec
                                         used will be chosen based on the
                                         file extension

 

没错 他和 VBoxManage 一样有 startvm 这样可以理解了!~哈哈

于是我修改VBS

DIM objShell  
set objShell=wscript.createObject("wscript.shell")  
iReturn=objShell.Run("VBoxHeadless -startvm hadoop", 0, TRUE)

 

保存,运行start.vbs 哇!~ 没有任何反映 看进程 有了 VBoxHeadless

 

ping 虚拟机

C:/Users/IXR>ping 10.0.0.100

正在 Ping 10.0.0.100 具有 32 字节的数据:
来自 10.0.0.100 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.100 的回复: 字节=32 时间<1ms TTL=64
来自 10.0.0.100 的回复: 字节=32 时间<1ms TTL=64

 

启动了,呵呵 ssh连接上吧!~

 

### 如何优化VirtualBox上Ubuntu性能 #### 安装Guest Additions 为了改善鼠标响应和其他图形界面交互,在新安装的Ubuntu系统中应立即安装VirtualBox Guest Additions。这组工具能够显著提升用户体验,解决鼠标反应迟钝等问题[^2]。 ```bash sudo apt update && sudo apt install build-essential dkms linux-headers-generic cd /media/$USER/VBOXADDITIONS_* sudo sh VBoxLinuxAdditions.run ``` #### 配置硬件资源分配 合理设置虚拟机所使用的CPU核心数与RAM大小至关重要。虽然增加这些参数可能看似简单直接的办法,但过度配置反而可能导致效率低下甚至引起宿主机资源紧张。建议依据实际需求适当调整: - CPU数量:通常情况下2到4核已经足够大多数应用场景; - 内存容量:对于日常办公或开发环境来说,2GB至4GB是比较合理的范围; 此外,启用3D加速功能有助于提高桌面环境下的视觉效果流畅度,并且确保已勾选“Enable PAE/NX”。 #### 修改内核服务启动项 某些不必要的后台进程和服务会在开机过程中耗费大量时间,通过禁用它们可有效缩短加载耗时并减轻系统负担。以下是具体的命令操作指南[^3]: ```bash sudo systemctl disable plymouth-quit-wait.service sudo systemctl disable NetworkManager-wait-online.service sudo systemctl disable avahi-daemon.service sudo systemctl disable snapd.service ``` 以上措施综合运用后应该能明显感觉到Ubuntu在VirtualBox中的表现有所改观,不再频繁出现卡顿现象。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值