1. 程式人生 > >[已解決]vagrant共享資料夾掛載失敗.Vagrant was unable to mount VirtualBox shared folders

[已解決]vagrant共享資料夾掛載失敗.Vagrant was unable to mount VirtualBox shared folders

問題現象

到公司開啟筆記本,啟動vagrant 虛擬機器. 提示以下錯誤

請看截圖


錯誤資訊:

Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:
mount -t vboxsf -o uid=1001,gid=1001 work_ /work
The error output from the command was:
/sbin/mount.vboxsf: mounting failed with the error: No such file or directory

讓我們來翻譯下:

vagrant 無法裝載VirtualBox的共享資料夾,因為檔案系統"vboxsf"無法使用.

這個檔案系統通過VirtualBox客戶新增核心模組獲得,請確認是否被正確安裝.

這不是vagrant的問題,而是VirtualBox引起的問題.

請嘗試執行,以下命令:

mount -t vboxsf -o uid=1001,gid=1001 work_ /work

命令輸出的錯誤資訊為:

sbin/mount.vboxsf:掛載失敗:找不到這個檔案或目錄

問題分析

這個共享資料夾,可以把windows的目錄和linux的某個目錄互相對映,當在win下做了檔案新增,刪除,修改等操作後,會自動同步到linu的某個目錄下,
在本機開發環境,用來編寫php程式碼,可以帶來很多方便. 錯誤現象中, "這不是vagrant的問題,而是VirtualBox引起的問題"

看到這句話我笑了,vagrant和vitualBox互相配合使用,這就開始互相甩鍋了嗎? 哈哈 我就想,這麼共享目錄是在哪裡配置的呢? 從Vagrantfile配置檔案中,看到這樣一段配置:
 # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"
  #config.vm.synced_folder "E:/project/projects/server", "/work/", owner: "www-data", group: "www-data"
  #自動同步的目錄
  config.vm.synced_folder "D:/Project/php/", "/work/", owner: "www-data", group: "www-data"
開啟Oracle VM VirtualBox軟體時,也可以看到這樣的配置:

我嘗試把自動掛載開啟. 然後重啟,無效. 更換新的目錄重新對映, 無效.

問題原因

百思不得其解時,我再次想起了錯誤現象中的那句, "這不是vagrant的問題,而是VirtualBox引起的問題",或許這幾句話是對的呢.

順著這個思路,我訪問了VirtualBox官網的buglist, 找到了這個資訊



可以看到,是在5.1.20這個版本中出現的這個問題, 我看了下我使用的版本是5.1.16, 竟然比這個有問題的版本還低.

最下面寫到,已在5.1.22修復了這個問題.

解決方法

那麼,立刻升級吧.  下載新版本安裝後,重新啟動, 果然,問題解決了,請看截圖,提示共享目錄,掛載成功.


所思所想

錯誤現象中提供的資訊,雖然不可盡信,但也不得不信,   至少提供了一個解決問題的方向. 順著它試一試,說不定會有奇效. 若有疑問,評論中進行溝通.謝謝各位小夥伴.