3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vagrant upが遅いときの対処法

Posted at

Vagrantが遅い!

ある日のこと。いつも通りvagrant upやらvagrant haltをしていたら、動作が非常に重くなりました。
最初のvagrant upは素早くささっと片づけてくれるのですが、そのあとのhaltやupが非常に遅い。
インストールしたソフトが重いのかとCPUのコア数を増やしたりメモリの割り当て量を増やしてみましたが何も解決しませんでした。

vagrant upするとマウントするところでこのようなエラーが出ます。VMの起動は出来ています。

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

The error output from the last command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

VMは起動しているのでvagrant sshでログインすることはできます。

環境

Windows 10 + VirtualBox + Vagrant + Centos 7.2

dns lookupを止める

sshdのUseDNSがyesになっていると名前解決を繰り返してしまい、それが遅くなる原因のようです。

vi /etc/ssh/sshd_config
sshd_config
UseDNS no

sshdの設定を無効化して再起動します。
期待を込めて星5つにしたのですが、何も変わりませんでした……。まだ他に悪さをしているところがある模様。

VBoxAddのリビルド

このホストOSのディレクトリをマウントする機能はVirtualBoxの機能らしい。マウントに失敗するとこれが壊れてしまう。なのでvboxのセットアップをやり直せばいいと。なるほど。

# /opt/VBoxGuestAdditions-5.0.20/init/vboxadd setup
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module                   [  OK  ]
Building the shared folder support module                  [  OK  ]
Building the graphics driver module                        [  OK  ]
Doing non-kernel setup of the Guest Additions              [  OK  ]
Starting the VirtualBox Guest Additions Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.
/usr/bin/VBoxClient: error while loading shared libraries: libX11.so.6: cannot open shared object file: No such file or directory
                                                           [  OK  ]

一旦ログアウトしてvagrant halt、vagrant upをします。

$ vagrant up                                                                                        
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> 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) => 2200 (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:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => E:/test_vm
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

無事に起動しました。エラーも謎の遅さもありません。

3
6
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
3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?