roots / trellis

WordPress LEMP stack with PHP 8.2, Composer, WP-CLI and more
https://roots.io/trellis/
MIT License
2.5k stars 608 forks source link

SMB shared folders under Windows don't mount #1072

Closed phox4ever closed 2 years ago

phox4ever commented 5 years ago

Submit a feature request or bug report


What is the current behavior?

Mounting a share with SMB on Windows 10 from Ubuntu 18.04 using sec=ntlm is not possible and results in an error.

What is the expected or desired behavior?

Vagrant should be mounting smb shares with sec=ntlmssp by default or there should at least be an option to override mount options with a variable in 'vagrant.local.yml'. It's currently hard coded in 'vagrant.rb':

def mount_options(mount_type, dmode:, fmode:)
  if mount_type == 'smb'
    ["vers=3.02", "mfsymlinks", "dir_mode=0#{dmode}", "file_mode=0#{fmode}", "sec=ntlm"]
  else
    ["dmode=#{dmode}", "fmode=#{fmode}"]
  end
end

Bug report

Please provide steps to reproduce, including full log output:

On a Windows 10 machine set vagrant_mount_type: 'smb' & run vagrant.exe up in WSL bash.

==> default: Mounting SMB shared folders...
    default: C:/www/example/site => /srv/www/example.com/current
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t cifs -o vers=3.02,credentials=/etc/smb_creds_vgt-99f5d71b70bf68e858791a200d4a8d5e-e479127ed736b223e213a63dcf9cd6db,uid=1000,gid=33,mfsymlinks,dir_mode=0776,file_mo
de=0775,sec=ntlm //192.168.1.100/vgt-99f5d71b70bf68e858791a200d4a8d5e-e479127ed736b223e213a63dcf9cd6db /srv/www/example.com/current

The error output from the last command was:

mount error(22): Invalid argument
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

Please describe your local environment:

Ansible version: 2.7.8

OS: Windows 10 Version 1803 (OS Build 17134.590) using WSL with vagrant.exe

Vagrant version: 2.2.1

Where did the bug happen? Development or remote servers?

Development

swalkinshaw commented 5 years ago

@phox4ever thanks for the report, would you like to contribute this fix?

phox4ever commented 5 years ago

@swalkinshaw I realized that it probably needs a better solution than just updating the sec parameter. Best would be to provide an option to override the defaults. And it's missing a way to change the smb_host which is very handy if you are switching between LAN & Wi-Fi.

As a workaround I created my own Vagrantfile in the root folder of my project that expands trellis Vagrantfile, because trellis doesn't seem to support a local Vagrantfile. I've also switched to vers=3.0 because I occasionally get weird reading errors from the share in Wordpress, but I don't think this has fixed it though.

trellis_vagrantfile = File.expand_path('../trellis/Vagrantfile', __FILE__)
load trellis_vagrantfile if File.exists?(trellis_vagrantfile)

def mount_options_smb(dmode:, fmode:)
    ["vers=3.0", "mfsymlinks", "dir_mode=0#{dmode}", "file_mode=0#{fmode}", "sec=ntlmssp"]
end

trellis_config = Trellis::Config.new(root_path: ANSIBLE_PATH)
vconfig = YAML.load_file("#{ANSIBLE_PATH}/vagrant.local.yml")
vagrant_mount_type = vconfig.fetch('vagrant_mount_type')

Vagrant.configure('2') do |config|
  if vagrant_mount_type == 'smb'

    bin_path = File.join(ANSIBLE_PATH_ON_VM, 'bin')

    extra_options = {
          smb_username: vconfig.fetch('vagrant_smb_username', 'vagrant'),
          smb_password: vconfig.fetch('vagrant_smb_password', 'vagrant'),
          smb_host: vconfig.fetch('vagrant_smb_host'),
        }

    trellis_config.wordpress_sites.each_pair do |name, site|
       config.vm.synced_folder local_site_path(site), remote_site_path(name, site), owner: 'vagrant', group: 'www-data', mount_options: mount_options_smb(dmode: 776, fmode: 775), type: vagrant_mount_type, **extra_options
    end

    config.vm.synced_folder ANSIBLE_PATH, ANSIBLE_PATH_ON_VM, mount_options: mount_options_smb(dmode: 755, fmode: 644), type: vagrant_mount_type, **extra_options
    config.vm.synced_folder File.join(ANSIBLE_PATH, 'bin'), bin_path, mount_options: mount_options_smb(dmode: 755, fmode: 755), type: vagrant_mount_type, **extra_options

  end
end
Xilonz commented 5 years ago

I've just removed the whole "sec=ntlmssp" argument and that's what works for me. Also while testing with smb make sure the /srv/www is owned by vagrant and not root, thats what happened to me.

I too get the weird (php) errors, but thats just because the file isn't fully synced with the vm yet.

What VM are you using? Because NFS shares should work better.

alexandrubau commented 4 years ago

Hi guys, any updates regarding this issue? Thanks

swalkinshaw commented 2 years ago

Closing this since it's quite old and potentially stale. I'm also not sure if this a Trellis issue or something with Vagrant + VirtualBox (which might have been fixed).

Feel free to comment if there's any new information.