【解決方法】Vagrantで構築したUbuntu20.04へsynced_folder を設定した際に発生するマウントエラーの対処
この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
Vagrantで構築したUbuntu20.04へsynced_folder を設定した際に発生するマウントエラーの対処についてメモしました。
環境
- Vagrant 2.2.16
- VirtualBox 6.1.22 r144080
- Ubuntu 20.04
発生したエラー
実行ログ
vagrant upコマンドを実行したログになります。
vbnet$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'bento/ubuntu-20.04'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'bento/ubuntu-20.04' version '202105.25.0' is up to date...
==> default: Setting the name of the VM: sakura-tools_default_1622883076513_78645
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> 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: Warning: Connection reset. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
[default] GuestAdditions seems to be installed (6.1.22) correctly, but not running.
update-initramfs: Generating /boot/initrd.img-5.4.0-73-generic
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Kernel headers not found for target kernel
5.4.0-73-generic. Please install them and execute
/sbin/rcvboxadd setup
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted
Restarting VM to apply changes...
==> default: Attempting graceful shutdown of VM...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: Warning: Connection reset. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /var/www/html => /Users/XXXXX/ubuntu/html
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=1000,gid=1000,_netdev var_www_html /var/www/html
The error output from the command was:
: Invalid argument
原因
必要なモジュールが足りないことが原因でした。
解決手順
VMへログイン
vagrant sshでVMへログインします。
terminal|ホストOS$ vagrant ssh
必要パッケージのインストール
アップデート
最初にapt-getコマンドでパッケージの最新化を実施します。
terminal|ゲストOSsudo apt update && sudo apt upgrade -y
インストール
apt-getコマンドでlinux-headers-genericのパッケージをインストールします。
terminal|ゲストOS$ sudo apt-get install -y linux-headers-generic
apt-getコマンドでgcc make perlのパッケージをインストールします。
terminal|ゲストOS$ sudo apt-get install -y gcc make perl
ログアウト
exitコマンドでログアウトします。
terminal|ゲストOS$ exit;
VMの再起動
vagrant reloadコマンドでVMを再起動します。
terminal|ホストOS$ vagrant reload
これで解決しました。
原因調査
原因調査さした際のログになります。
vbguestプラグイン
vbguestプラグインはすでにインストール済みです。
t$ vagrant vbguest --status
[default] GuestAdditions seems to be installed (6.1.22) correctly, but not running.
VMへログイン
vagrant sshでVMへログインします。
セットアップの再実施して確認
再度直接セットアップを実施して確認してみます。
yaml$ sudo sh /opt/VBoxGuestAdditions-6.1.22/init/vboxadd setup
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Kernel headers not found for target kernel
5.4.0-73-generic. Please install them and execute
/sbin/rcvboxadd setup
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted
エラーの内容
ログを確認するとヘッダーが見つからないというエラーが出ています。
rustVirtualBox Guest Additions: Kernel headers not found for target kernel
linux-headers-genericのインストール
linux-headers-genericのインストールを実施します。
arduino$ apt-get install linux-headers-5.4.0-74-generic
// 中略
Setting up linux-headers-generic (5.4.0.74.77) ...
セットアップの再実施
再度直接セットアップを実施して確認してみます。
vbnet$ sudo sh /opt/VBoxGuestAdditions-6.1.22/init/vboxadd setup
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel 5.4.0-74-generic.
This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted
エラーの内容
gcc make perlのパッケージをインストールが必要というエラーが出ています。
vbnetThis system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
gcc make perlのインストール
gcc make perlのパッケージをインストールします。
arduino$ sudo apt-get install gcc make perl -y
// 中略
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
セットアップの再実施
再度直接セットアップを実施して確認してみます。
yaml$ sudo sh /opt/VBoxGuestAdditions-6.1.22/init/vboxadd setup
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel 5.4.0-74-generic.
update-initramfs: Generating /boot/initrd.img-5.4.0-74-generic
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted
VMを再起動
vagrant reloadコマンドでVMを再起動します。
yaml$ vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'bento/ubuntu-20.04' version '202105.25.0' is up to date...
==> 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: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> 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: Warning: Connection reset. Retrying...
==> default: Machine booted and ready!
[default] GuestAdditions seems to be installed (6.1.22) correctly, but not running.
update-initramfs: Generating /boot/initrd.img-5.4.0-74-generic
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel 5.4.0-74-generic.
update-initramfs: Generating /boot/initrd.img-5.4.0-74-generic
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted
Restarting VM to apply changes...
==> default: Attempting graceful shutdown of VM...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /var/www/html => /Users/XXXXX/ubuntu/html
以上で解決できました。
article【早見表】よく使うVagrantコマンドとオプションの一覧まとめ
articlevagrantで起動したVM内で立ち上げているDockerのVolume(MySQLデータ永続化)で書き込みエラーになる件の対処
article【解決方法】Vagrantで構築したUbuntu20.04へsynced_folder を設定した際に発生するマウントエラーの対処
article【設定方法】VagrantとVirtualBoxでUbuntu20.04の仮想環境をサクッと構築する手順
article【設定方法】VagrantとVirtualBoxでCentOS8の仮想環境をサクッと構築する手順
article【解決方法】Vagrantを起動した際に発生するumount: /mnt: not mounted.の対処について
articleReact クリーンアーキテクチャ実践:UI・アプリ・ドメイン・データの責務分離
articleWebLLM vs サーバー推論 徹底比較:レイテンシ・コスト・スケールの実測レポート
articleVitest モック技術比較:MSW / `vi.mock` / 手動スタブ — API テストの最適解はどれ?
articlePython ORMs 実力検証:SQLAlchemy vs Tortoise vs Beanie の選び方
articleVite で Web Worker / SharedWorker を TypeScript でバンドルする初期設定
articlePrisma Accelerate と PgBouncer を比較:サーバレス時代の接続戦略ベンチ
blogiPhone 17シリーズの発表!全モデルiPhone 16から進化したポイントを見やすく整理
blogGoogleストアから訂正案内!Pixel 10ポイント有効期限「1年」表示は誤りだった
blog【2025年8月】Googleストア「ストアポイント」は1年表記はミス?2年ルールとの整合性を検証
blogGoogleストアの注文キャンセルはなぜ起きる?Pixel 10購入前に知るべき注意点
blogPixcel 10シリーズの発表!全モデル Pixcel 9 から進化したポイントを見やすく整理
blogフロントエンドエンジニアの成長戦略:コーチングで最速スキルアップする方法
review今の自分に満足していますか?『持たざる者の逆襲 まだ何者でもない君へ』溝口勇児
reviewついに語られた業界の裏側!『フジテレビの正体』堀江貴文が描くテレビ局の本当の姿
review愛する勇気を持てば人生が変わる!『幸せになる勇気』岸見一郎・古賀史健のアドラー実践編で真の幸福を手に入れる
review週末を変えれば年収も変わる!『世界の一流は「休日」に何をしているのか』越川慎司の一流週末メソッド
review新しい自分に会いに行こう!『自分の変え方』村岡大樹の認知科学コーチングで人生リセット
review科学革命から AI 時代へ!『サピエンス全史 下巻』ユヴァル・ノア・ハラリが予見する人類の未来