Vagrant using Trellis on Windows 10 WSL2

@TechHedz Hey David, and thanks for checking in.

I have not gotten it to work, but will try your suggestions when I get home tonight.

Not sure why I installed NTFS instead of exfat

Hmm, would it even be advisable using exFAT on your Windows drive? I do use the machine as my daily driver.

Thanks again, will make sure to keep you posted.

exfat is better for compatibility between machines and supported by macs, Linux and so on. Windows NT is best if you only deal with windows. Maybe I was mistaken in mentioning exfat. I thought windows started to automatically use exfat but I may be wrong. I know exfat supports chmod which is good for changing permissions through WSL. I just don’t ever remember having problems with Trellis-CLI before on a windows machine like this. I’m on my work PC though and it could also be firewall and security protocols messing things up since we are pretty much locked down now.

@TechHedz Back at it again, and unfortunately still not working.

I’m going to try removing everything and starting over. I figure I must be doing something wrong if I’m following the guide and it isn’t working?

Quick update, still haven’t gotten it to work.

Apologies if this is obvious, but on WSL, is your dev folder supposed to be located inside the Windows file system, e.g. /mnt/c/dev/example.com? I realize this is what TechHedz said, just trying to understand how it works.

I’ve now tried to create the project within here, and it’s incredibly slow. I stopped it after 30 minutes. Or are you supposed to set it up in /home/User/example.com and then move it afterwards?

Tried that too, and that is just as slow.

Or are you supposed to create your project on the linux side and use some sort of symlink to the Windows FS?

Thanks very much guys, really trying here.

@decoycircuit Hello!

Haha yes you can definitely tag me anytime, and apologies my delayed response, I’ve just returned from a period of offline time.

I’m also on NTFS so that should be just fine, are you still encountering the same issue after adjusting the wsl.conf as suggested by @TechHedz ?

@TechHedz if you’re able to access the machine via ssh, but it isn’t showing in the browser, it may be an issue related to your hosts file. You can try navigating to C → Windows → System32 → drivers → etc - > hosts and adding the following two lines:

192.168.56.5 example.test
192.168.56.5 www.example.test

(The IP would need to be 192.168.50.5) if you’re using an older version of trellis, but you can see this value by viewing your Vagrant config file in your Trellis project.

@cheezman Thanks very much for getting back to this thread.

Yes, issue persist and I’m still not up and running.

My last post describes where I’m at.

  1. I don’t see it in the docs, so asking it here. Are you supposed to run the trellis new setup command in the Linux or NTFS filesystem?

  2. On further reading, I see people mentioning NFS. Are you supposed to install that?

I’m trying to piece it together.

Very much appreciated, thanks again.

@decoycircuit Pleasure!

Alright, not a problem, seems like you’re in the final stretch :slight_smile:

  1. trellis new example.com will need to be run from within your WSL environment. It may take a while on the “Installing dependencies” step.

  2. NFS isn’t necessary no, the only two vagrant plugins I have installed are:

vagrant-bindfs (1.1.8, global)
vagrant-hostmanager (1.8.9, global)

Let me know how the above goes :dancer:

2 Likes

Thanks again, @cheezman, really appreciate the hand holding :slight_smile:

trellis new example.com will need to be run from within your WSL environment. It may take a while on the “Installing dependencies” step.

Yes, thanks, that’s what I’m doing but what I’m asking is: Do I run the command within the /home/user/dev (linux) folder structure or the Windows one /mnt/c/Users/user/dev?

