Vagrant/VirtualBox:如何创建所需的仅主机以太网适配器

Vagrant/VirtualBox:如何创建所需的仅主机以太网适配器

六年前,我在一台 Win10 主机上设置了一个 CentOS VM,当时我主要依靠其他人的知识 - 我当时只是勉强弄清楚了如何让它工作。现在,我正把所有东西都搬到一台新电脑(Win11)上。我安装了 VirtualBox 和 Vagrant,将我知道的所有文件复制到与旧机器相同的路径中,然后祈祷一切顺利,并尝试了一下。我得到了以下输出:

PS C:\dev\7and7> vagrant up
Bringing machine '7and7' up with 'virtualbox' provider...
==> 7and7: Resuming suspended VM...
==> 7and7: 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", "797d2c9c-557c-4f5c-a988-502c3bcfae8e", "--type", "headless"]

Stderr: VBoxManage.exe: error: Nonexistent host networking interface, name 'VirtualBox Host-Only Ethernet Adapter #4' (VERR_INTERNAL_ERROR)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole

嗯,所以我猜我需要创建“VirtualBox 仅主机以太网适配器 #4”。在我的旧机器上的 VirtualBox 中,文件 -> 主机网络管理器显示三个这样的适配器 - #2、#3 和 #4。我不记得我是在 VBox 中还是通过其他方法创建的。在新机器上没有,但如果我单击“创建”,它会显示“创建仅主机网络接口”几秒钟,然后以“无法创建主机网络接口”结束。详细信息如下:

Failed to create a host network interface.

Assertion failed: [!aInterfaceName.isEmpty()] at 'F:\tinderbox\win-6.1\src\VBox\Main\src-server\HostNetworkInterfaceImpl.cpp' (76) in long __cdecl HostNetworkInterface::init(class com::Utf8Str,class com::Utf8Str,class com::Guid,enum __MIDL___MIDL_itf_VirtualBox_0000_0000_0046).

Please contact the product vendor!.

Result Code: E_FAIL (0x80004005)
Component: HostNetworkInterfaceWrap
Interface: IHostNetworkInterface {455f8c45-44a0-a470-ba20-27890b96dba9}

我不明白其中的大部分内容,但我知道我没有 F 驱动器/分区(在任何一台机器上),并且不清楚在这种情况下“tinderbox”可能是什么(互联网认为它是一个笔记工具)。“请联系产品供应商” - 哪个产品?Windows?VBox?Vagrant?我的 VM?

您可能已经看出来了,我的能力远远超出了我的水平——有人能给我指出正确的方向吗?我正在运行 VBox 6.1.36 和 Vagrant 2.2.19。

编辑:我发现当我将虚拟机复制到新主机时,虚拟机已暂停(而不是停止),因此我在旧机器上将其停止并再次复制,然后尝试启动它。这次我遇到了不同的错误 - 首先,Windows 向我询问了至少 5 次 VirtualBox 访问硬盘的权限 - 在旧机器上,启动虚拟机时它根本不会询问这一点。然后输出如下:

PS C:\dev\7and7> vagrant up
Bringing machine '7and7' up with 'virtualbox' provider...
==> 7and7: Clearing any previously set forwarded ports...
Vagrant is currently configured to create VirtualBox synced folders with
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant
guest is not trusted, you may want to disable this option. For more
information on this option, please refer to the VirtualBox manual:

  https://www.virtualbox.org/manual/ch04.html#sharedfolders

This option can be disabled globally with an environment variable:

  VAGRANT_DISABLE_VBOXSYMLINKCREATE=1

or on a per folder basis within the Vagrantfile:

  config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false
==> 7and7: Clearing any previously set network interfaces...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["hostonlyif", "create"]

Stderr: 0%...
Progress state: E_INVALIDARG
VBoxManage.exe: error: Failed to create the host-only adapter
VBoxManage.exe: error: Assertion failed: [!aInterfaceName.isEmpty()] at 'F:\tinderbox\win-6.1\src\VBox\Main\src-server\HostNetworkInterfaceImpl.cpp' (76) in long __cdecl HostNetworkInterface::init(class com::Utf8Str,class com::Utf8Str,class com::Guid,enum __MIDL___MIDL_itf_VirtualBox_0000_0000_0046).
VBoxManage.exe: error: Please contact the product vendor!
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface
VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleCreate(struct HandlerArg *)" at line 95 of file VBoxManageHostonly.cpp

因此,我猜想应该是 Vagrant 启动了主机专用适配器的创建(当 VM 从关机状态启动时),而不是我在 VBox 中手动执行此操作。无论如何,它仍然不起作用。

答案1

对于那些有类似困扰的人来说可能会发现这篇文章......

我认为我的问题的最初原因是尝试重新启动暂停VM 移动到之前从未运行过 VBox 或该 VM 的新主机后。(当我移动时,我不记得它已被暂停。)失败后,我vagrant halt在旧主机上执行了该操作,并将暂停的 VM 复制到新主机以代替暂停的 VM,但那时新主机的设置已被搞乱。教训 #1:当移动到新主机时,请务必先完全关闭虚拟机。

至于由此产生的低级错误消息,你可以在我在这个问题上找到的评论中看到https://stackoverflow.com/a/33733454并尝试禁用“VirtualBox Host-Only Network”条目设置 / 网络和 Internet / 高级网络设置,但它拒绝被禁用。显然,我当时已经接近解决方案了。

最后的线索在这里:https://forums.virtualbox.org/viewtopic.php?f=6&t=100406&p=487497#p487353去引用:“尝试重新启动主机,这样 Virtualbox 进程就不会运行,然后转到主机的网络适配器,您可以右键单击它们并设置属性或禁用/启用它们。尝试禁用仅主机适配器,然后重新启用它们。”我遗漏的线索是先重启,不要触碰 VBox——这在流行的 StackOverflow 答案中没有提到。果然,重启后,我能够禁用仅主机适配器并重新启用它。就我而言,这解决了问题,我的虚拟机成功启动了。教训#2:如果您收到与主机专用适配器相关的奇怪错误,请重新启动主机,然后在设置或控制面板中禁用/重新启用该适配器,然后再次尝试您的虚拟机 - 顺序很重要。

相关内容