1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ruby on Rails | Apple SiliconでVagrantを使うときにハマったエラーと解決メモ

Posted at

はじめに

現在、独習Ruby on Railsで勉強しており、MacBook Air M1 で Vagrant + VirtualBox を使おうとして盛大にハマったので、エラー→原因→解決までのトライ&エラーを備忘録としてまとめます。環境依存の落とし穴が多いので、同じ症状で詰まっている人の参考になれば嬉しいです。

目次

  1. 背景とゴール
  2. 検証環境
  3. エラー① NS_ERROR_FAILURE (0x80004005)
  4. エラー② Box 404(generic/ubuntu2204-arm64)
  5. エラー③ SSH Connection reset / disconnect
  6. 最終的な解決策と Vagrantfile
  7. まとめ
  8. 参考リンク

1. 背景とゴール

• Apple Silicon(arm64)上で Ubuntu 22.04 LTS の開発用 VM を立てたい。
• なるべく 無料 で完結したいので、VirtualBox + Vagrant が第一候補。
• 最終的に高速・安定に動く環境が作れれば OK。


2. 検証環境

項目 バージョン
macOS Sonoma 14.5
チップ Apple M1
Vagrant 2.4.1
VirtualBox 7.0.18
Homebrew QEMU 10.0.2

3. エラー① NS_ERROR_FAILURE (0x80004005)

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/xenial64'...
...
VBoxManage: error: The VM session was aborted
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005)

原因
• VirtualBox は Apple Silicon で ARM64 ゲストを正式サポートしていない。
• 公式 ubuntu/xenial64 など x86_64 Box は起動時にクラッシュする。

対応案 (却下)
• Parallels / VMware に乗り換える → 有償ライセンス必須。
• QEMU プラグイン に切り替える → 無料 & ARM ネイティブで動作 ← 今回採用。


4. エラー② Box 404(generic/ubuntu2204-arm64)

$ vagrant up --provider=qemu
Box 'generic/ubuntu2204-arm64' could not be found (... Error 404)

原因
• generic/ubuntu2204-arm64 は libvirt/qemu プロバイダ用メタデータが無いか、公開停止中。

解決
• 代替 Box として perk/ubuntu-2204-arm64 を使用。

$ vagrant init perk/ubuntu-2204-arm64
$ vagrant up --provider=qemu

5. エラー③ SSH Connection reset / disconnect

Waiting for machine to boot...
SSH address: 127.0.0.1:50022
Warning: Connection reset. Retrying...

原因
• 初回ブートで cloud-init が数分かかる → SSH ポートが開く前にタイムアウト。

解決手順

  1. ブートタイムアウトを延長:

    config.vm.boot_timeout = 600  # 10 分待つ
    
  2. QEMU 高速化&リソース増量:

    config.vm.provider :qemu do |q|
      q.memory = 4096
      q.cpus   = 4
      q.accel  = "hvf"   # Apple Hypervisor Framework
    end
    
  3. vagrant up --provider=qemu を再実行 → Machine booted and ready!


6. 最終的な Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "perk/ubuntu-2204-arm64"
  config.vm.boot_timeout = 600

  # 共有フォルダ (9p)
  config.vm.synced_folder ".", "/home/vagrant/workspace", type: "9p"

  # QEMU 設定
  config.vm.provider :qemu do |q|
    q.memory = 4096
    q.cpus   = 4
    q.accel  = "hvf"   # Apple Silicon なら必ず入れる
  end
end

7. まとめ

エラー 原因 解決
NS_ERROR_FAILURE VirtualBox が ARM64 非対応 QEMU プラグインに乗換え
Box 404 Box メタデータ不足 perk/ubuntu-2204-arm64 など別 Box を使用
SSH タイムアウト cloud-init が遅い boot_timeout 延長 + hvf で高速化

Apple Silicon で無料ツールだけを使いたい場合、QEMU + ARM64 Box が最短ルートでした。共有フォルダは 9P、ポート転送は provider オプションで手動指定など、VirtualBox と比べて設定がやや多いものの、動き出してしまえば快適です。


8. 参考リンク

• vagrant-qemu – GitHub
• perk/ubuntu-2204-arm64 – Vagrant Cloud
• 公式ドキュメント: Using Vagrant with QEMU

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?