0

I'm following the old tutorials off of gettingstartedwithdjango.com.

This series is quite old and I'm new to Django which is why I hit that site in the first place. It became my first introduction to Vagrant. Because the series is old and there are now new versions of Django, Vagrant, etc, I've found just getting through the first tutorial was quite difficult. This was mainly just the gap between Django v1.4 and the current version 1.9 which is what I'm running, including some syntax differences in settings.py and also some discrepancies between the text errata and the video which I had to sort through. It's a pretty detailed exercise if you're completely new to all of this (which I am), so it was quite challenging, and I was thrilled when after probably 12 hours of solid effort I was able to get everything working as was being described in the video but using all new versions of software. Once I got it all set up and working, I halted my Vagrant VM for the night and when I turned it back up (vagrant up) the next morning, I found that the VM would no longer mount its shared folders, essentially rendering the Vagrant VM useless to me as I'm then unable to run code which resides on the host machine (I'm running Windows 7) from within the VM (which is accomplished via the VirtualBox shared folders feature).

Not knowing what was wrong, this prompted me to completely reinstall my Vagrant VM. I was able to get things redeployed successfully with about one hour worth of effort, backtracking through steps I had taken to successfully complete the first tutorial in the first place, in order to back to the same point where I started (before I did the previous vagrant halt). When reinstalling the Vagrant VM I noticed messages that my VirtualBox Guest Additions (4.2.0) did not match the version of VirtualBox I have installed (5.0.10), which I recalled seeing the first time but ignored because it also said this isn't usually a problem and should work (if it weren't for bad luck, I'd have no luck at all). Since for me it didn't work, this led me down a whole rabbit hole of posts from various websites including SO, which ultimately had me updating my Vagrant VM, downloading/mounting/building/installing a new version of VirtualBox Guest Additions, and reloading my Vagrant VM only to wind up in the same boat. Shared folders were still not working!

To be very specific, this is more or less what I tried based on information from many websites:

cd /home/vagrant
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install dkms build-essential linux-headers-generic
sudo apt-get install linux-headers-3.2.0-23-generic
# mounted VBoxGuestAdditions_5.0.10.iso to Vagrant VM
cd /media/cdrom
sudo sh ./VBoxLinuxAdditions.run
sudo reboot
sudo /etc/init.d/vboxadd setup
sudo reload
c:\VAGRANT\vagrant plugin install vagrant-vbguest
c:\VAGRANT\vagrant reload

I was utterly convinced this was going to resolve the issue but it didn't.

4

1 回答 1

0

然后我发现了这个宝石:

http://ddelizia.blogspot.com/2011/02/how-to-share-folder-on-virtual-box-with.html

这显示了如何从 Vagrant VM 中将共享文件夹挂载回您的 Windows 7 主机。具体来说,当我发现一切恢复正常时,我是这样做的:

cd /vagrant
ls -la
<this yielded nothing>
sudo mount.vboxsf vagrant /vagrant # see your VirtualBox Shared Folders settings
cd ~ # /home/vagrant
cd - # /vagrant
ls -la
# this yielded the expected folders from my Win7 host

在上面的 mount.vboxsf 命令中,第一个 vagrant(没有 /)来自我的 VirtualBox 共享文件夹设置中的 Name 列。这本质上是一个别名,用于引用 Win7 主机上的实际路径,在我的例子中是:C:/VAGRANT。该命令中的第二个 vagrant(带有 /)是 Vagrant VM (linux) 上的 /vagrant 文件夹。

鉴于我今天大部分时间都在处理这个问题,而且我认为有很多人会遇到同样或相关的问题,所以我想我会尽力帮助大家,为大家节省大量时间。祝你好运。

于 2015-12-21T22:36:24.970 回答