hashicorp/vagrant · error · Vagrant::Errors::SharedFolderCreateFailed

Failed to create the following shared folder on the host sys

Error message

Failed to create the following shared folder on the host system. This is usually because Vagrant does not have sufficient permissions to create the folder.

%{path}

Please create the folder manually or specify another path to share.

What it means

In the synced_folders setup step, hostpaths marked `create: true` that do not exist are made with Pathname#mkpath. If the host OS raises Errno::EACCES — the vagrant process lacks permission to create directories under the parent — the error is converted to SharedFolderCreateFailed naming the path.

Source

Thrown at lib/vagrant/action/builtin/synced_folders.rb:62

          folders.each do |_, fs|
            fs.each do |id, data|
              next if data[:hostpath_exact]

              data[:hostpath] = File.expand_path(
                data[:hostpath], env[:root_path])

              # Expand the symlink if this is a path that exists
              if File.file?(data[:hostpath])
                data[:hostpath] = File.realpath(data[:hostpath])
              end

              # Create the hostpath if it doesn't exist and we've been told to
              if !File.directory?(data[:hostpath]) && data[:create]
                @logger.info("Creating shared folder host directory: #{data[:hostpath]}")
                begin
                  Pathname.new(data[:hostpath]).mkpath
                rescue Errno::EACCES
                  raise Vagrant::Errors::SharedFolderCreateFailed,
                    path: data[:hostpath]
                end
              end

              if File.directory?(data[:hostpath])
                data[:hostpath] = File.realpath(data[:hostpath])
                data[:hostpath] = Util::Platform.fs_real_path(data[:hostpath]).to_s
              end
            end
          end

          # Build up the instances of the synced folders. We do this once
          # so that they can store state.
          folders = folders.map do |impl_name, fs|
            instance = plugins[impl_name.to_sym][0].new
            [instance, impl_name, fs]
          end

View on GitHub (pinned to 35f3160f4a)

Solutions

  1. Pre-create the directory yourself with proper ownership: `sudo mkdir -p /srv/data && sudo chown $USER /srv/data`, then drop `create: true` (or keep it).
  2. Or move the hostpath somewhere you own, e.g. `~/vagrant-data`.
  3. Or run vagrant from an account with write access to the target parent directory.

Example fix

# before
config.vm.synced_folder "/srv/shared-data", "/data", create: true
# => SharedFolderCreateFailed (EACCES under /srv)

# after: pre-create + own the dir
#   sudo mkdir -p /srv/shared-data && sudo chown "$USER" /srv/shared-data
config.vm.synced_folder "/srv/shared-data", "/data"
# or simply:
config.vm.synced_folder "~/vagrant-data", "/data", create: true
Defensive patterns

Strategy: validation

Validate before calling

# Ruby: check you can create the hostpath before vagrant does
require "fileutils"
hostpath = File.expand_path("/srv/shared-data")
begin
  FileUtils.mkdir_p(hostpath) unless Dir.exist?(hostpath)
rescue Errno::EACCES
  abort "no permission to create #{hostpath}; sudo mkdir/chown it first"
end

Prevention

When it happens

Trigger: `config.vm.synced_folder "PATH", "/guest", create: true` where PATH's parent is not writable by the current user: paths under /srv, /opt, another user's home, or on a read-only mount (lib/vagrant/action/builtin/synced_folders.rb:54-66).

Common situations: Sharing system directories on locked-down/corporate hosts; running vagrant as an unprivileged user against root-owned trees; read-only or network mounts used as the synced-folder root; SELinux/AppArmor denying writes.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21). Data as JSON: /api/errors/ec6ff1070ab14d7e. Report an issue: GitHub.