🗳️

macOS Montereyでvagrant upに失敗する

4 min read

  • TCP/IPの本で環境構築をVagrant/Virtualboxで行っていたのでmacOS Montereyで行ったところ、失敗したのでメモを残しておく

事象

環境

  • VagrantもVirtualboxもhomebrewでインストールしたものになります
$ sw_vers
ProductName:	macOS
ProductVersion:	12.0.1
BuildVersion:	21A559

$ vagrant -v
Vagrant 2.2.18

$ brew -v
Homebrew 3.3.2-33-gcb32066
Homebrew/homebrew-core (git revision 1e9d510578e; last commit 2021-11-03)
Homebrew/homebrew-cask (git revision d5198633bb; last commit 2021-11-03)

エラー内容

  • Vagrantfileが作成されている状態で、vagrant upを実行すると以下のようなエラーになり仮想マシンが起動しませんでした
$ vagrant init ubuntu/focal64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

$ ls
Vagrantfile

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/focal64' version '20211026.0.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: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "3e336932-d167-496b-83ed-537b6fa52468", "--type", "headless"]

Stderr: VBoxManage: error: The virtual machine 'ubuntu2004_default_1635924448821_54833' has terminated unexpectedly during startup because of signal 10
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine

試したこと

  • 検索したところ、近い例として”Oracleのソフトウェアの実行許可を出す必要がある”というものがあったが、こちらはHomebrewでインストールする際にクリアしていたので、今回の事象の原因ではなかった

https://qiita.com/akane_kato/items/c103332729e3d0ac39e6

解決方法

Vagrantfileを編集

  • 起動に使用するVagrantfile内のconfig.vm.providerの設定ブロックでvb.guiをtrueにする
# `config.vm.provider` のブロックと`vb.gui=true`のコメントアウトを外す
$ vim Vagrantfile
config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true

    # Customize the amount of memory on the VM:
    # vb.memory = "1024"
end

結果

  • GUIをtrueにしたためか)GUIが起動して、vagrant upのコマンドが無事完了する

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/focal64' version '20211026.0.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: Forwarding ports...
    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:
    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: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => ...

$ vagrant status
Current machine states:

default                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

原因

  • Vagrantにそれらしいissueがあった
  • headlessモードに問題があるみたいなので、これを回避する手段がGUIでの起動みたい

https://github.com/hashicorp/vagrant/issues/12557

参考

https://apple.stackexchange.com/questions/429609/running-vagrant-via-vagrant-up-on-macos-monterey-12-0-1-fails

Discussion

ログインするとコメントできます