简体   繁体   中英

ssh session hanging with vagrant virtualbox

I've been using Virtualbox + Vagrant to spin up an ubuntu vm on my mac to use as a space to play and mess around with various programs tools etc..

I have mounted a directory in my Vagrant file like so..

config.vm.synced_folder "~/projects", "/vagrant/projects"

in almost every ssh session or every 2nd session . after a while of being in this directory and doing some basic terminal commands.. eg cd , making . deleting files etc, my session just hangs and I need to send the terminal kill command or close the terminal window and reconnect..

I just accepted this behaviour as a quirk of the software but I'd like to know more about why its happening.. I'm not sure where to look for clues, but I was wondering if other people had similar issues ? Know the cause or know the fix?

My suspicions is something to do with the way it does dir syncing? But again I don't know how to confirm.

Would it be better to just not mount a shared folder and use the vm's filesystem instead?

We've found much better Vagrant reliability between Mac hosts and Ubuntu guests when using NFS-based shared folders. Here's a config that will work in your Vagrantfile to get you started. You don't need any special plugin on the guest or host side.

folder_mount_options = {
  :type => "nfs",
  :mount_options => ['noatime', 'vers=3', 'proto=udp', 'actimeo=2']
}

config.vm.synced_folder '~/projects', '/vagrant/projects', folder_mount_options

One limitation of NFS that you might need to be aware of is that you can't share a parent folder and a subfolder as separate mount points, but that's not too big of a deal. For example, you couldn't share ~/projects as /vagrant/projects as well as ~/projects/specialproject at /var/www

Finally, if you want to try to dig into what's happening when things do freeze, try running dmesg inside of your vagrant box, or look at Console.app (you can find it with Spotlight) in your Mac. You might find some clues there.

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM