How to copy the hosts file to Windows guest in VirtualBox?

I have used xdissent / ievms to set up multiple Windows guest OSs in VirtualBox on my Mac.

I want to add entries to every Windows VM file hosts

. I can successfully copy a file hosts

from Windows guest OS to my Mac like this:

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

      

On my Mac, I can also successfully add entries to the copied file using echo -e "blah blah\r\n" >> hosts

.

However, I was unable to copy the modified file back to the correct location in the Windows guest OS. I can copy it to the Windows desktop, but if I try to copy it to the correct folder, I get:

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 ...

      

Next, I tried to move the file that I successfully copied to the Windows desktop to the correct folder:

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 ...

      

It seems that the key VERR_ACCESS_DENIED

, i.e. permissions problem.

The user is IEUser

configured as administrator, so I don't understand why he cannot write to the directory etc

. Any ideas?

+3


source to share


3 answers


VBoxManage guestcontrol

not always easy to use. If you are using ievms boxes, you can use the cli utility ievmsrb

provided by gem ievms-ruby . To copy the file to the guest machine using ievmsrb, enter:

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

      

Since it C:\Windows\System32\Drivers\Etc\hosts

is writable by administrators, you must use the command copy_to_as_adm

.



Check if it was copied successfully with

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

      

+1


source


To copy to a virtual machine, you must use copyto instead of copyfrom.



0


source


Do not specify the full destination path, and it will be placed in the c: \ windows \ system32 folder (provided that you are connected as Administrator).

Then after that, you can use the "ren" subcommand to move the file to "drivers \ etc \ hosts" (assuming you delete the original first).

Example:

VBoxManage guestcontrol "$ inputVMID" cp "$ tFile" 'hosts.new' --username Administrator --password *** --verbose

and then:

delete original file

VBoxManage guestcontrol "$ inputVMID" rm "drivers \ etc \ hosts' --username Administrator --password ** --verbose

and finally

rename the new hosts file

VBoxManage guestcontrol "$ inputVMID" ren 'hosts.new' 'drivers \ etc \ hosts' --username Administrator --password * --verbose

NTN

0


source







All Articles