从Windows主机上的Windows框中访问共享的Vagrant文​​件夹,而无需'net use'

时间:2018-07-24 09:00:53

标签: windows batch-file vagrant virtualbox

从虚拟机(Windows Server 2016 Core),我无法访问共享文件夹 C:\ Vagrant (符号链接到\ vboxsrv \ vagrant,默认为vagrant的VirtualBox提供者),而无需首先访问将其作为网络驱动器连接。 我什至不必通过网络驱动器访问它,只需附加它就可以了...

在虚拟机上显示行为的控制台:

C:\>dir
 Volume in drive C is Windows 2016
 Volume Serial Number is 9814-DDEB

 Directory of C:\

04/05/2018  02:09 PM    <DIR>          inetpub
04/05/2018  01:33 PM    <DIR>          Logs
07/16/2016  01:18 PM    <DIR>          PerfLogs
04/05/2018  02:18 PM    <DIR>          Program Files
04/05/2018  02:17 PM    <DIR>          Program Files (x86)
04/05/2018  02:07 PM    <DIR>          Scripts
07/24/2018  08:21 AM    <DIR>          Users
07/24/2018  08:20 AM    <SYMLINKD>     vagrant [\\vboxsrv\vagrant]
07/24/2018  08:21 AM    <DIR>          Windows
               0 File(s)              0 bytes
               9 Dir(s)  30,747,582,464 bytes free

C:\>cd Vagrant
The system cannot find the path specified.

C:\>cd vagrant
The system cannot find the path specified.

C:\>net use X: \\vboxsrv\vagrant
The command completed successfully.


C:\>cd vagrant

C:\vagrant>    LOL  <------------------------

无业游民的文件如下:

Vagrant.configure("2") do |config|
    config.vm.box = "ajourtestserver"
    config.vm.box_url = "file:///u:/TestImage/ajourtestserver.json"
    config.vm.box_check_update = true
    config.vm.provider "virtualbox" do |vb|
        vb.memory = 4096
        vb.cpus = 4
    end 
end

任何人都可以解释发生了什么吗?这对我来说似乎很奇怪...

1 个答案:

答案 0 :(得分:0)

我从未找到任何解释,但是将“ net use”语句添加为内联shell配置似乎是一个可靠的解决方法。对于其他有此问题的人,以下是我的解决方法的详细信息。

以下内容已添加到VagrantFile:

config.vm.provision "symlink-fix", type: "shell" do |s|
    s.inline = "net use X: \\vboxsrv\vagrant"
end

该语句实际上失败了:

==> default: Running provisioner: symlink-fix (shell)...
    default: Running: inline PowerShell script
==> default: System error 67 has occurred.
==> default: The network name cannot be found.

...因此没有添加“ X:”网络驱动器-但是现在可以访问C:\ Vagrant文​​件夹¯\ _(ツ)_ /¯