LoginSignup
39
26

More than 5 years have passed since last update.

Vagrantの起動時に発生するUID競合を修正してみた

Posted at

概要

Vagrantを使用して仮想マシンを起動していると、稀にVMの作成ユーザのID(UID)が競合してしまい、起動できない事があります。

作成したVMを壊して(vagrant destroy)、再作成(vagrant up)すると起動できるようになりますが一から構成し直すのは面倒です。
そこで、競合しているUIDを修正してみました。

症状

仮想マシンを起動すると、以下のようなエラーが発生します。

$ vagrant up
The VirtualBox VM was created with a user that doesn't match the
current user running Vagrant. VirtualBox requires that the same user
be used to manage the VM that was created. Please re-run Vagrant with
that user. This is not a Vagrant issue.

The UID used to create the VM was: 0
Your UID is: 1001

仮想マシンが認識しているユーザはUID:0なのですが、実際の現在のUIDはUID:1001となっています。
そのため、競合が発生しています。

対応

Vagrantの構成情報でVMを作成したUIDを保有しているファイルを修正します。
対象は以下のファイルです。

  • /.vagrant/machines/default/virtualbox/creator_uid

creator_uidを開くと以下のようにVagrantが認識しているUIDが記載されています。

0

このファイルを以下のように現在のUIDに変更します。

1001

結果

creator_uidファイルを修正した後に仮想マシンを起動(vagrant up)します。
すると以下のように、エラーなく仮想マシンの起動が始まります。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> 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: 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
39
26
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
39
26