The reason I ask is, if I run in it /home/user/dev it’s super fast, but I get the error from a few posts up (even after running the ´export VAGRANT_WSL …` commands.

If I run it (trellis new) in mnt/c/Users/user/dev it is incredibly slow – it takes 30 minutes for it to create, and sometimes times out.

Is this just how it works, or am I not doing it right?

Thanks again buddy

@decoycircuit All good!

  • You would run the command from within your Windows environment.
  • I’ve just ran a trellis new from within my Linux folder and it completed successfully, however I also received the below error:
The host path of the shared folder is not supported from WSL. Host
path of the shared folder must be located on a file system with
DrvFs type.

Please do try running a trellis up from within one of the projects you’ve created on your Windows filesystem.

My pleasure, let me know how it goes :sunglasses:

@cheezman It’s working - at least within the mnt/c/Users/ path. But it is painfully slow, whereas if created in the Linux path (/home/user/dev) it’s close to instant.

Is that just how it is - I have to create it in the Windows env? Or is there some sort of “link” I can create, allowing to maybe set it up under Linux? Sorry if I’m asking the same again, just want to make absolutely sure.

The error you’re getting is what I’m getting too (thanks for testing that out, btw) - but I was under the impression that is what I was fixing inputting the export commands?

I’ve now also gotten to installing Sage, following instructions. All works, but again, yarn build took:

❯ yarn build
yarn run v1.22.21
$ bud build

╭ sage [776635f9d9aa3c07]                                                                                  ./public
│
│ app
│  ◉ js/runtime.e97f88.js                                                                                 ✔ 1.22 kB
│  ◉ css/app.194f0a.css                                                                                   ✔ 5.35 kB
│  ◉ js/app.c6fc6f.js                                                                                   ✔ 359 bytes
│
│ editor
│  ◉ js/runtime.e97f88.js                                                                                 ✔ 1.22 kB
│  ◉ css/editor.ef46db.css                                                                                      ✔ ø
│  ◉ js/editor.8c1474.js                                                                                  ✔ 1.67 kB
│
╰ 1m 59s 451ms 8 modules [0/8 modules cached]

Done in 227.14s.

4 minutes for every build. Is that normal? It seems excessive to me

@decoycircuit Glad!

From my experience, yes it has to be created from within Windows. You can definitely have a go at it, but I remember running into some permissions related errors (along with the shared folder error above).

Lovely stuff, I’ve run a yarn build now on a project of mine with a larger codebase and it compiled within 80s.

◉  js/391.dd35a4.js                         248.4 kB
◉  css/app.8e021a.css                       233.41 kB
◉  js/app.3be9cc.js                         15.11 kB
◉  js/runtime.3ca2ea.js                     1.11 kB
◉  js/editor.6e8560.js                      376 bytes
◉  js/575.baac18.js                         232 bytes
◉  css/editor.31d6cf.css                    0 bytes
◯  images/Karbon-MediumItalic.62fad9.svg    442.38 kB
◯  images/Karbon-SemiboldItalic.6bf08c.svg  441.44 kB
◯  images/Karbon-Semibold.c2054b.svg        414.17 kB
◯  images/Karbon-Medium.be64d1.svg          412.77 kB
◯  images/Karbon-Light.fd61b5.svg           354.11 kB

+ 61 additional static assets

duration  10s 357ms (6s 459ms + 3s 898ms)

mode        production  hash     7ba1006fafc3d67b78a9
@roots/bud  6.3.3       webpack  5.73.0
node        16.10.0

Done in 84.45s.

What kind of machine are you running? Just out of curiosity, as I have an i7 processor (2.11GHz) with 16GB of RAM.

@cheezman You’re a gentleman and a scholar :slight_smile:

Thanks for retesting my environment, that’s very nice of you.

it compiled within 80s.

Got it- -in that case it’s probably not out of the ordinary for what I have going on.

I’m also on an i7 with 32 gigs of RAM, albeit an older i7.

Follow up: From reading reports, it looks like slow speeds from file system to file system within WSL is quite common.

Last issue: I run vagrant up within /trellis and it starts up the VM.

However, I cannot access the site in the the browser on the .test domain.

wordpress_sites.yml:

wordpress_sites:
  mysite.com:
    site_hosts:
    - canonical: mysite.test
      redirects:
      - www.mysite.test
    local_path: ../site
    admin_email: admin@mysite.test
    multisite:
      enabled: false
    ssl:
      enabled: false
      provider: self-signed
    cache:
      enabled: false

I see the entries in my /etc/hosts:

## vagrant-hostmanager-start id: 5e16476f-1386-4db7-a89f-7da2d3a
192.168.56.5    mysite.test
192.168.56.5    www.mysite.test
## vagrant-hostmanager-end

It’s not at all trying to connect. Can’t reach it via the IP above, either.

What could be going on here?

@decoycircuit Hiya! Just a few questions from my end:

  • Did the initial vagrant provision or trellis provision development complete successfully?
  • What is the value of vagrant_ip in your trellis folder → vagrant.default.yml?
  • Are the lines you’ve shared also present in your Windows hosts file? (C → Windows → System32 → drivers → etc - > hosts)
1 Like

@cheezman by all means, ask away!

  • Can’t get any sort of provisioning to complete. Neither trellis ssh development, vagrant provision, trellis provision development – and vagrant ssh doesn’t do anything.

trellis ssh development returns:

❯ trellis ssh development
Running command => ssh vagrant@mysite.test
Error running ssh: exit status 255
❯ trellis provision development
Starting galaxy role install process
- composer (1.9.0) is already installed, skipping.
- ntp (2.3.1) is already installed, skipping.
- logrotate (v0.0.5) is already installed, skipping.
- swapfile (v2.0.36) is already installed, skipping.
- mailpit (v1.0.0) is already installed, skipping.

Running command => ansible-playbook dev.yml --inventory-file=.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory -e env=development

PLAY [WordPress Server: Install LEMP Stack with PHP and MariaDB MySQL] *********

TASK [Gathering Facts] *********************************************************
[WARNING]: Unhandled error in Python interpreter discovery for host default:
Failed to connect to the host via ssh: ssh: connect to host 172.18.208.1 port
2222: Connection timed out
fatal: [default]: UNREACHABLE! => {"changed": false, "msg": "Data could not be sent to remote host \"172.18.208.1\". Make sure this host can be reached over ssh: ssh: connect to host 172.18.208.1 port 2222: Connection timed out\r\n", "unreachable": true}

PLAY RECAP *********************************************************************
default                    : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0

exit status 4

There appears to be issues with connecting via ssh.

  • vagrant_ip in vagrant.default.yml:
    vagrant_ip: '192.168.56.5'

  • The lines I’ve shared are NOT present in my Windows hosts (C → Windows → System32 → drivers → etc - > hosts)


Upon reading up on this, I found this thread from '22 Trellis hanging on installing dependencies - #23 by dannytaki

I tried what seemed to be the solution:

To try another mount type, create a vagrant.local.yml file and add this:

vagrant_mount_type: virtualbox

It hasn’t really done anything.

Following up: OK so I’m past the SSH issue, somewhat.

I finally landed on SSH timeout on vagrant up with Windows 10 + WLS2 (virtualbox_WSL2 plugin installed) - #10 by dome and that worked.

The solution is to disabled Windows Defender Firewall protection for vEthernet (WSL) Domain, Private, and Public profiles.

I ran trellis up and it run the entire build process, it looks like.

As per docs, I’m told to run trellis ssh development to access the VM.

Still getting:

❯ trellis ssh development
Running command => ssh vagrant@mysite.test
Error running ssh: exit status 255

But I can ssh into vagrant:

❯ vagrant ssh
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-83-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Mon Jan 15 10:10:18 PM UTC 2024

  System load:  0.02880859375      Processes:             146
  Usage of /:   15.7% of 30.34GB   Users logged in:       0
  Memory usage: 33%                IPv4 address for eth0: 10.0.2.15
  Swap usage:   2%                 IPv4 address for eth1: 192.168.56.5


This system is built by the Bento project by Chef Software
More information can be found at https://github.com/chef/bento

@cheezman, what an absolute trooper you are. Thanks very much for lending a hand, means a lot.

Following up again:

So, trellis up now works and it does appear to build it all out correctly.

I still can’t reach the domain in the browser. mysite.test just returns “can’t connect”, and it happens immediately.

If I run curl mysite.com in the in WSL, it returns Wordpress-like HTML, so that seems to work.

Do I need to manually update the Windows hosts file? If so, with what? The IP for vagrant?

EDIT: To answer my own question, apparently Trellis is supposed to edit the hosts file, but with it being Windows, this process can be unreliable. The test domain should point to the IP of the VM. I’ll try that today when I get home. Discourse source

And there we have it, ladies and gentlemen.

Pointed my project domain at the VM IP in the Windows hosts file manually, and now I can reach my WP install on mysite.test.

The solution is to disable Windows Defender Firewall protection for vEthernet (WSL) Domain, Private, and Public profiles.

Thanks for following along. Special thanks goes out to @cheezman

2 Likes

@decoycircuit Ayy lovely news! Very happy to hear it :man_dancing:

There will likely be smaller issues cropping up in the future, but they’re quite descriptive and usually quite easy to troubleshoot (specifically during the provisioning step).

All the best with it!

1 Like

Coming in fairly late but trying everything to switch to Windows and set up projects like I have on my mac is really unusable. There are way to many issues with Trellis/Vagrant on WSL 2 and it’s really not a priority seamingly for anyone.

I’ve tried running every possible scenario. If you are trying to run it on DrvFS (meaning /mnt/c… ) folders WSL 2 has so many issues that performance is atrocius and barely usable and running trellis cli to create a new project and virtual environment gets stuck due to pip having issues on WSL 2 and DrvFS. It just gets stuck and won’t create a project.

Add to this if you want to have Dropbox like most people have to back-up your projects the issue with permissions is another headache when files are on DrvFS. The issue here is vagrant really. Not supporting filesystem within WSL 2 is really silly. Btw, it did work up until version 1.9.4 as it didn’t do the check for it.

On the other hand, if you want trellis cli to work as intended, you have to be inside the WSL 2 filesystem, but then Vagrant’s synced folders won’t work as you’ve noticed.

WSL 2 is just a toy at this point and really impractical for any reliable work. Maybe for some basic Ubuntu things if you want to mess with it but for actual serious development it’s definitely not ready. And this is just issue with Vagrant/Trellis. Wait until you try Docker.

At this point I am simply running Mac for coding and PC for 3d work, Unreal Engine and similar. Maybe things will get better with WSL 3, newer versions of Vagrant but it’s questionable if it will even happen.