首页 > 解决方案 > 从 windows-host 上的 windows-box 访问共享的 vagrant-folder 而不使用“net use”

问题描述

在虚拟机(Windows Server 2016 Core)中,我无法访问共享文件夹C:\Vagrant(符号链接到 \vboxsrv\vagrant,默认为 VirtualBox-provider of vagrant),而无需先将其附加为网络驱动器。我什至不必通过网络驱动器访问它,附加它就足够了......

来自显示行为的虚拟机的控制台:

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 文件如下所示:

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

谁能解释发生了什么?这对我来说似乎很奇怪......

标签: windowsbatch-filevagrantvirtualbox

解决方案


我从来没有找到解释,但添加“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 文件夹¯\_(ツ)_/¯


推荐阅读