LoginSignup
4
1

More than 3 years have passed since last update.

How to accelerate booting ubuntu VirtualBox image on vagrant

Posted at

課題

vagrantのvirtualboxの公開ボックス・イメージ:ubuntu/focal64を起動に時間がかかる(分単位での待ちが必要)。
これは、なぜか必ず、ubuntu/focal64の起動中に1回のPanicが発生することが原因。

MacPro 13-inch, 2016 2G dualでの時間測定の起動ログはこちら。

$ vagrant init ubuntu/focal64
$ date;vagrant up;date
2020年 5月30日 土曜日 17時43分27秒 JST
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 '20200528.0.0' is up to date...
==> default: Setting the name of the VM: \qiita_default_1590826964884_8511
==> 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: 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
ここで、5分弱の待ち。
==> default: Machine booted and ready!
...
==> default: flag to force provisioning. Provisioners marked to run always will still run.
2020年 5月30日 土曜日 17時48分00秒 JST


ubuntu/bionic64では、未発生。
ちょっと、使えないなーと思っていた矢先、Web上に解決方法があったので、メモしておく。

解決策

解決策は、launchpadのバグの説明箇所に記載あり。
どうやら、ubuntu/focal64の起動オプションとして、ttyS0が有効となっていることが原因らしい。
コメントを参考に、Vagrantfileに以下の行を追加。

  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
    vb.customize ["modifyvm", :id, "--uartmode1", "file", File::NULL]
  end

効果

5分弱→1分弱。
大幅な改善。
起動のPanicなし。

以下、課題と同じ環境での起動ログ。

$ date;vagrant up;date
2020年 5月30日 土曜日 17時51分16秒 JST
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/focal64' version '20200528.0.0' is up to date...
==> 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: 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: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
default: /vagrant => /Users/hogehoge/vagrant/qiita
==> default: Machine already provisioned. Run vagrant provision or use the --provision
==> default: flag to force provisioning. Provisioners marked to run always will still run.
2020年 5月30日 土曜日 17時51分57秒 JST
$


4
1
1

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
4
1