Vagrant環境とのファイル共有がうまくいかないときにやったことメモ

2022/3/20

(最終更新: 2022/3/20

はじめに

Vagrant 環境と、ローカル環境ではフォルダを共有することができる。

Vagrantfile に設定を入れてもうまくいかなかったので、原因を探した。 結論としてはvagrant-vbguestをアンインストールすることで解決した。

詳細をメモしておく。

環境

  • Windows 環境の上に、VirtualBox + Vagrant で構築した Linux 環境を利用。
  • OS は ubuntu を利用。
    • Distributor ID: Ubuntu
    • Description: Ubuntu 18.04.4 LTS
    • Release: 18.04
    • Codename: bionic

おきたこと

Vagrantfile に以下の記載を入れることで、Vagrant とローカルでフォルダを共有することができる。

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.synced_folder "./gatsby/gatsby-starter-blog", "/home/vagrant/gatsby/gatsby-starter-blog"
end

そのはずなのだが、Vagrant を立ち上げ直してもフォルダの中身が共有されなかった。

エラーメッセージ

Vagrant 立ち上げ時のログは以下のようになっていた。

> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/bionic64' version '20200130.1.0' is up to date...
==> default: A newer version of the box 'ubuntu/bionic64' for provider 'virtualbox' is
==> default: available! You currently have version '20200130.1.0'. The latest is version
==> default: '20220317.0.0'. Run `vagrant box update` to update.
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 8000 (guest) => 8000 (host) (adapter 1)
    default: 3000 (guest) => 3000 (host) (adapter 1)
    default: 9000 (guest) => 9000 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.2.8
VBoxService inside the vm claims: 5.2.42
Going on, assuming VBoxService is correct...
[default] A Virtualbox Guest Additions installation was found but no tools to rebuild or start them.
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:   5.2.8
VBoxService inside the vm claims: 5.2.42
Going on, assuming VBoxService is correct...
Reading package lists...
Building dependency tree...
Reading state information...
Package 'virtualbox-guest-dkms' is not installed, so not removed
Package 'virtualbox-guest-x11' is not installed, so not removed
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 linux-headers-generic : Depends: linux-headers-4.15.0-171-generic but it is not going to be installed
 linux-image-4.15.0-171-generic : Depends: linux-modules-4.15.0-171-generic but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
Reading package lists...
Building dependency tree...
Reading state information...
linux-headers-4.15.0-169-generic is already the newest version (4.15.0-169.177).
linux-headers-4.15.0-169-generic set to manually installed.
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 dkms : Depends: gcc but it is not going to be installed
        Depends: dpkg-dev but it is not going to be installed
        Depends: make or
                 build-essential but it is not going to be installed
        Recommends: fakeroot
 linux-headers-generic : Depends: linux-headers-4.15.0-171-generic but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 https://download.docker.com/linux/ubuntu bionic InRelease
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Fetched 252 kB in 3s (74.2 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
linux-headers-4.15.0-169-generic is already the newest version (4.15.0-169.177).
linux-headers-4.15.0-169-generic set to manually installed.
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
        Depends: dpkg-dev but it is not going to be installed
        Depends: make or
                 build-essential but it is not going to be installed
        Recommends: fakeroot
 linux-headers-generic : Depends: linux-headers-4.15.0-171-generic but it is not going to be installed
 linux-image-4.15.0-171-generic : Depends: linux-modules-4.15.0-171-generic but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
Unmounting Virtualbox Guest Additions ISO from: /mnt
umount: /mnt: not mounted.
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 5.2.42
    default: VirtualBox Version: 6.0
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

umount /mnt

Stdout from the command:

Stderr from the command:

umount: /mnt: not mounted.

詳しくはわからないが、

 dkms : Depends: gcc but it is not going to be installed

あたりからエラーが頻発しているように見える。

対処方法

自動でバージョンを更新してくれるプラグインvagrant-vbguestをアンインストールする。

> vagrant plugin install vagrant-vbguest

結果、ファイル共有することができた。 他の方のブログだと、逆にこのプラグインをインストールしたら上手くいった、という人もいる。。

おわりに

詳細は難しいが、Vagrant 環境とローカル環境のファイル共有ができない問題を解決することができた。



個別連絡はこちらへ→Twitterお問い合わせ

プロフィール

プロフィールイメージ

はち子

事業会社のシステム部門で働きはじめて5年目の会社員。システム企画/要件定義/システムアーキテクチャ等。

Twitter→@bun_sugi

過去の記事について

はてなブログに掲載の記事(主にプログラミングメモ)についてはこちらに掲載しております。(本ブログに移行中)

タグ一覧

関連記事

Copyright© 2024, エンジニアを目指す日常ブログ

お問い合わせ|プライバシーポリシー