如何将主机文件复制到VirtualBox中的Windows guest操作系统?

问题描述:

我已经使用xdissent/ievms在我的Mac上的VirtualBox中设置了多个Windows客户操作系统。如何将主机文件复制到VirtualBox中的Windows guest操作系统?

我想将条目添加到每个Windows VM的hosts文件。我可以从Windows客户机操作系统hosts文件成功复制到我的Mac这样的:

VBoxManage guestcontrol "IE9 - Win7" copyfrom "C:\\Windows\\system32\\drivers\\etc\\hosts" ~/Desktop/hosts --username IEUser --password Passw0rd\! 

我的Mac上我也能成功添加条目使用echo -e "blah blah\r\n" >> hosts复制的文件。

但是我无法将修改后的文件复制回Windows客户机操作系统上的正确位置。我可以把它复制到Windows桌面,但如果我尝试将它复制到正确的文件夹中,我得到:

VBoxManage guestcontrol "IE9 - Win7" copyto ~/Desktop/hosts "C:\\Windows\\system32\\drivers\\etc\\hosts" --username IEUser --password Passw0rd\! --verbose 
Opening guest session as user 'IEUser' ... 
Waiting for guest session to start ... 
Guest session (ID 1) has been started 
Copying from host to guest ... 
Directory "." already exists 
Source: /Users/andy/Desktop/hosts 
Copying "/Users/andy/Desktop/hosts" to "./C:\Windows\system32\drivers\etc\hosts" ... 
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%... 
Progress state: VBOX_E_IPRT_ERROR 
VBoxManage: error: Copying file "/Users/andy/Desktop/hosts" failed with status 500, exit code 1. 
VBoxManage: error: Error processing "/Users/andy/Desktop/hosts", rc=VERR_GENERAL_FAILURE 
Closing guest session ... 

接下来我试着动我成功复制到Windows桌面到正确的文件夹中的文件:

VBoxManage guestcontrol "IE9 - Win7" mv "/Documents and Settings/IEUser/Desktop/hosts" "/Windows/System32/drivers/etc/hosts2" --username IEUser --password Passw0rd\! --verbose 
Opening guest session as user 'IEUser' ... 
Waiting for guest session to start ... 
Guest session (ID 1) has been started 
Renaming 1 entry ... 
Renaming file "/Documents and Settings/IEUser/Desktop/hosts" to "/Windows/System32/drivers/etc/hosts2" ... 
VBoxManage: error: Renaming guest file failed: VERR_ACCESS_DENIED 
VBoxManage: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component GuestSession, interface IGuestSession, callee nsISupports 
VBoxManage: error: Context: "FileRename(Bstr(strCurSource).raw(), Bstr(strCurDest).raw(), ComSafeArrayAsInParam(aRenameFlags))" at line 3015 of file VBoxManageGuestCtrl.cpp 
Warning: Not all sources were renamed 
Closing guest session ... 

线索似乎是VERR_ACCESS_DENIED,即权限问题。

IEUser用户设置为管理员,所以我不明白为什么它不能写入etc目录。有任何想法吗?

VBoxManage guestcontrol并不总是易于使用。如果您使用ievms框,则可以使用由gem ievms-ruby提供的cli实用程序ievmsrb。将文件复制到来宾机ievmsrb输入:

$ ievmsrb copy_to_as_adm "IE9 - Win7" ~/Desktop/hosts 'C:\Windows\System32\Drivers\Etc\hosts' 

因为C:\Windows\System32\Drivers\Etc\hosts只可写的管理员必须使用copy_to_as_adm命令。

检查它是否与

ievmsrb cat "IE9 - Win7" 'C:\Windows\System32\Drivers\Etc\hosts' 
+1

成功复制我只是想你的宝石(18个月后......) - 这是梦幻般的。它直接解决了我的问题。谢谢 :) – 2017-03-27 15:30:42

要将复制到虚拟机,您应该使用copyto而不是copyfrom。

请不要指定完整的目标路径,它将放置在c:\ windows \ system32文件夹中(假设您以管理员身份进行连接)。

然后,您可以使用“ren”子命令将文件移动到'drivers \ etc \ hosts'中(假设您先删除原始文件)。

例子:

VBoxManage guestcontrol “$ inputVMID” CP “$ tFile” 'hosts.new' --username管理员--password *** --verbose

依次为:

删除原始文件,

VBoxManage guestcontrol “$ inputVMID” RM“drivers \ etc下\主机的管理员--username ** - 密码--verbose

和f inally

重命名新的hosts文件

VBoxManage guestcontrol “$ inputVMID” 仁“hosts.new'drivers \ etc下\主机的管理员--username --password * --verbose

HTH