✌🏻

VagarntでUbuntu 20.04のboxを起動すると、「SSH auth method: private key」でスタックする

2022/11/05に公開

VagarntでUbuntu 20.04のboxが起動できずに嵌ったので、メモとして記録しておきます。

確認したバージョンは下記になります。OSはWindows 10です。

  • VirtulBox : 6.1.40
  • Vagrant : 2.3.2

現象

Ubuntu 20.04のboxをvagrant upで起動すると、「SSH auth method: private key」が表示されたところで止まります。

F:\vagrant\ubuntu>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/focal64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/focal64' version '20221102.0.0' is up to date...
==> default: A newer version of the box 'ubuntu/focal64' for provider 'virtualbox' is
==> default: available! You currently have version '20221102.0.0'. The latest is version
==> default: '20221103.0.0'. Run `vagrant box update` to update.
==> default: Setting the name of the VM: ubuntu_default_1667637688808_65999
==> 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

そして、一定時間超えると、タイムアウトするような形になります。

Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

F:\vagrant\ubuntu>

Ubuntu 20.04となる下記の2つのboxで試しましたが、どちらも同じ現象でした。

他のbox(CentOS 7.9のboxを試した)ところ、問題無く起動できました。

原因

VagrantのIssueとしてあがっていました。
VirtualMachinePlatformが有効(Enabled)になっていると、このような現象が発生します。(WSL2使っていたら有効にしているはず)

VirtualMachinePlatformが有効になっているかどうかは、PowerShellから下記のコマンドで確認できます。

Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

StateがEnabledになっていれば有効です。

PS C:\WINDOWS\system32> Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

FeatureName      : VirtualMachinePlatform
DisplayName      : 仮想マシン プラットフォーム
Description      : 仮想マシンのプラットフォーム サポートを有効にします
RestartRequired  : Possible
State            : Enabled
CustomProperties :

対応方法

VirtualMachinePlatformを無効にすれば回避できます。

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -All

もう一つ方法として、VirtualBoxのGUIで該当VMを選択するといった方法があります。
こうすると、なぜかスタックせずに起動することができます。(スタックした後に選択する形でOK)

VirtualMachinePlatformの無効/有効を切り替えるのは面倒なので、とりあえず問題が解消されるまでは、VirtualBoxのGUIで選択することで回避していこうと思います。

Discussion