{"record":{"id":"098be695b7a4d300","repo":"hashicorp/vagrant","slug":"vagrant-is-unable-to-setup-a-requested-smb-share","errorCode":null,"errorMessage":"Vagrant is unable to setup a requested SMB share. An SMB share already\nexists with the given name.\n\nShare name: %{name}\n\nCurrent path: %{existing_path}\n\nRequested path: %{path}","messagePattern":"Vagrant is unable to setup a requested SMB share\\. An SMB share already\nexists with the given name\\.\n\nShare name: %(.+?)\n\nCurrent path: %(.+?)\n\nRequested path: %(.+?)","errorType":"exception","errorClass":"VagrantPlugins::SyncedFolderSMB::Errors::SMBNameError","httpStatus":null,"severity":"error","filePath":"plugins/hosts/windows/cap/smb.rb","lineNumber":88,"sourceCode":"\n        def self.smb_prepare(env, machine, folders, opts)\n          script_path = File.expand_path(\"../../scripts/set_share.ps1\", __FILE__)\n\n          shares = []\n          current_shares = existing_shares\n          folders.each do |id, data|\n            hostpath = data[:hostpath].to_s\n\n            chksum_id = Digest::MD5.hexdigest(id)\n            name = \"vgt-#{machine_id(machine)}-#{chksum_id}\"\n            data[:smb_id] ||= name\n\n            # Check if this name is already in use\n            if share_info = current_shares[data[:smb_id]]\n              exist_path = File.expand_path(share_info[\"Path\"]).downcase\n              request_path = File.expand_path(hostpath).downcase\n              if !hostpath.empty? && exist_path != request_path\n                raise SyncedFolderSMB::Errors::SMBNameError,\n                  path: hostpath,\n                  existing_path: share_info[\"Path\"],\n                  name: data[:smb_id]\n              end\n              @@logger.info(\"skip creation of existing share name=#{name} id=#{data[:smb_id]}\")\n              next\n            end\n\n            @@logger.info(\"creating new share name=#{name} id=#{data[:smb_id]}\")\n\n            shares << [\n              \"\\\"#{hostpath.gsub(\"/\", \"\\\\\")}\\\"\",\n              name,\n              data[:smb_id]\n            ]\n          end\n          if !shares.empty?\n            uac_notified = false","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/plugins/hosts/windows/cap/smb.rb#L70-L106","documentation":"SyncedFolderSMB::Errors::SMBNameError raised at plugins/hosts/windows/cap/smb.rb:88 in smb_prepare. For each folder Vagrant derives a deterministic name `vgt-<machine_id>-<md5(folder id)>` (data[:smb_id] defaults to it); if that share already exists in current_shares but its recorded Path — after File.expand_path and downcase — differs from the requested host path, it raises. Windows permits one share per name, and silently remapping would hide a real config change.","triggerScenarios":"A machine whose vgt-* share survives from a previous run while the Vagrantfile's host path for that folder changed: the project moved, the synced_folder path was edited, or machine state was restored with the same ID — so existing Path != requested path (empty hostpath is exempt via the `!hostpath.empty?` guard).","commonSituations":"Project directory moved/renamed between runs; Vagrantfile synced_folder path edited after first up; machine re-imported with the same ID; leftovers after a crashed destroy.","solutions":["Delete the stale share named in the error (elevated): `Remove-SmbShare -Name \"<name>\" -Force`, then re-run vagrant","Or fully `vagrant destroy` the machine so its shares are pruned, then `vagrant up`","Or change the Vagrantfile path back to the share's Current path printed in the error","With no machines running, bulk-clean: `Get-SmbShare vgt-* | Remove-SmbShare -Force`"],"exampleFix":"# before — project moved, old share still points at the old path\nconfig.vm.synced_folder \"C:/old/location\", \"/data\", type: \"smb\"\n# after — remove the stale share once, keep the new config\n# powershell: Remove-SmbShare -Name \"vgt-<machine>-<md5>\" -Force\nconfig.vm.synced_folder \"C:/new/location\", \"/data\", type: \"smb\"","handlingStrategy":"validation","validationCode":"# Before `vagrant up`, ensure no existing share conflicts with the intended path\n# powershell:\n#   $name = 'vgt-<machine-id>-<md5-of-folder-id>'\n#   $s = Get-SmbShare -Name $name -ErrorAction SilentlyContinue\n#   if ($s -and $s.Path -ne 'C:\\intended\\host\\path') { Remove-SmbShare -Name $name -Force }\nnames = `powershell -NoProfile -Command \"Get-SmbShare -Name 'vgt-*' | ForEach-Object { $_.Name + '=' + $_.Path }\"`.split(\"\\n\")\nconflict = names.find { |l| l.start_with?(expected_share_name) && !l.end_with?(intended_path.downcase) }\nsystem(\"powershell -Command \\\"Remove-SmbShare -Name '#{conflict.split('=').first}' -Force\\\"\") if conflict","typeGuard":null,"tryCatchPattern":"begin\n  env.machine_action(:up)\nrescue VagrantPlugins::SyncedFolderSMB::Errors::SMBNameError => e\n  puts \"share '#{e.data[:name]}' already points at #{e.data[:existing_path]}, requested #{e.data[:path]}\"\n  # decide: remove stale share (Remove-SmbShare -Force) or revert path, then retry\n  raise\nend","preventionTips":["Don't move project directories or edit SMB synced-folder paths without cleaning up shares","After a crashed run, run `Get-SmbShare vgt-*` and remove leftovers before the next up","Fully `vagrant destroy` machines when relocating them"],"tags":["smb","windows","share-name","conflict","synced-folders"],"backgroundTag":"share-name-collision","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}